Only handle events of own steamid

This commit is contained in:
glax 2024-01-14 02:10:24 +01:00
parent f77f5bc3b4
commit 8526c6b00b
3 changed files with 9 additions and 2 deletions

View File

@ -12,9 +12,15 @@ public class CS2MessageHandler
public event CS2EventHandler? OnRoundWin;
public event CS2EventHandler? OnRoundLoss;
public void HandleCS2Message(string message)
public void HandleCS2Message(string message, string mySteamId)
{
JObject messageJson = JObject.Parse(message);
string? steamId = messageJson.SelectToken("player.steamid", false)?.Value<string>();
if (steamId is null || steamId != mySteamId)
{
Console.WriteLine("Not my steamid");
return;
}
RoundState currentRoundState = ParseRoundStateFromString(messageJson.SelectToken("round.phase", false)?.Value<string>());
RoundState previousRoundState = ParseRoundStateFromString(messageJson.SelectToken("previously.round.phase", false)?.Value<string>());

View File

@ -64,6 +64,6 @@ public class OpenCS2hock
Directory.CreateDirectory(Path.Combine(Environment.CurrentDirectory, "CS2Events"));
string fileName = Path.Combine(Environment.CurrentDirectory, "CS2Events" ,$"{DateTime.Now.ToLongTimeString().Replace(':','.')}.json");
File.WriteAllText(fileName, content);
_cs2MessageHandler.HandleCS2Message(content);
_cs2MessageHandler.HandleCS2Message(content, _settings.SteamId);
}
}

View File

@ -4,6 +4,7 @@ namespace OpenCS2hock;
public struct Settings
{
public string SteamId = "";
public OpenShockSettings OpenShockSettings = new()
{
Endpoint = "https://api.shocklink.net",