Skip to content
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
40 changes: 16 additions & 24 deletions RLBotCS/Server/FlatBuffersSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public readonly record struct DistributeBallPrediction(BallPredictionT BallPredi

public readonly record struct StopMatch(bool Force) : SessionMessage;

public readonly record struct UpdateRendering(RenderingStatus Status) : SessionMessage;
public readonly record struct UpdateRendering(RenderingStatusT Status) : SessionMessage;

public readonly record struct PingResponse(ulong Cookie) : SessionMessage;
}
Expand All @@ -52,7 +52,7 @@ class FlatBuffersSession
private readonly Channel<SessionMessage> _incomingMessages;
private readonly ChannelWriter<IServerMessage> _rlbotServer;
private readonly ChannelWriter<IBridgeMessage> _bridge;
private readonly Dictionary<uint, bool> _gotInput = new();
private readonly Dictionary<uint, bool> _gotInput = [];

/// <summary>Indicates that we received a ConnectionSettings message from the client, and that
/// we now know its agent id (if any) and whether it is interested in ball prediction, match comms,
Expand All @@ -72,7 +72,7 @@ class FlatBuffersSession

private string _agentId = string.Empty;
private uint _team = Team.Other;
private List<PlayerIdPair> _playerIdPairs = new();
private List<PlayerIdPair> _playerIdPairs = [];
private bool _sessionForceClosed;
private bool _closed;

Expand Down Expand Up @@ -311,7 +311,7 @@ await _bridge.WriteAsync(
break;

case InterfaceMessage.RenderingStatus:
var renderingStatus = msg.MessageAsRenderingStatus();
var renderingStatus = msg.MessageAsRenderingStatus().UnPack();
await _rlbotServer.WriteAsync(new UpdateRendering(renderingStatus));
break;

Expand Down Expand Up @@ -422,28 +422,20 @@ private async Task HandleInternalMessages()
when m.Force || (_connectionEstablished && _closeBetweenMatches):
_sessionForceClosed = m.Force;
return;
case SessionMessage.UpdateRendering m
when (m.Status.IsBot && (_team == Team.Blue || _team == Team.Orange))
|| (!m.Status.IsBot && _team == Team.Scripts):

foreach (var player in _playerIdPairs)
case SessionMessage.UpdateRendering m:
if (_team == Team.Other)
{
if (player.Index == m.Status.Index)
{
_renderingIsEnabled = m.Status.Status;
SendPayloadToClient(
CoreMessageUnion.FromRenderingStatus(
new RenderingStatusT()
{
Index = player.Index,
IsBot = m.Status.IsBot,
Status = m.Status.Status,
}
)
);
SendPayloadToClient(CoreMessageUnion.FromRenderingStatus(m.Status));
return;
}

break;
}
bool isCorrectTeam =
(m.Status.IsBot && (_team == Team.Blue || _team == Team.Orange))
|| (!m.Status.IsBot && _team == Team.Scripts);
if (isCorrectTeam && _playerIdPairs.Exists(p => p.Index == m.Status.Index))
{
_renderingIsEnabled = m.Status.Status;
SendPayloadToClient(CoreMessageUnion.FromRenderingStatus(m.Status));
}

break;
Expand Down
2 changes: 1 addition & 1 deletion RLBotCS/Server/ServerMessage/UpdateRendering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace RLBotCS.Server.ServerMessage;

readonly struct UpdateRendering(RenderingStatus Status) : IServerMessage
readonly struct UpdateRendering(RenderingStatusT Status) : IServerMessage
{
public ServerAction Execute(ServerContext context)
{
Expand Down
Loading