-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsocket.go
64 lines (52 loc) · 1.06 KB
/
websocket.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
// Opcode distinguishes network actions from either the server or a client
type Opcode int
// Server-to-client packets
const (
OpPing Opcode = iota
OpMatchmaking
OpGameStart
OpGameEnd
OpRoundStart
OpRoundEnd
OpBoardUpdate
OpOpponentStatus
OpForceSubmit
)
// Client-to-server packets
const (
OpPong Opcode = iota
OpFindGame
OpSubmit
)
// Packet represents a websocket packet
type Packet[T any] struct {
Opcode Opcode `json:"op"`
Data T `json:"d,omitempty"`
}
type ParamsFindGame struct {
Username string `json:"username"`
Combi [5]Colour `json:"combi"`
}
type ParamsGameStart struct {
Opponent string `json:"opponent"`
}
type ParamsRoundStart struct {
RoundNum int `json:"roundNum"`
}
type BoardUpdate struct {
Board []GuessRow `json:"board"`
}
type ParamsSubmit struct {
Combi [5]Colour `json:"combi"`
}
type ParamsOpponentStatus struct {
Status [5]Colour `json:"status"`
}
type ParamsGameEnd struct {
Win *bool `json:"win"`
Error bool `json:"error"`
}
type ParamsForceSubmit struct {
Combi [5]Colour `json:"combi"`
}