Skip to content

Commit 8811bc3

Browse files
committed
gateway fixes
1 parent e124208 commit 8811bc3

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

http/gateway/handler.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Handle(c *websocket.Conn) {
3939
err := c.ReadJSON(&msg)
4040
if err != nil {
4141
fmt.Println(err)
42-
//handleClose(&ws)
42+
handleClose(&ws)
4343
break
4444
}
4545

@@ -51,7 +51,7 @@ func Handle(c *websocket.Conn) {
5151
case OpEvent:
5252
handleEvent(&ws, &msg)
5353
case OpClose:
54-
//handleClose(&ws)
54+
handleClose(&ws)
5555
break
5656
}
5757
}
@@ -111,10 +111,22 @@ func handleHello(c *WebSocketConnection, d *AnyMessage) {
111111

112112
r.Players = append(r.Players, &p)
113113

114-
// TODO: check if room is elimination room and if it meets requirements for room start
115-
116-
// TODO: send room data to client
117114
fmt.Println(r)
115+
c.Send(AnyMessage{
116+
Op: OpEvent,
117+
T: HeartbeatEvent,
118+
Data: map[string]interface{}{
119+
"user": p,
120+
"users": r.Players,
121+
"objects": r.Map.Objects,
122+
"interval": PingInterval,
123+
"items": r.Items,
124+
"roomCreatedAt": r.CreatedAt,
125+
"state": r.State,
126+
"countdownStarted": r.CountdownStarted,
127+
},
128+
})
129+
// TODO: check if room is elimination room and if it meets requirements for room start
118130
}
119131

120132
func handleHeartbeat(c *WebSocketConnection, d *AnyMessage) {

http/gateway/types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const (
1717
ItemCollectEvent = "itemCollect"
1818
ItemUpdateEvent = "itemUpdate"
1919
StatsChangeEvent = "statsChange"
20+
HeartbeatEvent = "heartbeat"
2021

2122
// Kick types
2223
RoomFullKick = 0
@@ -28,6 +29,11 @@ const (
2829
WinKick = 6
2930
RoomEndKick = 7
3031
FlagLimitKick = 8
32+
33+
// Other
34+
// Clients send a ping every N milliseconds
35+
PingInterval = 3000
36+
PingIntervalLimit = 10000
3137
)
3238

3339
type AnyMessage struct {

models/gamemap/gamemap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type GameMapSize struct {
1414
}
1515

1616
type GameMapObject struct {
17-
NoNomAreas []GameMapNoNomArea `json:"noNomAreas"`
17+
NoNomAreas []GameMapNoNomArea `json:"noNomArea"`
1818
Walls []GameMapWall `json:"walls"`
1919
}
2020

public/js/game.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,14 @@ if (["Android", "iOS"].some(v => window.navigator.userAgent.includes(v))) {
145145
Blobpeek = "../assets/blobpeek.png",
146146
Blobnom = "../assets/blobnom.png"
147147
}
148+
enum BlobID {
149+
Blobowo,
150+
Blobevil,
151+
Blobeyes,
152+
Blobkittenknife,
153+
Blobpeek,
154+
Blobnom
155+
}
148156
enum ItemType {
149157
HEALTH = 0,
150158
COIN = 1
@@ -794,7 +802,7 @@ if (["Android", "iOS"].some(v => window.navigator.userAgent.includes(v))) {
794802

795803
// Own blob
796804
ownBlob.owner = eventData.user.username;
797-
ownBlob.blob = eventData.user.blob;
805+
ownBlob.blob = <BlobType>blobIDToString(eventData.user.blob);
798806
ownBlob.directionChangedAt = Date.now();
799807
ownBlob.directionChangeCoordinates.x = ownBlob.x = eventData.user.x;
800808
ownBlob.directionChangeCoordinates.y = ownBlob.y = eventData.user.y;
@@ -1559,6 +1567,28 @@ if (["Android", "iOS"].some(v => window.navigator.userAgent.includes(v))) {
15591567
wsc.onopen = (): any => wsc.send(data);
15601568
}
15611569
}
1570+
function blobIDToString(id: BlobID): string | null {
1571+
switch (id) {
1572+
case BlobID.Blobowo:
1573+
return BlobType.Blobowo;
1574+
break;
1575+
case BlobID.Blobevil:
1576+
return BlobType.Blobevil;
1577+
break;
1578+
case BlobID.Blobeyes:
1579+
return BlobType.Blobeyes;
1580+
break;
1581+
case BlobID.Blobkittenknife:
1582+
return BlobType.Blobkittenknife;
1583+
case BlobID.Blobpeek:
1584+
return BlobType.Blobpeek;
1585+
break;
1586+
case BlobID.Blobnom:
1587+
return BlobType.Blobnom;
1588+
default:
1589+
return null;
1590+
}
1591+
}
15621592

15631593

15641594

0 commit comments

Comments
 (0)