11 type ToCltCmd interface {
16 //go:generate ./cmdno.sh tocltcmds ToClt toClt uint16 Cmd newToCltCmd
18 // ToCltHello is sent as a response to ToSrvInit.
19 // The client responds to ToCltHello by authenticating.
20 type ToCltHello struct {
22 Compression CompressionModes
28 // ToCltAcceptAuth is sent after the client successfully authenticates.
29 // The client responds to ToCltAcceptAuth with ToSrvInit2.
30 type ToCltAcceptAuth struct {
31 // The client does the equivalent of
33 // before using PlayerPos.
38 SudoAuthMethods AuthMethods
41 type ToCltAcceptSudoMode struct{}
43 type ToCltDenySudoMode struct{}
45 // ToCltDisco tells that the client that it has been disconnected by the server.
46 type ToCltDisco struct {
48 //mt:assert %s.Reason < maxDiscoReason
50 //mt:if dr := %s.Reason; dr == Custom || dr == Shutdown || dr == Crash
54 //mt:if dr := %s.Reason; dr == Shutdown || dr == Crash
59 type DiscoReason uint8
62 WrongPasswd DiscoReason = iota
78 func (cmd ToCltDisco) String() (msg string) {
81 return "wrong password"
83 return "unexpected data"
84 case SrvIsSingleplayer:
85 return "server is singleplayer"
87 return "unsupported client version"
89 return "disallowed character(s) in player name"
91 return "disallowed player name"
93 return "too many clients"
95 return "empty password"
96 case AlreadyConnected:
97 return "another client is already connected with the same name"
103 msg = "server shutdown"
107 msg = fmt.Sprintf("DiscoReason(%d)", cmd.Reason)
110 if cmd.Custom != "" {
111 msg += ": " + cmd.Custom
117 // ToCltBlkData tells the client the contents of a nearby MapBlk.
118 type ToCltBlkData struct {
123 // ToCltAddNode tells the client that a nearby node changed
124 // to something other than air.
125 type ToCltAddNode struct {
131 // ToCltRemoveNode tells the client that a nearby node changed to air.
132 type ToCltRemoveNode struct {
136 // ToCltInv updates the client's inventory.
137 type ToCltInv struct {
142 // ToCltTimeOfDay updates the client's in-game time of day.
143 type ToCltTimeOfDay struct {
144 Time uint16 // %24000
145 Speed float32 // Speed times faster than real time
148 // ToCltCSMRestrictionFlags tells the client how use of CSMs should be restricted.
149 type ToCltCSMRestrictionFlags struct {
150 Flags CSMRestrictionFlags
152 // MapRange is the maximum distance from the player CSMs can read the map
153 // if Flags&LimitMapRange != 0.
157 type CSMRestrictionFlags uint64
160 NoCSMs CSMRestrictionFlags = 1 << iota
168 // ToCltAddPlayerVel tells the client to add Vel to the player's velocity.
169 type ToCltAddPlayerVel struct {
173 // ToCltMediaPush is sent when a media file is dynamically added.
174 type ToCltMediaPush struct {
175 //mt:const uint16(sha1.Size)
184 // ToCltChatMsg tells the client that is has received a chat message.
185 type ToCltChatMsg struct {
193 Timestamp int64 // Unix time.
196 type ChatMsgType uint8
199 RawMsg ChatMsgType = iota // raw
201 AnnounceMsg // announce
206 //go:generate stringer -linecomment -type ChatMsgType
208 // ToCltAORmAdd tells the client that AOs have been removed from and/or added to
209 // the AOs that it can see.
210 type ToCltAORmAdd struct {
214 //mt:const genericCAO
221 // ToCltAOMsgs updates the client about nearby AOs.
222 type ToCltAOMsgs struct {
227 // ToCltHP updates the player's HP on the client.
228 type ToCltHP struct {
232 // ToCltMovePlayer tells the client that the player has been moved server-side.
233 type ToCltMovePlayer struct {
238 type ToCltDiscoLegacy struct {
243 // ToCltFOV tells the client to change its FOV.
244 type ToCltFOV struct {
247 TransitionTime float32
250 // ToCltDeathScreen tells the client to show the death screen.
251 type ToCltDeathScreen struct {
256 // ToCltMedia responds to a ToSrvMedia packet with the requested media files.
257 type ToCltMedia struct {
258 // N is the total number of ToCltMedia packets.
259 // I is the index of this packet.
271 // ToCltNodeDefs tells the client the definitions of nodes.
272 type ToCltNodeDefs struct {
279 // See (de)serialize.fmt.
286 // ToCltAnnounceMedia tells the client what media is available on request.
287 // See ToSrvReqMedia.
288 type ToCltAnnounceMedia struct {
296 // ToCltItemDefs tells the client the definitions of items.
297 type ToCltItemDefs struct {
304 Aliases []struct{ Alias, Orig string }
310 // ToCltPlaySound tells the client to play a sound.
311 type ToCltPlaySound struct {
324 // ToCltStopSound tells the client to stop playing a sound.
325 type ToCltStopSound struct {
329 // ToCltPrivs tells the client its privs.
330 type ToCltPrivs struct {
334 // ToCltInvFormspec tells the client its inventory formspec.
335 type ToCltInvFormspec struct {
340 // ToCltDetachedInv updates a detached inventory on the client.
341 type ToCltDetachedInv struct {
344 Len uint16 // deprecated
350 // ToCltShowFormspec tells the client to show a formspec.
351 type ToCltShowFormspec struct {
358 // ToCltMovement tells the client how to move.
359 type ToCltMovement struct {
360 DefaultAccel, AirAccel, FastAccel,
361 WalkSpeed, CrouchSpeed, FastSpeed, ClimbSpeed, JumpSpeed,
362 Fluidity, Smoothing, Sink, // liquids
366 // ToCltSpawnParticle tells the client to spawn a particle.
367 type ToCltSpawnParticle struct {
368 Pos, Vel, Acc [3]float32
369 ExpirationTime float32 // in seconds.
386 type ParticleSpawnerID uint32
388 // ToCltAddParticleSpawner tells the client to add a particle spawner.
389 type ToCltAddParticleSpawner struct {
392 Pos, Vel, Acc [2][3]float32
393 ExpirationTime [2]float32 // in seconds.
414 // ToCltHUDAdd tells the client to add a HUD.
415 type ToCltAddHUD struct {
438 ImgHUD HUDType = iota
446 //go:generate stringer -type HUDType
448 // ToCltRmHUD tells the client to remove a HUD.
449 type ToCltRmHUD struct {
453 // ToCltChangeHUD tells the client to change a field in a HUD.
454 type ToCltChangeHUD struct {
459 //mt:assert %s.Field < hudMax
461 //mt:if %s.Field == HUDPos
465 //mt:if %s.Field == HUDName
469 //mt:if %s.Field == HUDScale
473 //mt:if %s.Field == HUDText
477 //mt:if %s.Field == HUDNumber
481 //mt:if %s.Field == HUDItem
485 //mt:if %s.Field == HUDDir
489 //mt:if %s.Field == HUDAlign
493 //mt:if %s.Field == HUDOffset
497 //mt:if %s.Field == HUDWorldPos
501 //mt:if %s.Field == HUDSize
505 //mt:if %s.Field == HUDZIndex
509 //mt:if %s.Field == HUDText2
517 HUDPos HUDField = iota
533 //go:generate stringer -trimprefix HUD -type HUDField
535 // ToCltHUDFlags tells the client to update its HUD flags.
536 type ToCltHUDFlags struct {
545 ShowHotbar HUDFlags = 1 << iota
554 // ToCltSetHotbarParam tells the client to set a hotbar parameter.
555 type ToCltSetHotbarParam struct {
558 //mt:if %s.Param == HotbarSize
559 //mt:const uint16(4) // Size of Size field.
563 //mt:if %s.Param != HotbarSize
568 type HotbarParam uint16
571 HotbarSize HotbarParam = 1 + iota
576 //go:generate stringer -trimprefix Hotbar -type HotbarParam
578 // ToCltBreath tells the client how much breath it has.
579 type ToCltBreath struct {
583 // ToCltSkyParams tells the client how to render the sky.
584 type ToCltSkyParams struct {
588 SunFogTint color.NRGBA
589 MoonFogTint color.NRGBA
592 //mt:if %s.Type == "skybox"
596 //mt:if %s.Type == "regular"
598 DawnSky, DawnHorizon,
599 NightSky, NightHorizon,
604 // ToCltOverrideDayNightRatio overrides the client's day-night ratio
605 type ToCltOverrideDayNightRatio struct {
610 // ToCltLocalPlayerAnim tells the client how to animate the player.
611 type ToCltLocalPlayerAnim struct {
612 Idle, Walk, Dig, WalkDig [2]int32
616 // ToCltEyeOffset tells the client where to position the camera
617 // relative to the player.
618 type ToCltEyeOffset struct {
622 // ToCltDelParticleSpawner tells the client to delete a particle spawner.
623 type ToCltDelParticleSpawner struct {
627 // ToCltCloudParams tells the client how to render the clouds.
628 type ToCltCloudParams struct {
630 DiffuseColor color.NRGBA
631 AmbientColor color.NRGBA
637 // ToCltFadeSound tells the client to fade a sound.
638 type ToCltFadeSound struct {
644 // ToCltUpdatePlayerList informs the client of players leaving or joining.
645 type ToCltUpdatePlayerList struct {
646 Type PlayerListUpdateType
650 type PlayerListUpdateType uint8
653 InitPlayers PlayerListUpdateType = iota // init
655 RemovePlayers // remove
658 //go:generate stringer -linecomment -type PlayerListUpdateType
660 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
661 type ToCltModChanMsg struct {
667 // ToCltModChanMsg tells the client it has received a signal on a mod channel.
668 type ToCltModChanSig struct {
673 type ModChanSig uint8
676 JoinOK ModChanSig = iota
684 //go:generate stringer -type ModChanSig
686 // ToCltModChanMsg is sent when node metadata near the client changes.
687 type ToCltNodeMetasChanged struct {
689 Changed map[[3]int16]*NodeMeta
693 // ToCltSunParams tells the client how to render the sun.
694 type ToCltSunParams struct {
703 // ToCltMoonParams tells the client how to render the moon.
704 type ToCltMoonParams struct {
711 // ToCltStarParams tells the client how to render the stars.
712 type ToCltStarParams struct {
719 type ToCltSRPBytesSaltB struct {
723 // ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
724 type ToCltFormspecPrepend struct {
728 // ToCltMinimapModes tells the client the set of available minimap modes.
729 type ToCltMinimapModes struct {
734 func (cmd *ToCltMinimapModes) serialize(w io.Writer) error {
735 buf := make([]byte, 4)
736 if len(cmd.Modes) > math.MaxUint16 {
739 be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
740 be.PutUint16(buf[2:4], cmd.Current)
741 if _, err := w.Write(buf); err != nil {
744 for i := range cmd.Modes {
745 if err := serialize(w, &cmd.Modes[i]); err != nil {
752 func (cmd *ToCltMinimapModes) deserialize(r io.Reader) error {
753 buf := make([]byte, 4)
754 if _, err := io.ReadFull(r, buf); err != nil {
757 cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
758 cmd.Current = be.Uint16(buf[2:4])
759 for i := range cmd.Modes {
760 if err := deserialize(r, &cmd.Modes[i]); err != nil {