diff --git a/CS2WebSocketTelemetryPlugin/CS2WebSocketTelemetryPlugin.cs b/CS2WebSocketTelemetryPlugin/CS2WebSocketTelemetryPlugin.cs index e209b0b..fd76c15 100644 --- a/CS2WebSocketTelemetryPlugin/CS2WebSocketTelemetryPlugin.cs +++ b/CS2WebSocketTelemetryPlugin/CS2WebSocketTelemetryPlugin.cs @@ -51,6 +51,7 @@ public class MetaWebSocketPlugin : BasePlugin private CancellationTokenSource? _serverCts; private Task? _acceptTask; private volatile bool _serverRunning = false; + private volatile string _phase = "unknown"; private readonly ConcurrentDictionary _clients = new(); private int _clientSeq = 0; @@ -63,6 +64,14 @@ public class MetaWebSocketPlugin : BasePlugin public string? CertPassword { get; set; } // optional } + private void SetPhase(string p) + { + var s = (p ?? "unknown").ToLowerInvariant(); + if (s == _phase) return; + _phase = s; + Broadcast(JsonSerializer.Serialize(new { type = "phase", phase = _phase, t = NowMs() })); + } + private sealed class ClientState { public required TcpClient Tcp; @@ -74,6 +83,17 @@ public class MetaWebSocketPlugin : BasePlugin // ------------- Helpers ------------- private static long NowMs() => DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + private string BuildMapPayload() + { + return JsonSerializer.Serialize(new { + type = "map", + name = _mapName, + phase = _phase, + t = NowMs() + }); + } + + private void TrySafeInitialPush() { try @@ -82,9 +102,10 @@ public class MetaWebSocketPlugin : BasePlugin if (!string.IsNullOrEmpty(mn)) { _mapName = mn!; - Broadcast(JsonSerializer.Serialize(new { type = "map", name = _mapName, t = NowMs() })); + Broadcast(BuildMapPayload()); // 👈 statt anonymes Json } SendFullPlayerList(); // nur hier oder aus Events heraus aufrufen + Broadcast(JsonSerializer.Serialize(new { type = "phase", phase = _phase, t = NowMs() })); } catch (Exception ex) { @@ -197,6 +218,18 @@ public class MetaWebSocketPlugin : BasePlugin RegisterEventHandler(OnPlayerConnectFull); RegisterEventHandler(OnPlayerDisconnect); + // Runden-/Bomben-Phase + RegisterEventHandler(OnRoundStart); + RegisterEventHandler(OnRoundFreezeEnd); + RegisterEventHandler(OnRoundEnd); + RegisterEventHandler(OnBombPlanted); + RegisterEventHandler(OnBombDefused); + RegisterEventHandler(OnBombExploded); + + // (optional, falls verfügbar) + // RegisterEventHandler(OnWarmupStart); + // RegisterEventHandler(OnWarmupEnd); + LoadAndApplyConfig(); if (_enabled) StartWebSocket(); @@ -217,12 +250,15 @@ public class MetaWebSocketPlugin : BasePlugin private void OnMapStart(string newMap) { _mapName = newMap ?? Server.MapName ?? ""; - Broadcast(JsonSerializer.Serialize(new { type = "map", name = _mapName, t = NowMs() })); - // Nach Mapstart zusätzlich die Spielerliste pushen + + SetPhase("warmup"); // 👈 zuerst Phase setzen (sendet auch ein separates phase-Event) + Broadcast(BuildMapPayload()); // 👈 Map + Phase zusammen SendFullPlayerList(); + Logger.LogInformation($"[WS] Map gewechselt: '{(_mapName ?? "")}' – Meta gesendet."); } + private HookResult OnPlayerConnectFull(EventPlayerConnectFull ev, GameEventInfo info) { try @@ -274,6 +310,49 @@ public class MetaWebSocketPlugin : BasePlugin return HookResult.Continue; } + private HookResult OnRoundStart(EventRoundStart ev, GameEventInfo info) + { + // Start der Runde == Freezezeit + SetPhase("freezetime"); + return HookResult.Continue; + } + + private HookResult OnRoundFreezeEnd(EventRoundFreezeEnd ev, GameEventInfo info) + { + // Ende Freeze -> Live + SetPhase("live"); + return HookResult.Continue; + } + + private HookResult OnRoundEnd(EventRoundEnd ev, GameEventInfo info) + { + SetPhase("over"); + return HookResult.Continue; + } + + private HookResult OnBombPlanted(EventBombPlanted ev, GameEventInfo info) + { + SetPhase("bomb"); + return HookResult.Continue; + } + + private HookResult OnBombDefused(EventBombDefused ev, GameEventInfo info) + { + // Bombe ist weg, Runde läuft weiter bis RoundEnd + SetPhase("live"); + return HookResult.Continue; + } + + private HookResult OnBombExploded(EventBombExploded ev, GameEventInfo info) + { + SetPhase("over"); + return HookResult.Continue; + } + + // (optional) + // private HookResult OnWarmupStart(EventWarmupStart ev, GameEventInfo info) { SetPhase("warmup"); return HookResult.Continue; } + // private HookResult OnWarmupEnd(EventWarmupEnd ev, GameEventInfo info) { SetPhase("freezetime"); return HookResult.Continue; } + // ------------- Console Commands ------------- [ConsoleCommand("css_meta_enable", "WS(S)-Server aktivieren/deaktivieren: css_meta_enable 1|0")] [CommandHelper(minArgs: 1, usage: "<1|0>")] @@ -385,7 +464,7 @@ public class MetaWebSocketPlugin : BasePlugin [ConsoleCommand("css_meta_sendmap", "Sendet die aktuelle Karte an alle verbundenen Clients")] public void CmdSendMap(CCSPlayerController? caller, CommandInfo cmd) { - Broadcast(JsonSerializer.Serialize(new { type = "map", name = _mapName, t = NowMs() })); + Broadcast(BuildMapPayload()); cmd.ReplyToCommand($"[WS] Map '{_mapName}' an Clients gesendet."); } @@ -552,14 +631,16 @@ public class MetaWebSocketPlugin : BasePlugin try { if (!_clients.ContainsKey(id) || state.Cts.IsCancellationRequested) return; - var nowMs = NowMs(); - SendTextFrame(state, JsonSerializer.Serialize(new { type = "map", name = _mapName, t = nowMs })); - var buf = BuildPlayersPayload(); // jetzt safe + SendTextFrame(state, BuildMapPayload()); // 👈 + var buf = BuildPlayersPayload(); SendTextFrame(state, buf); + // optional zusätzlich: + // SendTextFrame(state, JsonSerializer.Serialize(new { type = "phase", phase = _phase, t = NowMs() })); } catch { /* ignore */ } }); + await ReceiveLoop(state, serverCt); } catch (OperationCanceledException) { } diff --git a/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll b/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll index ed89f4b..63afde8 100644 Binary files a/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll and b/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll differ diff --git a/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb b/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb index fac5a87..26359b5 100644 Binary files a/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb and b/CS2WebSocketTelemetryPlugin/bin/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb differ diff --git a/CS2WebSocketTelemetryPlugin/obj/CS2WebSocketTelemetryPlugin.csproj.nuget.g.props b/CS2WebSocketTelemetryPlugin/obj/CS2WebSocketTelemetryPlugin.csproj.nuget.g.props index 2b4790d..6fb2b23 100644 --- a/CS2WebSocketTelemetryPlugin/obj/CS2WebSocketTelemetryPlugin.csproj.nuget.g.props +++ b/CS2WebSocketTelemetryPlugin/obj/CS2WebSocketTelemetryPlugin.csproj.nuget.g.props @@ -5,18 +5,18 @@ NuGet $(MSBuildThisFileDirectory)project.assets.json $(UserProfile)\.nuget\packages\ - C:\Users\Rother\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages + C:\Users\Chris\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages PackageReference - 6.14.0 + 6.11.1 - + - C:\Users\Rother\.nuget\packages\microsoft.dotnet.apicompat.task\8.0.203 + C:\Users\Chris\.nuget\packages\microsoft.dotnet.apicompat.task\8.0.203 \ No newline at end of file diff --git a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.AssemblyInfo.cs b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.AssemblyInfo.cs index 7639833..0fbb7f7 100644 --- a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.AssemblyInfo.cs +++ b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.AssemblyInfo.cs @@ -13,10 +13,10 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("CS2WebSocketTelemetryPlugin")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+476da04a6d243eceba7c8b28e101211f978faf12")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+5cd0409eda59707069d32b70b5c63a1fd2d8956a")] [assembly: System.Reflection.AssemblyProductAttribute("CS2WebSocketTelemetryPlugin")] [assembly: System.Reflection.AssemblyTitleAttribute("CS2WebSocketTelemetryPlugin")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] -// Generated by the MSBuild WriteCodeFragment class. +// Von der MSBuild WriteCodeFragment-Klasse generiert. diff --git a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.GeneratedMSBuildEditorConfig.editorconfig b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.GeneratedMSBuildEditorConfig.editorconfig index e69493c..93b1b8b 100644 --- a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.GeneratedMSBuildEditorConfig.editorconfig +++ b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.GeneratedMSBuildEditorConfig.editorconfig @@ -8,8 +8,6 @@ build_property.PlatformNeutralAssembly = build_property.EnforceExtendedAnalyzerRules = build_property._SupportedPlatformList = Linux,macOS,Windows build_property.RootNamespace = CS2WebSocketTelemetryPlugin -build_property.ProjectDir = C:\Users\Rother\fork\ironie-cs2-websocket-plugin\CS2WebSocketTelemetryPlugin\ +build_property.ProjectDir = C:\Users\Chris\fork\ironie-cs2-websocket-plugin\CS2WebSocketTelemetryPlugin\ build_property.EnableComHosting = build_property.EnableGeneratedComInterfaceComImportInterop = -build_property.EffectiveAnalysisLevelStyle = 8.0 -build_property.EnableCodeStyleSeverity = diff --git a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll index ed89f4b..63afde8 100644 Binary files a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll and b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.dll differ diff --git a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb index fac5a87..26359b5 100644 Binary files a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb and b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/CS2WebSocketTelemetryPlugin.pdb differ diff --git a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/ref/CS2WebSocketTelemetryPlugin.dll b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/ref/CS2WebSocketTelemetryPlugin.dll index 43c280b..beb2a0d 100644 Binary files a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/ref/CS2WebSocketTelemetryPlugin.dll and b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/ref/CS2WebSocketTelemetryPlugin.dll differ diff --git a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/refint/CS2WebSocketTelemetryPlugin.dll b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/refint/CS2WebSocketTelemetryPlugin.dll index 43c280b..beb2a0d 100644 Binary files a/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/refint/CS2WebSocketTelemetryPlugin.dll and b/CS2WebSocketTelemetryPlugin/obj/Debug/net8.0/refint/CS2WebSocketTelemetryPlugin.dll differ diff --git a/CS2WebSocketTelemetryPlugin/obj/project.assets.json b/CS2WebSocketTelemetryPlugin/obj/project.assets.json index 416fe03..e6270f5 100644 --- a/CS2WebSocketTelemetryPlugin/obj/project.assets.json +++ b/CS2WebSocketTelemetryPlugin/obj/project.assets.json @@ -2555,31 +2555,29 @@ ] }, "packageFolders": { - "C:\\Users\\Rother\\.nuget\\packages\\": {}, + "C:\\Users\\Chris\\.nuget\\packages\\": {}, "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {} }, "project": { "version": "1.0.0", "restore": { - "projectUniqueName": "C:\\Users\\Rother\\fork\\ironie-cs2-websocket-plugin\\CS2WebSocketTelemetryPlugin\\CS2WebSocketTelemetryPlugin.csproj", + "projectUniqueName": "C:\\Users\\Chris\\fork\\ironie-cs2-websocket-plugin\\CS2WebSocketTelemetryPlugin\\CS2WebSocketTelemetryPlugin.csproj", "projectName": "CS2WebSocketTelemetryPlugin", - "projectPath": "C:\\Users\\Rother\\fork\\ironie-cs2-websocket-plugin\\CS2WebSocketTelemetryPlugin\\CS2WebSocketTelemetryPlugin.csproj", - "packagesPath": "C:\\Users\\Rother\\.nuget\\packages\\", - "outputPath": "C:\\Users\\Rother\\fork\\ironie-cs2-websocket-plugin\\CS2WebSocketTelemetryPlugin\\obj\\", + "projectPath": "C:\\Users\\Chris\\fork\\ironie-cs2-websocket-plugin\\CS2WebSocketTelemetryPlugin\\CS2WebSocketTelemetryPlugin.csproj", + "packagesPath": "C:\\Users\\Chris\\.nuget\\packages\\", + "outputPath": "C:\\Users\\Chris\\fork\\ironie-cs2-websocket-plugin\\CS2WebSocketTelemetryPlugin\\obj\\", "projectStyle": "PackageReference", "fallbackFolders": [ "C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages" ], "configFilePaths": [ - "C:\\Users\\Rother\\AppData\\Roaming\\NuGet\\NuGet.Config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config", - "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config" + "C:\\Users\\Chris\\AppData\\Roaming\\NuGet\\NuGet.Config", + "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config" ], "originalTargetFrameworks": [ "net8.0" ], "sources": { - "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {}, "https://api.nuget.org/v3/index.json": {} }, "frameworks": { @@ -2597,8 +2595,7 @@ "enableAudit": "true", "auditLevel": "low", "auditMode": "direct" - }, - "SdkAnalysisLevel": "9.0.300" + } }, "frameworks": { "net8.0": { @@ -2625,7 +2622,7 @@ "privateAssets": "all" } }, - "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.304/PortableRuntimeIdentifierGraph.json" + "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\8.0.408/PortableRuntimeIdentifierGraph.json" } } }