diff --git a/RLBotCS/Conversion/FlatToCommand.cs b/RLBotCS/Conversion/FlatToCommand.cs index d439ed0..59b067c 100644 --- a/RLBotCS/Conversion/FlatToCommand.cs +++ b/RLBotCS/Conversion/FlatToCommand.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; namespace RLBotCS.Conversion; diff --git a/RLBotCS/Conversion/FlatToModel.cs b/RLBotCS/Conversion/FlatToModel.cs index f4a5edd..e760ea6 100644 --- a/RLBotCS/Conversion/FlatToModel.cs +++ b/RLBotCS/Conversion/FlatToModel.cs @@ -1,7 +1,7 @@ using Bridge.Models.Command; using Bridge.Models.Control; using Bridge.State; -using rlbot.flat; +using RLBot.Flat; using Color = System.Drawing.Color; using LoadoutPaint = Bridge.Models.Command.LoadoutPaint; using Physics = Bridge.Models.Phys.Physics; @@ -66,7 +66,7 @@ internal static RenderAnchor ToRenderAnchor(RenderAnchorT offset, GameState game internal static Color ToColor(ColorT c) => Color.FromArgb(c.A, c.R, c.G, c.B); - internal static Rotator ToRotator(rlbot.flat.Rotator r) => + internal static Rotator ToRotator(RLBot.Flat.Rotator r) => new Rotator(r.Pitch, r.Yaw, r.Roll); internal static Loadout ToLoadout(PlayerLoadoutT l, uint team) diff --git a/RLBotCS/Conversion/GameStateToFlat.cs b/RLBotCS/Conversion/GameStateToFlat.cs index 176b27c..9ca3f0e 100644 --- a/RLBotCS/Conversion/GameStateToFlat.cs +++ b/RLBotCS/Conversion/GameStateToFlat.cs @@ -1,9 +1,9 @@ using Bridge.Models.Message; using Bridge.Packet; using Bridge.State; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Model; -using CollisionShapeUnion = rlbot.flat.CollisionShapeUnion; +using CollisionShapeUnion = RLBot.Flat.CollisionShapeUnion; using MatchPhase = Bridge.Models.Message.MatchPhase; using Rotator = Bridge.Models.Phys.Rotator; using Vector2 = Bridge.Models.Phys.Vector2; @@ -86,17 +86,17 @@ public static GamePacketT ToFlatBuffers(this GameState gameState) balls.Add(new() { Physics = ballPhysics, Shape = collisionShape }); } - rlbot.flat.MatchPhase matchPhase = gameState.MatchPhase switch + RLBot.Flat.MatchPhase matchPhase = gameState.MatchPhase switch { - MatchPhase.Inactive => rlbot.flat.MatchPhase.Inactive, - MatchPhase.Countdown => rlbot.flat.MatchPhase.Countdown, - MatchPhase.Kickoff => rlbot.flat.MatchPhase.Kickoff, - MatchPhase.Active => rlbot.flat.MatchPhase.Active, - MatchPhase.GoalScored => rlbot.flat.MatchPhase.GoalScored, - MatchPhase.Replay => rlbot.flat.MatchPhase.Replay, - MatchPhase.Paused => rlbot.flat.MatchPhase.Paused, - MatchPhase.Ended => rlbot.flat.MatchPhase.Ended, - _ => rlbot.flat.MatchPhase.Inactive, + MatchPhase.Inactive => RLBot.Flat.MatchPhase.Inactive, + MatchPhase.Countdown => RLBot.Flat.MatchPhase.Countdown, + MatchPhase.Kickoff => RLBot.Flat.MatchPhase.Kickoff, + MatchPhase.Active => RLBot.Flat.MatchPhase.Active, + MatchPhase.GoalScored => RLBot.Flat.MatchPhase.GoalScored, + MatchPhase.Replay => RLBot.Flat.MatchPhase.Replay, + MatchPhase.Paused => RLBot.Flat.MatchPhase.Paused, + MatchPhase.Ended => RLBot.Flat.MatchPhase.Ended, + _ => RLBot.Flat.MatchPhase.Inactive, }; MatchInfoT matchInfo = new() @@ -170,7 +170,7 @@ public static GamePacketT ToFlatBuffers(this GameState gameState) Name = car.Name, Team = car.Team, Boost = car.Boost, - SpawnId = car.SpawnId, + PlayerId = car.PlayerId, ScoreInfo = new() { Score = car.ScoreInfo.Score, diff --git a/RLBotCS/Conversion/PsyonixLoadouts.cs b/RLBotCS/Conversion/PsyonixLoadouts.cs index 726bb4e..327529e 100644 --- a/RLBotCS/Conversion/PsyonixLoadouts.cs +++ b/RLBotCS/Conversion/PsyonixLoadouts.cs @@ -1,5 +1,5 @@ using System.Collections.Frozen; -using rlbot.flat; +using RLBot.Flat; namespace RLBotCS.Conversion; diff --git a/RLBotCS/Main.cs b/RLBotCS/Main.cs index b209b32..e74e4ea 100644 --- a/RLBotCS/Main.cs +++ b/RLBotCS/Main.cs @@ -8,7 +8,7 @@ if (args.Length > 0 && args[0] == "--version") { - Console.WriteLine("RLBotServer v5.beta.6.10"); + Console.WriteLine("RLBotServer v5.beta.7.0"); Environment.Exit(0); } diff --git a/RLBotCS/ManagerTools/AgentMapping.cs b/RLBotCS/ManagerTools/AgentMapping.cs index 1e71137..7cc860b 100644 --- a/RLBotCS/ManagerTools/AgentMapping.cs +++ b/RLBotCS/ManagerTools/AgentMapping.cs @@ -1,4 +1,4 @@ -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Model; namespace RLBotCS.ManagerTools; @@ -6,7 +6,7 @@ namespace RLBotCS.ManagerTools; public struct PlayerIdPair { public uint Index; - public int SpawnId; + public int PlayerId; } public class AgentMapping @@ -38,7 +38,7 @@ public void SetAgents(MatchConfigurationT matchConfig) playerConfig.Team, playerConfig.Name, playerConfig.AgentId, - playerConfig.SpawnId + playerConfig.PlayerId ) ); } @@ -53,7 +53,7 @@ public void SetAgents(MatchConfigurationT matchConfig) Team.Scripts, scriptConfig.Name, scriptConfig.AgentId, - scriptConfig.SpawnId + scriptConfig.ScriptId ) ); } @@ -69,7 +69,7 @@ public void SetAgents(MatchConfigurationT matchConfig) player.SetClient(clientId); return ( - new PlayerIdPair { Index = player.Index, SpawnId = player.SpawnId }, + new PlayerIdPair { Index = player.Index, PlayerId = player.PlayerId }, player.Team ); } @@ -99,7 +99,7 @@ public void SetAgents(MatchConfigurationT matchConfig) new PlayerIdPair { Index = playerMetadata.Index, - SpawnId = playerMetadata.SpawnId, + PlayerId = playerMetadata.PlayerId, } ); } diff --git a/RLBotCS/ManagerTools/BallPredictor.cs b/RLBotCS/ManagerTools/BallPredictor.cs index 7677d66..ebb66b5 100644 --- a/RLBotCS/ManagerTools/BallPredictor.cs +++ b/RLBotCS/ManagerTools/BallPredictor.cs @@ -1,5 +1,5 @@ using System.Runtime.InteropServices; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Model; namespace RLBotCS.ManagerTools; diff --git a/RLBotCS/ManagerTools/ConfigParser.cs b/RLBotCS/ManagerTools/ConfigParser.cs index a5df60d..4c2dbcf 100644 --- a/RLBotCS/ManagerTools/ConfigParser.cs +++ b/RLBotCS/ManagerTools/ConfigParser.cs @@ -1,7 +1,6 @@ using System.Diagnostics; -using System.Runtime.InteropServices; using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Model; using Tomlyn; using Tomlyn.Model; @@ -346,7 +345,7 @@ private PlayerConfigurationT ParseCarTable(TomlTable table, string matchConfigPa Hivemind = false, RootDir = "", RunCommand = "", - SpawnId = 0, + PlayerId = 0, }; } @@ -409,7 +408,7 @@ private PlayerConfigurationT LoadPlayerConfig( RunCommand = GetRunCommand(settings), Hivemind = GetValue(settings, Fields.AgentHivemind, false), RootDir = rootDir, - SpawnId = 0, + PlayerId = 0, Variety = variety, }; } diff --git a/RLBotCS/ManagerTools/ConfigValidator.cs b/RLBotCS/ManagerTools/ConfigValidator.cs index 193b485..bb54c9a 100644 --- a/RLBotCS/ManagerTools/ConfigValidator.cs +++ b/RLBotCS/ManagerTools/ConfigValidator.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; using RLBotCS.Model; @@ -161,7 +161,7 @@ List players break; } - player.SpawnId = + player.PlayerId = player.Variety.Type == PlayerClass.Human ? 0 : $"{player.AgentId}/{player.Team}/{i}".GetHashCode(); @@ -209,7 +209,7 @@ List scripts script.Name ??= ""; script.RunCommand ??= ""; script.RootDir ??= ""; - script.SpawnId = $"{script.AgentId}/{Team.Scripts}/{i}".GetHashCode(); + script.ScriptId = $"{script.AgentId}/{Team.Scripts}/{i}".GetHashCode(); } return valid; diff --git a/RLBotCS/ManagerTools/LaunchManager.cs b/RLBotCS/ManagerTools/LaunchManager.cs index 4bcf08b..b0dc231 100644 --- a/RLBotCS/ManagerTools/LaunchManager.cs +++ b/RLBotCS/ManagerTools/LaunchManager.cs @@ -154,7 +154,7 @@ private static void LaunchGameViaHeroic() } public static void LaunchBots( - List bots, + List bots, int rlbotSocketsPort ) { @@ -199,7 +199,7 @@ int rlbotSocketsPort } public static void LaunchScripts( - List scripts, + List scripts, int rlbotSocketsPort ) { @@ -246,7 +246,7 @@ int rlbotSocketsPort } public static void LaunchRocketLeague( - rlbot.flat.Launcher launcherPref, + RLBot.Flat.Launcher launcherPref, string extraArg, int gamePort ) @@ -254,7 +254,7 @@ int gamePort #if WINDOWS switch (launcherPref) { - case rlbot.flat.Launcher.Steam: + case RLBot.Flat.Launcher.Steam: string steamPath = GetWindowsSteamPath(); Process steam = new(); steam.StartInfo.FileName = steamPath; @@ -266,7 +266,7 @@ int gamePort ); steam.Start(); break; - case rlbot.flat.Launcher.Epic: + case RLBot.Flat.Launcher.Epic: bool nonRLBotGameRunning = IsRocketLeagueRunning(); // we don't need to start the game because there's another instance of non-rlbot rocket league open @@ -333,7 +333,7 @@ int gamePort }).Start(); break; - case rlbot.flat.Launcher.Custom: + case RLBot.Flat.Launcher.Custom: if (extraArg.ToLower() == "legendary") { LaunchGameViaLegendary(); @@ -346,13 +346,13 @@ int gamePort } throw new NotSupportedException($"Unexpected launcher, \"{extraArg}\""); - case rlbot.flat.Launcher.NoLaunch: + case RLBot.Flat.Launcher.NoLaunch: break; } #else switch (launcherPref) { - case rlbot.flat.Launcher.Steam: + case RLBot.Flat.Launcher.Steam: string args = string.Join("%20", GetIdealArgs(gamePort)); Process rocketLeague = new(); rocketLeague.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; @@ -364,11 +364,11 @@ int gamePort ); rocketLeague.Start(); break; - case rlbot.flat.Launcher.Epic: + case RLBot.Flat.Launcher.Epic: throw new NotSupportedException( "Epic Games Store is not directly supported on Linux." ); - case rlbot.flat.Launcher.Custom: + case RLBot.Flat.Launcher.Custom: if (extraArg.ToLower() == "legendary") { LaunchGameViaLegendary(); @@ -381,7 +381,7 @@ int gamePort } throw new NotSupportedException($"Unexpected launcher, \"{extraArg}\""); - case rlbot.flat.Launcher.NoLaunch: + case RLBot.Flat.Launcher.NoLaunch: break; } #endif diff --git a/RLBotCS/ManagerTools/Logging.cs b/RLBotCS/ManagerTools/Logging.cs index 9db7d97..f39c364 100644 --- a/RLBotCS/ManagerTools/Logging.cs +++ b/RLBotCS/ManagerTools/Logging.cs @@ -33,7 +33,8 @@ public class Logging : ILogger public Logging(string name, LogLevel minLevel) { - _name = name.PadLeft(16); + // Longest logger: "FlatBuffersSession" with 18 characters + _name = name.PadLeft(18); _minLevel = minLevel; } diff --git a/RLBotCS/ManagerTools/MatchStarter.cs b/RLBotCS/ManagerTools/MatchStarter.cs index 976ffb9..6cfbbca 100644 --- a/RLBotCS/ManagerTools/MatchStarter.cs +++ b/RLBotCS/ManagerTools/MatchStarter.cs @@ -1,7 +1,7 @@ using System.Diagnostics; using Bridge.Models.Message; using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using MatchPhase = Bridge.Models.Message.MatchPhase; namespace RLBotCS.ManagerTools; @@ -36,6 +36,7 @@ class MatchStarter(int gamePort, int rlbotSocketsPort) public void ResetMatchStarting() { + Logger.LogDebug("Reset MatchStarter"); _deferredMatchConfig = null; _matchConfig = null; HasSpawnedMap = false; @@ -271,7 +272,7 @@ private void LoadMatch(MatchConfigurationT matchConfig, PlayerSpawner spawner) if (matchConfig.PlayerConfigurations.Count <= i) { - toDespawnIds.Add(lastPlayerConfig.SpawnId); + toDespawnIds.Add(lastPlayerConfig.PlayerId); toDespawnNames.Add( $"{lastPlayerConfig.AgentId} (index {i}, team {lastPlayerConfig.Team})" ); @@ -284,7 +285,7 @@ private void LoadMatch(MatchConfigurationT matchConfig, PlayerSpawner spawner) || lastPlayerConfig.Team != playerConfig.Team ) { - toDespawnIds.Add(lastPlayerConfig.SpawnId); + toDespawnIds.Add(lastPlayerConfig.PlayerId); toDespawnNames.Add( $"{lastPlayerConfig.AgentId} (index {i}, team {lastPlayerConfig.Team})" ); diff --git a/RLBotCS/ManagerTools/PerfMonitor.cs b/RLBotCS/ManagerTools/PerfMonitor.cs index d25b02c..f8bec8c 100644 --- a/RLBotCS/ManagerTools/PerfMonitor.cs +++ b/RLBotCS/ManagerTools/PerfMonitor.cs @@ -1,5 +1,5 @@ using Bridge.State; -using rlbot.flat; +using RLBot.Flat; namespace RLBotCS.ManagerTools; diff --git a/RLBotCS/ManagerTools/PlayerSpawner.cs b/RLBotCS/ManagerTools/PlayerSpawner.cs index 66982a4..2b810d9 100644 --- a/RLBotCS/ManagerTools/PlayerSpawner.cs +++ b/RLBotCS/ManagerTools/PlayerSpawner.cs @@ -2,7 +2,7 @@ using Bridge.Models.Command; using Bridge.Models.Message; using Bridge.State; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; namespace RLBotCS.ManagerTools; @@ -18,7 +18,7 @@ public void SpawnBot(PlayerConfigurationT config, BotSkill skill, uint desiredIn { PlayerMetadata? alreadySpawnedPlayer = _gameState .PlayerMapping.GetKnownPlayers() - .FirstOrDefault(kp => config.SpawnId == kp.SpawnId); + .FirstOrDefault(kp => config.PlayerId == kp.PlayerId); if (alreadySpawnedPlayer != null) // We've already spawned this player, don't duplicate them. return; @@ -36,7 +36,7 @@ public void SpawnBot(PlayerConfigurationT config, BotSkill skill, uint desiredIn new SpawnTracker { CommandId = commandId, - SpawnId = config.SpawnId, + PlayerId = config.PlayerId, DesiredPlayerIndex = desiredIndex, IsCustomBot = skill == BotSkill.Custom, IsBot = true, @@ -51,7 +51,7 @@ public void SpawnHuman(PlayerConfigurationT config, uint desiredIndex) PlayerMetadata? alreadySpawnedPlayer = _gameState .PlayerMapping.GetKnownPlayers() - .FirstOrDefault(kp => config.SpawnId == kp.SpawnId); + .FirstOrDefault(kp => config.PlayerId == kp.PlayerId); if (alreadySpawnedPlayer != null) { _gameState.PlayerMapping.QueueIndexChange( @@ -65,7 +65,7 @@ public void SpawnHuman(PlayerConfigurationT config, uint desiredIndex) new SpawnTracker { CommandId = 0, // Human spawning must use command id 0 for reasons in bridge - SpawnId = config.SpawnId, + PlayerId = config.PlayerId, DesiredPlayerIndex = desiredIndex, IsBot = false, IsCustomBot = false, @@ -79,13 +79,13 @@ public void MakeHumanSpectate() spawnCommandQueue.AddConsoleCommand("spectate"); } - public void DespawnPlayers(List spawnIds) + public void DespawnPlayers(List playerIds) { - foreach (int spawnId in spawnIds) + foreach (int playerId in playerIds) { PlayerMetadata? player = _gameState .PlayerMapping.GetKnownPlayers() - .FirstOrDefault(p => p.SpawnId == spawnId); + .FirstOrDefault(p => p.PlayerId == playerId); if (player != null) { diff --git a/RLBotCS/ManagerTools/QuickChat.cs b/RLBotCS/ManagerTools/QuickChat.cs index 51c4d25..b0243ed 100644 --- a/RLBotCS/ManagerTools/QuickChat.cs +++ b/RLBotCS/ManagerTools/QuickChat.cs @@ -1,5 +1,5 @@ using Bridge.State; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Model; namespace RLBotCS.ManagerTools; diff --git a/RLBotCS/ManagerTools/Rendering.cs b/RLBotCS/ManagerTools/Rendering.cs index 241ba40..6382a51 100644 --- a/RLBotCS/ManagerTools/Rendering.cs +++ b/RLBotCS/ManagerTools/Rendering.cs @@ -2,7 +2,7 @@ using Bridge.Controller; using Bridge.State; using Bridge.TCP; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; using Color = System.Drawing.Color; diff --git a/RLBotCS/Model/AgentMetadata.cs b/RLBotCS/Model/AgentMetadata.cs index 17b823a..6c547f2 100644 --- a/RLBotCS/Model/AgentMetadata.cs +++ b/RLBotCS/Model/AgentMetadata.cs @@ -1,12 +1,12 @@ namespace RLBotCS.Model; -public class AgentMetadata(uint index, uint team, string name, string agentId, int spawnId) +public class AgentMetadata(uint index, uint team, string name, string agentId, int playerId) { public readonly uint Index = index; public readonly uint Team = team; public readonly string Name = name; public readonly string AgentId = agentId; - public readonly int SpawnId = spawnId; + public readonly int PlayerId = playerId; public int? ClientId { get; private set; } = null; public bool Ready { get; set; } = false; diff --git a/RLBotCS/RLBotCS.csproj b/RLBotCS/RLBotCS.csproj index bf394bb..69b1dc6 100644 --- a/RLBotCS/RLBotCS.csproj +++ b/RLBotCS/RLBotCS.csproj @@ -64,7 +64,7 @@ - + diff --git a/RLBotCS/Server/BridgeContext.cs b/RLBotCS/Server/BridgeContext.cs index a3a6d33..ad18703 100644 --- a/RLBotCS/Server/BridgeContext.cs +++ b/RLBotCS/Server/BridgeContext.cs @@ -3,7 +3,7 @@ using Bridge.State; using Bridge.TCP; using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; using RLBotCS.Server.BridgeMessage; using RLBotCS.Server.ServerMessage; diff --git a/RLBotCS/Server/BridgeHandler.cs b/RLBotCS/Server/BridgeHandler.cs index 3d71073..66303de 100644 --- a/RLBotCS/Server/BridgeHandler.cs +++ b/RLBotCS/Server/BridgeHandler.cs @@ -2,7 +2,7 @@ using Bridge.Conversion; using Bridge.TCP; using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; using RLBotCS.ManagerTools; using RLBotCS.Server.BridgeMessage; diff --git a/RLBotCS/Server/BridgeMessage/AddRenders.cs b/RLBotCS/Server/BridgeMessage/AddRenders.cs index df5d7c9..5e478fe 100644 --- a/RLBotCS/Server/BridgeMessage/AddRenders.cs +++ b/RLBotCS/Server/BridgeMessage/AddRenders.cs @@ -1,4 +1,4 @@ -using rlbot.flat; +using RLBot.Flat; namespace RLBotCS.Server.BridgeMessage; diff --git a/RLBotCS/Server/BridgeMessage/EndMatch.cs b/RLBotCS/Server/BridgeMessage/EndMatch.cs index 58f5259..290314f 100644 --- a/RLBotCS/Server/BridgeMessage/EndMatch.cs +++ b/RLBotCS/Server/BridgeMessage/EndMatch.cs @@ -1,4 +1,4 @@ -namespace RLBotCS.Server.BridgeMessage; +namespace RLBotCS.Server.BridgeMessage; record EndMatch() : IBridgeMessage { diff --git a/RLBotCS/Server/BridgeMessage/Input.cs b/RLBotCS/Server/BridgeMessage/Input.cs index 5455e9f..e0bfdc0 100644 --- a/RLBotCS/Server/BridgeMessage/Input.cs +++ b/RLBotCS/Server/BridgeMessage/Input.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; using PlayerInput = Bridge.Models.Control.PlayerInput; diff --git a/RLBotCS/Server/BridgeMessage/SetGameState.cs b/RLBotCS/Server/BridgeMessage/SetGameState.cs index e77e854..a006b07 100644 --- a/RLBotCS/Server/BridgeMessage/SetGameState.cs +++ b/RLBotCS/Server/BridgeMessage/SetGameState.cs @@ -1,4 +1,4 @@ -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; namespace RLBotCS.Server.BridgeMessage; diff --git a/RLBotCS/Server/BridgeMessage/SetInitLoadout.cs b/RLBotCS/Server/BridgeMessage/SetInitLoadout.cs index cf7d226..96d2b18 100644 --- a/RLBotCS/Server/BridgeMessage/SetInitLoadout.cs +++ b/RLBotCS/Server/BridgeMessage/SetInitLoadout.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; namespace RLBotCS.Server.BridgeMessage; @@ -7,7 +7,7 @@ namespace RLBotCS.Server.BridgeMessage; /// Sets the loadout of a bot that has yet to ready up and spawn (replaces loadout generators from v4). /// See also for loadout change during matches. /// -record SetInitLoadout(PlayerLoadoutT Loadout, int SpawnId) : IBridgeMessage +record SetInitLoadout(PlayerLoadoutT Loadout, int PlayerId) : IBridgeMessage { public void HandleMessage(BridgeContext context) { @@ -22,18 +22,18 @@ public void HandleMessage(BridgeContext context) { // BUG: If "wait_for_agents=false" then you cannot use the new 'loadout generators' context.Logger.LogWarning( - "Cannot set initial loadout of bot with spawn id {}. Cars have already spawned.", - SpawnId + "Cannot set initial loadout of bot with player id {}. Cars have already spawned.", + PlayerId ); return; } - var player = matchConfig.PlayerConfigurations.Find(p => p.SpawnId == SpawnId); + var player = matchConfig.PlayerConfigurations.Find(p => p.PlayerId == PlayerId); if (player is null) { context.Logger.LogError( - "Cannot set loadout of player with spawn id {}. No such player exists.", - SpawnId + "Cannot set loadout of player with player id {}. No such player exists.", + PlayerId ); return; } diff --git a/RLBotCS/Server/BridgeMessage/ShowQuickChat.cs b/RLBotCS/Server/BridgeMessage/ShowQuickChat.cs index 2957eac..fbed66e 100644 --- a/RLBotCS/Server/BridgeMessage/ShowQuickChat.cs +++ b/RLBotCS/Server/BridgeMessage/ShowQuickChat.cs @@ -1,4 +1,4 @@ -using rlbot.flat; +using RLBot.Flat; namespace RLBotCS.Server.BridgeMessage; diff --git a/RLBotCS/Server/BridgeMessage/StartMatch.cs b/RLBotCS/Server/BridgeMessage/StartMatch.cs index dd2168e..f7db8c9 100644 --- a/RLBotCS/Server/BridgeMessage/StartMatch.cs +++ b/RLBotCS/Server/BridgeMessage/StartMatch.cs @@ -1,4 +1,4 @@ -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Server.ServerMessage; namespace RLBotCS.Server.BridgeMessage; diff --git a/RLBotCS/Server/BridgeMessage/StateSetLoadout.cs b/RLBotCS/Server/BridgeMessage/StateSetLoadout.cs index b2453a9..a59b1a3 100644 --- a/RLBotCS/Server/BridgeMessage/StateSetLoadout.cs +++ b/RLBotCS/Server/BridgeMessage/StateSetLoadout.cs @@ -2,7 +2,7 @@ using Bridge.Models.Message; using Bridge.State; using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; namespace RLBotCS.Server.BridgeMessage; @@ -46,7 +46,7 @@ public void HandleMessage(BridgeContext context) new SpawnTracker { CommandId = commandId, - SpawnId = meta.SpawnId, + PlayerId = meta.PlayerId, DesiredPlayerIndex = meta.PlayerIndex, IsCustomBot = true, IsBot = true, diff --git a/RLBotCS/Server/FlatBuffersSession.cs b/RLBotCS/Server/FlatBuffersSession.cs index 25b32e5..7d9e803 100644 --- a/RLBotCS/Server/FlatBuffersSession.cs +++ b/RLBotCS/Server/FlatBuffersSession.cs @@ -1,13 +1,11 @@ using System.Net.Sockets; using System.Threading.Channels; -using Google.FlatBuffers; using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; using RLBotCS.Model; using RLBotCS.Server.BridgeMessage; using RLBotCS.Server.ServerMessage; -using RLBotCS.Types; using StartMatch = RLBotCS.Server.ServerMessage.StartMatch; namespace RLBotCS.Server; @@ -42,8 +40,8 @@ class FlatBuffersSession private readonly TcpClient _client; private readonly int _clientId; - private readonly SocketSpecStreamReader _socketSpecReader; - private readonly SocketSpecStreamWriter _socketSpecWriter; + private readonly SpecStreamReader _socketSpecReader; + private readonly SpecStreamWriter _socketSpecWriter; private readonly Channel _incomingMessages; private readonly ChannelWriter _rlbotServer; @@ -72,8 +70,6 @@ class FlatBuffersSession private bool _sessionForceClosed; private bool _closed; - private readonly FlatBufferBuilder _messageBuilder = new(1 << 10); - public string ClientName => _agentId != "" ? $"client {_clientId} (index {string.Join("+", _playerIdPairs.Select(p => p.Index))}, team {_team}, aid {_agentId})" @@ -98,22 +94,27 @@ bool stateSettingIsEnabled _stateSettingIsEnabled = stateSettingIsEnabled; NetworkStream stream = _client.GetStream(); - _socketSpecReader = new SocketSpecStreamReader(stream); - _socketSpecWriter = new SocketSpecStreamWriter(stream); + _socketSpecReader = new SpecStreamReader(stream); + _socketSpecWriter = new SpecStreamWriter(stream); } - private async Task ParseClientMessage(TypedPayload message) + private async Task ParseClientMessage(InterfacePacket msg) { - ByteBuffer byteBuffer = new(message.Payload.Array, message.Payload.Offset); - - switch (message.Type) + switch (msg.MessageType) { - case DataType.None: + case InterfaceMessage.NONE: + Logger.LogError( + $"Received a message with type NONE from {ClientName}. " + + "Something has gone very wrong. Disconnecting." + ); + return false; + + case InterfaceMessage.DisconnectSignal: // The client requested that we close the connection return false; - case DataType.ConnectionSettings when !_connectionEstablished: - var readyMsg = ConnectionSettings.GetRootAsConnectionSettings(byteBuffer); + case InterfaceMessage.ConnectionSettings when !_connectionEstablished: + var readyMsg = msg.MessageAsConnectionSettings(); _agentId = readyMsg.AgentId ?? ""; _wantsBallPredictions = readyMsg.WantsBallPredictions; @@ -136,11 +137,11 @@ await _rlbotServer.WriteAsync( _connectionEstablished = true; break; - case DataType.SetLoadout when _connectionEstablished: + case InterfaceMessage.SetLoadout when _connectionEstablished: if (_isReady && !_stateSettingIsEnabled) break; - var setLoadout = SetLoadout.GetRootAsSetLoadout(byteBuffer).UnPack(); + var setLoadout = msg.MessageAsSetLoadout().UnPack(); if (_isReady) { @@ -161,7 +162,7 @@ await _bridge.WriteAsync( if (maybeIdPair is { } pair) { await _bridge.WriteAsync( - new SetInitLoadout(setLoadout.Loadout, pair.SpawnId) + new SetInitLoadout(setLoadout.Loadout, pair.PlayerId) ); } else @@ -177,7 +178,7 @@ await _bridge.WriteAsync( break; - case DataType.InitComplete when _connectionEstablished && !_isReady: + case InterfaceMessage.InitComplete when _connectionEstablished && !_isReady: if (_closeBetweenMatches) { await _bridge.WriteAsync(new SessionReady(_clientId)); @@ -187,13 +188,13 @@ await _bridge.WriteAsync( _isReady = true; break; - case DataType.StopCommand: - var stopCommand = StopCommand.GetRootAsStopCommand(byteBuffer); + case InterfaceMessage.StopCommand: + var stopCommand = msg.MessageAsStopCommand(); await _rlbotServer.WriteAsync(new StopMatch(stopCommand.ShutdownServer)); break; - case DataType.StartCommand: - var startCommand = StartCommand.GetRootAsStartCommand(byteBuffer); + case InterfaceMessage.StartCommand: + var startCommand = msg.MessageAsStartCommand(); var parser = new ConfigParser(); if ( parser.TryLoadMatchConfig(startCommand.ConfigPath, out var tomlMatchConfig) @@ -204,18 +205,16 @@ await _bridge.WriteAsync( } break; - case DataType.MatchConfig: - var matchConfig = MatchConfiguration - .GetRootAsMatchConfiguration(byteBuffer) - .UnPack(); + case InterfaceMessage.MatchConfiguration: + var matchConfig = msg.MessageAsMatchConfiguration().UnPack(); if (ConfigValidator.Validate(matchConfig)) { await _rlbotServer.WriteAsync(new StartMatch(matchConfig)); } break; - case DataType.PlayerInput when _connectionEstablished: - var playerInputMsg = PlayerInput.GetRootAsPlayerInput(byteBuffer).UnPack(); + case InterfaceMessage.PlayerInput when _connectionEstablished: + var playerInputMsg = msg.MessageAsPlayerInput().UnPack(); // ensure the provided index is a bot we control if ( @@ -238,8 +237,8 @@ await _bridge.WriteAsync( await _bridge.WriteAsync(new Input(playerInputMsg)); break; - case DataType.MatchComms: - var matchComms = MatchComm.GetRootAsMatchComm(byteBuffer).UnPack(); + case InterfaceMessage.MatchComm: + var matchComms = msg.MessageAsMatchComm().UnPack(); if (_agentId != "") { @@ -274,53 +273,39 @@ await _rlbotServer.WriteAsync( break; - case DataType.RenderGroup: + case InterfaceMessage.RenderGroup: if (!_renderingIsEnabled) break; - var renderingGroup = RenderGroup.GetRootAsRenderGroup(byteBuffer).UnPack(); + var renderingGroup = msg.MessageAsRenderGroup().UnPack(); await _bridge.WriteAsync( new AddRenders(_clientId, renderingGroup.Id, renderingGroup.RenderMessages) ); break; - case DataType.RemoveRenderGroup: + case InterfaceMessage.RemoveRenderGroup: if (!_renderingIsEnabled) break; - var removeRenderGroup = RemoveRenderGroup.GetRootAsRemoveRenderGroup( - byteBuffer - ); + var removeRenderGroup = msg.MessageAsRemoveRenderGroup(); await _bridge.WriteAsync(new RemoveRenders(_clientId, removeRenderGroup.Id)); break; - case DataType.DesiredGameState: + case InterfaceMessage.DesiredGameState: if (!_stateSettingIsEnabled) break; - var desiredGameState = DesiredGameState - .GetRootAsDesiredGameState(byteBuffer) - .UnPack(); + var desiredGameState = msg.MessageAsDesiredGameState().UnPack(); await _bridge.WriteAsync(new SetGameState(desiredGameState)); break; - - case DataType.GamePacket: - case DataType.FieldInfo: - case DataType.BallPrediction: - default: - Logger.LogError( - $"Core got unexpected message type {message.Type} from client. " - + $"Got ConnectionSettings: {_connectionEstablished}." - ); - break; } return true; } - private void SendPayloadToClient(TypedPayload payload) + private void SendPayloadToClient(CoreMessageUnion payload) { try { @@ -345,37 +330,22 @@ private async Task HandleInternalMessages() switch (message) { case SessionMessage.FieldInfo m: - _messageBuilder.Clear(); - _messageBuilder.Finish(FieldInfo.Pack(_messageBuilder, m.Info).Value); - - SendPayloadToClient( - TypedPayload.FromFlatBufferBuilder(DataType.FieldInfo, _messageBuilder) - ); + SendPayloadToClient(CoreMessageUnion.FromFieldInfo(m.Info)); break; case SessionMessage.MatchConfig m: - _messageBuilder.Clear(); - _messageBuilder.Finish( - MatchConfiguration.Pack(_messageBuilder, m.Config).Value - ); - - SendPayloadToClient( - TypedPayload.FromFlatBufferBuilder( - DataType.MatchConfig, - _messageBuilder - ) - ); + SendPayloadToClient(CoreMessageUnion.FromMatchConfiguration(m.Config)); break; case SessionMessage.PlayerIdPairs m: _team = m.Team; _playerIdPairs = m.IdMaps; - List controllables = new( - _playerIdPairs.Select(playerInfo => new ControllableInfoT() + List controllables = _playerIdPairs + .Select(playerInfo => new ControllableInfoT() { Index = playerInfo.Index, - SpawnId = playerInfo.SpawnId, + Identifier = playerInfo.PlayerId, }) - ); + .ToList(); ControllableTeamInfoT playerMappings = new() { @@ -383,16 +353,8 @@ private async Task HandleInternalMessages() Controllables = controllables, }; - _messageBuilder.Clear(); - _messageBuilder.Finish( - ControllableTeamInfo.Pack(_messageBuilder, playerMappings).Value - ); - SendPayloadToClient( - TypedPayload.FromFlatBufferBuilder( - DataType.ControllableTeamInfo, - _messageBuilder - ) + CoreMessageUnion.FromControllableTeamInfo(playerMappings) ); Logger.LogDebug("Reserved agents for {}", ClientName); @@ -400,30 +362,10 @@ private async Task HandleInternalMessages() break; case SessionMessage.DistributeBallPrediction m when _isReady && _wantsBallPredictions: - _messageBuilder.Clear(); - _messageBuilder.Finish( - BallPrediction.Pack(_messageBuilder, m.BallPrediction).Value - ); - - SendPayloadToClient( - TypedPayload.FromFlatBufferBuilder( - DataType.BallPrediction, - _messageBuilder - ) - ); + SendPayloadToClient(CoreMessageUnion.FromBallPrediction(m.BallPrediction)); break; case SessionMessage.DistributeGameState m when _isReady: - _messageBuilder.Clear(); - _messageBuilder.Finish( - GamePacket.Pack(_messageBuilder, m.GameState).Value - ); - - SendPayloadToClient( - TypedPayload.FromFlatBufferBuilder( - DataType.GamePacket, - _messageBuilder - ) - ); + SendPayloadToClient(CoreMessageUnion.FromGamePacket(m.GameState)); foreach (var (index, gotInput) in _gotInput) { @@ -453,15 +395,7 @@ private async Task HandleInternalMessages() } } - _messageBuilder.Clear(); - _messageBuilder.Finish(MatchComm.Pack(_messageBuilder, m.Message).Value); - - SendPayloadToClient( - TypedPayload.FromFlatBufferBuilder( - DataType.MatchComms, - _messageBuilder - ) - ); + SendPayloadToClient(CoreMessageUnion.FromMatchComm(m.Message)); break; case SessionMessage.StopMatch m @@ -473,7 +407,7 @@ private async Task HandleInternalMessages() private async Task HandleClientMessages() { - await foreach (TypedPayload message in _socketSpecReader.ReadAllAsync()) + await foreach (InterfacePacket message in _socketSpecReader.ReadAllAsync()) { // if the session is closed, ignore any incoming messages // this should allow the client to close cleanly @@ -528,12 +462,9 @@ public void Cleanup() // try to politely close the connection try { - TypedPayload msg = new() - { - Type = DataType.None, - Payload = new ArraySegment([1]), - }; - SendPayloadToClient(msg); + SendPayloadToClient( + CoreMessageUnion.FromDisconnectSignal(new DisconnectSignalT()) + ); } catch (Exception) { diff --git a/RLBotCS/Server/ServerMessage/DistributeFieldInfo.cs b/RLBotCS/Server/ServerMessage/DistributeFieldInfo.cs index e2c163f..6647178 100644 --- a/RLBotCS/Server/ServerMessage/DistributeFieldInfo.cs +++ b/RLBotCS/Server/ServerMessage/DistributeFieldInfo.cs @@ -1,5 +1,5 @@ using Bridge.State; -using rlbot.flat; +using RLBot.Flat; using GoalInfo = Bridge.Packet.GoalInfo; namespace RLBotCS.Server.ServerMessage; diff --git a/RLBotCS/Server/ServerMessage/DistributeGamePacket.cs b/RLBotCS/Server/ServerMessage/DistributeGamePacket.cs index 91eb6f3..33d9268 100644 --- a/RLBotCS/Server/ServerMessage/DistributeGamePacket.cs +++ b/RLBotCS/Server/ServerMessage/DistributeGamePacket.cs @@ -1,4 +1,4 @@ -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; namespace RLBotCS.Server.ServerMessage; diff --git a/RLBotCS/Server/ServerMessage/SendMatchComm.cs b/RLBotCS/Server/ServerMessage/SendMatchComm.cs index 13dd2ea..11ff10c 100644 --- a/RLBotCS/Server/ServerMessage/SendMatchComm.cs +++ b/RLBotCS/Server/ServerMessage/SendMatchComm.cs @@ -1,5 +1,5 @@ using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; namespace RLBotCS.Server.ServerMessage; diff --git a/RLBotCS/Server/ServerMessage/ServerContext.cs b/RLBotCS/Server/ServerMessage/ServerContext.cs index 8b43e95..2af005f 100644 --- a/RLBotCS/Server/ServerMessage/ServerContext.cs +++ b/RLBotCS/Server/ServerMessage/ServerContext.cs @@ -1,7 +1,7 @@ using System.Net.Sockets; using System.Threading.Channels; using Microsoft.Extensions.Logging; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; using RLBotCS.Server.BridgeMessage; diff --git a/RLBotCS/Server/ServerMessage/StartMatch.cs b/RLBotCS/Server/ServerMessage/StartMatch.cs index 0219a57..9e453ba 100644 --- a/RLBotCS/Server/ServerMessage/StartMatch.cs +++ b/RLBotCS/Server/ServerMessage/StartMatch.cs @@ -1,5 +1,5 @@ using System.Diagnostics; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; using RLBotCS.Server.BridgeMessage; diff --git a/RLBotCS/Server/SocketSpecStreamReader.cs b/RLBotCS/Server/SocketSpecStreamReader.cs deleted file mode 100644 index 5b206f2..0000000 --- a/RLBotCS/Server/SocketSpecStreamReader.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Net.Sockets; -using RLBotCS.Types; - -namespace RLBotCS.Server; - -/** - * https://wiki.rlbot.org/framework/sockets-specification/ - */ -class SocketSpecStreamReader -{ - private BufferedStream _bufferedStream; - private byte[] _ushortReader = new byte[2]; - private byte[] _payloadReader = new byte[ushort.MaxValue]; - - public SocketSpecStreamReader(NetworkStream stream) - { - _bufferedStream = new BufferedStream(stream, 4 + ushort.MaxValue); - } - - internal async IAsyncEnumerable ReadAllAsync() - { - while (true) - { - DataType dataType; - ushort payloadSize; - - try - { - await _bufferedStream.ReadExactlyAsync(_ushortReader); - dataType = ReadDataType(_ushortReader); - - await _bufferedStream.ReadExactlyAsync(_ushortReader); - payloadSize = ReadPayloadSize(_ushortReader); - - await _bufferedStream.ReadExactlyAsync(_payloadReader, 0, payloadSize); - } - catch (Exception) - { - break; - } - - yield return new() - { - Type = dataType, - Payload = new(_payloadReader, 0, payloadSize), - }; - } - } - - private static DataType ReadDataType(Span bytes) - { - return (DataType)((bytes[0] << 8) | bytes[1]); - } - - private static ushort ReadPayloadSize(Span bytes) - { - return (ushort)((bytes[0] << 8) | bytes[1]); - } -} diff --git a/RLBotCS/Server/SocketSpecStreamWriter.cs b/RLBotCS/Server/SocketSpecStreamWriter.cs deleted file mode 100644 index 6f51ce9..0000000 --- a/RLBotCS/Server/SocketSpecStreamWriter.cs +++ /dev/null @@ -1,65 +0,0 @@ -using Microsoft.Extensions.Logging; -using RLBotCS.ManagerTools; -using RLBotCS.Types; - -namespace RLBotCS.Server; - -/** - * Communicates with bots and scripts over TCP according to the spec - * defined at https://wiki.rlbot.org/framework/sockets-specification/ - */ -class SocketSpecStreamWriter(Stream stream) -{ - private static readonly ILogger Logger = Logging.GetLogger("SocketSpecStreamWriter"); - - private readonly byte[] _dataTypeBuffer = new byte[2]; - private readonly byte[] _messageLengthBuffer = new byte[2]; - private readonly byte[] _messageBuffer = new byte[4 + ushort.MaxValue]; - - private void PrepareMessageLength(ushort length) => - WriteBigEndian(length, _messageLengthBuffer); - - private void PrepareDataType(DataType dataType) => - WriteBigEndian((ushort)dataType, _dataTypeBuffer); - - private static void WriteBigEndian(ushort value, byte[] buffer) - { - buffer[0] = (byte)((value >> 8) & 0xFF); - buffer[1] = (byte)(value & 0xFF); - } - - internal void Write(TypedPayload message) - { - if (message.Payload.Count > ushort.MaxValue) - { - // Can't send if the message size is bigger than our header can describe. - Logger.LogError( - $"Cannot send message because size of {message.Payload.Count} cannot be described by a ushort." - ); - return; - } - - if (message.Payload.Count == 0 || message.Payload.Array == null) - { - Logger.LogWarning("Cannot send an empty message."); - return; - } - - PrepareDataType(message.Type); - PrepareMessageLength((ushort)message.Payload.Count); - - Array.Copy(_dataTypeBuffer, 0, _messageBuffer, 0, 2); - Array.Copy(_messageLengthBuffer, 0, _messageBuffer, 2, 2); - Array.Copy( - message.Payload.Array, - message.Payload.Offset, - _messageBuffer, - 4, - message.Payload.Count - ); - - stream.Write(_messageBuffer, 0, 4 + message.Payload.Count); - } - - internal void Send() => stream.Flush(); -} diff --git a/RLBotCS/Server/SpecStreamReader.cs b/RLBotCS/Server/SpecStreamReader.cs new file mode 100644 index 0000000..d5a2eb1 --- /dev/null +++ b/RLBotCS/Server/SpecStreamReader.cs @@ -0,0 +1,48 @@ +using System.Net.Sockets; +using Google.FlatBuffers; +using RLBot.Flat; + +namespace RLBotCS.Server; + +/** + * https://wiki.rlbot.org/framework/sockets-specification/ + */ +class SpecStreamReader +{ + private BufferedStream _bufferedStream; + private byte[] _ushortReader = new byte[2]; + private byte[] _payloadReader = new byte[ushort.MaxValue]; + + public SpecStreamReader(NetworkStream stream) + { + _bufferedStream = new BufferedStream(stream, 2 + ushort.MaxValue); + } + + internal async IAsyncEnumerable ReadAllAsync() + { + while (true) + { + ushort payloadSize; + + try + { + await _bufferedStream.ReadExactlyAsync(_ushortReader); + payloadSize = ReadBigEndian(_ushortReader); + + await _bufferedStream.ReadExactlyAsync(_payloadReader, 0, payloadSize); + } + catch (Exception) + { + break; + } + + ByteBuffer byteBuffer = new(_payloadReader, 0); + yield return InterfacePacket.GetRootAsInterfacePacket(byteBuffer); + } + } + + private static ushort ReadBigEndian(Span bytes) + { + return (ushort)((bytes[0] << 8) | bytes[1]); + } +} diff --git a/RLBotCS/Server/SpecStreamWriter.cs b/RLBotCS/Server/SpecStreamWriter.cs new file mode 100644 index 0000000..94e3366 --- /dev/null +++ b/RLBotCS/Server/SpecStreamWriter.cs @@ -0,0 +1,58 @@ +using Google.FlatBuffers; +using Microsoft.Extensions.Logging; +using RLBot.Flat; +using RLBotCS.ManagerTools; + +namespace RLBotCS.Server; + +/** + * Communicates with bots and scripts over TCP according to the spec + * defined at https://wiki.rlbot.org/framework/sockets-specification/ + */ +class SpecStreamWriter(Stream stream) +{ + private static readonly ILogger Logger = Logging.GetLogger("SpecStreamWriter"); + + private readonly FlatBufferBuilder _messageBuilder = new(1 << 12); + private readonly byte[] _messageBuffer = new byte[2 + ushort.MaxValue]; + + private static void WriteBigEndian(ushort value, byte[] buffer) + { + buffer[0] = (byte)((value >> 8) & 0xFF); + buffer[1] = (byte)(value & 0xFF); + } + + internal void Write(CoreMessageUnion message) + { + var packet = new CorePacketT { Message = message }; + + _messageBuilder.Clear(); + _messageBuilder.Finish(CorePacket.Pack(_messageBuilder, packet).Value); + ArraySegment payload = _messageBuilder.DataBuffer.ToArraySegment( + _messageBuilder.DataBuffer.Position, + _messageBuilder.DataBuffer.Length - _messageBuilder.DataBuffer.Position + ); + + if (payload.Count > ushort.MaxValue) + { + // Can't send if the message size is bigger than our header can describe. + Logger.LogError( + $"Cannot send message because size of {payload.Count} cannot be described by a ushort." + ); + return; + } + + if (payload.Count == 0 || payload.Array == null) + { + Logger.LogWarning("Cannot send an empty message."); + return; + } + + WriteBigEndian((ushort)payload.Count, _messageBuffer); + Array.Copy(payload.Array, payload.Offset, _messageBuffer, 2, payload.Count); + + stream.Write(_messageBuffer, 0, 2 + payload.Count); + } + + internal void Send() => stream.Flush(); +} diff --git a/RLBotCS/Types/DataType.cs b/RLBotCS/Types/DataType.cs deleted file mode 100644 index 8fbba68..0000000 --- a/RLBotCS/Types/DataType.cs +++ /dev/null @@ -1,53 +0,0 @@ -namespace RLBotCS.Types; - -/** - * https://wiki.rlbot.org/framework/sockets-specification/#data-types - */ -public enum DataType : ushort -{ - None, - - /// - /// Arrives at a high rate according to https://wiki.rlbot.org/botmaking/tick-rate/ except - /// "desired tick rate" is not relevant here - /// - GamePacket, - - /// - /// Sent once when a match starts, or when you first connect. - /// - FieldInfo, - - /// - /// Sent once when a match starts, or when you first connect. - /// - StartCommand, - MatchConfig, - PlayerInput, - DesiredGameState, - RenderGroup, - RemoveRenderGroup, - MatchComms, - BallPrediction, - - /// - /// Clients must send this after connecting to the socket. - /// - ConnectionSettings, - - /// - /// used to end a match and shut down bots (optionally the server as well) - /// - StopCommand, - - /// - /// Use to dynamically set the loadout of a bot - /// - SetLoadout, - - /// - /// Indicates that a connection is ready to receive `GameTickPacket`s - /// - InitComplete, - ControllableTeamInfo, -} diff --git a/RLBotCS/Types/TypedPayload.cs b/RLBotCS/Types/TypedPayload.cs deleted file mode 100644 index abd8f65..0000000 --- a/RLBotCS/Types/TypedPayload.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Google.FlatBuffers; - -namespace RLBotCS.Types; - -public class TypedPayload -{ - public DataType Type; - public ArraySegment Payload; - - public static TypedPayload FromFlatBufferBuilder(DataType type, FlatBufferBuilder builder) - { - return new TypedPayload - { - Type = type, - Payload = builder.DataBuffer.ToArraySegment( - builder.DataBuffer.Position, - builder.DataBuffer.Length - builder.DataBuffer.Position - ), - }; - } -} diff --git a/RLBotCS/lib/Bridge.dll b/RLBotCS/lib/Bridge.dll index 5cd02ca..a14d6ed 100644 Binary files a/RLBotCS/lib/Bridge.dll and b/RLBotCS/lib/Bridge.dll differ diff --git a/RLBotCSTests/ConfigParserTest.cs b/RLBotCSTests/ConfigParserTest.cs index cdfa766..af11636 100644 --- a/RLBotCSTests/ConfigParserTest.cs +++ b/RLBotCSTests/ConfigParserTest.cs @@ -1,7 +1,7 @@ using System; using System.IO; using Microsoft.VisualStudio.TestTools.UnitTesting; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; namespace RLBotCSTests; diff --git a/RLBotCSTests/ConfigValidatorTest.cs b/RLBotCSTests/ConfigValidatorTest.cs index 3ed71b8..4ebb068 100644 --- a/RLBotCSTests/ConfigValidatorTest.cs +++ b/RLBotCSTests/ConfigValidatorTest.cs @@ -1,5 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.ManagerTools; namespace RLBotCSTests; diff --git a/RLBotCSTests/FlatbufferTest.cs b/RLBotCSTests/FlatbufferTest.cs index 9eaad04..2935f49 100644 --- a/RLBotCSTests/FlatbufferTest.cs +++ b/RLBotCSTests/FlatbufferTest.cs @@ -3,7 +3,7 @@ using System.Linq; using Google.FlatBuffers; using Microsoft.VisualStudio.TestTools.UnitTesting; -using rlbot.flat; +using RLBot.Flat; namespace RLBotCSTests; diff --git a/RLBotCSTests/GameState.cs b/RLBotCSTests/GameState.cs index 9b7f8d1..0e843d4 100644 --- a/RLBotCSTests/GameState.cs +++ b/RLBotCSTests/GameState.cs @@ -2,7 +2,7 @@ using Bridge.State; using Google.FlatBuffers; using Microsoft.VisualStudio.TestTools.UnitTesting; -using rlbot.flat; +using RLBot.Flat; using RLBotCS.Conversion; namespace RLBotCSTests; diff --git a/RLBotCSTests/PlayerMappingTest.cs b/RLBotCSTests/PlayerMappingTest.cs index 0644bc0..9f4b4cc 100644 --- a/RLBotCSTests/PlayerMappingTest.cs +++ b/RLBotCSTests/PlayerMappingTest.cs @@ -17,7 +17,7 @@ public void Init() [TestMethod] public void TestSpawnProcess() { - int spawnId = 2398249; + int playerId = 2398249; string agentId = "dev/abot"; uint desiredIndex = 2; ushort actorId = 2398; @@ -25,7 +25,7 @@ public void TestSpawnProcess() var spawnTracker = new SpawnTracker() { - SpawnId = spawnId, + PlayerId = playerId, AgentId = agentId, CommandId = commandId, DesiredPlayerIndex = desiredIndex, @@ -39,7 +39,7 @@ public void TestSpawnProcess() var metadata = _playerMapping.ApplyCarSpawn(actorId, commandId); Assert.AreEqual(desiredIndex, _playerMapping.PlayerIndexFromActorId(actorId)); - Assert.AreEqual(spawnId, metadata.SpawnId); + Assert.AreEqual(playerId, metadata.PlayerId); Assert.AreEqual(agentId, metadata.AgentId); Assert.IsTrue(metadata.IsBot); Assert.IsTrue(!metadata.IsCustomBot); @@ -51,7 +51,7 @@ public void TestSpawnProcess() Assert.AreEqual(0u, _playerMapping.PlayerIndexFromActorId(111)); Assert.IsNotNull(index); Assert.AreEqual(0u, index); - Assert.AreNotEqual(0, metadata2.SpawnId); + Assert.AreNotEqual(0, metadata2.PlayerId); Assert.AreEqual(desiredIndex, _playerMapping.PlayerIndexFromActorId(actorId)); Assert.IsTrue(!metadata2.IsBot); Assert.IsTrue(!metadata2.IsCustomBot); diff --git a/flatbuffers-schema b/flatbuffers-schema index 805c3cb..8922aa5 160000 --- a/flatbuffers-schema +++ b/flatbuffers-schema @@ -1 +1 @@ -Subproject commit 805c3cb5f0cd8aa13b940d98f9af59914aab0012 +Subproject commit 8922aa53c8c59812e153ec173f88525c4adc1de8 diff --git a/generate-flatbuffers.bat b/generate-flatbuffers.bat index e508125..9003582 100644 --- a/generate-flatbuffers.bat +++ b/generate-flatbuffers.bat @@ -4,11 +4,15 @@ cd /D "%~dp0" echo Generating flatbuffers header file... -.\flatbuffers-schema\flatc.exe --csharp --gen-all --gen-object-api --gen-onefile -o .\FlatBuffer .\flatbuffers-schema\rlbot.fbs +.\flatbuffers-schema\binaries\flatc.exe --csharp --gen-all --gen-object-api --gen-onefile -o .\FlatBuffer .\flatbuffers-schema\schema\rlbot.fbs IF EXIST .\FlatBuffer\rlbot.cs del .\FlatBuffer\rlbot.cs -REM the file produced is called rlbot_generated.cs, rename it to rlbot.cs after removing the old one -ren .\FlatBuffer\rlbot_generated.cs rlbot.cs +REM the file produced is called rlbot_generated.cs, rename it to RLBot.cs after removing the old one +ren .\FlatBuffer\rlbot_generated.cs RLBot.cs + +REM CMD doesn't have native text replacement tools, use PowerShell +REM Replaces 'rlbot.flat' with 'RLBot.Flat' +powershell -Command "(Get-Content .\FlatBuffer\RLBot.cs) -replace 'rlbot\.flat', 'RLBot.Flat' | Set-Content .\FlatBuffer\RLBot.cs" echo Done. \ No newline at end of file diff --git a/generate-flatbuffers.sh b/generate-flatbuffers.sh index 75e920a..d69dd77 100755 --- a/generate-flatbuffers.sh +++ b/generate-flatbuffers.sh @@ -2,10 +2,11 @@ cd "$(dirname "$0")" echo Generating flatbuffers header file... -./flatbuffers-schema/flatc --gen-all --csharp --gen-object-api --gen-onefile -o ./FlatBuffer ./flatbuffers-schema/rlbot.fbs +./flatbuffers-schema/binaries/flatc --gen-all --csharp --gen-object-api --gen-onefile -o ./FlatBuffer ./flatbuffers-schema/schema/rlbot.fbs -# the file produced is called rlbot_generated.cs, rename it to rlbot.cs after removing the old one -rm -f ./FlatBuffer/rlbot.cs -mv ./FlatBuffer/rlbot_generated.cs ./FlatBuffer/rlbot.cs +# the file produced is called rlbot_generated.cs, rename it to RLBot.cs after removing the old one +rm -f ./FlatBuffer/RLBot.cs +mv ./FlatBuffer/rlbot_generated.cs ./FlatBuffer/RLBot.cs +sed -i 's/rlbot\.flat/RLBot.Flat/g' ./FlatBuffer/RLBot.cs echo Done. \ No newline at end of file