9 "github.com/dragonfireclient/mt/rudp"
12 type ToCltCmd interface {
17 //go:generate ./cmdno.sh tocltcmds ToClt toClt uint16 Cmd newToCltCmd
19 // ToCltHello is sent as a response to ToSrvInit.
20 // The client responds to ToCltHello by authenticating.
21 type ToCltHello struct {
23 Compression CompressionModes
29 // ToCltAcceptAuth is sent after the client successfully authenticates.
30 // The client responds to ToCltAcceptAuth with ToSrvInit2.
31 type ToCltAcceptAuth struct {
32 // The client does the equivalent of
34 // before using PlayerPos.
39 SudoAuthMethods AuthMethods
42 type ToCltAcceptSudoMode struct {
43 SudoAuthMethods AuthMethods
47 type ToCltDenySudoMode struct{}
49 // ToCltKick tells that the client that it has been kicked by the server.
50 type ToCltKick struct {
52 //mt:assert %s.Reason < maxKickReason
54 //mt:if dr := %s.Reason; dr == Custom || dr == Shutdown || dr == Crash
58 //mt:if dr := %s.Reason; dr == Shutdown || dr == Crash
63 // A KickReason is the reason a ToCltKick has been sent.
67 WrongPasswd KickReason = iota
83 func (cmd ToCltKick) String() (msg string) {
86 return "wrong password"
88 return "unexpected data"
89 case SrvIsSingleplayer:
90 return "server is singleplayer"
92 return "unsupported client version"
94 return "disallowed character(s) in player name"
96 return "disallowed player name"
98 return "too many clients"
100 return "empty password"
101 case AlreadyConnected:
102 return "another client is already connected with the same name"
104 return "server error"
108 msg = "server shutdown"
112 msg = fmt.Sprintf("KickReason(%d)", cmd.Reason)
115 if cmd.Custom != "" {
116 msg += ": " + cmd.Custom
122 // ToCltBlkData tells the client the contents of a nearby MapBlk.
123 type ToCltBlkData struct {
130 // ToCltAddNode tells the client that a nearby node changed
131 // to something other than air.
132 type ToCltAddNode struct {
138 // ToCltRemoveNode tells the client that a nearby node changed to air.
139 type ToCltRemoveNode struct {
143 // ToCltInv updates the client's inventory.
144 type ToCltInv struct {
149 // ToCltTimeOfDay updates the client's in-game time of day.
150 type ToCltTimeOfDay struct {
151 Time uint16 // %24000
152 Speed float32 // Speed times faster than real time
155 // ToCltCSMRestrictionFlags tells the client how use of CSMs should be restricted.
156 type ToCltCSMRestrictionFlags struct {
157 Flags CSMRestrictionFlags
159 // MapRange is the maximum distance from the player CSMs can read the map
160 // if Flags&LimitMapRange != 0.
164 type CSMRestrictionFlags uint64
167 NoCSMs CSMRestrictionFlags = 1 << iota
175 // ToCltAddPlayerVel tells the client to add Vel to the player's velocity.
176 type ToCltAddPlayerVel struct {
180 // ToCltMediaPush is sent when a media file is dynamically added.
181 type ToCltMediaPush struct {
188 // ToCltChatMsg tells the client that is has received a chat message.
189 type ToCltChatMsg struct {
197 Timestamp int64 // Unix time.
200 type ChatMsgType uint8
203 RawMsg ChatMsgType = iota // raw
205 AnnounceMsg // announce
210 //go:generate stringer -linecomment -type ChatMsgType
212 // ToCltAORmAdd tells the client that AOs have been removed from and/or added to
213 // the AOs that it can see.
214 type ToCltAORmAdd struct {
221 //mt:const genericCAO
227 // ToCltAOMsgs updates the client about nearby AOs.
228 type ToCltAOMsgs struct {
233 // ToCltHP updates the player's HP on the client.
234 type ToCltHP struct {
238 // ToCltMovePlayer tells the client that the player has been moved server-side.
239 type ToCltMovePlayer struct {
244 type ToCltLegacyKick struct {
249 // ToCltFOV tells the client to change its FOV.
250 type ToCltFOV struct {
253 TransitionTime float32
256 // ToCltDeathScreen tells the client to show the death screen.
257 type ToCltDeathScreen struct {
262 // ToCltMedia responds to a ToSrvMedia packet with the requested media files.
263 type ToCltMedia struct {
264 // N is the total number of ToCltMedia packets.
265 // I is the index of this packet.
277 // ToCltNodeDefs tells the client the definitions of nodes.
278 type ToCltNodeDefs struct {
285 // See (de)serialize.fmt.
292 // ToCltAnnounceMedia tells the client what media is available on request.
293 // See ToSrvReqMedia.
294 type ToCltAnnounceMedia struct {
302 // ToCltItemDefs tells the client the definitions of items.
303 type ToCltItemDefs struct {
310 Aliases []struct{ Alias, Orig string }
316 // ToCltPlaySound tells the client to play a sound.
317 type ToCltPlaySound struct {
330 // ToCltStopSound tells the client to stop playing a sound.
331 type ToCltStopSound struct {
335 // ToCltPrivs tells the client its privs.
336 type ToCltPrivs struct {
340 // ToCltInvFormspec tells the client its inventory formspec.
341 type ToCltInvFormspec struct {
346 // ToCltDetachedInv updates a detached inventory on the client.
347 type ToCltDetachedInv struct {
350 Len uint16 // deprecated
356 // ToCltShowFormspec tells the client to show a formspec.
357 type ToCltShowFormspec struct {
364 // ToCltMovement tells the client how to move.
365 type ToCltMovement struct {
366 DefaultAccel, AirAccel, FastAccel,
367 WalkSpeed, CrouchSpeed, FastSpeed, ClimbSpeed, JumpSpeed,
368 Fluidity, Smoothing, Sink, // liquids
372 // ToCltSpawnParticle tells the client to spawn a particle.
373 type ToCltSpawnParticle struct {
374 Pos, Vel, Acc [3]float32
375 ExpirationTime float32 // in seconds.
392 type ParticleSpawnerID uint32
394 // ToCltAddParticleSpawner tells the client to add a particle spawner.
395 type ToCltAddParticleSpawner struct {
398 Pos, Vel, Acc [2][3]float32
399 ExpirationTime [2]float32 // in seconds.
439 // ToCltHUDAdd tells the client to add a HUD.
440 type ToCltAddHUD struct {
448 ImgHUD HUDType = iota
456 //go:generate stringer -type HUDType
458 // ToCltRmHUD tells the client to remove a HUD.
459 type ToCltRmHUD struct {
463 // ToCltChangeHUD tells the client to change a field in a HUD.
464 type ToCltChangeHUD struct {
469 //mt:assert %s.Field < hudMax
471 //mt:if %s.Field == HUDPos
475 //mt:if %s.Field == HUDName
479 //mt:if %s.Field == HUDScale
483 //mt:if %s.Field == HUDText
487 //mt:if %s.Field == HUDNumber
491 //mt:if %s.Field == HUDItem
495 //mt:if %s.Field == HUDDir
499 //mt:if %s.Field == HUDAlign
503 //mt:if %s.Field == HUDOffset
507 //mt:if %s.Field == HUDWorldPos
511 //mt:if %s.Field == HUDSize
515 //mt:if %s.Field == HUDZIndex
519 //mt:if %s.Field == HUDText2
523 //mt:if %s.Field == HUDStyle
531 HUDPos HUDField = iota
548 //go:generate stringer -trimprefix HUD -type HUDField
550 type HUDStyleFlags uint32
553 StyleBold HUDStyleFlags = 1 << iota
558 //go:generate stringer -trimprefix Style -type HUDStyleFlags
560 // ToCltHUDFlags tells the client to update its HUD flags.
561 type ToCltHUDFlags struct {
570 ShowHotbar HUDFlags = 1 << iota
579 // ToCltSetHotbarParam tells the client to set a hotbar parameter.
580 type ToCltSetHotbarParam struct {
583 //mt:if %s.Param == HotbarSize
584 //mt:const uint16(4) // Size of Size field.
588 //mt:if %s.Param != HotbarSize
593 type HotbarParam uint16
596 HotbarSize HotbarParam = 1 + iota
601 //go:generate stringer -trimprefix Hotbar -type HotbarParam
603 // ToCltBreath tells the client how much breath it has.
604 type ToCltBreath struct {
608 // ToCltSkyParams tells the client how to render the sky.
609 type ToCltSkyParams struct {
613 SunFogTint color.NRGBA
614 MoonFogTint color.NRGBA
617 //mt:if %s.Type == "skybox"
621 //mt:if %s.Type == "regular"
623 DawnSky, DawnHorizon,
624 NightSky, NightHorizon,
629 // ToCltOverrideDayNightRatio overrides the client's day-night ratio
630 type ToCltOverrideDayNightRatio struct {
635 // ToCltLocalPlayerAnim tells the client how to animate the player.
636 type ToCltLocalPlayerAnim struct {
637 Idle, Walk, Dig, WalkDig [2]int32
641 // ToCltEyeOffset tells the client where to position the camera
642 // relative to the player.
643 type ToCltEyeOffset struct {
647 // ToCltDelParticleSpawner tells the client to delete a particle spawner.
648 type ToCltDelParticleSpawner struct {
652 // ToCltCloudParams tells the client how to render the clouds.
653 type ToCltCloudParams struct {
655 DiffuseColor color.NRGBA
656 AmbientColor color.NRGBA
662 // ToCltFadeSound tells the client to fade a sound.
663 type ToCltFadeSound struct {
669 // ToCltUpdatePlayerList informs the client of players leaving or joining.
670 type ToCltUpdatePlayerList struct {
671 Type PlayerListUpdateType
675 type PlayerListUpdateType uint8
678 InitPlayers PlayerListUpdateType = iota // init
680 RemovePlayers // remove
683 //go:generate stringer -linecomment -type PlayerListUpdateType
685 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
686 type ToCltModChanMsg struct {
692 // ToCltModChanMsg tells the client it has received a signal on a mod channel.
693 type ToCltModChanSig struct {
698 type ModChanSig uint8
701 JoinOK ModChanSig = iota
709 //go:generate stringer -type ModChanSig
711 // ToCltModChanMsg is sent when node metadata near the client changes.
712 type ToCltNodeMetasChanged struct {
714 Changed map[[3]int16]*NodeMeta
718 // ToCltSunParams tells the client how to render the sun.
719 type ToCltSunParams struct {
728 // ToCltMoonParams tells the client how to render the moon.
729 type ToCltMoonParams struct {
736 // ToCltStarParams tells the client how to render the stars.
737 type ToCltStarParams struct {
744 type ToCltSRPBytesSaltB struct {
748 // ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
749 type ToCltFormspecPrepend struct {
753 // ToCltMinimapModes tells the client the set of available minimap modes.
754 type ToCltMinimapModes struct {
759 var _ serializer = (*ToCltMinimapModes)(nil)
761 func (cmd *ToCltMinimapModes) serialize(w io.Writer) {
762 buf := make([]byte, 4)
763 if len(cmd.Modes) > math.MaxUint16 {
766 be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
767 be.PutUint16(buf[2:4], cmd.Current)
768 _, err := w.Write(buf)
770 for i := range cmd.Modes {
771 chk(serialize(w, &cmd.Modes[i]))
775 var _ deserializer = (*ToCltMinimapModes)(nil)
777 func (cmd *ToCltMinimapModes) deserialize(r io.Reader) {
778 buf := make([]byte, 4)
779 _, err := io.ReadFull(r, buf)
781 cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
782 cmd.Current = be.Uint16(buf[2:4])
783 for i := range cmd.Modes {
784 chk(deserialize(r, &cmd.Modes[i]))
788 type ToCltDisco struct{}
790 func (*ToCltDisco) cmd() {}
791 func (*ToCltDisco) toCltCmdNo() uint16 { return 0xffff }
792 func (*ToCltDisco) DefaultPktInfo() rudp.PktInfo { return rudp.PktInfo{} }