#include <amxmodx>
#include <amxmisc>
#include <regex>
#include <httpx>
#define PLUGIN "CSSERVERS Vote"
#define VERSION "2.2"
#define AUTHOR "LondoN eXtream"
#define REGEX_STRING "voturi-azi^">(.*?)</a>"
native zp_get_user_ammo_packs(Player);
native zp_set_user_ammo_packs(Player, Packs);
new g_CurrentVotes, g_LastVotes;
new g_PlayerID;
new g_CvarServer;
new g_MaxPlayers;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR);
register_clcmd("say /vote", "VoteazaServer");
g_CvarServer = register_cvar("csservers_server", "zm.darkland.ro");
g_MaxPlayers = get_maxplayers();
set_task(120.0, "VerificaOnline", .flags="b");
set_task(120.0, "PrintMessage", .flags="b");
}
public PrintMessage() Print(0, "^x04[BONUS]^x01 Daca doresti^x03 200^x01 Ammo Packs tasteaza^x04 /vote^x01 si voteaza serverul!");
public VerificaOnline()
{
// Stocam voturile actuale
new Server[32], URL[256];
get_pcvar_string(g_CvarServer, Server, charsmax(Server));
formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", Server);
HTTPX_Download(URL, _, _, "SalveazaVoturile");
}
public VoteazaServer(Player)
{
// Stocam voturile actuale
new Server[32], URL[256];
get_pcvar_string(g_CvarServer, Server, charsmax(Server));
formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", Server);
HTTPX_Download(URL, _, _, "SalveazaVoturile");
// Afisam pagina de votare
formatex(URL, charsmax(URL), "http://www.csservers.ro/voteaza/%s", Server);
show_motd(Player, URL);
// Stocam jucatorul
g_PlayerID = Player;
// Verificam din nou peste ceva timp
set_task(25.0, "VerificaVoturile", Player);
}
public SalveazaVoturile(DownloadID)
{
new g_Buffer[1024], g_Error[64], g_Votes[16], iVotes, iNum;
new Regex:Voturi;
while(HTTPX_GetData(g_Buffer, charsmax(g_Buffer)))
{
Voturi = regex_match(g_Buffer, REGEX_STRING, iNum, g_Error, charsmax(g_Error));
if(Voturi)
{
regex_substr(Voturi, 1, g_Votes, charsmax(g_Votes));
iVotes = str_to_num(g_Votes);
g_LastVotes = iVotes;
server_print("[CSSERVERS] Serverul are %d voturi", iVotes);
regex_free(Voturi);
}
}
}
public VerificaVoturile(Player)
{
new g_Server[32], URL[256];
get_pcvar_string(g_CvarServer, g_Server, charsmax(g_Server));
formatex(URL, charsmax(URL), "http://www.csservers.ro/evidenta/%s", g_Server);
new DownloadID = HTTPX_Download(URL, _, _, "VoturiCurente");
HTTPX_SetCustom(DownloadID, Player);
}
public VoturiCurente(DownloadID)
{
new g_Buffer[1024], g_Error[64], g_Votes[16], iVotes, iNum;
new Regex:Voturi;
while(HTTPX_GetData(g_Buffer, charsmax(g_Buffer)))
{
Voturi = regex_match(g_Buffer, REGEX_STRING, iNum, g_Error, charsmax(g_Error));
if(Voturi)
{
regex_substr(Voturi, 1, g_Votes, charsmax(g_Votes));
iVotes = str_to_num(g_Votes);
g_CurrentVotes = iVotes;
if(g_CurrentVotes > g_LastVotes)
{
new Player = g_PlayerID;
if(!(1 <= Player <= g_MaxPlayers))
return;
zp_set_user_ammo_packs(Player, zp_get_user_ammo_packs(Player) + 200);
Print(Player, "^x04[CSSERVERS]^x01 Felicitari! Ai votat serverul si ai primit^x03 200^x01 Ammo Packs");
}
regex_free(Voturi);
}
}
}
stock Print(const id, const input[], any:...) {
new count = 1, players[32];
static msg[191];
vformat(msg, 190, input, 3);
if(id) players[0] = id;
else get_players(players, count, "ch"); {
for(new i = 0; i < count; i++) {
if(is_user_connected(players)) {
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, players);
write_byte(players);
write_string(msg);
message_end();
}
}
}
}