]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
use urllib for weaponstats sending
authorRudolf Polzer <divVerent@xonotic.org>
Wed, 17 Aug 2011 19:10:20 +0000 (21:10 +0200)
committerRudolf Polzer <divVerent@xonotic.org>
Wed, 17 Aug 2011 19:10:20 +0000 (21:10 +0200)
qcsrc/server/cl_player.qc
qcsrc/server/g_world.qc

index 6f82d9f1043c7b30d21d98a6a2c52830944737ca..d322ef3cff944686d356239a6e32a56706f5867e 100644 (file)
@@ -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)
index fc29f2af83c0e575894e49b9babb0cf4bfbd56f8..2a8948c9987f9d8aa771e41b9a2b6a252b6bef7e 100644 (file)
@@ -1586,6 +1586,7 @@ void NextLevel()
        FOR_EACH_CLIENT(e)
                PlayerStats_AddGlobalInfo(e);
        PlayerStats_Shutdown();
+       WeaponStats_Shutdown();
 
        if(autocvar_sv_eventlog)
                GameLogEcho(":gameover");