diff --git a/G5API.cs b/G5API.cs index 6e8cb9a..441fe0d 100644 --- a/G5API.cs +++ b/G5API.cs @@ -12,13 +12,13 @@ public class Get5Status public required string PluginVersion { get; set; } [JsonPropertyName("gamestate")] - public int GameState { get; set; } + public string GameState { get; set; } } public class G5WebAvailable { [JsonPropertyName("gamestate")] - public int GameState { get; init; } + public string GameState { get; init; } [JsonPropertyName("available")] public int Available { get; } = 1; @@ -31,7 +31,8 @@ public partial class MatchZy [ConsoleCommand("get5_status", "Returns get5 status")] public void Get5StatusCommand(CCSPlayerController? player, CommandInfo command) { - command.ReplyToCommand(JsonSerializer.Serialize(new Get5Status { PluginVersion = "0.15.0", GameState = 0 })); + // TODO: Add remaining Get5 status data as specified in https://splewis.github.io/get5/latest/commands/#get5_status + command.ReplyToCommand(JsonSerializer.Serialize(new Get5Status { PluginVersion = "0.15.0", GameState = getGet5Gamestate() })); } [ConsoleCommand("get5_web_available", "Returns get5 web available")] @@ -39,5 +40,60 @@ public void Get5WebAvailable(CCSPlayerController? player, CommandInfo command) { command.ReplyToCommand(JsonSerializer.Serialize(new G5WebAvailable())); } + + private string getGet5Gamestate() + { + // Get state from MatchZy state phase data and map to get5 state + // Get5 states: pre_veto, veto, warmup, knife, waiting_for_knife_decision, going_live, live, pending_restore, post_game + // Please note, that Get5 have moved from integer based states to string based states, so the integer based states are not used. + // + // TODO: Missing "going_live" state, as this is not tracked. It has an event (GoingLiveEvent), but it is not read (only ever dispatched). + // Therefore, a "proxy" is used to determine if the match is going live (and no other state is "active") + string state = "none"; + + // The order of checks have been checked to work. Please be carefull if you change the order. + if (!isMatchSetup) + { + state = "none"; // If the match has not been set up, then the state is none + } + else if (isVeto) + { + state = "veto"; + } + else if (isPreVeto) + { + state = "pre_veto"; + } + else if (isKnifeRound) + { + state = "knife"; + } + else if (isSideSelectionPhase) + { + state = "waiting_for_knife_decision"; + } + else if (IsPostGamePhase()) + { + state = "post_game"; + } + else if (isMatchLive) + { + state = "live"; + } + else if (isRoundRestoring) + { + state = "pending_restore"; + } + else if (matchStarted) + { + state = "going_live"; + } + else if (isWarmup) + { + state = "warmup"; + } + + return state; + } } } diff --git a/documentation/docs/configuration.md b/documentation/docs/configuration.md index 2fa865c..42bf504 100644 --- a/documentation/docs/configuration.md +++ b/documentation/docs/configuration.md @@ -40,12 +40,12 @@ There are two ways to create an admin for MatchZy; you can choose the most conve Inside `csgo/cfg/MatchZy`, a file named `admins.json` should be present. If it is not there, it will be automatically created when the plugin is loaded. You can add Steam64 id of admins in that JSON file like mentioned in the below example: - ```json - { - "76561198154367261": "", - "": "" - } - ``` + ```json + { + "76561198154367261": "", + "": "" + } + ``` ### Configuring MatchZy Settings (ConVars) Again, inside `csgo/cfg/MatchZy`, a file named `config.cfg` should be present. This file is executed whenever the plugin is loaded. If you make any changes in this file and want to reload the config, simply execute `exec MatchZy/config.cfg` command on the server.