Skip to content

Commit

Permalink
Fix field info not being distributed
Browse files Browse the repository at this point in the history
Make `StopCommand` end the match
  • Loading branch information
VirxEC committed Aug 11, 2024
1 parent 33c2f25 commit 7a23f61
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 21 deletions.
13 changes: 5 additions & 8 deletions RLBotCS/Server/BridgeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,17 @@ private async Task HandleServer()
bool timeAdvanced = deltaTime > 0.001;

if (timeAdvanced)
{
_context.PerfMonitor.AddRLBotSample(deltaTime);
_context.Writer.TryWrite(new DistributeGameState(_context.GameState));
}
_context.Writer.TryWrite(
new DistributeGameState(_context.GameState, timeAdvanced)
);

var matchStarted = MessageHandler.ReceivedMatchInfo(messageClump);
if (matchStarted)
{
_context.RenderingMgmt.ClearAllRenders();
_context.MatchHasStarted = true;
_context.Writer.TryWrite(
new MapSpawned(
_context.GameState.GameStateType == GameStateType.Inactive
)
);
_context.Writer.TryWrite(new MapSpawned());
}

bool matchEnded = _context.GameState.GameStateType == GameStateType.Inactive;
Expand Down Expand Up @@ -131,6 +127,7 @@ _context is
_context.DelayMatchCommandSend = false;
_context.QueuedMatchCommands = false;

_context.Logger.LogInformation("Sending delayed match commands");
_context.MatchCommandSender.Send();
}

Expand Down
18 changes: 9 additions & 9 deletions RLBotCS/Server/BridgeMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ internal record ConsoleCommand(string Command) : IBridgeMessage
public void HandleMessage(BridgeContext context) => context.QueueConsoleCommand(Command);
}

internal record SetPaused(bool Pause) : IBridgeMessage
{
public void HandleMessage(BridgeContext context)
{
context.QueuedMatchCommands = true;
context.MatchCommandSender.AddSetPausedCommand(Pause);
}
}

internal record SpawnMap(MatchSettingsT MatchSettings) : IBridgeMessage
{
public void HandleMessage(BridgeContext context)
Expand Down Expand Up @@ -312,6 +303,15 @@ public void HandleMessage(BridgeContext context)
}
}

internal record EndMatch() : IBridgeMessage
{
public void HandleMessage(BridgeContext context)
{
context.MatchCommandSender.AddMatchEndCommand();
context.MatchCommandSender.Send();
}
}

internal record ShowQuickChat(MatchCommT MatchComm) : IBridgeMessage
{
public void HandleMessage(BridgeContext context) =>
Expand Down
10 changes: 7 additions & 3 deletions RLBotCS/Server/FlatbuffersMessage/DistributeGameState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace RLBotCS.Server.FlatbuffersMessage;

internal record DistributeGameState(GameState GameState) : IServerMessage
internal record DistributeGameState(GameState GameState, bool timeAdvanced) : IServerMessage
{
private static void UpdateFieldInfo(ServerContext context, GameState gameState)
{
Expand Down Expand Up @@ -107,8 +107,12 @@ private static void DistributeState(ServerContext context, GameState gameState)
public ServerAction Execute(ServerContext context)
{
UpdateFieldInfo(context, GameState);
DistributeBallPrediction(context, GameState);
DistributeState(context, GameState);

if (timeAdvanced)
{
DistributeBallPrediction(context, GameState);
DistributeState(context, GameState);
}

return ServerAction.Continue;
}
Expand Down
2 changes: 1 addition & 1 deletion RLBotCS/Server/FlatbuffersMessage/MapSpawned.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace RLBotCS.Server.FlatbuffersMessage;

internal record MapSpawned(bool NotifyMatchStarter) : IServerMessage
internal record MapSpawned() : IServerMessage
{
public ServerAction Execute(ServerContext context)
{
Expand Down
1 change: 1 addition & 0 deletions RLBotCS/Server/FlatbuffersMessage/StopMatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public ServerAction Execute(ServerContext context)
return ServerAction.Stop;
}

context.Bridge.TryWrite(new EndMatch());
foreach (var (writer, _) in context.Sessions.Values)
writer.TryWrite(new SessionMessage.StopMatch(ShutdownServer));
return ServerAction.Continue;
Expand Down

0 comments on commit 7a23f61

Please sign in to comment.