10 "github.com/anon55555/mt/rudp"
13 type ToCltCmd interface {
18 //go:generate ./cmdno.sh tocltcmds ToClt toClt uint16 Cmd newToCltCmd
20 // ToCltHello is sent as a response to ToSrvInit.
21 // The client responds to ToCltHello by authenticating.
22 type ToCltHello struct {
24 Compression CompressionModes
30 // ToCltAcceptAuth is sent after the client successfully authenticates.
31 // The client responds to ToCltAcceptAuth with ToSrvInit2.
32 type ToCltAcceptAuth struct {
33 // The client does the equivalent of
35 // before using PlayerPos.
40 SudoAuthMethods AuthMethods
43 type ToCltAcceptSudoMode struct {
44 SudoAuthMethods AuthMethods
48 type ToCltDenySudoMode struct{}
50 // ToCltKick tells that the client that it has been kicked by the server.
51 type ToCltKick struct {
53 //mt:assert %s.Reason < maxKickReason
55 //mt:if dr := %s.Reason; dr == Custom || dr == Shutdown || dr == Crash
59 //mt:if dr := %s.Reason; dr == Shutdown || dr == Crash
64 // A KickReason is the reason a ToCltKick has been sent.
68 WrongPasswd KickReason = iota
84 func (cmd ToCltKick) String() (msg string) {
87 return "wrong password"
89 return "unexpected data"
90 case SrvIsSingleplayer:
91 return "server is singleplayer"
93 return "unsupported client version"
95 return "disallowed character(s) in player name"
97 return "disallowed player name"
99 return "too many clients"
101 return "empty password"
102 case AlreadyConnected:
103 return "another client is already connected with the same name"
105 return "server error"
109 msg = "server shutdown"
113 msg = fmt.Sprintf("KickReason(%d)", cmd.Reason)
116 if cmd.Custom != "" {
117 msg += ": " + cmd.Custom
123 // ToCltBlkData tells the client the contents of a nearby MapBlk.
124 type ToCltBlkData struct {
129 // ToCltAddNode tells the client that a nearby node changed
130 // to something other than air.
131 type ToCltAddNode struct {
137 // ToCltRemoveNode tells the client that a nearby node changed to air.
138 type ToCltRemoveNode struct {
142 // ToCltInv updates the client's inventory.
143 type ToCltInv struct {
148 // ToCltTimeOfDay updates the client's in-game time of day.
149 type ToCltTimeOfDay struct {
150 Time uint16 // %24000
151 Speed float32 // Speed times faster than real time
154 // ToCltCSMRestrictionFlags tells the client how use of CSMs should be restricted.
155 type ToCltCSMRestrictionFlags struct {
156 Flags CSMRestrictionFlags
158 // MapRange is the maximum distance from the player CSMs can read the map
159 // if Flags&LimitMapRange != 0.
163 type CSMRestrictionFlags uint64
166 NoCSMs CSMRestrictionFlags = 1 << iota
174 // ToCltAddPlayerVel tells the client to add Vel to the player's velocity.
175 type ToCltAddPlayerVel struct {
179 // ToCltMediaPush is sent when a media file is dynamically added.
180 type ToCltMediaPush struct {
181 //mt:const uint16(sha1.Size)
190 // ToCltChatMsg tells the client that is has received a chat message.
191 type ToCltChatMsg struct {
199 Timestamp int64 // Unix time.
202 type ChatMsgType uint8
205 RawMsg ChatMsgType = iota // raw
207 AnnounceMsg // announce
212 //go:generate stringer -linecomment -type ChatMsgType
214 // ToCltAORmAdd tells the client that AOs have been removed from and/or added to
215 // the AOs that it can see.
216 type ToCltAORmAdd struct {
223 //mt:const genericCAO
229 // ToCltAOMsgs updates the client about nearby AOs.
230 type ToCltAOMsgs struct {
235 // ToCltHP updates the player's HP on the client.
236 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.
440 // ToCltHUDAdd tells the client to add a HUD.
441 type ToCltAddHUD struct {
449 ImgHUD HUDType = iota
457 //go:generate stringer -type HUDType
459 // ToCltRmHUD tells the client to remove a HUD.
460 type ToCltRmHUD struct {
464 // ToCltChangeHUD tells the client to change a field in a HUD.
465 type ToCltChangeHUD struct {
470 //mt:assert %s.Field < hudMax
472 //mt:if %s.Field == HUDPos
476 //mt:if %s.Field == HUDName
480 //mt:if %s.Field == HUDScale
484 //mt:if %s.Field == HUDText
488 //mt:if %s.Field == HUDNumber
492 //mt:if %s.Field == HUDItem
496 //mt:if %s.Field == HUDDir
500 //mt:if %s.Field == HUDAlign
504 //mt:if %s.Field == HUDOffset
508 //mt:if %s.Field == HUDWorldPos
512 //mt:if %s.Field == HUDSize
516 //mt:if %s.Field == HUDZIndex
520 //mt:if %s.Field == HUDText2
528 HUDPos HUDField = iota
544 //go:generate stringer -trimprefix HUD -type HUDField
546 // ToCltHUDFlags tells the client to update its HUD flags.
547 type ToCltHUDFlags struct {
556 ShowHotbar HUDFlags = 1 << iota
565 // ToCltSetHotbarParam tells the client to set a hotbar parameter.
566 type ToCltSetHotbarParam struct {
569 //mt:if %s.Param == HotbarSize
570 //mt:const uint16(4) // Size of Size field.
574 //mt:if %s.Param != HotbarSize
579 type HotbarParam uint16
582 HotbarSize HotbarParam = 1 + iota
587 //go:generate stringer -trimprefix Hotbar -type HotbarParam
589 // ToCltBreath tells the client how much breath it has.
590 type ToCltBreath struct {
594 // ToCltSkyParams tells the client how to render the sky.
595 type ToCltSkyParams struct {
599 SunFogTint color.NRGBA
600 MoonFogTint color.NRGBA
603 //mt:if %s.Type == "skybox"
607 //mt:if %s.Type == "regular"
609 DawnSky, DawnHorizon,
610 NightSky, NightHorizon,
615 // ToCltOverrideDayNightRatio overrides the client's day-night ratio
616 type ToCltOverrideDayNightRatio struct {
621 // ToCltLocalPlayerAnim tells the client how to animate the player.
622 type ToCltLocalPlayerAnim struct {
623 Idle, Walk, Dig, WalkDig [2]int32
627 // ToCltEyeOffset tells the client where to position the camera
628 // relative to the player.
629 type ToCltEyeOffset struct {
633 // ToCltDelParticleSpawner tells the client to delete a particle spawner.
634 type ToCltDelParticleSpawner struct {
638 // ToCltCloudParams tells the client how to render the clouds.
639 type ToCltCloudParams struct {
641 DiffuseColor color.NRGBA
642 AmbientColor color.NRGBA
648 // ToCltFadeSound tells the client to fade a sound.
649 type ToCltFadeSound struct {
655 // ToCltUpdatePlayerList informs the client of players leaving or joining.
656 type ToCltUpdatePlayerList struct {
657 Type PlayerListUpdateType
661 type PlayerListUpdateType uint8
664 InitPlayers PlayerListUpdateType = iota // init
666 RemovePlayers // remove
669 //go:generate stringer -linecomment -type PlayerListUpdateType
671 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
672 type ToCltModChanMsg struct {
678 // ToCltModChanMsg tells the client it has received a signal on a mod channel.
679 type ToCltModChanSig struct {
684 type ModChanSig uint8
687 JoinOK ModChanSig = iota
695 //go:generate stringer -type ModChanSig
697 // ToCltModChanMsg is sent when node metadata near the client changes.
698 type ToCltNodeMetasChanged struct {
700 Changed map[[3]int16]*NodeMeta
704 // ToCltSunParams tells the client how to render the sun.
705 type ToCltSunParams struct {
714 // ToCltMoonParams tells the client how to render the moon.
715 type ToCltMoonParams struct {
722 // ToCltStarParams tells the client how to render the stars.
723 type ToCltStarParams struct {
730 type ToCltSRPBytesSaltB struct {
734 // ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
735 type ToCltFormspecPrepend struct {
739 // ToCltMinimapModes tells the client the set of available minimap modes.
740 type ToCltMinimapModes struct {
745 var _ serializer = (*ToCltMinimapModes)(nil)
747 func (cmd *ToCltMinimapModes) serialize(w io.Writer) {
748 buf := make([]byte, 4)
749 if len(cmd.Modes) > math.MaxUint16 {
752 be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
753 be.PutUint16(buf[2:4], cmd.Current)
754 _, err := w.Write(buf)
756 for i := range cmd.Modes {
757 chk(serialize(w, &cmd.Modes[i]))
761 var _ deserializer = (*ToCltMinimapModes)(nil)
763 func (cmd *ToCltMinimapModes) deserialize(r io.Reader) {
764 buf := make([]byte, 4)
765 _, err := io.ReadFull(r, buf)
767 cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
768 cmd.Current = be.Uint16(buf[2:4])
769 for i := range cmd.Modes {
770 chk(deserialize(r, &cmd.Modes[i]))
774 type ToCltDisco struct{}
776 func (*ToCltDisco) cmd() {}
777 func (*ToCltDisco) toCltCmdNo() uint16 { return 0xffff }
778 func (*ToCltDisco) DefaultPktInfo() rudp.PktInfo { return rudp.PktInfo{} }