From 141865538f70237c7729289bde73e64b11c30289 Mon Sep 17 00:00:00 2001 From: ChillerDragon Date: Mon, 24 Jun 2024 22:50:15 +0800 Subject: [PATCH] Finish adding all 0.7 snap items that are actually sent --- network7/network7.go | 6 +++ object7/character.go | 4 +- object7/damage.go | 64 ++++++++++++++++++++++++++++++++ object7/death.go | 48 ++++++++++++++++++++++++ object7/explosion.go | 45 +++++++++++++++++++++++ object7/flag.go | 4 +- object7/game_data.go | 4 +- object7/game_data_flag.go | 4 +- object7/game_data_race.go | 56 ++++++++++++++++++++++++++++ object7/game_data_team.go | 4 +- object7/hammer_hit.go | 45 +++++++++++++++++++++++ object7/laser.go | 54 +++++++++++++++++++++++++++ object7/pickup.go | 14 +++---- object7/player_info.go | 4 +- object7/player_info_race.go | 50 +++++++++++++++++++++++++ object7/player_input.go | 73 +++++++++++++++++++++++++++++++++++++ object7/projectile.go | 57 +++++++++++++++++++++++++++++ object7/snap_object.go | 45 +++++++++++++++++------ object7/sound_world.go | 48 ++++++++++++++++++++++++ object7/spawn.go | 45 +++++++++++++++++++++++ object7/spectator_info.go | 51 ++++++++++++++++++++++++++ object7/unknown.go | 4 +- 22 files changed, 697 insertions(+), 32 deletions(-) create mode 100644 object7/damage.go create mode 100644 object7/death.go create mode 100644 object7/explosion.go create mode 100644 object7/game_data_race.go create mode 100644 object7/hammer_hit.go create mode 100644 object7/laser.go create mode 100644 object7/player_info_race.go create mode 100644 object7/player_input.go create mode 100644 object7/projectile.go create mode 100644 object7/sound_world.go create mode 100644 object7/spawn.go create mode 100644 object7/spectator_info.go diff --git a/network7/network7.go b/network7/network7.go index 7920974..ce5477e 100644 --- a/network7/network7.go +++ b/network7/network7.go @@ -13,6 +13,11 @@ const ( TeamRed GameTeam = 0 TeamBlue GameTeam = 1 + SpecFreeview Spec = 0 + SpecPlayer Spec = 1 + SpecFlagred Spec = 2 + SpecFlagblue Spec = 3 + VoteUnknown Vote = 0 VoteStartOp Vote = 1 VoteStartKick Vote = 2 @@ -191,6 +196,7 @@ const ( ) type GameStateFlag int +type Spec int type Vote int type Pickup int type Emote int diff --git a/object7/character.go b/object7/character.go index b952b2a..2b90cf5 100644 --- a/object7/character.go +++ b/object7/character.go @@ -39,7 +39,7 @@ func (o *Character) Id() int { return o.ItemId } -func (o *Character) Type() int { +func (o *Character) TypeId() int { return network7.ObjCharacter } @@ -49,7 +49,7 @@ func (o *Character) Size() int { func (o *Character) Pack() []byte { return slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.Tick), diff --git a/object7/damage.go b/object7/damage.go new file mode 100644 index 0000000..a3aaad3 --- /dev/null +++ b/object7/damage.go @@ -0,0 +1,64 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +// damage indicicator +// displayed as yellow stars around the tee receiving damage +type Damage struct { + ItemId int + + X int + Y int + // affected player receiving damage + ClientId int + Angle int + HealthAmount int + ArmorAmount int + // true if the damage receiver the damage dealer + Self bool +} + +func (o *Damage) Id() int { + return o.ItemId +} + +func (o *Damage) TypeId() int { + return network7.ObjDamage +} + +func (o *Damage) Size() int { + return reflect.TypeOf(Damage{}).NumField() - 1 +} + +func (o *Damage) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + packer.PackInt(o.ClientId), + packer.PackInt(o.Angle), + packer.PackInt(o.HealthAmount), + packer.PackInt(o.ArmorAmount), + packer.PackBool(o.Self), + ) +} + +func (o *Damage) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + o.ClientId = u.GetInt() + o.Angle = u.GetInt() + o.HealthAmount = u.GetInt() + o.ArmorAmount = u.GetInt() + o.Self = u.GetInt() != 0 + + return nil +} diff --git a/object7/death.go b/object7/death.go new file mode 100644 index 0000000..de01692 --- /dev/null +++ b/object7/death.go @@ -0,0 +1,48 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type Death struct { + ItemId int + + X int + Y int + ClientId int +} + +func (o *Death) Id() int { + return o.ItemId +} + +func (o *Death) TypeId() int { + return network7.ObjDeath +} + +func (o *Death) Size() int { + return reflect.TypeOf(Death{}).NumField() - 1 +} + +func (o *Death) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + packer.PackInt(o.ClientId), + ) +} + +func (o *Death) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + o.ClientId = u.GetInt() + + return nil +} diff --git a/object7/explosion.go b/object7/explosion.go new file mode 100644 index 0000000..931628c --- /dev/null +++ b/object7/explosion.go @@ -0,0 +1,45 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type Explosion struct { + ItemId int + + X int + Y int +} + +func (o *Explosion) Id() int { + return o.ItemId +} + +func (o *Explosion) TypeId() int { + return network7.ObjExplosion +} + +func (o *Explosion) Size() int { + return reflect.TypeOf(Explosion{}).NumField() - 1 +} + +func (o *Explosion) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + ) +} + +func (o *Explosion) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + + return nil +} diff --git a/object7/flag.go b/object7/flag.go index 22af572..68b4fa9 100644 --- a/object7/flag.go +++ b/object7/flag.go @@ -20,7 +20,7 @@ func (o *Flag) Id() int { return o.ItemId } -func (o *Flag) Type() int { +func (o *Flag) TypeId() int { return network7.ObjFlag } @@ -30,7 +30,7 @@ func (o *Flag) Size() int { func (o *Flag) Pack() []byte { return slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.X), diff --git a/object7/game_data.go b/object7/game_data.go index 0f93fe4..d89f89b 100644 --- a/object7/game_data.go +++ b/object7/game_data.go @@ -25,7 +25,7 @@ func (o *GameData) Id() int { return o.ItemId } -func (o *GameData) Type() int { +func (o *GameData) TypeId() int { return network7.ObjGameData } @@ -35,7 +35,7 @@ func (o *GameData) Size() int { func (o *GameData) Pack() []byte { return slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.GameStartTick), diff --git a/object7/game_data_flag.go b/object7/game_data_flag.go index c9964f4..09e3ef7 100644 --- a/object7/game_data_flag.go +++ b/object7/game_data_flag.go @@ -33,7 +33,7 @@ func (o *GameDataFlag) Id() int { return o.ItemId } -func (o *GameDataFlag) Type() int { +func (o *GameDataFlag) TypeId() int { return network7.ObjGameDataFlag } @@ -43,7 +43,7 @@ func (o *GameDataFlag) Size() int { func (o *GameDataFlag) Pack() []byte { return slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.FlagCarrierRed), diff --git a/object7/game_data_race.go b/object7/game_data_race.go new file mode 100644 index 0000000..c5db474 --- /dev/null +++ b/object7/game_data_race.go @@ -0,0 +1,56 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +// this is a new snap item that was added after the 0.7 release +// so for backwards compability it includes a size field +// and older clients ignore it +// +// this message is not used by official servers +// and is part of an effort to support community made race modifications +type GameDataRace struct { + ItemId int + + BestTime int + Precision int + RaceFlags int +} + +func (o *GameDataRace) Id() int { + return o.ItemId +} + +func (o *GameDataRace) TypeId() int { + return network7.ObjGameDataRace +} + +func (o *GameDataRace) Size() int { + // TODO: is this correct? is this just payload size or does it contain the size field as well? + return reflect.TypeOf(GameDataRace{}).NumField() - 1 +} + +func (o *GameDataRace) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + packer.PackInt(o.Size()), + + packer.PackInt(o.BestTime), + packer.PackInt(o.Precision), + packer.PackInt(o.RaceFlags), + ) +} + +func (o *GameDataRace) Unpack(u *packer.Unpacker) error { + o.BestTime = u.GetInt() + o.Precision = u.GetInt() + o.RaceFlags = u.GetInt() + + return nil +} diff --git a/object7/game_data_team.go b/object7/game_data_team.go index c249ed2..393cee3 100644 --- a/object7/game_data_team.go +++ b/object7/game_data_team.go @@ -19,7 +19,7 @@ func (o *GameDataTeam) Id() int { return o.ItemId } -func (o *GameDataTeam) Type() int { +func (o *GameDataTeam) TypeId() int { return network7.ObjGameDataTeam } @@ -29,7 +29,7 @@ func (o *GameDataTeam) Size() int { func (o *GameDataTeam) Pack() []byte { return slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.TeamscoreRed), diff --git a/object7/hammer_hit.go b/object7/hammer_hit.go new file mode 100644 index 0000000..175bd4e --- /dev/null +++ b/object7/hammer_hit.go @@ -0,0 +1,45 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type HammerHit struct { + ItemId int + + X int + Y int +} + +func (o *HammerHit) Id() int { + return o.ItemId +} + +func (o *HammerHit) TypeId() int { + return network7.ObjHammerHit +} + +func (o *HammerHit) Size() int { + return reflect.TypeOf(HammerHit{}).NumField() - 1 +} + +func (o *HammerHit) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + ) +} + +func (o *HammerHit) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + + return nil +} diff --git a/object7/laser.go b/object7/laser.go new file mode 100644 index 0000000..44e41bd --- /dev/null +++ b/object7/laser.go @@ -0,0 +1,54 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type Laser struct { + ItemId int + + X int + Y int + FromX int + FromY int + StartTick int +} + +func (o *Laser) Id() int { + return o.ItemId +} + +func (o *Laser) TypeId() int { + return network7.ObjLaser +} + +func (o *Laser) Size() int { + return reflect.TypeOf(Laser{}).NumField() - 1 +} + +func (o *Laser) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + packer.PackInt(o.FromX), + packer.PackInt(o.FromY), + packer.PackInt(o.StartTick), + ) +} + +func (o *Laser) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + o.FromX = u.GetInt() + o.FromY = u.GetInt() + o.StartTick = u.GetInt() + + return nil +} diff --git a/object7/pickup.go b/object7/pickup.go index 1b84f46..ae41cb7 100644 --- a/object7/pickup.go +++ b/object7/pickup.go @@ -11,16 +11,16 @@ import ( type Pickup struct { ItemId int - X int - Y int - PickupType network7.Pickup + X int + Y int + Type network7.Pickup } func (o *Pickup) Id() int { return o.ItemId } -func (o *Pickup) Type() int { +func (o *Pickup) TypeId() int { return network7.ObjPickup } @@ -30,19 +30,19 @@ func (o *Pickup) Size() int { func (o *Pickup) Pack() []byte { return slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.X), packer.PackInt(o.Y), - packer.PackInt(int(o.PickupType)), + packer.PackInt(int(o.Type)), ) } func (o *Pickup) Unpack(u *packer.Unpacker) error { o.X = u.GetInt() o.Y = u.GetInt() - o.PickupType = network7.Pickup(u.GetInt()) + o.Type = network7.Pickup(u.GetInt()) return nil } diff --git a/object7/player_info.go b/object7/player_info.go index d596988..fe2c526 100644 --- a/object7/player_info.go +++ b/object7/player_info.go @@ -21,7 +21,7 @@ func (o *PlayerInfo) Id() int { return o.ItemId } -func (o *PlayerInfo) Type() int { +func (o *PlayerInfo) TypeId() int { return network7.ObjPlayerInfo } @@ -31,7 +31,7 @@ func (o *PlayerInfo) Size() int { func (o *PlayerInfo) Pack() []byte { return slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.PlayerFlags), diff --git a/object7/player_info_race.go b/object7/player_info_race.go new file mode 100644 index 0000000..7c081dd --- /dev/null +++ b/object7/player_info_race.go @@ -0,0 +1,50 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +// this is a new snap item that was added after the 0.7 release +// so for backwards compability it includes a size field +// and older clients ignore it +// +// this message is not used by official servers +// and is part of an effort to support community made race modifications +type PlayerInfoRace struct { + ItemId int + + RaceStartTick int +} + +func (o *PlayerInfoRace) Id() int { + return o.ItemId +} + +func (o *PlayerInfoRace) TypeId() int { + return network7.ObjPlayerInfoRace +} + +func (o *PlayerInfoRace) Size() int { + // TODO: is this correct? is this just payload size or does it contain the size field as well? + return reflect.TypeOf(PlayerInfoRace{}).NumField() - 1 +} + +func (o *PlayerInfoRace) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + packer.PackInt(o.Size()), + + packer.PackInt(o.RaceStartTick), + ) +} + +func (o *PlayerInfoRace) Unpack(u *packer.Unpacker) error { + o.RaceStartTick = u.GetInt() + + return nil +} diff --git a/object7/player_input.go b/object7/player_input.go new file mode 100644 index 0000000..e1291b4 --- /dev/null +++ b/object7/player_input.go @@ -0,0 +1,73 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +// this object is never included in the snap +// the same order of ints is sent in the system message input +// +// but technically this item is unused +type PlayerInput struct { + ItemId int + + Direction int + TargetX int + TargetY int + Jump int + Fire int + Hook int + PlayerFlags int + WantedWeapon int + NextWeapon int + PrevWeapon int +} + +func (o *PlayerInput) Id() int { + return o.ItemId +} + +func (o *PlayerInput) TypeId() int { + return network7.ObjPlayerInput +} + +func (o *PlayerInput) Size() int { + return reflect.TypeOf(PlayerInput{}).NumField() - 1 +} + +func (o *PlayerInput) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.Direction), + packer.PackInt(o.TargetX), + packer.PackInt(o.TargetY), + packer.PackInt(o.Jump), + packer.PackInt(o.Fire), + packer.PackInt(o.Hook), + packer.PackInt(o.PlayerFlags), + packer.PackInt(o.WantedWeapon), + packer.PackInt(o.NextWeapon), + packer.PackInt(o.PrevWeapon), + ) +} + +func (o *PlayerInput) Unpack(u *packer.Unpacker) error { + o.Direction = u.GetInt() + o.TargetX = u.GetInt() + o.TargetY = u.GetInt() + o.Jump = u.GetInt() + o.Fire = u.GetInt() + o.Hook = u.GetInt() + o.PlayerFlags = u.GetInt() + o.WantedWeapon = u.GetInt() + o.NextWeapon = u.GetInt() + o.PrevWeapon = u.GetInt() + + return nil +} diff --git a/object7/projectile.go b/object7/projectile.go new file mode 100644 index 0000000..37d58d5 --- /dev/null +++ b/object7/projectile.go @@ -0,0 +1,57 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type Projectile struct { + ItemId int + + X int + Y int + VelX int + VelY int + Type int + StartTick int +} + +func (o *Projectile) Id() int { + return o.ItemId +} + +func (o *Projectile) TypeId() int { + return network7.ObjProjectile +} + +func (o *Projectile) Size() int { + return reflect.TypeOf(Projectile{}).NumField() - 1 +} + +func (o *Projectile) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + packer.PackInt(o.VelX), + packer.PackInt(o.VelY), + packer.PackInt(o.Type), + packer.PackInt(o.StartTick), + ) +} + +func (o *Projectile) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + o.VelX = u.GetInt() + o.VelY = u.GetInt() + o.Type = u.GetInt() + o.StartTick = u.GetInt() + + return nil +} diff --git a/object7/snap_object.go b/object7/snap_object.go index 7be5789..72645db 100644 --- a/object7/snap_object.go +++ b/object7/snap_object.go @@ -8,8 +8,13 @@ import ( ) type SnapObject interface { + // id separating this snap item from other items with same type + // the ids are unique per type + // for players it matches their ClientId Id() int - Type() int + + // type of the snap item + TypeId() int // number of packed integers // not the number of bytes @@ -21,29 +26,47 @@ type SnapObject interface { // Comes without payload // you have to call item.Unpack(u) manually after getting it -func NewObject(itemType int, itemId int) SnapObject { - if itemType == network7.ObjFlag { +func NewObject(typeId int, itemId int) SnapObject { + if typeId == network7.ObjProjectile { + return &Projectile{ItemId: itemId} + } else if typeId == network7.ObjLaser { + return &Laser{ItemId: itemId} + } else if typeId == network7.ObjFlag { return &Flag{ItemId: itemId} - } else if itemType == network7.ObjPickup { + } else if typeId == network7.ObjPickup { return &Pickup{ItemId: itemId} - } else if itemType == network7.ObjGameData { + } else if typeId == network7.ObjGameData { return &GameData{ItemId: itemId} - } else if itemType == network7.ObjGameDataTeam { + } else if typeId == network7.ObjGameDataTeam { return &GameDataTeam{ItemId: itemId} - } else if itemType == network7.ObjGameDataFlag { + } else if typeId == network7.ObjGameDataFlag { return &GameDataFlag{ItemId: itemId} - } else if itemType == network7.ObjCharacter { + } else if typeId == network7.ObjCharacter { return &Character{ItemId: itemId} - } else if itemType == network7.ObjPlayerInfo { + } else if typeId == network7.ObjPlayerInfo { return &PlayerInfo{ItemId: itemId} + } else if typeId == network7.ObjSpectatorInfo { + return &SpectatorInfo{ItemId: itemId} + } else if typeId == network7.ObjExplosion { + return &Explosion{ItemId: itemId} + } else if typeId == network7.ObjSpawn { + return &Spawn{ItemId: itemId} + } else if typeId == network7.ObjHammerHit { + return &HammerHit{ItemId: itemId} + } else if typeId == network7.ObjDeath { + return &Death{ItemId: itemId} + } else if typeId == network7.ObjSoundWorld { + return &SoundWorld{ItemId: itemId} + } else if typeId == network7.ObjDamage { + return &Damage{ItemId: itemId} } // TODO: remove this is just for debugging - log.Fatalf("unknown item type %d\n", itemType) + log.Fatalf("unknown item type %d\n", typeId) unknown := &Unknown{ ItemId: itemId, - ItemType: itemType, + ItemType: typeId, } return unknown } diff --git a/object7/sound_world.go b/object7/sound_world.go new file mode 100644 index 0000000..409eb72 --- /dev/null +++ b/object7/sound_world.go @@ -0,0 +1,48 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SoundWorld struct { + ItemId int + + X int + Y int + SoundId int +} + +func (o *SoundWorld) Id() int { + return o.ItemId +} + +func (o *SoundWorld) TypeId() int { + return network7.ObjSoundWorld +} + +func (o *SoundWorld) Size() int { + return reflect.TypeOf(SoundWorld{}).NumField() - 1 +} + +func (o *SoundWorld) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + packer.PackInt(o.SoundId), + ) +} + +func (o *SoundWorld) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + o.SoundId = u.GetInt() + + return nil +} diff --git a/object7/spawn.go b/object7/spawn.go new file mode 100644 index 0000000..fe62735 --- /dev/null +++ b/object7/spawn.go @@ -0,0 +1,45 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type Spawn struct { + ItemId int + + X int + Y int +} + +func (o *Spawn) Id() int { + return o.ItemId +} + +func (o *Spawn) TypeId() int { + return network7.ObjSpawn +} + +func (o *Spawn) Size() int { + return reflect.TypeOf(Spawn{}).NumField() - 1 +} + +func (o *Spawn) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(o.X), + packer.PackInt(o.Y), + ) +} + +func (o *Spawn) Unpack(u *packer.Unpacker) error { + o.X = u.GetInt() + o.Y = u.GetInt() + + return nil +} diff --git a/object7/spectator_info.go b/object7/spectator_info.go new file mode 100644 index 0000000..63ed3ef --- /dev/null +++ b/object7/spectator_info.go @@ -0,0 +1,51 @@ +package object7 + +import ( + "reflect" + "slices" + + "github.com/teeworlds-go/go-teeworlds-protocol/network7" + "github.com/teeworlds-go/go-teeworlds-protocol/packer" +) + +type SpectatorInfo struct { + ItemId int + + SpecMode network7.Spec + SpectatorID int + X int + Y int +} + +func (o *SpectatorInfo) Id() int { + return o.ItemId +} + +func (o *SpectatorInfo) TypeId() int { + return network7.ObjSpectatorInfo +} + +func (o *SpectatorInfo) Size() int { + return reflect.TypeOf(SpectatorInfo{}).NumField() - 1 +} + +func (o *SpectatorInfo) Pack() []byte { + return slices.Concat( + packer.PackInt(o.TypeId()), + packer.PackInt(o.Id()), + + packer.PackInt(int(o.SpecMode)), + packer.PackInt(o.SpectatorID), + packer.PackInt(o.X), + packer.PackInt(o.Y), + ) +} + +func (o *SpectatorInfo) Unpack(u *packer.Unpacker) error { + o.SpecMode = network7.Spec(u.GetInt()) + o.SpectatorID = u.GetInt() + o.X = u.GetInt() + o.Y = u.GetInt() + + return nil +} diff --git a/object7/unknown.go b/object7/unknown.go index 3dafeb3..b71db57 100644 --- a/object7/unknown.go +++ b/object7/unknown.go @@ -23,7 +23,7 @@ func (o *Unknown) Id() int { return o.ItemId } -func (o *Unknown) Type() int { +func (o *Unknown) TypeId() int { return o.ItemType } @@ -33,7 +33,7 @@ func (o *Unknown) Size() int { func (o *Unknown) Pack() []byte { data := slices.Concat( - packer.PackInt(o.Type()), + packer.PackInt(o.TypeId()), packer.PackInt(o.Id()), packer.PackInt(o.Size()), )