1 //go:generate ./cmdno.sh tocltcmds ToClt toClt uint16 Cmd newToCltCmd
13 type ToCltCmd interface {
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
206 func (t ChatMsgType) String() string {
208 return fmt.Sprintf("ChatMsgType(%d)", t)
219 // ToCltAORmAdd tells the client that AOs have been removed from and/or added to
220 // the AOs that it can see.
221 type ToCltAORmAdd struct {
225 //mt:const genericCAO
232 // ToCltAOMsgs updates the client about nearby AOs.
233 type ToCltAOMsgs struct {
238 // ToCltHP updates the player's HP on the client.
239 type ToCltHP struct {
243 // ToCltMovePlayer tells the client that the player has been moved server-side.
244 type ToCltMovePlayer struct {
249 type ToCltDiscoLegacy struct {
254 // ToCltFOV tells the client to change its FOV.
255 type ToCltFOV struct {
258 TransitionTime float32
261 // ToCltDeathScreen tells the client to show the death screen.
262 type ToCltDeathScreen struct {
267 // ToCltMedia responds to a ToSrvMedia packet with the requested media files.
268 type ToCltMedia struct {
269 // N is the total number of ToCltMedia packets.
270 // I is the index of this packet.
282 // ToCltNodeDefs tells the client the definitions of nodes.
283 type ToCltNodeDefs struct {
290 // See (de)serialize.fmt.
297 // ToCltAnnounceMedia tells the client what media is available on request.
298 // See ToSrvReqMedia.
299 type ToCltAnnounceMedia struct {
307 // ToCltItemDefs tells the client the definitions of items.
308 type ToCltItemDefs struct {
315 Aliases []struct{ Alias, Orig string }
321 // ToCltPlaySound tells the client to play a sound.
322 type ToCltPlaySound struct {
335 // ToCltStopSound tells the client to stop playing a sound.
336 type ToCltStopSound struct {
340 // ToCltPrivs tells the client its privs.
341 type ToCltPrivs struct {
345 // ToCltInvFormspec tells the client its inventory formspec.
346 type ToCltInvFormspec struct {
351 // ToCltDetachedInv updates a detached inventory on the client.
352 type ToCltDetachedInv struct {
355 Len uint16 // deprecated
361 // ToCltShowFormspec tells the client to show a formspec.
362 type ToCltShowFormspec struct {
369 // ToCltMovement tells the client how to move.
370 type ToCltMovement struct {
371 DefaultAccel, AirAccel, FastAccel,
372 WalkSpeed, CrouchSpeed, FastSpeed, ClimbSpeed, JumpSpeed,
373 Fluidity, Smoothing, Sink, // liquids
377 // ToCltSpawnParticle tells the client to spawn a particle.
378 type ToCltSpawnParticle struct {
379 Pos, Vel, Acc [3]float32
380 ExpirationTime float32 // in seconds.
397 type ParticleSpawnerID uint32
399 // ToCltAddParticleSpawner tells the client to add a particle spawner.
400 type ToCltAddParticleSpawner struct {
403 Pos, Vel, Acc [2][3]float32
404 ExpirationTime [2]float32 // in seconds.
425 // ToCltHUDAdd tells the client to add a HUD.
426 type ToCltAddHUD struct {
449 ImgHUD HUDType = iota
457 // ToCltRmHUD tells the client to remove a HUD.
458 type ToCltRmHUD struct {
462 // ToCltChangeHUD tells the client to change a field in a HUD.
463 type ToCltChangeHUD struct {
468 //mt:assert %s.Field < hudMax
470 //mt:if %s.Field == HUDPos
474 //mt:if %s.Field == HUDName
478 //mt:if %s.Field == HUDScale
482 //mt:if %s.Field == HUDText
486 //mt:if %s.Field == HUDNumber
490 //mt:if %s.Field == HUDItem
494 //mt:if %s.Field == HUDDir
498 //mt:if %s.Field == HUDAlign
502 //mt:if %s.Field == HUDOffset
506 //mt:if %s.Field == HUDWorldPos
510 //mt:if %s.Field == HUDSize
514 //mt:if %s.Field == HUDZIndex
518 //mt:if %s.Field == HUDText2
526 HUDPos HUDField = iota
542 // ToCltHUDFlags tells the client to update its HUD flags.
543 type ToCltHUDFlags struct {
552 ShowHotbar HUDFlags = 1 << iota
561 // ToCltSetHotbarParam tells the client to set a hotbar parameter.
562 type ToCltSetHotbarParam struct {
565 //mt:if %s.Param == HotbarSize
566 //mt:const uint16(4) // Size of Size field.
570 //mt:if %s.Param != HotbarSize
575 type HotbarParam uint16
578 HotbarSize HotbarParam = 1 + iota
583 // ToCltBreath tells the client how much breath it has.
584 type ToCltBreath struct {
588 // ToCltSkyParams tells the client how to render the sky.
589 type ToCltSkyParams struct {
593 SunFogTint color.NRGBA
594 MoonFogTint color.NRGBA
597 //mt:if %s.Type == "skybox"
601 //mt:if %s.Type == "regular"
603 DawnSky, DawnHorizon,
604 NightSky, NightHorizon,
609 // ToCltOverrideDayNightRatio overrides the client's day-night ratio
610 type ToCltOverrideDayNightRatio struct {
615 // ToCltLocalPlayerAnim tells the client how to animate the player.
616 type ToCltLocalPlayerAnim struct {
617 Idle, Walk, Dig, WalkDig [2]int32
621 // ToCltEyeOffset tells the client where to position the camera
622 // relative to the player.
623 type ToCltEyeOffset struct {
627 // ToCltDelParticleSpawner tells the client to delete a particle spawner.
628 type ToCltDelParticleSpawner struct {
632 // ToCltCloudParams tells the client how to render the clouds.
633 type ToCltCloudParams struct {
635 DiffuseColor color.NRGBA
636 AmbientColor color.NRGBA
642 // ToCltFadeSound tells the client to fade a sound.
643 type ToCltFadeSound struct {
649 // ToCltUpdatePlayerList informs the client of players leaving or joining.
650 type ToCltUpdatePlayerList struct {
651 Type PlayerListUpdateType
655 type PlayerListUpdateType uint8
658 InitPlayers PlayerListUpdateType = iota
663 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
664 type ToCltModChanMsg struct {
670 // ToCltModChanMsg tells the client it has received a signal on a mod channel.
671 type ToCltModChanSig struct {
676 type ModChanSig uint8
679 JoinOK ModChanSig = iota
687 // ToCltModChanMsg is sent when node metadata near the client changes.
688 type ToCltNodeMetasChanged struct {
690 Changed map[[3]int16]*NodeMeta
694 // ToCltSunParams tells the client how to render the sun.
695 type ToCltSunParams struct {
704 // ToCltMoonParams tells the client how to render the moon.
705 type ToCltMoonParams struct {
712 // ToCltStarParams tells the client how to render the stars.
713 type ToCltStarParams struct {
720 type ToCltSRPBytesSaltB struct {
724 // ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
725 type ToCltFormspecPrepend struct {
729 // ToCltMinimapModes tells the client the set of available minimap modes.
730 type ToCltMinimapModes struct {
735 func (cmd *ToCltMinimapModes) serialize(w io.Writer) error {
736 buf := make([]byte, 4)
737 if len(cmd.Modes) > math.MaxUint16 {
740 be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
741 be.PutUint16(buf[2:4], cmd.Current)
742 if _, err := w.Write(buf); err != nil {
745 for i := range cmd.Modes {
746 if err := serialize(w, &cmd.Modes[i]); err != nil {
753 func (cmd *ToCltMinimapModes) deserialize(r io.Reader) error {
754 buf := make([]byte, 4)
755 if _, err := io.ReadFull(r, buf); err != nil {
758 cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
759 cmd.Current = be.Uint16(buf[2:4])
760 for i := range cmd.Modes {
761 if err := deserialize(r, &cmd.Modes[i]); err != nil {