WebPanelBridge 0.2.0: leave out admins hidden with CS2-SimpleAdmin's css_hide

This commit is contained in:
Astra 2026-09-27 18:10:22 +01:00
parent d02c8454df
commit b68113733e
4 changed files with 30 additions and 5 deletions

View file

@ -3,19 +3,22 @@ using System.Text.Json.Serialization;
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Core.Capabilities;
using CounterStrikeSharp.API.Modules.Commands;
using CounterStrikeSharp.API.Modules.Cvars;
using CounterStrikeSharp.API.Modules.Utils;
using CS2_SimpleAdminApi;
namespace WebPanelBridge;
// Reports live match state to simpleadmin-web over RCON. The server console command prints one
// JSON object per line, each prefixed with "wpb ", so the web panel can pick them out of whatever
// else lands in the RCON response. Nothing here changes game state.
// else lands in the RCON response. Admins hidden with CS2-SimpleAdmin's css_hide are left out, as if
// they weren't connected. Nothing here changes game state.
public class WebPanelBridge : BasePlugin
{
public override string ModuleName => "WebPanelBridge";
public override string ModuleVersion => "0.1.0";
public override string ModuleVersion => "0.2.0";
public override string ModuleAuthor => "astra";
public override string ModuleDescription => "Live server status for simpleadmin-web, over RCON";
@ -27,6 +30,8 @@ public class WebPanelBridge : BasePlugin
DefaultIgnoreCondition = JsonIgnoreCondition.Never,
};
private static readonly PluginCapability<ICS2_SimpleAdminApi> SimpleAdminCapability = new("simpleadmin:api");
private record ServerLine(int V, string Hostname, string Map, int MaxPlayers, int ScoreT, int ScoreCt, bool Warmup);
private record PlayerLine(int Userid, string Name, string Steamid, int Team, int Kills, int Deaths, uint Ping, bool Bot);
@ -56,10 +61,22 @@ public class WebPanelBridge : BasePlugin
scoreT, scoreCt, warmup);
command.ReplyToCommand(Prefix + JsonSerializer.Serialize(server, JsonOptions));
// Fetched on every call, so reloading SimpleAdmin doesn't leave a stale instance here.
ICS2_SimpleAdminApi? simpleAdmin = null;
try
{
simpleAdmin = SimpleAdminCapability.Get();
}
catch (KeyNotFoundException)
{
}
foreach (var player in Utilities.GetPlayers())
{
if (player is not { IsValid: true, IsHLTV: false } || player.Connected != PlayerConnectedState.Connected)
continue;
if (!player.IsBot && simpleAdmin?.IsAdminSilent(player) == true)
continue;
var stats = player.ActionTrackingServices?.MatchStats;
var line = new PlayerLine(