9 "github.com/Minetest-j45/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 {
128 // ToCltAddNode tells the client that a nearby node changed
129 // to something other than air.
130 type ToCltAddNode struct {
136 // ToCltRemoveNode tells the client that a nearby node changed to air.
137 type ToCltRemoveNode struct {
141 // ToCltInv updates the client's inventory.
142 type ToCltInv struct {
147 // ToCltTimeOfDay updates the client's in-game time of day.
148 type ToCltTimeOfDay struct {
149 Time uint16 // %24000
150 Speed float32 // Speed times faster than real time
153 // ToCltCSMRestrictionFlags tells the client how use of CSMs should be restricted.
154 type ToCltCSMRestrictionFlags struct {
155 Flags CSMRestrictionFlags
157 // MapRange is the maximum distance from the player CSMs can read the map
158 // if Flags&LimitMapRange != 0.
162 type CSMRestrictionFlags uint64
165 NoCSMs CSMRestrictionFlags = 1 << iota
173 // ToCltAddPlayerVel tells the client to add Vel to the player's velocity.
174 type ToCltAddPlayerVel struct {
178 // ToCltMediaPush is sent when a media file is dynamically added.
179 type ToCltMediaPush struct {
186 // ToCltChatMsg tells the client that is has received a chat message.
187 type ToCltChatMsg struct {
195 Timestamp int64 // Unix time.
198 type ChatMsgType uint8
201 RawMsg ChatMsgType = iota // raw
203 AnnounceMsg // announce
208 //go:generate stringer -linecomment -type ChatMsgType
210 // ToCltAORmAdd tells the client that AOs have been removed from and/or added to
211 // the AOs that it can see.
212 type ToCltAORmAdd struct {
219 //mt:const genericCAO
225 // ToCltAOMsgs updates the client about nearby AOs.
226 type ToCltAOMsgs struct {
231 // ToCltHP updates the player's HP on the client.
232 type ToCltHP struct {
236 // ToCltMovePlayer tells the client that the player has been moved server-side.
237 type ToCltMovePlayer struct {
242 type ToCltLegacyKick struct {
247 // ToCltFOV tells the client to change its FOV.
248 type ToCltFOV struct {
251 TransitionTime float32
254 // ToCltDeathScreen tells the client to show the death screen.
255 type ToCltDeathScreen struct {
260 // ToCltMedia responds to a ToSrvMedia packet with the requested media files.
261 type ToCltMedia struct {
262 // N is the total number of ToCltMedia packets.
263 // I is the index of this packet.
275 // ToCltNodeDefs tells the client the definitions of nodes.
276 type ToCltNodeDefs struct {
283 // See (de)serialize.fmt.
290 // ToCltAnnounceMedia tells the client what media is available on request.
291 // See ToSrvReqMedia.
292 type ToCltAnnounceMedia struct {
300 // ToCltItemDefs tells the client the definitions of items.
301 type ToCltItemDefs struct {
308 Aliases []struct{ Alias, Orig string }
314 // ToCltPlaySound tells the client to play a sound.
315 type ToCltPlaySound struct {
328 // ToCltStopSound tells the client to stop playing a sound.
329 type ToCltStopSound struct {
333 // ToCltPrivs tells the client its privs.
334 type ToCltPrivs struct {
338 // ToCltInvFormspec tells the client its inventory formspec.
339 type ToCltInvFormspec struct {
344 // ToCltDetachedInv updates a detached inventory on the client.
345 type ToCltDetachedInv struct {
348 Len uint16 // deprecated
354 // ToCltShowFormspec tells the client to show a formspec.
355 type ToCltShowFormspec struct {
362 // ToCltMovement tells the client how to move.
363 type ToCltMovement struct {
364 DefaultAccel, AirAccel, FastAccel,
365 WalkSpeed, CrouchSpeed, FastSpeed, ClimbSpeed, JumpSpeed,
366 Fluidity, Smoothing, Sink, // liquids
370 // ToCltSpawnParticle tells the client to spawn a particle.
371 type ToCltSpawnParticle struct {
372 Pos, Vel, Acc [3]float32
373 ExpirationTime float32 // in seconds.
390 type ParticleSpawnerID uint32
392 // ToCltAddParticleSpawner tells the client to add a particle spawner.
393 type ToCltAddParticleSpawner struct {
396 Pos, Vel, Acc [2][3]float32
397 ExpirationTime [2]float32 // in seconds.
437 // ToCltHUDAdd tells the client to add a HUD.
438 type ToCltAddHUD struct {
446 ImgHUD HUDType = iota
454 //go:generate stringer -type HUDType
456 // ToCltRmHUD tells the client to remove a HUD.
457 type ToCltRmHUD struct {
461 // ToCltChangeHUD tells the client to change a field in a HUD.
462 type ToCltChangeHUD struct {
467 //mt:assert %s.Field < hudMax
469 //mt:if %s.Field == HUDPos
473 //mt:if %s.Field == HUDName
477 //mt:if %s.Field == HUDScale
481 //mt:if %s.Field == HUDText
485 //mt:if %s.Field == HUDNumber
489 //mt:if %s.Field == HUDItem
493 //mt:if %s.Field == HUDDir
497 //mt:if %s.Field == HUDAlign
501 //mt:if %s.Field == HUDOffset
505 //mt:if %s.Field == HUDWorldPos
509 //mt:if %s.Field == HUDSize
513 //mt:if %s.Field == HUDZIndex
517 //mt:if %s.Field == HUDText2
521 //mt:if %s.Field == HUDStyle
529 HUDPos HUDField = iota
546 //go:generate stringer -trimprefix HUD -type HUDField
548 type HUDStyleFlags uint32
551 StyleBold HUDStyleFlags = 1 << iota
556 //go:generate stringer -trimprefix Style -type HUDStyleFlags
558 // ToCltHUDFlags tells the client to update its HUD flags.
559 type ToCltHUDFlags struct {
568 ShowHotbar HUDFlags = 1 << iota
577 // ToCltSetHotbarParam tells the client to set a hotbar parameter.
578 type ToCltSetHotbarParam struct {
581 //mt:if %s.Param == HotbarSize
582 //mt:const uint16(4) // Size of Size field.
586 //mt:if %s.Param != HotbarSize
591 type HotbarParam uint16
594 HotbarSize HotbarParam = 1 + iota
599 //go:generate stringer -trimprefix Hotbar -type HotbarParam
601 // ToCltBreath tells the client how much breath it has.
602 type ToCltBreath struct {
606 // ToCltSkyParams tells the client how to render the sky.
607 type ToCltSkyParams struct {
611 SunFogTint color.NRGBA
612 MoonFogTint color.NRGBA
615 //mt:if %s.Type == "skybox"
619 //mt:if %s.Type == "regular"
621 DawnSky, DawnHorizon,
622 NightSky, NightHorizon,
627 // ToCltOverrideDayNightRatio overrides the client's day-night ratio
628 type ToCltOverrideDayNightRatio struct {
633 // ToCltLocalPlayerAnim tells the client how to animate the player.
634 type ToCltLocalPlayerAnim struct {
635 Idle, Walk, Dig, WalkDig [2]int32
639 // ToCltEyeOffset tells the client where to position the camera
640 // relative to the player.
641 type ToCltEyeOffset struct {
645 // ToCltDelParticleSpawner tells the client to delete a particle spawner.
646 type ToCltDelParticleSpawner struct {
650 // ToCltCloudParams tells the client how to render the clouds.
651 type ToCltCloudParams struct {
653 DiffuseColor color.NRGBA
654 AmbientColor color.NRGBA
660 // ToCltFadeSound tells the client to fade a sound.
661 type ToCltFadeSound struct {
667 // ToCltUpdatePlayerList informs the client of players leaving or joining.
668 type ToCltUpdatePlayerList struct {
669 Type PlayerListUpdateType
673 type PlayerListUpdateType uint8
676 InitPlayers PlayerListUpdateType = iota // init
678 RemovePlayers // remove
681 //go:generate stringer -linecomment -type PlayerListUpdateType
683 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
684 type ToCltModChanMsg struct {
690 // ToCltModChanMsg tells the client it has received a signal on a mod channel.
691 type ToCltModChanSig struct {
696 type ModChanSig uint8
699 JoinOK ModChanSig = iota
707 //go:generate stringer -type ModChanSig
709 // ToCltModChanMsg is sent when node metadata near the client changes.
710 type ToCltNodeMetasChanged struct {
712 Changed map[[3]int16]*NodeMeta
716 // ToCltSunParams tells the client how to render the sun.
717 type ToCltSunParams struct {
726 // ToCltMoonParams tells the client how to render the moon.
727 type ToCltMoonParams struct {
734 // ToCltStarParams tells the client how to render the stars.
735 type ToCltStarParams struct {
742 type ToCltSRPBytesSaltB struct {
746 // ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
747 type ToCltFormspecPrepend struct {
751 // ToCltMinimapModes tells the client the set of available minimap modes.
752 type ToCltMinimapModes struct {
757 var _ serializer = (*ToCltMinimapModes)(nil)
759 func (cmd *ToCltMinimapModes) serialize(w io.Writer) {
760 buf := make([]byte, 4)
761 if len(cmd.Modes) > math.MaxUint16 {
764 be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
765 be.PutUint16(buf[2:4], cmd.Current)
766 _, err := w.Write(buf)
768 for i := range cmd.Modes {
769 chk(serialize(w, &cmd.Modes[i]))
773 var _ deserializer = (*ToCltMinimapModes)(nil)
775 func (cmd *ToCltMinimapModes) deserialize(r io.Reader) {
776 buf := make([]byte, 4)
777 _, err := io.ReadFull(r, buf)
779 cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
780 cmd.Current = be.Uint16(buf[2:4])
781 for i := range cmd.Modes {
782 chk(deserialize(r, &cmd.Modes[i]))
786 type ToCltDisco struct{}
788 func (*ToCltDisco) cmd() {}
789 func (*ToCltDisco) toCltCmdNo() uint16 { return 0xffff }
790 func (*ToCltDisco) DefaultPktInfo() rudp.PktInfo { return rudp.PktInfo{} }