9 "github.com/anon55555/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.
436 // ToCltHUDAdd tells the client to add a HUD.
437 type ToCltAddHUD struct {
445 ImgHUD HUDType = iota
453 //go:generate stringer -type HUDType
455 // ToCltRmHUD tells the client to remove a HUD.
456 type ToCltRmHUD struct {
460 // ToCltChangeHUD tells the client to change a field in a HUD.
461 type ToCltChangeHUD struct {
466 //mt:assert %s.Field < hudMax
468 //mt:if %s.Field == HUDPos
472 //mt:if %s.Field == HUDName
476 //mt:if %s.Field == HUDScale
480 //mt:if %s.Field == HUDText
484 //mt:if %s.Field == HUDNumber
488 //mt:if %s.Field == HUDItem
492 //mt:if %s.Field == HUDDir
496 //mt:if %s.Field == HUDAlign
500 //mt:if %s.Field == HUDOffset
504 //mt:if %s.Field == HUDWorldPos
508 //mt:if %s.Field == HUDSize
512 //mt:if %s.Field == HUDZIndex
516 //mt:if %s.Field == HUDText2
524 HUDPos HUDField = iota
540 //go:generate stringer -trimprefix HUD -type HUDField
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 //go:generate stringer -trimprefix Hotbar -type HotbarParam
585 // ToCltBreath tells the client how much breath it has.
586 type ToCltBreath struct {
590 // ToCltSkyParams tells the client how to render the sky.
591 type ToCltSkyParams struct {
595 SunFogTint color.NRGBA
596 MoonFogTint color.NRGBA
599 //mt:if %s.Type == "skybox"
603 //mt:if %s.Type == "regular"
605 DawnSky, DawnHorizon,
606 NightSky, NightHorizon,
611 // ToCltOverrideDayNightRatio overrides the client's day-night ratio
612 type ToCltOverrideDayNightRatio struct {
617 // ToCltLocalPlayerAnim tells the client how to animate the player.
618 type ToCltLocalPlayerAnim struct {
619 Idle, Walk, Dig, WalkDig [2]int32
623 // ToCltEyeOffset tells the client where to position the camera
624 // relative to the player.
625 type ToCltEyeOffset struct {
629 // ToCltDelParticleSpawner tells the client to delete a particle spawner.
630 type ToCltDelParticleSpawner struct {
634 // ToCltCloudParams tells the client how to render the clouds.
635 type ToCltCloudParams struct {
637 DiffuseColor color.NRGBA
638 AmbientColor color.NRGBA
644 // ToCltFadeSound tells the client to fade a sound.
645 type ToCltFadeSound struct {
651 // ToCltUpdatePlayerList informs the client of players leaving or joining.
652 type ToCltUpdatePlayerList struct {
653 Type PlayerListUpdateType
657 type PlayerListUpdateType uint8
660 InitPlayers PlayerListUpdateType = iota // init
662 RemovePlayers // remove
665 //go:generate stringer -linecomment -type PlayerListUpdateType
667 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
668 type ToCltModChanMsg struct {
674 // ToCltModChanMsg tells the client it has received a signal on a mod channel.
675 type ToCltModChanSig struct {
680 type ModChanSig uint8
683 JoinOK ModChanSig = iota
691 //go:generate stringer -type ModChanSig
693 // ToCltModChanMsg is sent when node metadata near the client changes.
694 type ToCltNodeMetasChanged struct {
696 Changed map[[3]int16]*NodeMeta
700 // ToCltSunParams tells the client how to render the sun.
701 type ToCltSunParams struct {
710 // ToCltMoonParams tells the client how to render the moon.
711 type ToCltMoonParams struct {
718 // ToCltStarParams tells the client how to render the stars.
719 type ToCltStarParams struct {
726 type ToCltSRPBytesSaltB struct {
730 // ToCltFormspecPrepend tells the client to prepend a string to all formspecs.
731 type ToCltFormspecPrepend struct {
735 // ToCltMinimapModes tells the client the set of available minimap modes.
736 type ToCltMinimapModes struct {
741 var _ serializer = (*ToCltMinimapModes)(nil)
743 func (cmd *ToCltMinimapModes) serialize(w io.Writer) {
744 buf := make([]byte, 4)
745 if len(cmd.Modes) > math.MaxUint16 {
748 be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
749 be.PutUint16(buf[2:4], cmd.Current)
750 _, err := w.Write(buf)
752 for i := range cmd.Modes {
753 chk(serialize(w, &cmd.Modes[i]))
757 var _ deserializer = (*ToCltMinimapModes)(nil)
759 func (cmd *ToCltMinimapModes) deserialize(r io.Reader) {
760 buf := make([]byte, 4)
761 _, err := io.ReadFull(r, buf)
763 cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
764 cmd.Current = be.Uint16(buf[2:4])
765 for i := range cmd.Modes {
766 chk(deserialize(r, &cmd.Modes[i]))
770 type ToCltDisco struct{}
772 func (*ToCltDisco) cmd() {}
773 func (*ToCltDisco) toCltCmdNo() uint16 { return 0xffff }
774 func (*ToCltDisco) DefaultPktInfo() rudp.PktInfo { return rudp.PktInfo{} }