From: Rudolf Polzer Date: Wed, 17 Aug 2011 19:10:20 +0000 (+0200) Subject: use urllib for weaponstats sending X-Git-Tag: xonotic-v0.5.0~111^2~4^2~10 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3087a6390a8bebbea7bf9f7615c784398c15fd8b;p=xonotic%2Fxonotic-data.pk3dir.git use urllib for weaponstats sending --- diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 6f82d9f10..d322ef3cf 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -13,23 +13,19 @@ void WeaponStats_Init() #define WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot) (((vwep) + (awep) * (WEP_LAST - WEP_FIRST + 1) - (WEP_FIRST + WEP_FIRST * (WEP_LAST - WEP_FIRST + 1))) * 4 + (abot) * 2 + (vbot)) -void WeaponStats_Shutdown() +string WeaponStats_prefix; +void WeaponStats_ready(entity fh, entity pass, float status) { float i, j, ibot, jbot, idx; - float fh; vector v; string prefix; - if(weaponstats_buffer < 0) - return; - prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t"); - if(autocvar_sv_weaponstats_file != "") + switch(status) { - fh = fopen(autocvar_sv_weaponstats_file, FILE_APPEND); - if(fh >= 0) - { - fputs(fh, "#begin statsfile\n"); - fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n")); - fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_changes)), "\n")); + case URL_READY_CANWRITE: + prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t"); + url_fputs(fh, "#begin statsfile\n"); + url_fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n")); + url_fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_changes)), "\n")); for(i = WEP_FIRST; i <= WEP_LAST; ++i) for(ibot = 0; ibot <= 1; ++ibot) for(j = WEP_FIRST; j <= WEP_LAST; ++j) for(jbot = 0; jbot <= 1; ++jbot) { @@ -38,17 +34,38 @@ void WeaponStats_Shutdown() if(v != '0 0 0') { //vector is: kills hits damage - fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot)); - fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z)); + url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot)); + url_fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z)); } } - fputs(fh, "#end\n\n"); - fclose(fh); + url_fputs(fh, "#end\n\n"); + url_fclose(fh, WeaponStats_ready, world); + buf_del(weaponstats_buffer); + weaponstats_buffer = -1; + break; + case URL_READY_CLOSED: print("Weapon stats written\n"); - } + break; + case URL_READY_ERROR: + default: + print("Weapon stats writing failed: ", ftos(status), "\n"); + break; + } +} + +void WeaponStats_Shutdown() +{ + if(weaponstats_buffer < 0) + return; + if(autocvar_sv_weaponstats_file != "") + { + url_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, world); + } + else + { + buf_del(weaponstats_buffer); + weaponstats_buffer = -1; } - buf_del(weaponstats_buffer); - weaponstats_buffer = -1; } void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector item) diff --git a/qcsrc/server/g_world.qc b/qcsrc/server/g_world.qc index fc29f2af8..2a8948c99 100644 --- a/qcsrc/server/g_world.qc +++ b/qcsrc/server/g_world.qc @@ -1586,6 +1586,7 @@ void NextLevel() FOR_EACH_CLIENT(e) PlayerStats_AddGlobalInfo(e); PlayerStats_Shutdown(); + WeaponStats_Shutdown(); if(autocvar_sv_eventlog) GameLogEcho(":gameover");