diff --git a/RLBotCS/Main.cs b/RLBotCS/Main.cs index e37f369..b209b32 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.9"); + Console.WriteLine("RLBotServer v5.beta.6.10"); Environment.Exit(0); } diff --git a/RLBotCS/Server/BridgeHandler.cs b/RLBotCS/Server/BridgeHandler.cs index 6200e7d..3d71073 100644 --- a/RLBotCS/Server/BridgeHandler.cs +++ b/RLBotCS/Server/BridgeHandler.cs @@ -18,11 +18,20 @@ class BridgeHandler( MatchStarter matchStarter ) { + private ManualResetEvent startReadingInternalMsgs = new ManualResetEvent(false); + private const int MAX_TICK_SKIP = 1; private readonly BridgeContext _context = new(writer, reader, messenger, matchStarter); private async Task HandleInternalMessages() { + // if Rocket League is already running, + // we wait for it to connect to us first + if (LaunchManager.IsRocketLeagueRunningWithArgs()) + startReadingInternalMsgs.WaitOne(); + + _context.Logger.LogDebug("Started reading internal messages"); + await foreach (IBridgeMessage message in _context.Reader.ReadAllAsync()) { lock (_context) @@ -47,10 +56,21 @@ private async Task HandleServer() _context.Logger.LogInformation("Connected to Rocket League"); + bool isFirstTick = true; + await foreach (var messageClump in _context.Messenger.ReadAllAsync()) { lock (_context) { + if (isFirstTick) + { + isFirstTick = false; + // Trigger HandleInternalMessages to start processing messages + // it will still wait until we're done, + // since we have a lock on _context + startReadingInternalMsgs.Set(); + } + // reset the counter that lets us know if we're sending too many bytes // technically this resets every time Rocket League renders a frame, // but we don't know when that is. Since every message from the game diff --git a/RLBotCS/Server/ServerMessage/StartMatch.cs b/RLBotCS/Server/ServerMessage/StartMatch.cs index e40ee80..0219a57 100644 --- a/RLBotCS/Server/ServerMessage/StartMatch.cs +++ b/RLBotCS/Server/ServerMessage/StartMatch.cs @@ -12,6 +12,7 @@ public ServerAction Execute(ServerContext context) Debug.Assert(ConfigValidator.Validate(MatchConfig)); context.Bridge.TryWrite(new ClearRenders()); + context.Bridge.TryWrite(new EndMatch()); foreach (var (writer, _) in context.Sessions.Values) writer.TryWrite(new SessionMessage.StopMatch(false));