mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-09-27 20:17:04 +02:00
fix: query command cleaning up
This commit is contained in:
parent
a758b9a7a7
commit
1118939e62
2 changed files with 63 additions and 82 deletions
|
|
@ -11,9 +11,8 @@ using CounterStrikeSharp.API.Modules.Utils;
|
|||
using CS2_SimpleAdmin.Managers;
|
||||
using CS2_SimpleAdmin.Menus;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Newtonsoft.Json;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
public partial class CS2_SimpleAdmin
|
||||
|
|
@ -45,96 +44,78 @@ public partial class CS2_SimpleAdmin
|
|||
{
|
||||
if (!Config.IsCSSPanel) return;
|
||||
|
||||
List<CCSPlayerController> playersToTarget = Utilities.GetPlayers().Where(player => caller!.CanTarget(player) && !player.IsHLTV).ToList();
|
||||
var playersToTarget = Utilities.GetPlayers()
|
||||
.Where(player => caller!.CanTarget(player) && !player.IsHLTV)
|
||||
.ToList();
|
||||
|
||||
string Map = Server.MapName;
|
||||
int Players = playersToTarget.Count;
|
||||
int MaxPlayers = Server.MaxPlayers;
|
||||
string[] Maps;
|
||||
string mapName = Server.MapName;
|
||||
int playersCount = playersToTarget.Count;
|
||||
int maxPlayers = ConVar.Find("sv_visiblemaxplayers")?.GetPrimitiveValue<int>() is int value and > 0 ? value : Server.MaxPlayers;
|
||||
|
||||
MaxPlayers = ConVar.Find("sv_visiblemaxplayers")?.GetPrimitiveValue<int>() ?? -1;
|
||||
MaxPlayers = MaxPlayers <= -1 ? Server.MaxPlayers : MaxPlayers;
|
||||
string serverName = ConVar.Find("hostname")?.StringValue ?? "Unknown";
|
||||
|
||||
string ServerName = ConVar.Find("hostname")?.StringValue ?? "Unknown";
|
||||
|
||||
try
|
||||
{
|
||||
Maps = Server.GetMapList();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Maps = Array.Empty<string>(); // return an empty array
|
||||
}
|
||||
// string[] maps;
|
||||
// try
|
||||
// {
|
||||
// maps = Server.GetMapList();
|
||||
// }
|
||||
// catch (Exception)
|
||||
// {
|
||||
// maps = Array.Empty<string>();
|
||||
// }
|
||||
|
||||
var server = new
|
||||
{
|
||||
map = Map,
|
||||
hN = ServerName,
|
||||
p = Players,
|
||||
mP = MaxPlayers,
|
||||
// maps = Maps,
|
||||
map = mapName,
|
||||
hN = serverName,
|
||||
p = playersCount,
|
||||
mP = maxPlayers,
|
||||
// maps = maps,
|
||||
pr = ModuleVersion
|
||||
};
|
||||
|
||||
List<Task<object>> playerTasks = playersToTarget
|
||||
.FindAll(player => !player.IsBot && !player.IsHLTV && player.PlayerName != "")
|
||||
.Select(player =>
|
||||
try
|
||||
{
|
||||
string deaths = player.ActionTrackingServices!.MatchStats.Deaths.ToString();
|
||||
string headshots = player.ActionTrackingServices!.MatchStats.HeadShotKills.ToString();
|
||||
string assists = player.ActionTrackingServices!.MatchStats.Assists.ToString();
|
||||
string damage = player.ActionTrackingServices!.MatchStats.Damage.ToString();
|
||||
string kills = player.ActionTrackingServices!.MatchStats.Kills.ToString();
|
||||
string time = player.ActionTrackingServices!.MatchStats.LiveTime.ToString();
|
||||
var user = new
|
||||
var filteredPlayers = playersToTarget
|
||||
.Where(player => !player.IsBot && !player.IsHLTV && !string.IsNullOrWhiteSpace(player.PlayerName));
|
||||
|
||||
var players = filteredPlayers.Select(player =>
|
||||
{
|
||||
var stats = player.ActionTrackingServices!.MatchStats;
|
||||
|
||||
return new
|
||||
{
|
||||
id = player.UserId,
|
||||
// playerName = player.PlayerName,
|
||||
// ipAddress = player.IpAddress?.Split(":")[0],
|
||||
// accountId = player.AuthorizedSteamID?.AccountId.ToString(),
|
||||
// steamId2 = player.AuthorizedSteamID?.SteamId2,
|
||||
// steamId3 = player.AuthorizedSteamID?.SteamId3,
|
||||
// accountId = player.AuthorizedSteamID?.AccountId.ToString() ?? "",
|
||||
// steamId2 = player.AuthorizedSteamID?.SteamId2.ToString() ?? "",
|
||||
// steamId3 = player.AuthorizedSteamID?.SteamId3.ToString() ?? "",
|
||||
pn = player.PlayerName,
|
||||
s64 = player.AuthorizedSteamID?.SteamId64.ToString(),
|
||||
s64 = player.AuthorizedSteamID?.SteamId64.ToString() ?? "",
|
||||
// ping = player.Ping,
|
||||
t = player.Team,
|
||||
// clanName = player.ClanName,
|
||||
k = kills,
|
||||
d = deaths,
|
||||
// assists,
|
||||
// headshots,
|
||||
// damage,
|
||||
k = stats.Kills.ToString(),
|
||||
d = stats.Deaths.ToString(),
|
||||
// stats.Assists.ToString(),
|
||||
// stats.HeadShotKills.ToString(),
|
||||
// stats.Damage.ToString(),
|
||||
s = player.Score,
|
||||
// roundScore = player.RoundScore,
|
||||
// roundsWon = player.RoundsWon,
|
||||
// mvps = player.MVPs,
|
||||
// time, // ? Fix this, it's not the time the player has been connected
|
||||
// stats.LiveTime.ToString(), // ? Fix this, it's not the time the player has been connected
|
||||
// avatar = player.AuthorizedSteamID != null ? await GetProfilePictureAsync(player.AuthorizedSteamID.SteamId64.ToString(), true) : ""
|
||||
};
|
||||
return Task.FromResult((object)user);
|
||||
}).ToList();
|
||||
|
||||
List<object> players = new List<object>();
|
||||
try
|
||||
{
|
||||
players = Task.WhenAll(playerTasks).Result.ToList();
|
||||
}
|
||||
catch (AggregateException ex)
|
||||
{
|
||||
foreach (var innerEx in ex.InnerExceptions)
|
||||
{
|
||||
Logger.LogError(innerEx, "Error while querying players");
|
||||
}
|
||||
}
|
||||
|
||||
string jsonString = JsonConvert.SerializeObject(
|
||||
new
|
||||
{
|
||||
server,
|
||||
players
|
||||
}
|
||||
);
|
||||
|
||||
string jsonString = JsonSerializer.Serialize(new { server, players });
|
||||
Server.PrintToConsole(jsonString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.LogError(ex, "Unexpected error while query command");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -169,9 +169,9 @@ public static class PlayerExtensions
|
|||
)
|
||||
{
|
||||
controller.PlayerPawn.Value.Teleport(
|
||||
target.PlayerPawn.Value.AbsOrigin,
|
||||
target.PlayerPawn.Value.AbsRotation,
|
||||
target.PlayerPawn.Value.AbsVelocity
|
||||
target.PlayerPawn.Value.AbsOrigin!.ToVector_t(),
|
||||
target.PlayerPawn.Value.AbsRotation!.ToQAngle_t(),
|
||||
target.PlayerPawn.Value.AbsVelocity.ToVector_t()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue