PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <regex>
#include <http>
#define SERVER_IP "78.110.163.197:27015"
new g_DownloadId[33];
new g_MaxClients;
enum patternsEnum {
Prefix[32],
Pattern[128]
}
new g_Info[][patternsEnum] = {
{ "First Seen:", "\w{3} [0-3][0-9], [12][019][0-9][0-9]" },
{ "Last Seen:", "Online Now|(((Yester|To)day)|(\w{3} [0-3][0-9], [12][019][0-9][0-9])) (1[0-2]|[0-9]):[0-5]\d [A|P]M" },
{ "Score:", "(?<=\s)\d+" },
{ "Minutes Played:", "(?<=\s)\d+" },
{ "Score per Minute:", "(?<=\s)\d+\.?\d?" },
{ "Rank on Server:", "#\d+ out of \d+" }
};
public plugin_init() {
register_plugin("Test Plugin 9", "", "");
register_clcmd("say /myinfo", "cmd_MyInfo");
g_MaxClients = global_get(glb_maxClients); // Get maximum possible ammount of players
}
public cmd_MyInfo(id, level, cid) {
if ( g_DownloadId[id] ) // Spam protection.
return;
new name[40];
new url[128];
get_user_name(id, name, charsmax(name)); // Retrieve user name.
formatex(url, charsmax(url), "http://www.gametracker.com/player/%s/%s/", name, SERVER_IP); // Format the url.
formatex(name[strlen(name)], charsmax(name) - strlen(name), ".txt"); // We'll reuse the name variable to store the filename since we're done with the name.
g_DownloadId[id] = HTTP_DownloadFile(url, name);
}
public client_disconnect(id) {
HTTP_AbortTransfer(g_DownloadId[id]); // No need to download the file if the user isn't interested.
g_DownloadId[id] = 0; // We have to reset the spam protection, otherwise a joining player might be blocked for no reason.
}
public HTTP_Download(const szFile[] , iDownloadID , iBytesRecv , iFileSize , bool:TransferComplete) {
if ( ! TransferComplete )
return; // SHUT UP!
new id;
for ( new i = 0 ; i <= g_MaxClients ; i++ ) {
if ( g_DownloadId[i] == iDownloadID ) // Find the person who's requested this download.
id = i; // Store it.
}
g_DownloadId[id] = 0; // Reset the spam protection so people can use the command more than once.
if ( ! is_user_connected(id) ) // Just in case.
return;
new buffer[1024], i, bool: searching; // Variables of the file reading.
new result[128], num; // Variables of RegEx.
new message[1024], len; // Variables of the hudmessage.
new hFile = fopen(szFile, "r"); // Open the file.
if ( ! hFile ) // Just in case.
return;
while ( ! feof(hFile) && i < sizeof g_Info ) {
fgets(hFile, buffer, charsmax(buffer)); // Read contents of result.
if ( ! searching && contain(buffer, g_Info[i][Prefix]) != -1 ) // Does it contain the prefix?
searching = true; // Because then we will start the regex search.
if ( searching ) { // To avoid false positives since this is a multiple line file.
new Regex:hRegex = regex_match(buffer, g_Info[i][Pattern], num, result, 127); // Search for the pattern in the current line.
if ( hRegex <= REGEX_PATTERN_FAIL )
server_print("Regex error: %d, %s", num, result); // WROOOOONG!
if ( hRegex >= REGEX_OK ) { // Do we have a match?
regex_substr(hRegex, 0, result, charsmax(result)); // Read the first match of the regex.
len += formatex(message[len], charsmax(message) - len, "%s^t%s^n", g_Info[i][Prefix], result); // Add the prefix and result to the hudmessage.
regex_free(hRegex); // We don't want leaked memory and open handles.
searching = false; // To avoid false positives.
i++; // NEXT!
}
}
}
fclose(hFile); // We don't want leaked memory and open handles.
set_hudmessage(_,_,_,_,_,_,_,15.0,_,_,-1);
show_hudmessage(id, message);
set_task(3.0, "DeleteFile", id + 1253862, szFile, strlen(szFile)); // It doesn't seem to work if you do it instantly for some reason.
}
public DeleteFile(const szFile[]) {
delete_file(szFile);
}