Skip to content

Commit

Permalink
Basic implementation of match comms
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jul 18, 2024
1 parent 26565e6 commit 344f53f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
13 changes: 12 additions & 1 deletion RLBotCS/Server/FlatBuffersSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public record RendersAllowed(bool Allowed) : SessionMessage;

public record StateSettingAllowed(bool Allowed) : SessionMessage;

public record MatchComm(MatchCommT matchComm) : SessionMessage;

public record StopMatch : SessionMessage;
}

Expand Down Expand Up @@ -120,7 +122,7 @@ private async Task<bool> ParseClientMessage(TypedPayload message)
break;

var matchComms = MatchComm.GetRootAsMatchComm(byteBuffer).UnPack();
// todo: send to server to send to other clients
await _rlbotServer.WriteAsync(new SendMatchComm(_clientId, matchComms));

break;

Expand Down Expand Up @@ -209,6 +211,15 @@ await SendPayloadToClientAsync(
break;
case SessionMessage.StateSettingAllowed m:
_stateSettingIsEnabled = m.Allowed;
break;
case SessionMessage.MatchComm m when _isReady && _wantsComms:
_messageBuilder.Clear();
_messageBuilder.Finish(MatchComm.Pack(_messageBuilder, m.matchComm).Value);

await SendPayloadToClientAsync(
TypedPayload.FromFlatBufferBuilder(DataType.MatchComms, _messageBuilder)
);

break;
case SessionMessage.StopMatch when _isReady && _closeAfterMatch:
Console.WriteLine("Core got stop match message from server.");
Expand Down
25 changes: 25 additions & 0 deletions RLBotCS/Server/FlatbuffersMessage/SendMatchComm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using rlbot.flat;

namespace RLBotCS.Server.FlatbuffersMessage;

internal record SendMatchComm(int ClientId, MatchCommT MatchComm) : IServerMessage
{
public ServerAction Execute(ServerContext context)
{
var message = new SessionMessage.MatchComm(MatchComm);

foreach (var session in context.Sessions)
{
var id = session.Key;
var writer = session.Value;

// Don't send the message back to the client that sent it.
if (id != ClientId)
{
writer.writer.TryWrite(message);
}
}

return ServerAction.Continue;
}
}

0 comments on commit 344f53f

Please sign in to comment.