Skip to content

Commit

Permalink
prevent accidental redeem replay
Browse files Browse the repository at this point in the history
queue spawns til a bit later
  • Loading branch information
Govorunb committed Jun 13, 2024
1 parent d83921b commit d930e78
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions SCHIZO/SwarmControl/MessageProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net.WebSockets;
using SCHIZO.Commands.Base;
using SCHIZO.Commands.Context;
Expand All @@ -13,6 +14,10 @@ namespace SCHIZO.SwarmControl;
internal sealed class MessageProcessor
{
private readonly ControlWebSocket _socket;

//private readonly Dictionary<Guid, RedeemMessage> _redeems = [];
private readonly Dictionary<Guid, ResultMessage> _results = [];

public MessageProcessor(ControlWebSocket socket)
{
_socket = socket;
Expand Down Expand Up @@ -74,6 +79,13 @@ private void OnRedeem(RedeemMessage msg)
SendResult(guid, false, "Command not found");
return;
}
// prevents server replaying redeems in case we receive one but the game doesn't acknowledge it or something (so the server thinks it didn't send and replays it later)
// ...but we do still want to be able to replay manually
if (msg.Source == CommandInvocationSource.Swarm && _results.TryGetValue(guid, out ResultMessage? result))
{
_socket.SendMessage(result);
return;
}

JsonContext ctx = new()
{
Expand Down Expand Up @@ -138,11 +150,13 @@ private void SendHello()

private void SendResult(Guid guid, bool success, string? message = null)
{
_socket.SendMessage(new ResultMessage()
ResultMessage msg = new()
{
Guid = guid,
Success = success,
Message = message
});
};
_results[msg.Guid] = msg;
_socket.SendMessage(msg);
}
}
1 change: 1 addition & 0 deletions SCHIZO/SwarmControl/SwarmControlManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public string PrivateApiKey
&& !Player.main.IsPilotingSeatruck()
#endif
&& !Player.main.IsInBase()
&& !Player.main.cinematicModeActive
//&& Time.timeScale > 0
;

Expand Down

0 comments on commit d930e78

Please sign in to comment.