3 changed files with 149 additions and 27 deletions
@ -0,0 +1,65 @@ |
|||
JSON_Object payload = new JSON_Object(); |
|||
payload.SetBool("status", true); |
|||
|
|||
int player_count = 0; |
|||
payload.SetInt("max_players", MaxClients); |
|||
|
|||
char map_name[128]; |
|||
GetCurrentMap(map_name, sizeof(map_name)); |
|||
payload.SetString("map_name", map_name); |
|||
|
|||
JSON_Array players = new JSON_Array(); |
|||
|
|||
for(int client = 0; client <= MaxClients; client++) { |
|||
if (IsValidClient(client)) { |
|||
player_count++; |
|||
JSON_Object player = new JSON_Object(); |
|||
/* Name */ |
|||
char name[64]; |
|||
GetClientName(client, name, sizeof(name)); |
|||
player.SetString("name", name); |
|||
/* Score */ |
|||
player.SetInt("score", GetClientFrags(client)); |
|||
player.SetInt("deads", GetClientDeaths(client)); |
|||
/* Duration */ |
|||
char duration[16]; |
|||
int ct = RoundFloat(GetClientTime(client)); |
|||
int h = ct / 3600; |
|||
int m = ct % 3600 / 60; |
|||
int s = ct % 60; |
|||
Format(duration, sizeof(duration), "%02d:%02d:%02d", h, m, s); |
|||
player.SetString("duration", duration); |
|||
/* Id */ |
|||
player.SetInt("id", GetClientUserId(client)); |
|||
/* Ip */ |
|||
char ip[32]; |
|||
GetClientIP(client, ip, sizeof(ip), false); |
|||
player.SetString("ip", ip); |
|||
/* Loss */ |
|||
player.SetInt("loss",RoundFloat(GetClientAvgLoss(client, NetFlow_Both)*1000.0)); |
|||
/* Ping */ |
|||
player.SetInt("ping",RoundFloat(GetClientLatency(client, NetFlow_Both)*1000.0)); |
|||
/* State */ |
|||
player.SetString("state", "active") |
|||
/* Steam 2 так надо, не надо спрашивать почему*/ |
|||
char steam2[32]; |
|||
GetClientAuthId(client, AuthId_Steam3, steam2, sizeof(steam2)); |
|||
player.SetString("steam2", steam2); |
|||
/* Position on map */ |
|||
float pos[3]; |
|||
GetClientAbsOrigin(client, pos); |
|||
player.SetFloat("pos_x", pos[0]); |
|||
player.SetFloat("pos_y", pos[1]); |
|||
player.SetFloat("pos_z", pos[2]); |
|||
/* Player class */ |
|||
player.SetInt("clz", TF2_GetPlayerClass(client)); |
|||
/* Player team */ |
|||
player.SetInt("team", TF2_GetClientTeam(client)); |
|||
/* push */ |
|||
players.PushObject(player); |
|||
json_cleanup_and_delete(player); |
|||
} |
|||
} |
|||
|
|||
payload.SetObject("players", players); |
|||
payload.SetInt("player_count", player_count); |
|||
Loading…
Reference in new issue