Skip to content

Commit 1b43455

Browse files
authored
Fix matches preemptively starting (#116)
* Fix matches preemptively starting * Only wait when RL isn't started * Stop match before starting a new one * Use `ManualResetEvent` and trigger at the start * Rename variable
1 parent 36056e0 commit 1b43455

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

RLBotCS/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
if (args.Length > 0 && args[0] == "--version")
1010
{
11-
Console.WriteLine("RLBotServer v5.beta.6.9");
11+
Console.WriteLine("RLBotServer v5.beta.6.10");
1212
Environment.Exit(0);
1313
}
1414

RLBotCS/Server/BridgeHandler.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ class BridgeHandler(
1818
MatchStarter matchStarter
1919
)
2020
{
21+
private ManualResetEvent startReadingInternalMsgs = new ManualResetEvent(false);
22+
2123
private const int MAX_TICK_SKIP = 1;
2224
private readonly BridgeContext _context = new(writer, reader, messenger, matchStarter);
2325

2426
private async Task HandleInternalMessages()
2527
{
28+
// if Rocket League is already running,
29+
// we wait for it to connect to us first
30+
if (LaunchManager.IsRocketLeagueRunningWithArgs())
31+
startReadingInternalMsgs.WaitOne();
32+
33+
_context.Logger.LogDebug("Started reading internal messages");
34+
2635
await foreach (IBridgeMessage message in _context.Reader.ReadAllAsync())
2736
{
2837
lock (_context)
@@ -47,10 +56,21 @@ private async Task HandleServer()
4756

4857
_context.Logger.LogInformation("Connected to Rocket League");
4958

59+
bool isFirstTick = true;
60+
5061
await foreach (var messageClump in _context.Messenger.ReadAllAsync())
5162
{
5263
lock (_context)
5364
{
65+
if (isFirstTick)
66+
{
67+
isFirstTick = false;
68+
// Trigger HandleInternalMessages to start processing messages
69+
// it will still wait until we're done,
70+
// since we have a lock on _context
71+
startReadingInternalMsgs.Set();
72+
}
73+
5474
// reset the counter that lets us know if we're sending too many bytes
5575
// technically this resets every time Rocket League renders a frame,
5676
// but we don't know when that is. Since every message from the game

RLBotCS/Server/ServerMessage/StartMatch.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public ServerAction Execute(ServerContext context)
1212
Debug.Assert(ConfigValidator.Validate(MatchConfig));
1313

1414
context.Bridge.TryWrite(new ClearRenders());
15+
context.Bridge.TryWrite(new EndMatch());
1516

1617
foreach (var (writer, _) in context.Sessions.Values)
1718
writer.TryWrite(new SessionMessage.StopMatch(false));

0 commit comments

Comments
 (0)