1 void WeaponStats_Init()
3 weaponstats_buffer = ((autocvar_sv_weaponstats_file != "") ? buf_create() : -1);
6 void WeaponStats_ready(entity fh, entity pass, float status)
8 float i, j, n, ibot, jbot, idx;
13 case URL_READY_CANWRITE:
15 prefix = strcat(autocvar_hostname, "\t", GetGametype(), "_", GetMapname(), "\t");
16 url_fputs(fh, "#begin statsfile\n");
17 url_fputs(fh, strcat("#date ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"));
19 url_fputs(fh, strcat("#version ", WATERMARK, "\n"));
21 url_fputs(fh, strcat("#config ", ftos(crc16(FALSE, cvar_purechanges)), "\n"));
22 url_fputs(fh, strcat("#cvar_purechanges ", ftos(cvar_purechanges_count), "\n"));
23 n = tokenizebyseparator(cvar_purechanges, "\n");
24 for(i = 0; i < n; ++i)
25 url_fputs(fh, strcat("#cvar_purechange ", argv(i), "\n"));
26 for(i = WEP_FIRST; i <= WEP_LAST; ++i) for(ibot = 0; ibot <= 1; ++ibot)
27 for(j = WEP_FIRST; j <= WEP_LAST; ++j) for(jbot = 0; jbot <= 1; ++jbot)
29 idx = WEAPONSTATS_GETINDEX(i, ibot, j, jbot);
30 v = stov(bufstr_get(weaponstats_buffer, idx));
33 //vector is: kills hits damage
34 url_fputs(fh, sprintf("%s%d %d\t%d %d\t", prefix, i, ibot, j, jbot));
35 url_fputs(fh, sprintf("%d %d %g\n", v_x, v_y, v_z));
38 url_fputs(fh, "#end\n\n");
41 case URL_READY_CANREAD:
42 // url_fclose is processing, we got a response for writing the data
43 // this must come from HTTP
44 print("Got response from weapon stats server:\n");
45 while((s = url_fgets(fh)))
47 print("End of response.\n");
50 case URL_READY_CLOSED:
51 // url_fclose has finished
52 print("Weapon stats written\n");
53 buf_del(weaponstats_buffer);
54 weaponstats_buffer = -1;
58 print("Weapon stats writing failed: ", ftos(status), "\n");
59 buf_del(weaponstats_buffer);
60 weaponstats_buffer = -1;
65 void WeaponStats_Shutdown()
67 if(weaponstats_buffer < 0)
69 if(autocvar_sv_weaponstats_file != "")
71 url_multi_fopen(autocvar_sv_weaponstats_file, FILE_APPEND, WeaponStats_ready, world);
75 buf_del(weaponstats_buffer);
76 weaponstats_buffer = -1;
80 void WeaponStats_LogItem(float awep, float abot, float vwep, float vbot, vector item)
83 if(weaponstats_buffer < 0)
85 if(awep < WEP_FIRST || vwep < WEP_FIRST)
87 if(awep > WEP_LAST || vwep > WEP_LAST)
89 idx = WEAPONSTATS_GETINDEX(awep,abot,vwep,vbot);
90 bufstr_set(weaponstats_buffer, idx, vtos(stov(bufstr_get(weaponstats_buffer, idx)) + item));
93 void WeaponStats_LogDamage(float awep, float abot, float vwep, float vbot, float damage)
96 error("negative damage?");
97 WeaponStats_LogItem(awep, abot, vwep, vbot, '0 0 1' * damage + '0 1 0');
100 void WeaponStats_LogKill(float awep, float abot, float vwep, float vbot)
102 WeaponStats_LogItem(awep, abot, vwep, vbot, '1 0 0');