This repository has been archived by the owner on Sep 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
357 lines (296 loc) · 7.92 KB
/
message.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package main
import (
"encoding/json"
_ "github.com/CuteReimu/bingo-server/myws"
"github.com/davyxu/cellnet"
"github.com/davyxu/cellnet/codec"
"github.com/davyxu/cellnet/msglog"
"github.com/davyxu/cellnet/util"
"github.com/ozgio/strutil"
"reflect"
"strings"
)
//go:generate protoc --proto_path=. --go_out=. data.proto
type MessageHandler interface {
Handle(s *bingoServer, session cellnet.Session, token, protoName string) error
}
func init() {
msglog.SetCurrMsgLogMode(msglog.MsgLogMode_BlackList)
c := codec.MustGetCodec("json")
initMessage(c, (*LoginCs)(nil))
initMessage(c, (*ErrorSc)(nil))
initMessage(c, (*RoomInfoSc)(nil))
initMessage(c, (*HeartCs)(nil))
initMessage(c, (*HeartSc)(nil))
initMessage(c, (*CreateRoomCs)(nil))
initMessage(c, (*JoinRoomCs)(nil))
initMessage(c, (*LeaveRoomCs)(nil))
initMessage(c, (*UpdateRoomTypeCs)(nil))
initMessage(c, (*UpdateNameCs)(nil))
initMessage(c, (*StartGameCs)(nil))
initMessage(c, (*SpellListSc)(nil))
initMessage(c, (*GetSpellsCs)(nil))
initMessage(c, (*StopGameCs)(nil))
initMessage(c, (*UpdateSpellCs)(nil))
initMessage(c, (*UpdateSpellSc)(nil))
initMessage(c, (*ResetRoomCs)(nil))
initMessage(c, (*ChangeCardCountCs)(nil))
initMessage(c, (*PauseCs)(nil))
initMessage(c, (*PauseSc)(nil))
initMessage(c, (*NextRoundCs)(nil))
initMessage(c, (*NextRoundSc)(nil))
initMessage(c, (*LinkTimeCs)(nil))
initMessage(c, (*LinkDataSc)(nil))
initMessage(c, (*SetPhaseCs)(nil))
initMessage(c, (*SetPhaseSc)(nil))
initMessage(c, (*SitDownCs)(nil))
initMessage(c, (*StandUpCs)(nil))
}
func initMessage(c cellnet.Codec, i any) {
t := reflect.TypeOf(i).Elem()
name := strings.Replace(t.Name(), "Msg", "", 1)
name = strutil.ToSnakeCase(strings.Join(strutil.SplitCamelCase(name), " "))
meta := &cellnet.MessageMeta{
Codec: c,
Type: t,
ID: int(util.StringHash(name)),
}
meta.SetContext("name", name)
cellnet.RegisterMessageMeta(meta)
if name == "heart_sc" || name == "heart_cs" {
if err := msglog.SetMsgLogRule(meta.FullName(), msglog.MsgLogRule_BlackList); err != nil {
panic(err)
}
}
}
type LoginCs struct {
Token string `json:"token"`
}
func (m *LoginCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type ErrorSc struct {
Code int `json:"code"`
Msg string `json:"msg"`
}
func (m *ErrorSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type RoomInfoSc struct {
RoomId string `json:"rid,omitempty"`
Type int32 `json:"type,omitempty"`
HostName string `json:"host,omitempty"`
PlayerNames []string `json:"names,omitempty"`
ChangeCardCount []uint32 `json:"change_card_count,omitempty"`
Started bool `json:"started,omitempty"`
Score []uint32 `json:"score,omitempty"`
Winner int32 `json:"winner,omitempty"`
Watchers []string `json:"watchers,omitempty"`
}
func (m *RoomInfoSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type CreateRoomCs struct {
Name string `json:"name"`
RoomId string `json:"rid"`
Type int32 `json:"type"`
Solo bool `json:"solo"`
AddRobot bool `json:"add_robot"`
}
func (m *CreateRoomCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type JoinRoomCs struct {
Name string `json:"name"`
RoomId string `json:"rid"`
}
func (m *JoinRoomCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type LeaveRoomCs struct {
}
func (m *LeaveRoomCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type UpdateRoomTypeCs struct {
Type int32 `json:"type"`
}
func (m *UpdateRoomTypeCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type UpdateNameCs struct {
Name string `json:"name"`
}
func (m *UpdateNameCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type HeartCs struct {
}
func (m *HeartCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type HeartSc struct {
Time int64 `json:"time"`
}
func (m *HeartSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type StartGameCs struct {
GameTime uint32 `json:"game_time"` // 游戏总时间(不含倒计时),单位:分
Countdown uint32 `json:"countdown"` // 倒计时,单位:秒
Games []string `json:"games"`
Ranks []string `json:"ranks"`
NeedWin uint32 `json:"need_win"`
Difficulty int32 `json:"difficulty"`
EnableTools bool `json:"enable_tools"`
IsPrivate bool `json:"is_private"`
}
func (m *StartGameCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type SpellListSc struct {
Spells []*Spell `json:"spells"`
Time int64 `json:"time"`
StartTime int64 `json:"start_time"`
GameTime uint32 `json:"game_time"` // 游戏总时间(不含倒计时),单位:分
Countdown uint32 `json:"countdown"` // 倒计时,单位:秒
NeedWin uint32 `json:"need_win"`
WhoseTurn int32 `json:"whose_turn"`
BanPick int32 `json:"ban_pick"`
TotalPauseTime int64 `json:"total_pause_time"`
PauseBeginMs int64 `json:"pause_begin_ms"`
Status []int32 `json:"status,omitempty"`
Phase int32 `json:"phase"`
Link *LinkData `json:"link_data,omitempty"`
Difficulty int32 `json:"difficulty"`
EnableTools bool `json:"enable_tools"`
LastGetTime []int64 `json:"last_get_time"`
}
func (m *SpellListSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type GetSpellsCs struct {
}
func (m *GetSpellsCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type StopGameCs struct {
Winner int32 `json:"winner"`
}
func (m *StopGameCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type UpdateSpellCs struct {
Idx uint32 `json:"idx"`
Status SpellStatus `json:"status"`
}
func (m *UpdateSpellCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type UpdateSpellSc struct {
Idx uint32 `json:"idx"`
Status SpellStatus `json:"status"`
WhoseTurn int32 `json:"whose_turn"`
BanPick int32 `json:"ban_pick"`
}
func (m *UpdateSpellSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type ResetRoomCs struct {
}
func (m *ResetRoomCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type ChangeCardCountCs struct {
Counts []uint32 `json:"cnt"`
}
func (m *ChangeCardCountCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type PauseCs struct {
Pause bool `json:"pause"`
}
func (m *PauseCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type PauseSc struct {
Time int64 `json:"time"`
TotalPauseMs int64 `json:"total_pause_ms,omitempty"`
PauseBeginMs int64 `json:"pause_begin_ms,omitempty"`
}
func (m *PauseSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type NextRoundCs struct {
}
func (m *NextRoundCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type NextRoundSc struct {
WhoseTurn int32 `json:"whose_turn"`
BanPick int32 `json:"ban_pick"`
}
func (m *NextRoundSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type LinkTimeCs struct {
Whose int32 `json:"whose"`
Event int32 `json:"event"`
}
func (m *LinkTimeCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type LinkDataSc LinkData
func (m *LinkDataSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type SetPhaseCs struct {
Phase int32 `json:"phase"`
}
func (m *SetPhaseCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type SetPhaseSc struct {
Phase int32 `json:"phase"`
}
func (m *SetPhaseSc) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type SitDownCs struct {
}
func (m *SitDownCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}
type StandUpCs struct {
}
func (m *StandUpCs) String() string {
buf, _ := json.Marshal(m)
return string(buf)
}