From fc4a3becde45bc7c14f6946afc46721247d86ac1 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Mon, 24 Jun 2024 14:56:04 +0800 Subject: [PATCH] Add some more game message structs --- messages7/ready_to_enter.go | 43 -------- messages7/sv_emoticon.go | 51 ++++++++++ messages7/sv_extra_projectile.go | 44 ++++++++ messages7/sv_kill_msg.go | 81 +++++++++++++++ messages7/sv_ready_to_enter.go | 43 ++++++++ messages7/sv_server_settings.go | 66 ++++++++++++ messages7/sv_tune_params.go | 144 +++++++++++++++++++++++++++ messages7/sv_vote_clear_options.go | 44 ++++++++ messages7/sv_vote_option_add.go | 50 ++++++++++ messages7/sv_vote_option_list_add.go | 67 +++++++++++++ messages7/sv_vote_option_remove.go | 50 ++++++++++ messages7/sv_vote_set.go | 62 ++++++++++++ messages7/sv_vote_status.go | 60 +++++++++++ messages7/sv_weapon_pickup.go | 51 ++++++++++ network7/network7.go | 62 ++++++++++-- protocol7/packet.go | 4 +- teeworlds7/callbacks.go | 6 +- teeworlds7/game.go | 2 +- 18 files changed, 872 insertions(+), 58 deletions(-) delete mode 100644 messages7/ready_to_enter.go create mode 100644 messages7/sv_emoticon.go create mode 100644 messages7/sv_extra_projectile.go create mode 100644 messages7/sv_kill_msg.go create mode 100644 messages7/sv_ready_to_enter.go create mode 100644 messages7/sv_server_settings.go create mode 100644 messages7/sv_tune_params.go create mode 100644 messages7/sv_vote_clear_options.go create mode 100644 messages7/sv_vote_option_add.go create mode 100644 messages7/sv_vote_option_list_add.go create mode 100644 messages7/sv_vote_option_remove.go create mode 100644 messages7/sv_vote_set.go create mode 100644 messages7/sv_vote_status.go create mode 100644 messages7/sv_weapon_pickup.go diff --git a/messages7/ready_to_enter.go b/messages7/ready_to_enter.go deleted file mode 100644 index db48dc7..0000000 --- a/messages7/ready_to_enter.go +++ /dev/null @@ -1,43 +0,0 @@ -package messages7 - -import ( - "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" - "github.com/teeworlds-go/go-teeworlds-protocol/network7" - "github.com/teeworlds-go/go-teeworlds-protocol/packer" -) - -type ReadyToEnter struct { - ChunkHeader *chunk7.ChunkHeader -} - -func (msg *ReadyToEnter) MsgId() int { - return network7.MsgGameReadyToEnter -} - -func (msg *ReadyToEnter) MsgType() network7.MsgType { - return network7.TypeNet -} - -func (msg *ReadyToEnter) System() bool { - return false -} - -func (msg *ReadyToEnter) Vital() bool { - return true -} - -func (msg *ReadyToEnter) Pack() []byte { - return []byte{} -} - -func (msg *ReadyToEnter) Unpack(u *packer.Unpacker) error { - return nil -} - -func (msg *ReadyToEnter) Header() *chunk7.ChunkHeader { - return msg.ChunkHeader -} - -func (msg *ReadyToEnter) SetHeader(header *chunk7.ChunkHeader) { - msg.ChunkHeader = header -} diff --git a/messages7/sv_emoticon.go b/messages7/sv_emoticon.go new file mode 100644 index 0000000..0212f15 --- /dev/null +++ b/messages7/sv_emoticon.go @@ -0,0 +1,51 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvEmoticon struct { + ChunkHeader *chunk7.ChunkHeader + + Emoticon network7.Emote +} + +func (msg *SvEmoticon) MsgId() int { + return network7.MsgGameSvEmoticon +} + +func (msg *SvEmoticon) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvEmoticon) System() bool { + return false +} + +func (msg *SvEmoticon) Vital() bool { + return true +} + +func (msg *SvEmoticon) Pack() []byte { + return slices.Concat( + packer.PackInt(int(msg.Emoticon)), + ) +} + +func (msg *SvEmoticon) Unpack(u *packer.Unpacker) error { + msg.Emoticon = network7.Emote(u.GetInt()) + + return nil +} + +func (msg *SvEmoticon) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvEmoticon) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_extra_projectile.go b/messages7/sv_extra_projectile.go new file mode 100644 index 0000000..bd6b30d --- /dev/null +++ b/messages7/sv_extra_projectile.go @@ -0,0 +1,44 @@ +package messages7 + +import ( + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +// this message is unused in the official 0.7.5 implementation +type SvExtraProjectile struct { + ChunkHeader *chunk7.ChunkHeader +} + +func (msg *SvExtraProjectile) MsgId() int { + return network7.MsgGameSvExtraProjectile +} + +func (msg *SvExtraProjectile) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvExtraProjectile) System() bool { + return false +} + +func (msg *SvExtraProjectile) Vital() bool { + return true +} + +func (msg *SvExtraProjectile) Pack() []byte { + return []byte{} +} + +func (msg *SvExtraProjectile) Unpack(u *packer.Unpacker) error { + return nil +} + +func (msg *SvExtraProjectile) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvExtraProjectile) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_kill_msg.go b/messages7/sv_kill_msg.go new file mode 100644 index 0000000..6f5cf3a --- /dev/null +++ b/messages7/sv_kill_msg.go @@ -0,0 +1,81 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvKillMsg struct { + ChunkHeader *chunk7.ChunkHeader + + // Client ID of the killer. + // Can be the same as the Victim. + // For example on a selfkill with grenade but also when a tee dies in a spike (death tile) or falls out of the world. + KillerId int + + // Client ID of the killed. + VictimId int + + // Weapon the tee was killed with. Can be one of those: + // + // -3 network7.WeaponGame (team switching etc) + // -2 network7.WeaponSelf (console kill command) + // -1 network7.WeaponWorld (death tiles etc) + // 0 network7.WeaponHammer + // 1 network7.WeaponGun + // 2 network7.WeaponShotgun + // 3 network7.WeaponGrenade + // 4 network7.WeaponLase + // 5 network7.WeaponNinja + Weapon network7.Weapon + + // For CTF, if the guy is carrying a flag for example. + // Only when the sv_gametype is ctf this mode is non zero. + // It is set in ctf.cpp when a flag is involved on death. + ModeSpecial int +} + +func (msg *SvKillMsg) MsgId() int { + return network7.MsgGameSvKillMsg +} + +func (msg *SvKillMsg) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvKillMsg) System() bool { + return false +} + +func (msg *SvKillMsg) Vital() bool { + return true +} + +func (msg *SvKillMsg) Pack() []byte { + return slices.Concat( + packer.PackInt(msg.KillerId), + packer.PackInt(msg.VictimId), + packer.PackInt(int(msg.Weapon)), + packer.PackInt(msg.ModeSpecial), + ) +} + +func (msg *SvKillMsg) Unpack(u *packer.Unpacker) error { + msg.KillerId = u.GetInt() + msg.VictimId = u.GetInt() + msg.Weapon = network7.Weapon(u.GetInt()) + msg.ModeSpecial = u.GetInt() + + return nil +} + +func (msg *SvKillMsg) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvKillMsg) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_ready_to_enter.go b/messages7/sv_ready_to_enter.go new file mode 100644 index 0000000..0c42d5f --- /dev/null +++ b/messages7/sv_ready_to_enter.go @@ -0,0 +1,43 @@ +package messages7 + +import ( + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvReadyToEnter struct { + ChunkHeader *chunk7.ChunkHeader +} + +func (msg *SvReadyToEnter) MsgId() int { + return network7.MsgGameSvReadyToEnter +} + +func (msg *SvReadyToEnter) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvReadyToEnter) System() bool { + return false +} + +func (msg *SvReadyToEnter) Vital() bool { + return true +} + +func (msg *SvReadyToEnter) Pack() []byte { + return []byte{} +} + +func (msg *SvReadyToEnter) Unpack(u *packer.Unpacker) error { + return nil +} + +func (msg *SvReadyToEnter) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvReadyToEnter) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_server_settings.go b/messages7/sv_server_settings.go new file mode 100644 index 0000000..1c4725b --- /dev/null +++ b/messages7/sv_server_settings.go @@ -0,0 +1,66 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvServerSettings struct { + ChunkHeader *chunk7.ChunkHeader + + KickVote bool + KickMin int + SpecVote bool + TeamLock bool + TeamBalance bool + PlayerSlots int +} + +func (msg *SvServerSettings) MsgId() int { + return network7.MsgGameSvServerSettings +} + +func (msg *SvServerSettings) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvServerSettings) System() bool { + return false +} + +func (msg *SvServerSettings) Vital() bool { + return true +} + +func (msg *SvServerSettings) Pack() []byte { + return slices.Concat( + packer.PackBool(msg.KickVote), + packer.PackInt(msg.KickMin), + packer.PackBool(msg.SpecVote), + packer.PackBool(msg.TeamLock), + packer.PackBool(msg.TeamBalance), + packer.PackInt(msg.PlayerSlots), + ) +} + +func (msg *SvServerSettings) Unpack(u *packer.Unpacker) error { + msg.KickVote = u.GetInt() != 0 + msg.KickMin = u.GetInt() + msg.SpecVote = u.GetInt() != 0 + msg.TeamLock = u.GetInt() != 0 + msg.TeamBalance = u.GetInt() != 0 + msg.PlayerSlots = u.GetInt() + + return nil +} + +func (msg *SvServerSettings) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvServerSettings) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_tune_params.go b/messages7/sv_tune_params.go new file mode 100644 index 0000000..a06498f --- /dev/null +++ b/messages7/sv_tune_params.go @@ -0,0 +1,144 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvTuneParams struct { + ChunkHeader *chunk7.ChunkHeader + + GroundControlSpeed float32 + GroundControlAccel float32 + GroundFriction float32 + GroundJumpImpulse float32 + AirJumpImpulse float32 + AirControlSpeed float32 + AirControlAccel float32 + AirFriction float32 + HookLength float32 + HookFireSpeed float32 + HookDragAccel float32 + HookDragSpeed float32 + Gravity float32 + VelrampStart float32 + VelrampRange float32 + VelrampCurvature float32 + GunCurvature float32 + GunSpeed float32 + GunLifetime float32 + ShotgunCurvature float32 + ShotgunSpeed float32 + ShotgunSpeeddiff float32 + ShotgunLifetime float32 + GrenadeCurvature float32 + GrenadeSpeed float32 + GrenadeLifetime float32 + LaserReach float32 + LaserBounceDelay float32 + LaserBounceNum float32 + LaserBounceCost float32 + PlayerCollision float32 + PlayerHooking float32 +} + +func (msg *SvTuneParams) MsgId() int { + return network7.MsgGameSvTuneParams +} + +func (msg *SvTuneParams) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvTuneParams) System() bool { + return false +} + +func (msg *SvTuneParams) Vital() bool { + return true +} + +func (msg *SvTuneParams) Pack() []byte { + return slices.Concat( + packer.PackInt(int(msg.GroundControlSpeed*100)), + packer.PackInt(int(msg.GroundControlAccel*100)), + packer.PackInt(int(msg.GroundFriction*100)), + packer.PackInt(int(msg.GroundJumpImpulse*100)), + packer.PackInt(int(msg.AirJumpImpulse*100)), + packer.PackInt(int(msg.AirControlSpeed*100)), + packer.PackInt(int(msg.AirControlAccel*100)), + packer.PackInt(int(msg.AirFriction*100)), + packer.PackInt(int(msg.HookLength*100)), + packer.PackInt(int(msg.HookFireSpeed*100)), + packer.PackInt(int(msg.HookDragAccel*100)), + packer.PackInt(int(msg.HookDragSpeed*100)), + packer.PackInt(int(msg.Gravity*100)), + packer.PackInt(int(msg.VelrampStart*100)), + packer.PackInt(int(msg.VelrampRange*100)), + packer.PackInt(int(msg.VelrampCurvature*100)), + packer.PackInt(int(msg.GunCurvature*100)), + packer.PackInt(int(msg.GunSpeed*100)), + packer.PackInt(int(msg.GunLifetime*100)), + packer.PackInt(int(msg.ShotgunCurvature*100)), + packer.PackInt(int(msg.ShotgunSpeed*100)), + packer.PackInt(int(msg.ShotgunSpeeddiff*100)), + packer.PackInt(int(msg.ShotgunLifetime*100)), + packer.PackInt(int(msg.GrenadeCurvature*100)), + packer.PackInt(int(msg.GrenadeSpeed*100)), + packer.PackInt(int(msg.GrenadeLifetime*100)), + packer.PackInt(int(msg.LaserReach*100)), + packer.PackInt(int(msg.LaserBounceDelay*100)), + packer.PackInt(int(msg.LaserBounceNum*100)), + packer.PackInt(int(msg.LaserBounceCost*100)), + packer.PackInt(int(msg.PlayerCollision*100)), + packer.PackInt(int(msg.PlayerHooking*100)), + ) +} + +func (msg *SvTuneParams) Unpack(u *packer.Unpacker) error { + msg.GroundControlSpeed = float32(u.GetInt()) / 100 + msg.GroundControlAccel = float32(u.GetInt()) / 100 + msg.GroundFriction = float32(u.GetInt()) / 100 + msg.GroundJumpImpulse = float32(u.GetInt()) / 100 + msg.AirJumpImpulse = float32(u.GetInt()) / 100 + msg.AirControlSpeed = float32(u.GetInt()) / 100 + msg.AirControlAccel = float32(u.GetInt()) / 100 + msg.AirFriction = float32(u.GetInt()) / 100 + msg.HookLength = float32(u.GetInt()) / 100 + msg.HookFireSpeed = float32(u.GetInt()) / 100 + msg.HookDragAccel = float32(u.GetInt()) / 100 + msg.HookDragSpeed = float32(u.GetInt()) / 100 + msg.Gravity = float32(u.GetInt()) / 100 + msg.VelrampStart = float32(u.GetInt()) / 100 + msg.VelrampRange = float32(u.GetInt()) / 100 + msg.VelrampCurvature = float32(u.GetInt()) / 100 + msg.GunCurvature = float32(u.GetInt()) / 100 + msg.GunSpeed = float32(u.GetInt()) / 100 + msg.GunLifetime = float32(u.GetInt()) / 100 + msg.ShotgunCurvature = float32(u.GetInt()) / 100 + msg.ShotgunSpeed = float32(u.GetInt()) / 100 + msg.ShotgunSpeeddiff = float32(u.GetInt()) / 100 + msg.ShotgunLifetime = float32(u.GetInt()) / 100 + msg.GrenadeCurvature = float32(u.GetInt()) / 100 + msg.GrenadeSpeed = float32(u.GetInt()) / 100 + msg.GrenadeLifetime = float32(u.GetInt()) / 100 + msg.LaserReach = float32(u.GetInt()) / 100 + msg.LaserBounceDelay = float32(u.GetInt()) / 100 + msg.LaserBounceNum = float32(u.GetInt()) / 100 + msg.LaserBounceCost = float32(u.GetInt()) / 100 + msg.PlayerCollision = float32(u.GetInt()) / 100 + msg.PlayerHooking = float32(u.GetInt()) / 100 + + return nil +} + +func (msg *SvTuneParams) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvTuneParams) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_vote_clear_options.go b/messages7/sv_vote_clear_options.go new file mode 100644 index 0000000..ac5da0e --- /dev/null +++ b/messages7/sv_vote_clear_options.go @@ -0,0 +1,44 @@ +package messages7 + +import ( + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +// This message is used by the server to empty all vote entries in the client menu. +type SvVoteClearOptions struct { + ChunkHeader *chunk7.ChunkHeader +} + +func (msg *SvVoteClearOptions) MsgId() int { + return network7.MsgGameSvVoteClearOptions +} + +func (msg *SvVoteClearOptions) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvVoteClearOptions) System() bool { + return false +} + +func (msg *SvVoteClearOptions) Vital() bool { + return true +} + +func (msg *SvVoteClearOptions) Pack() []byte { + return []byte{} +} + +func (msg *SvVoteClearOptions) Unpack(u *packer.Unpacker) error { + return nil +} + +func (msg *SvVoteClearOptions) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvVoteClearOptions) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_vote_option_add.go b/messages7/sv_vote_option_add.go new file mode 100644 index 0000000..505ad8f --- /dev/null +++ b/messages7/sv_vote_option_add.go @@ -0,0 +1,50 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvVoteOptionAdd struct { + ChunkHeader *chunk7.ChunkHeader + + Description string +} + +func (msg *SvVoteOptionAdd) MsgId() int { + return network7.MsgGameSvVoteOptionAdd +} + +func (msg *SvVoteOptionAdd) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvVoteOptionAdd) System() bool { + return false +} + +func (msg *SvVoteOptionAdd) Vital() bool { + return true +} + +func (msg *SvVoteOptionAdd) Pack() []byte { + return slices.Concat( + packer.PackStr(msg.Description), + ) +} + +func (msg *SvVoteOptionAdd) Unpack(u *packer.Unpacker) error { + msg.Description = u.GetString() + return nil +} + +func (msg *SvVoteOptionAdd) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvVoteOptionAdd) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_vote_option_list_add.go b/messages7/sv_vote_option_list_add.go new file mode 100644 index 0000000..51340cf --- /dev/null +++ b/messages7/sv_vote_option_list_add.go @@ -0,0 +1,67 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +// You have to manually set NumOptions to be the amount of Descriptions +// For example: +// +// options := []string{"foo", "bar", "baz"} +// voteAdd := SvVoteOptionListAdd{NumOptions: len(options), Descriptions: options} +type SvVoteOptionListAdd struct { + ChunkHeader *chunk7.ChunkHeader + + NumOptions int + Descriptions []string +} + +func (msg *SvVoteOptionListAdd) MsgId() int { + return network7.MsgGameSvVoteOptionListAdd +} + +func (msg *SvVoteOptionListAdd) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvVoteOptionListAdd) System() bool { + return false +} + +func (msg *SvVoteOptionListAdd) Vital() bool { + return true +} + +func (msg *SvVoteOptionListAdd) Pack() []byte { + options := []byte{} + for _, option := range msg.Descriptions { + options = append(options, packer.PackStr(option)...) + } + + return slices.Concat( + packer.PackInt(msg.NumOptions), + options, + ) +} + +func (msg *SvVoteOptionListAdd) Unpack(u *packer.Unpacker) error { + msg.NumOptions = u.GetInt() + msg.Descriptions = make([]string, msg.NumOptions) + for i := 0; i < msg.NumOptions; i++ { + msg.Descriptions[i] = u.GetString() + } + + return nil +} + +func (msg *SvVoteOptionListAdd) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvVoteOptionListAdd) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_vote_option_remove.go b/messages7/sv_vote_option_remove.go new file mode 100644 index 0000000..ba6c88d --- /dev/null +++ b/messages7/sv_vote_option_remove.go @@ -0,0 +1,50 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvVoteOptionRemove struct { + ChunkHeader *chunk7.ChunkHeader + + Description string +} + +func (msg *SvVoteOptionRemove) MsgId() int { + return network7.MsgGameSvVoteOptionRemove +} + +func (msg *SvVoteOptionRemove) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvVoteOptionRemove) System() bool { + return false +} + +func (msg *SvVoteOptionRemove) Vital() bool { + return true +} + +func (msg *SvVoteOptionRemove) Pack() []byte { + return slices.Concat( + packer.PackStr(msg.Description), + ) +} + +func (msg *SvVoteOptionRemove) Unpack(u *packer.Unpacker) error { + msg.Description = u.GetString() + return nil +} + +func (msg *SvVoteOptionRemove) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvVoteOptionRemove) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_vote_set.go b/messages7/sv_vote_set.go new file mode 100644 index 0000000..8e05325 --- /dev/null +++ b/messages7/sv_vote_set.go @@ -0,0 +1,62 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvVoteSet struct { + ChunkHeader *chunk7.ChunkHeader + + ClientId int + Type network7.Vote + Timeout int + Description string + Reason string +} + +func (msg *SvVoteSet) MsgId() int { + return network7.MsgGameSvVoteSet +} + +func (msg *SvVoteSet) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvVoteSet) System() bool { + return false +} + +func (msg *SvVoteSet) Vital() bool { + return true +} + +func (msg *SvVoteSet) Pack() []byte { + return slices.Concat( + packer.PackInt(msg.ClientId), + packer.PackInt(int(msg.Type)), + packer.PackInt(msg.Timeout), + packer.PackStr(msg.Description), + packer.PackStr(msg.Reason), + ) +} + +func (msg *SvVoteSet) Unpack(u *packer.Unpacker) error { + msg.ClientId = u.GetInt() + msg.Type = network7.Vote(u.GetInt()) + msg.Timeout = u.GetInt() + msg.Description = u.GetString() + msg.Reason = u.GetString() + return nil +} + +func (msg *SvVoteSet) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvVoteSet) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_vote_status.go b/messages7/sv_vote_status.go new file mode 100644 index 0000000..6c8f463 --- /dev/null +++ b/messages7/sv_vote_status.go @@ -0,0 +1,60 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvVoteStatus struct { + ChunkHeader *chunk7.ChunkHeader + + Yes int + No int + Pass int + Total int +} + +func (msg *SvVoteStatus) MsgId() int { + return network7.MsgGameSvVoteStatus +} + +func (msg *SvVoteStatus) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvVoteStatus) System() bool { + return false +} + +func (msg *SvVoteStatus) Vital() bool { + return true +} + +func (msg *SvVoteStatus) Pack() []byte { + return slices.Concat( + packer.PackInt(msg.Yes), + packer.PackInt(msg.No), + packer.PackInt(msg.Pass), + packer.PackInt(msg.Total), + ) +} + +func (msg *SvVoteStatus) Unpack(u *packer.Unpacker) error { + msg.Yes = u.GetInt() + msg.No = u.GetInt() + msg.Pass = u.GetInt() + msg.Total = u.GetInt() + + return nil +} + +func (msg *SvVoteStatus) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvVoteStatus) StatusHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/messages7/sv_weapon_pickup.go b/messages7/sv_weapon_pickup.go new file mode 100644 index 0000000..9ac3b15 --- /dev/null +++ b/messages7/sv_weapon_pickup.go @@ -0,0 +1,51 @@ +package messages7 + +import ( + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/chunk7" + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SvWeaponPickup struct { + ChunkHeader *chunk7.ChunkHeader + + Weapon network7.Weapon +} + +func (msg *SvWeaponPickup) MsgId() int { + return network7.MsgGameSvWeaponPickup +} + +func (msg *SvWeaponPickup) MsgType() network7.MsgType { + return network7.TypeNet +} + +func (msg *SvWeaponPickup) System() bool { + return false +} + +func (msg *SvWeaponPickup) Vital() bool { + return true +} + +func (msg *SvWeaponPickup) Pack() []byte { + return slices.Concat( + packer.PackInt(int(msg.Weapon)), + ) +} + +func (msg *SvWeaponPickup) Unpack(u *packer.Unpacker) error { + msg.Weapon = network7.Weapon(u.GetInt()) + + return nil +} + +func (msg *SvWeaponPickup) Header() *chunk7.ChunkHeader { + return msg.ChunkHeader +} + +func (msg *SvWeaponPickup) SetHeader(header *chunk7.ChunkHeader) { + msg.ChunkHeader = header +} diff --git a/network7/network7.go b/network7/network7.go index ad45bcc..7b4cc6c 100644 --- a/network7/network7.go +++ b/network7/network7.go @@ -13,6 +13,40 @@ const ( TeamRed GameTeam = 0 TeamBlue GameTeam = 1 + VoteUnknown Vote = 0 + VoteStartOp Vote = 1 + VoteStartKick Vote = 2 + VoteStartSpec Vote = 3 + VoteEndAbort Vote = 4 + VoteEndPass Vote = 5 + VoteEndFail Vote = 6 + + // oop! + EmoteOop Emote = 0 + // ! + EmoteExclamation Emote = 1 + EmoteHearts Emote = 2 + // tear + EmoteDrop Emote = 3 + // ... + EmoteDotdot Emote = 4 + EmoteMusic Emote = 5 + EmoteSorry Emote = 6 + EmoteGhost Emote = 7 + // annoyed + EmoteSushi Emote = 8 + // angry + EmoteSplattee Emote = 9 + EmoteDeviltee Emote = 10 + // swearing + EmoteZomg Emote = 11 + EmoteZzz Emote = 12 + EmoteWtf Emote = 13 + // happy + EmoteEyes Emote = 14 + // ?? + EmoteQuestion Emote = 15 + MsgCtrlKeepAlive = 0x00 MsgCtrlConnect = 0x01 MsgCtrlAccept = 0x02 @@ -59,14 +93,14 @@ const ( MsgGameSvTeam = 4 MsgGameSvKillMsg = 5 MsgGameSvTuneParams = 6 - MsgGameSvExtraProjectile = 7 - MsgGameReadyToEnter = 8 - MsgGameWeaponPickup = 9 - MsgGameEmoticon = 10 - MsgGameSvVoteClearoptions = 11 - MsgGameSvVoteOptionlistadd = 12 - MsgGameSvVotePptionadd = 13 - MsgGameSvVoteOptionremove = 14 + MsgGameSvExtraProjectile = 7 // unused + MsgGameSvReadyToEnter = 8 + MsgGameSvWeaponPickup = 9 + MsgGameSvEmoticon = 10 + MsgGameSvVoteClearOptions = 11 + MsgGameSvVoteOptionListAdd = 12 + MsgGameSvVoteOptionAdd = 13 + MsgGameSvVoteOptionRemove = 14 MsgGameSvVoteSet = 15 MsgGameSvVoteStatus = 16 MsgGameSvServerSettings = 17 @@ -97,6 +131,13 @@ const ( TypeNet MsgType = 2 TypeConnless MsgType = 3 + // can be sent by the server in kill messages + WeaponGame Weapon = -3 + WeaponSelf Weapon = -2 + WeaponWorld Weapon = -1 + + // can be sent by the client when requesting weapon switch + // or by the server in kill messages WeaponHammer Weapon = 0 WeaponGun Weapon = 1 WeaponShotgun Weapon = 2 @@ -106,7 +147,10 @@ const ( NumWeapons Weapon = 6 ) +type Vote int +type Emote int type ChatMode int type GameTeam int -type MsgType int type Weapon int + +type MsgType int diff --git a/protocol7/packet.go b/protocol7/packet.go index d83ce84..efafbb4 100644 --- a/protocol7/packet.go +++ b/protocol7/packet.go @@ -171,8 +171,8 @@ func (packet *Packet) unpackGame(msgId int, chunk chunk7.Chunk, u *packer.Unpack var msg messages7.NetMessage switch msgId { - case network7.MsgGameReadyToEnter: - msg = &messages7.ReadyToEnter{} + case network7.MsgGameSvReadyToEnter: + msg = &messages7.SvReadyToEnter{} case network7.MsgGameSvMotd: msg = &messages7.SvMotd{} case network7.MsgGameSvChat: diff --git a/teeworlds7/callbacks.go b/teeworlds7/callbacks.go index 6cc45cc..6d2f44b 100644 --- a/teeworlds7/callbacks.go +++ b/teeworlds7/callbacks.go @@ -64,9 +64,9 @@ type UserMsgCallbacks struct { // GameSvKillMsg func(*messages7.SvKillMsg, DefaultAction) // GameSvTuneParams func(*messages7.SvTuneParams, DefaultAction) // GameSvExtraProjectile func(*messages7.SvExtraProjectile, DefaultAction) - GameReadyToEnter func(*messages7.ReadyToEnter, DefaultAction) - // GameWeaponPickup func(*messages7.WeaponPickup, DefaultAction) - // GameEmoticon func(*messages7.Emoticon, DefaultAction) + GameReadyToEnter func(*messages7.SvReadyToEnter, DefaultAction) + // GameWeaponPickup func(*messages7.SvWeaponPickup, DefaultAction) + // GameEmoticon func(*messages7.SvEmoticon, DefaultAction) // GameSvVoteClearoptions func(*messages7.SvVoteClearoptions, DefaultAction) // GameSvVoteOptionlistadd func(*messages7.SvVoteOptionlistadd, DefaultAction) // GameSvVotePptionadd func(*messages7.SvVotePptionadd, DefaultAction) diff --git a/teeworlds7/game.go b/teeworlds7/game.go index cb01979..bda4005 100644 --- a/teeworlds7/game.go +++ b/teeworlds7/game.go @@ -54,7 +54,7 @@ func (client *Client) processGame(netMsg messages7.NetMessage, response *protoco } else { client.Callbacks.GameSvClientInfo(msg, defaultAction) } - case *messages7.ReadyToEnter: + case *messages7.SvReadyToEnter: defaultAction := func() { fmt.Println("got ready to enter") response.Messages = append(response.Messages, &messages7.EnterGame{})