-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtocltcmds.go
778 lines (638 loc) · 14.6 KB
/
tocltcmds.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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
package mt
import (
"crypto/sha1"
"fmt"
"image/color"
"io"
"math"
"github.com/anon55555/mt/rudp"
)
type ToCltCmd interface {
Cmd
toCltCmdNo() uint16
}
//go:generate ./cmdno.sh tocltcmds ToClt toClt uint16 Cmd newToCltCmd
// ToCltHello is sent as a response to ToSrvInit.
// The client responds to ToCltHello by authenticating.
type ToCltHello struct {
SerializeVer uint8
Compression CompressionModes
ProtoVer uint16
AuthMethods
Username string
}
// ToCltAcceptAuth is sent after the client successfully authenticates.
// The client responds to ToCltAcceptAuth with ToSrvInit2.
type ToCltAcceptAuth struct {
// The client does the equivalent of
// PlayerPos[1] -= 5
// before using PlayerPos.
PlayerPos Pos
MapSeed uint64
SendInterval float32
SudoAuthMethods AuthMethods
}
type ToCltAcceptSudoMode struct {
SudoAuthMethods AuthMethods
//mt:const [15]byte{}
}
type ToCltDenySudoMode struct{}
// ToCltKick tells that the client that it has been kicked by the server.
type ToCltKick struct {
Reason KickReason
//mt:assert %s.Reason < maxKickReason
//mt:if dr := %s.Reason; dr == Custom || dr == Shutdown || dr == Crash
Custom string
//mt:end
//mt:if dr := %s.Reason; dr == Shutdown || dr == Crash
Reconnect bool
//mt:end
}
// A KickReason is the reason a ToCltKick has been sent.
type KickReason uint8
const (
WrongPasswd KickReason = iota
UnexpectedData
SrvIsSingleplayer
UnsupportedVer
BadNameChars
BadName
TooManyClts
EmptyPasswd
AlreadyConnected
SrvErr
Custom
Shutdown
Crash
maxKickReason
)
func (cmd ToCltKick) String() (msg string) {
switch cmd.Reason {
case WrongPasswd:
return "wrong password"
case UnexpectedData:
return "unexpected data"
case SrvIsSingleplayer:
return "server is singleplayer"
case UnsupportedVer:
return "unsupported client version"
case BadNameChars:
return "disallowed character(s) in player name"
case BadName:
return "disallowed player name"
case TooManyClts:
return "too many clients"
case EmptyPasswd:
return "empty password"
case AlreadyConnected:
return "another client is already connected with the same name"
case SrvErr:
return "server error"
case Custom:
return cmd.Custom
case Shutdown:
msg = "server shutdown"
case Crash:
msg = "server crash"
default:
msg = fmt.Sprintf("KickReason(%d)", cmd.Reason)
}
if cmd.Custom != "" {
msg += ": " + cmd.Custom
}
return
}
// ToCltBlkData tells the client the contents of a nearby MapBlk.
type ToCltBlkData struct {
Blkpos [3]int16
Blk MapBlk
}
// ToCltAddNode tells the client that a nearby node changed
// to something other than air.
type ToCltAddNode struct {
Pos [3]int16
Node
KeepMeta bool
}
// ToCltRemoveNode tells the client that a nearby node changed to air.
type ToCltRemoveNode struct {
Pos [3]int16
}
// ToCltInv updates the client's inventory.
type ToCltInv struct {
//mt:raw
Inv string
}
// ToCltTimeOfDay updates the client's in-game time of day.
type ToCltTimeOfDay struct {
Time uint16 // %24000
Speed float32 // Speed times faster than real time
}
// ToCltCSMRestrictionFlags tells the client how use of CSMs should be restricted.
type ToCltCSMRestrictionFlags struct {
Flags CSMRestrictionFlags
// MapRange is the maximum distance from the player CSMs can read the map
// if Flags&LimitMapRange != 0.
MapRange uint32
}
type CSMRestrictionFlags uint64
const (
NoCSMs CSMRestrictionFlags = 1 << iota
NoChatMsgs
NoItemDefs
NoNodeDefs
LimitMapRange
NoPlayerList
)
// ToCltAddPlayerVel tells the client to add Vel to the player's velocity.
type ToCltAddPlayerVel struct {
Vel Vec
}
// ToCltMediaPush is sent when a media file is dynamically added.
type ToCltMediaPush struct {
//mt:const uint16(sha1.Size)
SHA1 [sha1.Size]byte
Filename string
ShouldCache bool
//mt:len32
Data []byte
}
// ToCltChatMsg tells the client that is has received a chat message.
type ToCltChatMsg struct {
//mt:const uint8(1)
Type ChatMsgType
//mt:utf16
Sender, Text string
Timestamp int64 // Unix time.
}
type ChatMsgType uint8
const (
RawMsg ChatMsgType = iota // raw
NormalMsg // normal
AnnounceMsg // announce
SysMsg // sys
maxMsg
)
//go:generate stringer -linecomment -type ChatMsgType
// ToCltAORmAdd tells the client that AOs have been removed from and/or added to
// the AOs that it can see.
type ToCltAORmAdd struct {
Remove []AOID
Add []AOAdd
}
type AOAdd struct {
ID AOID
//mt:const genericCAO
//mt:lenhdr 32
InitData AOInitData
//mt:end
}
// ToCltAOMsgs updates the client about nearby AOs.
type ToCltAOMsgs struct {
//mt:raw
Msgs []IDAOMsg
}
// ToCltHP updates the player's HP on the client.
type ToCltHP struct {
HP uint16
}
// ToCltMovePlayer tells the client that the player has been moved server-side.
type ToCltMovePlayer struct {
Pos
Pitch, Yaw float32
}
type ToCltLegacyKick struct {
//mt:utf16
Reason string
}
// ToCltFOV tells the client to change its FOV.
type ToCltFOV struct {
FOV float32
Multiplier bool
TransitionTime float32
}
// ToCltDeathScreen tells the client to show the death screen.
type ToCltDeathScreen struct {
PointCam bool
PointAt Pos
}
// ToCltMedia responds to a ToSrvMedia packet with the requested media files.
type ToCltMedia struct {
// N is the total number of ToCltMedia packets.
// I is the index of this packet.
N, I uint16
//mt:len32
Files []struct {
Name string
//mt:len32
Data []byte
}
}
// ToCltNodeDefs tells the client the definitions of nodes.
type ToCltNodeDefs struct {
//mt:lenhdr 32
//mt:zlib
// Version.
//mt:const uint8(1)
// See (de)serialize.fmt.
Defs []NodeDef
//mt:end
//mt:end
}
// ToCltAnnounceMedia tells the client what media is available on request.
// See ToSrvReqMedia.
type ToCltAnnounceMedia struct {
Files []struct {
Name string
Base64SHA1 string
}
URL string
}
// ToCltItemDefs tells the client the definitions of items.
type ToCltItemDefs struct {
//mt:lenhdr 32
//mt:zlib
//mt:const uint8(0)
Defs []ItemDef
Aliases []struct{ Alias, Orig string }
//mt:end
//mt:end
}
// ToCltPlaySound tells the client to play a sound.
type ToCltPlaySound struct {
ID SoundID
Name string
Gain float32
SrcType SoundSrcType
Pos
SrcAOID AOID
Loop bool
Fade float32
Pitch float32
Ephemeral bool
}
// ToCltStopSound tells the client to stop playing a sound.
type ToCltStopSound struct {
ID SoundID
}
// ToCltPrivs tells the client its privs.
type ToCltPrivs struct {
Privs []string
}
// ToCltInvFormspec tells the client its inventory formspec.
type ToCltInvFormspec struct {
//mt:len32
Formspec string
}
// ToCltDetachedInv updates a detached inventory on the client.
type ToCltDetachedInv struct {
Name string
Keep bool
Len uint16 // deprecated
//mt:raw
Inv string
}
// ToCltShowFormspec tells the client to show a formspec.
type ToCltShowFormspec struct {
//mt:len32
Formspec string
Formname string
}
// ToCltMovement tells the client how to move.
type ToCltMovement struct {
DefaultAccel, AirAccel, FastAccel,
WalkSpeed, CrouchSpeed, FastSpeed, ClimbSpeed, JumpSpeed,
Fluidity, Smoothing, Sink, // liquids
Gravity float32
}
// ToCltSpawnParticle tells the client to spawn a particle.
type ToCltSpawnParticle struct {
Pos, Vel, Acc [3]float32
ExpirationTime float32 // in seconds.
Size float32
Collide bool
//mt:len32
Texture
Vertical bool
CollisionRm bool
AnimParams TileAnim
Glow uint8
AOCollision bool
NodeParam0 Content
NodeParam2 uint8
NodeTile uint8
}
type ParticleSpawnerID uint32
// ToCltAddParticleSpawner tells the client to add a particle spawner.
type ToCltAddParticleSpawner struct {
Amount uint16
Duration float32
Pos, Vel, Acc [2][3]float32
ExpirationTime [2]float32 // in seconds.
Size [2]float32
Collide bool
//mt:len32
Texture
ID ParticleSpawnerID
Vertical bool
CollisionRm bool
AttachedAOID AOID
AnimParams TileAnim
Glow uint8
AOCollision bool
NodeParam0 Content
NodeParam2 uint8
NodeTile uint8
}
type HUD struct {
Type HUDType
Pos [2]float32
Name string
Scale [2]float32
Text string
Number uint32
Item uint32
Dir uint32
Align [2]float32
Offset [2]float32
WorldPos Pos
Size [2]int32
ZIndex int16
Text2 string
}
type HUDID uint32
// ToCltHUDAdd tells the client to add a HUD.
type ToCltAddHUD struct {
ID HUDID
HUD
}
type HUDType uint8
const (
ImgHUD HUDType = iota
TextHUD
StatbarHUD
InvHUD
WaypointHUD
ImgWaypointHUD
)
//go:generate stringer -type HUDType
// ToCltRmHUD tells the client to remove a HUD.
type ToCltRmHUD struct {
ID HUDID
}
// ToCltChangeHUD tells the client to change a field in a HUD.
type ToCltChangeHUD struct {
ID HUDID
Field HUDField
//mt:assert %s.Field < hudMax
//mt:if %s.Field == HUDPos
Pos [2]float32
//mt:end
//mt:if %s.Field == HUDName
Name string
//mt:end
//mt:if %s.Field == HUDScale
Scale [2]float32
//mt:end
//mt:if %s.Field == HUDText
Text string
//mt:end
//mt:if %s.Field == HUDNumber
Number uint32
//mt:end
//mt:if %s.Field == HUDItem
Item uint32
//mt:end
//mt:if %s.Field == HUDDir
Dir uint32
//mt:end
//mt:if %s.Field == HUDAlign
Align [2]float32
//mt:end
//mt:if %s.Field == HUDOffset
Offset [2]float32
//mt:end
//mt:if %s.Field == HUDWorldPos
WorldPos Pos
//mt:end
//mt:if %s.Field == HUDSize
Size [2]int32
//mt:end
//mt:if %s.Field == HUDZIndex
ZIndex int32
//mt:end
//mt:if %s.Field == HUDText2
Text2 string
//mt:end
}
type HUDField uint8
const (
HUDPos HUDField = iota
HUDName
HUDScale
HUDText
HUDNumber
HUDItem
HUDDir
HUDAlign
HUDOffset
HUDWorldPos
HUDSize
HUDZIndex
HUDText2
hudMax
)
//go:generate stringer -trimprefix HUD -type HUDField
// ToCltHUDFlags tells the client to update its HUD flags.
type ToCltHUDFlags struct {
// &^= Mask
// |= Flags
Flags, Mask HUDFlags
}
type HUDFlags uint32
const (
ShowHotbar HUDFlags = 1 << iota
ShowHealthBar
ShowCrosshair
ShowWieldedItem
ShowBreathBar
ShowMinimap
ShowRadarMinimap
)
// ToCltSetHotbarParam tells the client to set a hotbar parameter.
type ToCltSetHotbarParam struct {
Param HotbarParam
//mt:if %s.Param == HotbarSize
//mt:const uint16(4) // Size of Size field.
Size int32
//mt:end
//mt:if %s.Param != HotbarSize
Img Texture
//mt:end
}
type HotbarParam uint16
const (
HotbarSize HotbarParam = 1 + iota
HotbarImg
HotbarSelImg
)
//go:generate stringer -trimprefix Hotbar -type HotbarParam
// ToCltBreath tells the client how much breath it has.
type ToCltBreath struct {
Breath uint16
}
// ToCltSkyParams tells the client how to render the sky.
type ToCltSkyParams struct {
BgColor color.NRGBA
Type string
Clouds bool
SunFogTint color.NRGBA
MoonFogTint color.NRGBA
FogTintType string
//mt:if %s.Type == "skybox"
Textures []Texture
//mt:end
//mt:if %s.Type == "regular"
DaySky, DayHorizon,
DawnSky, DawnHorizon,
NightSky, NightHorizon,
Indoor color.NRGBA
//mt:end
}
// ToCltOverrideDayNightRatio overrides the client's day-night ratio
type ToCltOverrideDayNightRatio struct {
Override bool
Ratio uint16
}
// ToCltLocalPlayerAnim tells the client how to animate the player.
type ToCltLocalPlayerAnim struct {
Idle, Walk, Dig, WalkDig [2]int32
Speed float32
}
// ToCltEyeOffset tells the client where to position the camera
// relative to the player.
type ToCltEyeOffset struct {
First, Third Vec
}
// ToCltDelParticleSpawner tells the client to delete a particle spawner.
type ToCltDelParticleSpawner struct {
ID ParticleSpawnerID
}
// ToCltCloudParams tells the client how to render the clouds.
type ToCltCloudParams struct {
Density float32
DiffuseColor color.NRGBA
AmbientColor color.NRGBA
Height float32
Thickness float32
Speed [2]float32
}
// ToCltFadeSound tells the client to fade a sound.
type ToCltFadeSound struct {
ID SoundID
Step float32
Gain float32
}
// ToCltUpdatePlayerList informs the client of players leaving or joining.
type ToCltUpdatePlayerList struct {
Type PlayerListUpdateType
Players []string
}
type PlayerListUpdateType uint8
const (
InitPlayers PlayerListUpdateType = iota // init
AddPlayers // add
RemovePlayers // remove
)
//go:generate stringer -linecomment -type PlayerListUpdateType
// ToCltModChanMsg tells the client it has been sent a message on a mod channel.
type ToCltModChanMsg struct {
Channel string
Sender string
Msg string
}
// ToCltModChanMsg tells the client it has received a signal on a mod channel.
type ToCltModChanSig struct {
Signal ModChanSig
Channel string
}
type ModChanSig uint8
const (
JoinOK ModChanSig = iota
JoinFail
LeaveOK
LeaveFail
NotRegistered
SetState
)
//go:generate stringer -type ModChanSig
// ToCltModChanMsg is sent when node metadata near the client changes.
type ToCltNodeMetasChanged struct {
//mt:lenhdr 32
Changed map[[3]int16]*NodeMeta
//mt:end
}
// ToCltSunParams tells the client how to render the sun.
type ToCltSunParams struct {
Visible bool
Texture
ToneMap Texture
Rise Texture
Rising bool
Size float32
}
// ToCltMoonParams tells the client how to render the moon.
type ToCltMoonParams struct {
Visible bool
Texture
ToneMap Texture
Size float32
}
// ToCltStarParams tells the client how to render the stars.
type ToCltStarParams struct {
Visible bool
Count uint32
Color color.NRGBA
Size float32
}
type ToCltSRPBytesSaltB struct {
Salt, B []byte
}
// ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
type ToCltFormspecPrepend struct {
Prepend string
}
// ToCltMinimapModes tells the client the set of available minimap modes.
type ToCltMinimapModes struct {
Current uint16
Modes []MinimapMode
}
var _ serializer = (*ToCltMinimapModes)(nil)
func (cmd *ToCltMinimapModes) serialize(w io.Writer) {
buf := make([]byte, 4)
if len(cmd.Modes) > math.MaxUint16 {
chk(ErrTooLong)
}
be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
be.PutUint16(buf[2:4], cmd.Current)
_, err := w.Write(buf)
chk(err)
for i := range cmd.Modes {
chk(serialize(w, &cmd.Modes[i]))
}
}
var _ deserializer = (*ToCltMinimapModes)(nil)
func (cmd *ToCltMinimapModes) deserialize(r io.Reader) {
buf := make([]byte, 4)
_, err := io.ReadFull(r, buf)
chk(err)
cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
cmd.Current = be.Uint16(buf[2:4])
for i := range cmd.Modes {
chk(deserialize(r, &cmd.Modes[i]))
}
}
type ToCltDisco struct{}
func (*ToCltDisco) cmd() {}
func (*ToCltDisco) toCltCmdNo() uint16 { return 0xffff }
func (*ToCltDisco) DefaultPktInfo() rudp.PktInfo { return rudp.PktInfo{} }