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 {
240 // ToCltMovePlayer tells the client that the player has been moved server-side.
241 type ToCltMovePlayer struct {
246 type ToCltLegacyKick struct {
251 // ToCltFOV tells the client to change its FOV.
252 type ToCltFOV struct {
255 TransitionTime float32
258 // ToCltDeathScreen tells the client to show the death screen.
259 type ToCltDeathScreen struct {
264 // ToCltMedia responds to a ToSrvMedia packet with the requested media files.
265 type ToCltMedia struct {
266 // N is the total number of ToCltMedia packets.
267 // I is the index of this packet.
279 // ToCltNodeDefs tells the client the definitions of nodes.
280 type ToCltNodeDefs struct {
287 // See (de)serialize.fmt.
294 // ToCltAnnounceMedia tells the client what media is available on request.
295 // See ToSrvReqMedia.
296 type ToCltAnnounceMedia struct {
304 // ToCltItemDefs tells the client the definitions of items.
305 type ToCltItemDefs struct {
312 Aliases []struct{ Alias, Orig string }
318 // ToCltPlaySound tells the client to play a sound.
319 type ToCltPlaySound struct {
332 // ToCltStopSound tells the client to stop playing a sound.
333 type ToCltStopSound struct {
337 // ToCltPrivs tells the client its privs.
338 type ToCltPrivs struct {
342 // ToCltInvFormspec tells the client its inventory formspec.
343 type ToCltInvFormspec struct {
348 // ToCltDetachedInv updates a detached inventory on the client.
349 type ToCltDetachedInv struct {
352 Len uint16 // deprecated
358 // ToCltShowFormspec tells the client to show a formspec.
359 type ToCltShowFormspec struct {
366 // ToCltMovement tells the client how to move.
367 type ToCltMovement struct {
368 DefaultAccel, AirAccel, FastAccel,
369 WalkSpeed, CrouchSpeed, FastSpeed, ClimbSpeed, JumpSpeed,
370 Fluidity, Smoothing, Sink, // liquids
374 // ToCltSpawnParticle tells the client to spawn a particle.
375 type ToCltSpawnParticle struct {
376 Pos, Vel, Acc [3]float32
377 ExpirationTime float32 // in seconds.
394 type ParticleSpawnerID uint32
396 // ToCltAddParticleSpawner tells the client to add a particle spawner.
397 type ToCltAddParticleSpawner struct {
400 Pos, Vel, Acc [2][3]float32
401 ExpirationTime [2]float32 // in seconds.
441 // ToCltHUDAdd tells the client to add a HUD.
442 type ToCltAddHUD struct {
450 ImgHUD HUDType = iota
458 //go:generate stringer -type HUDType
460 // ToCltRmHUD tells the client to remove a HUD.
461 type ToCltRmHUD struct {
465 // ToCltChangeHUD tells the client to change a field in a HUD.
466 type ToCltChangeHUD struct {
471 //mt:assert %s.Field < hudMax
473 //mt:if %s.Field == HUDPos
477 //mt:if %s.Field == HUDName
481 //mt:if %s.Field == HUDScale
485 //mt:if %s.Field == HUDText
489 //mt:if %s.Field == HUDNumber
493 //mt:if %s.Field == HUDItem
497 //mt:if %s.Field == HUDDir
501 //mt:if %s.Field == HUDAlign
505 //mt:if %s.Field == HUDOffset
509 //mt:if %s.Field == HUDWorldPos
513 //mt:if %s.Field == HUDSize
517 //mt:if %s.Field == HUDZIndex
521 //mt:if %s.Field == HUDText2
525 //mt:if %s.Field == HUDStyle
533 HUDPos HUDField = iota
550 //go:generate stringer -trimprefix HUD -type HUDField
552 type HUDStyleFlags uint32
555 StyleBold HUDStyleFlags = 1 << iota
560 //go:generate stringer -trimprefix Style -type HUDStyleFlags
562 // ToCltHUDFlags tells the client to update its HUD flags.
563 type ToCltHUDFlags struct {
572 ShowHotbar HUDFlags = 1 << iota
581 // ToCltSetHotbarParam tells the client to set a hotbar parameter.
582 type ToCltSetHotbarParam struct {
585 //mt:if %s.Param == HotbarSize
586 //mt:const uint16(4) // Size of Size field.
590 //mt:if %s.Param != HotbarSize
595 type HotbarParam uint16
598 HotbarSize HotbarParam = 1 + iota
603 //go:generate stringer -trimprefix Hotbar -type HotbarParam
605 // ToCltBreath tells the client how much breath it has.
606 type ToCltBreath struct {
610 // ToCltSkyParams tells the client how to render the sky.
611 type ToCltSkyParams struct {
615 SunFogTint color.NRGBA
616 MoonFogTint color.NRGBA
619 //mt:if %s.Type == "skybox"
623 //mt:if %s.Type == "regular"
625 DawnSky, DawnHorizon,
626 NightSky, NightHorizon,
631 // ToCltOverrideDayNightRatio overrides the client's day-night ratio
632 type ToCltOverrideDayNightRatio struct {
637 // ToCltLocalPlayerAnim tells the client how to animate the player.
638 type ToCltLocalPlayerAnim struct {
639 Idle, Walk, Dig, WalkDig [2]int32
643 // ToCltEyeOffset tells the client where to position the camera
644 // relative to the player.
645 type ToCltEyeOffset struct {
649 // ToCltDelParticleSpawner tells the client to delete a particle spawner.
650 type ToCltDelParticleSpawner struct {
654 // ToCltCloudParams tells the client how to render the clouds.
655 type ToCltCloudParams struct {
657 DiffuseColor color.NRGBA
658 AmbientColor color.NRGBA
664 // ToCltFadeSound tells the client to fade a sound.
665 type ToCltFadeSound struct {
671 // ToCltUpdatePlayerList informs the client of players leaving or joining.
672 type ToCltUpdatePlayerList struct {
673 Type PlayerListUpdateType
677 type PlayerListUpdateType uint8
680 InitPlayers PlayerListUpdateType = iota // init
682 RemovePlayers // remove
685 //go:generate stringer -linecomment -type PlayerListUpdateType
687 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
688 type ToCltModChanMsg struct {
694 // ToCltModChanMsg tells the client it has received a signal on a mod channel.
695 type ToCltModChanSig struct {
700 type ModChanSig uint8
703 JoinOK ModChanSig = iota
711 //go:generate stringer -type ModChanSig
713 // ToCltModChanMsg is sent when node metadata near the client changes.
714 type ToCltNodeMetasChanged struct {
716 Changed map[[3]int16]*NodeMeta
720 // ToCltSunParams tells the client how to render the sun.
721 type ToCltSunParams struct {
730 // ToCltMoonParams tells the client how to render the moon.
731 type ToCltMoonParams struct {
738 // ToCltStarParams tells the client how to render the stars.
739 type ToCltStarParams struct {
746 type ToCltSRPBytesSaltB struct {
750 // ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
751 type ToCltFormspecPrepend struct {
755 // ToCltMinimapModes tells the client the set of available minimap modes.
756 type ToCltMinimapModes struct {
761 var _ serializer = (*ToCltMinimapModes)(nil)
763 func (cmd *ToCltMinimapModes) Serialize(w io.Writer) {
764 buf := make([]byte, 4)
765 if len(cmd.Modes) > math.MaxUint16 {
768 be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
769 be.PutUint16(buf[2:4], cmd.Current)
770 _, err := w.Write(buf)
772 for i := range cmd.Modes {
773 chk(serialize(w, &cmd.Modes[i]))
777 var _ deserializer = (*ToCltMinimapModes)(nil)
779 func (cmd *ToCltMinimapModes) Deserialize(r io.Reader) {
780 buf := make([]byte, 4)
781 _, err := io.ReadFull(r, buf)
783 cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
784 cmd.Current = be.Uint16(buf[2:4])
785 for i := range cmd.Modes {
786 chk(deserialize(r, &cmd.Modes[i]))
790 type ToCltDisco struct{}
792 func (*ToCltDisco) cmd() {}
793 func (*ToCltDisco) toCltCmdNo() uint16 { return 0xffff }
794 func (*ToCltDisco) DefaultPktInfo() rudp.PktInfo { return rudp.PktInfo{} }