PHP Code:
#include <regex>
stock GetStatsInfo()
{
decl String:buffer[256];
ServerCommandEx(buffer, sizeof(buffer), "stats");
new Handle:re = CompileRegex("(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+\\.\\d+)\\s+(\\d+)\\s+(?:(\\d+)\\s+)?");
new subCount = MatchRegex(re, buffer);
if (subCount != 8 || subCount != 9)
{
// not match
CloseHandle(re);
return;
}
decl String:cpu[12];
decl String:in[12];
decl String:out[12];
decl String:uptime[12];
decl String:mapchanges[12];
decl String:users[12];
decl String:fps[12];
decl String:players[12];
decl String:connects[12];
GetRegexSubString(re, 1, cpu, sizeof(cpu));
GetRegexSubString(re, 2, in, sizeof(in));
GetRegexSubString(re, 3, out, sizeof(out));
GetRegexSubString(re, 4, uptime, sizeof(uptime));
GetRegexSubString(re, 6, fps, sizeof(fps));
GetRegexSubString(re, 7, players, sizeof(players));
if (subCount == 8)
{
// L4D2, CSGO
// CPU In Out Uptime Users FPS Players
GetRegexSubString(re, 5, users, sizeof(users));
}
else
{
// CPU In (KB/s) Out (KB/s) Uptime Map changes FPS Players Connects
GetRegexSubString(re, 5, mapchanges, sizeof(mapchanges));
GetRegexSubString(re, 8, connects, sizeof(connects));
}
CloseHandle(re);
LogMessage("cpu=%s, fps=%s, uptime=%s", cpu, fps, uptime);
}
__________________