Skip to content

Update to v0.7 spec #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 38 additions & 93 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"net"
"os"
"strconv"

flat "github.com/RLBot/go-interface/flat"
flatbuffers "github.com/google/flatbuffers/go"
Expand Down Expand Up @@ -41,11 +40,6 @@ func (conn RLBotConnection) Initialize(default_agent_id string, wants_ball_predi
return nil, nil, nil, err
}

err = conn.SendPacket(&flat.InitCompleteT{})
if err != nil {
return nil, nil, nil, err
}

var match_config *flat.MatchConfigurationT
var field_info *flat.FieldInfoT
var controllables *flat.ControllableTeamInfoT
Expand All @@ -56,7 +50,7 @@ func (conn RLBotConnection) Initialize(default_agent_id string, wants_ball_predi
return nil, nil, nil, err
}

switch packet := packet.(type) {
switch packet := packet.Value.(type) {
case *flat.MatchConfigurationT:
match_config = packet
case *flat.FieldInfoT:
Expand All @@ -70,102 +64,72 @@ func (conn RLBotConnection) Initialize(default_agent_id string, wants_ball_predi
}
}

return match_config, field_info, controllables, nil
}
err = conn.SendPacket(&flat.InitCompleteT{})
if err != nil {
return nil, nil, nil, err
}

type PacketAbilities interface {
Pack(builder *flatbuffers.Builder) flatbuffers.UOffsetT
return match_config, field_info, controllables, nil
}

func (conn RLBotConnection) SendPacket(packet_obj PacketAbilities) error {
var packetPayload []byte
var packetType uint16

conn.builder.Reset()
func (conn RLBotConnection) SendPacket(msg any) error {
var packetType flat.InterfaceMessage

switch v := packet_obj.(type) {
case nil:
packetPayload = []byte{0}
packetType = 0
switch msg.(type) {
case *flat.StartCommandT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 3
packetType = flat.InterfaceMessageStartCommand
case *flat.MatchConfigurationT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 4
packetType = flat.InterfaceMessageMatchConfiguration
case *flat.PlayerInputT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 5
packetType = flat.InterfaceMessagePlayerInput
case *flat.DesiredGameStateT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 6
packetType = flat.InterfaceMessageDesiredGameState
case *flat.RenderGroupT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 7
packetType = flat.InterfaceMessageRenderGroup
case *flat.RemoveRenderGroupT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 8
packetType = flat.InterfaceMessageRemoveRenderGroup
case *flat.MatchCommT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 9
packetType = flat.InterfaceMessageMatchComm
case *flat.ConnectionSettingsT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 11
packetType = flat.InterfaceMessageConnectionSettings
case *flat.StopCommandT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 12
packetType = flat.InterfaceMessageStopCommand
case *flat.SetLoadoutT:
conn.builder.Finish(v.Pack(&conn.builder))
packetPayload = conn.builder.FinishedBytes()
packetType = 13
packetType = flat.InterfaceMessageSetLoadout
case *flat.InitCompleteT:
packetPayload = []byte{0}
packetType = 14
packetType = flat.InterfaceMessageInitComplete
case *flat.RenderingStatusT:
packetType = flat.InterfaceMessageRenderingStatus
default:
return errors.New("unsupported packet type")
}

finalBuf := []byte{}
packet := flat.InterfacePacketT{
Message: &flat.InterfaceMessageT{
Type: packetType,
Value: msg,
},
}

tempBuf := make([]byte, 2)
binary.BigEndian.PutUint16(tempBuf, packetType)
finalBuf = append(finalBuf, tempBuf...)
conn.builder.Reset()
conn.builder.Finish(packet.Pack(&conn.builder))
packetPayload := conn.builder.FinishedBytes()

tempBuf = make([]byte, 2)
binary.BigEndian.PutUint16(tempBuf, uint16(len(packetPayload)))
finalBuf = append(finalBuf, tempBuf...)
packetLen := len(packetPayload)
finalBuf := make([]byte, 2)

binary.BigEndian.PutUint16(finalBuf, uint16(packetLen))
finalBuf = append(finalBuf, packetPayload...)

_, err := conn.conn.Write(finalBuf)
if err != nil {
return err
}

return nil
return err
}

func (conn RLBotConnection) RecvPacket() (PacketAbilities, error) {
func (conn RLBotConnection) RecvPacket() (*flat.CoreMessageT, error) {
buffer := make([]byte, 2)

// Read packetType
_, err := io.ReadFull(conn.conn, buffer)
if err != nil {
return nil, err
}
packetType := binary.BigEndian.Uint16(buffer)

// Read packetLen
_, err = io.ReadFull(conn.conn, buffer)
_, err := io.ReadFull(conn.conn, buffer)
if err != nil {
return nil, err
}
Expand All @@ -178,24 +142,5 @@ func (conn RLBotConnection) RecvPacket() (PacketAbilities, error) {
return nil, err
}

switch packetType {
case 0:
return nil, nil
case 1: //flat.GamePacketT:
return flat.GetRootAsGamePacket(buffer, 0).UnPack(), nil
case 2: //flat.FieldInfoT:
return flat.GetRootAsFieldInfo(buffer, 0).UnPack(), nil
case 4: //flat.MatchConfigurationT:
return flat.GetRootAsMatchConfiguration(buffer, 0).UnPack(), nil
case 5: //flat.PlayerInputT:
return flat.GetRootAsPlayerInput(buffer, 0).UnPack(), nil
case 9: //flat.MatchCommT:
return flat.GetRootAsMatchComm(buffer, 0).UnPack(), nil
case 10: //flat.BallPredictionT:
return flat.GetRootAsBallPrediction(buffer, 0).UnPack(), nil
case 15: //flat.ControllableTeamInfoT:
return flat.GetRootAsControllableTeamInfo(buffer, 0).UnPack(), nil
default:
return nil, errors.New("unknown packet type: " + strconv.Itoa(int(packetType)))
}
return flat.GetRootAsCorePacket(buffer, 0).UnPack().Message, nil
}
8 changes: 4 additions & 4 deletions examples/atba/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func main() {

team := controllables.Team
index := controllables.Controllables[0].Index
spawnId := controllables.Controllables[0].SpawnId
playerId := controllables.Controllables[0].Identifier

var name string
for _, player := range match_config.PlayerConfigurations {
if player.SpawnId == spawnId {
name = player.Name
if player.PlayerId == playerId {
name = player.Variety.Value.(*RLBotFlat.CustomBotT).Name
break
}
}
Expand All @@ -56,7 +56,7 @@ func main() {
if err != nil {
panic(err)
}
gameTickPacket, ok := packet.(*RLBotFlat.GamePacketT)
gameTickPacket, ok := packet.Value.(*RLBotFlat.GamePacketT)
if !ok { // if not gametickpacket
continue
}
Expand Down
19 changes: 9 additions & 10 deletions examples/start_match/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,29 @@ func main() {
PlayerConfigurations: []*RLBotFlat.PlayerConfigurationT{{
Variety: &RLBotFlat.PlayerClassT{
Type: RLBotFlat.PlayerClassCustomBot,
Value: &RLBotFlat.CustomBotT{},
Value: &RLBotFlat.CustomBotT{
RootDir: dir + "/examples/atba",
RunCommand: "go run main.go",
AgentId: "rlbot/go-example-bot",
Name: "Go Example",
Loadout: &RLBotFlat.PlayerLoadoutT{},
},
},
RootDir: dir + "/examples/atba",
RunCommand: "go run main.go",
AgentId: "rlbot/go-example-bot",
Name: "Go Example",
Team: 0,
Loadout: &RLBotFlat.PlayerLoadoutT{},
}, {
Variety: &RLBotFlat.PlayerClassT{
Type: RLBotFlat.PlayerClassHuman,
Value: &RLBotFlat.HumanT{},
},
Name: "",
Team: 1,
Loadout: &RLBotFlat.PlayerLoadoutT{},
}},
GameMode: RLBotFlat.GameModeSoccer,
GameMode: RLBotFlat.GameModeSoccar,
GameMapUpk: "UtopiaStadium_P",
Mutators: &RLBotFlat.MutatorSettingsT{
MatchLength: RLBotFlat.MatchLengthMutatorUnlimited,
},
ExistingMatchBehavior: RLBotFlat.ExistingMatchBehaviorRestart,
EnableRendering: true,
EnableRendering: RLBotFlat.DebugRenderingAlwaysOff,
AutoStartAgents: true,
WaitForAgents: true,
})
Expand Down
9 changes: 0 additions & 9 deletions flat/extras.go

This file was deleted.

26 changes: 13 additions & 13 deletions flat/generated_ControllableInfo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading