From 8526c6b00bc1da531ddf9e9d8d6aaeae735034c3 Mon Sep 17 00:00:00 2001 From: glax Date: Sun, 14 Jan 2024 02:10:24 +0100 Subject: [PATCH] Only handle events of own steamid --- OpenCS2hock/CS2MessageHandler.cs | 8 +++++++- OpenCS2hock/OpenCS2hock.cs | 2 +- OpenCS2hock/Settings.cs | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/OpenCS2hock/CS2MessageHandler.cs b/OpenCS2hock/CS2MessageHandler.cs index bea9585..ab9e96b 100644 --- a/OpenCS2hock/CS2MessageHandler.cs +++ b/OpenCS2hock/CS2MessageHandler.cs @@ -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(); + if (steamId is null || steamId != mySteamId) + { + Console.WriteLine("Not my steamid"); + return; + } RoundState currentRoundState = ParseRoundStateFromString(messageJson.SelectToken("round.phase", false)?.Value()); RoundState previousRoundState = ParseRoundStateFromString(messageJson.SelectToken("previously.round.phase", false)?.Value()); diff --git a/OpenCS2hock/OpenCS2hock.cs b/OpenCS2hock/OpenCS2hock.cs index 9c880f2..924f9d9 100644 --- a/OpenCS2hock/OpenCS2hock.cs +++ b/OpenCS2hock/OpenCS2hock.cs @@ -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); } } \ No newline at end of file diff --git a/OpenCS2hock/Settings.cs b/OpenCS2hock/Settings.cs index fea077b..1aed736 100644 --- a/OpenCS2hock/Settings.cs +++ b/OpenCS2hock/Settings.cs @@ -4,6 +4,7 @@ namespace OpenCS2hock; public struct Settings { + public string SteamId = ""; public OpenShockSettings OpenShockSettings = new() { Endpoint = "https://api.shocklink.net",