-// files (-1 for URL)
+// files
.float url_fh;
+#define URL_FH_CURL -1
+#define URL_FH_STDOUT -2
// URLs
.string url_url;
url_fromid[id] = world;
// if we get here, we MUST have both buffers cleared
- if(e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh != -1)
+ if(e.url_rbuf != -1 || e.url_wbuf != -1 || e.url_fh != URL_FH_CURL)
error("url_URI_Get_Callback: not a request waiting for data");
if(status == 0)
e = spawn();
e.classname = "url_fopen_file";
e.url_url = strzone(url);
- e.url_fh = -1;
+ e.url_fh = URL_FH_CURL;
e.url_wbuf = buf_create();
if(e.url_wbuf < 0)
{
e = spawn();
e.classname = "url_fopen_file";
e.url_url = strzone(url);
- e.url_fh = -1;
+ e.url_fh = URL_FH_CURL;
e.url_rbuf = -1;
e.url_wbuf = -1;
e.url_ready = rdy;
break;
}
}
+ else if(url == "-")
+ {
+ switch(mode)
+ {
+ case FILE_WRITE:
+ case FILE_APPEND:
+ e = spawn();
+ e.classname = "url_fopen_stdout";
+ e.url_fh = URL_FH_STDOUT;
+ rdy(e, pass, URL_READY_CANWRITE);
+ break;
+ case FILE_READ:
+ print("url_fopen: cannot open '-' for reading\n");
+ rdy(world, pass, URL_READY_ERROR);
+ break;
+ }
+ }
else
{
float fh;
{
float i;
- if(e.url_fh < 0)
+ if(e.url_fh == URL_FH_CURL)
{
if(e.url_rbuf == -1 || e.url_wbuf != -1) // not(post GET/POST request)
if(e.url_rbuf != -1 || e.url_wbuf == -1) // not(pre POST request)
remove(e);
}
}
+ else if(e.url_fh == URL_FH_STDOUT)
+ {
+ rdy(e, pass, URL_READY_CLOSED); // closing creates no reading handle
+ remove(e);
+ }
else
{
// file
// with \n (blame FRIK_FILE)
string url_fgets(entity e)
{
- if(e.url_fh < 0)
+ if(e.url_fh == URL_FH_CURL)
{
if(e.url_rbuf == -1)
error("url_fgets: not readable in current state");
e.url_rbufpos += 1;
return s;
}
+ else if(e.url_fh == URL_FH_STDOUT)
+ {
+ // stdout
+ return string_null;
+ }
else
{
// file
// without \n (blame FRIK_FILE)
void url_fputs(entity e, string s)
{
- if(e.url_fh < 0)
+ if(e.url_fh == URL_FH_CURL)
{
if(e.url_wbuf == -1)
error("url_fputs: not writable in current state");
bufstr_set(e.url_wbuf, e.url_wbufpos, s);
e.url_wbufpos += 1;
}
+ else if(e.url_fh == URL_FH_STDOUT)
+ {
+ // stdout
+ print(s);
+ }
else
{
// file
float URI_GET_DISCARD = 0;
float URI_GET_IPBAN = 1;
float URI_GET_IPBAN_END = 16;
-float URI_GET_PLAYERSTATS_SENT = 17;
void URI_Get_Callback(float id, float status, string data)
{
// online ban list
OnlineBanList_URI_Get_Callback(id, status, data);
}
- else if (id == URI_GET_PLAYERSTATS_SENT)
- {
- PlayerStats_Sent_URI_Get_Callback(id, status, data);
- }
else
{
print("Received HTTP request data for an invalid id ", ftos(id), ".\n");
db_put(playerstats_db, key, ftos(val));
}
-void PlayerStats_Sent_URI_Get_Callback(float id, float status, string data)
-{
- if(playerstats_requested)
- playerstats_waitforme = TRUE;
-}
-
/*
format spec:
uri = autocvar_g_playerstats_uri;
if(uri != "")
{
- url_fopen(uri, FILE_APPEND, PlayerStats_ready, world);
playerstats_waitforme = FALSE;
+ url_fopen(uri, FILE_APPEND, PlayerStats_ready, world);
}
else
{
}
//#NO AUTOCVARS END
+void PlayerStats_Accuracy(entity p)
+{
+ entity a, w;
+ a = p.accuracy;
+ float i;
+
+ for(i = WEP_FIRST; i <= WEP_LAST; ++i)
+ {
+ w = get_weaponinfo(i);
+
+ PlayerStats_Event(p, strcat("acc-", w.netname, "-hit"), a.(accuracy_hit[i-1]));
+ PlayerStats_Event(p, strcat("acc-", w.netname, "-fired"), a.(accuracy_fired[i-1]));
+
+ PlayerStats_Event(p, strcat("acc-", w.netname, "-cnt-hit"), a.(accuracy_cnt_hit[i-1]));
+ PlayerStats_Event(p, strcat("acc-", w.netname, "-cnt-fired"), a.(accuracy_cnt_fired[i-1]));
+
+ PlayerStats_Event(p, strcat("acc-", w.netname, "-frags"), a.(accuracy_frags[i-1]));
+ }
+}
+
void PlayerStats_AddGlobalInfo(entity p)
{
if(playerstats_db < 0)
if(stof(db_get(playerstats_db, sprintf("%d:%s", p.playerstats_id, PLAYERSTATS_ALIVETIME))) > 0)
PlayerStats_Event(p, PLAYERSTATS_JOINS, 1);
+ PlayerStats_Accuracy(p);
+
strunzone(p.playerstats_id);
p.playerstats_id = string_null;
}
-void PlayerStats_Accuracy(entity p)
-{
- entity a, w;
- a = p.accuracy;
- float i;
-
- for(i = WEP_FIRST; i <= WEP_LAST; ++i)
- {
- w = get_weaponinfo(i);
-
- PlayerStats_Event(p, strcat("acc-", w.netname, "-hit"), a.(accuracy_hit[i-1]));
- PlayerStats_Event(p, strcat("acc-", w.netname, "-fired"), a.(accuracy_fired[i-1]));
-
- PlayerStats_Event(p, strcat("acc-", w.netname, "-cnt-hit"), a.(accuracy_cnt_hit[i-1]));
- PlayerStats_Event(p, strcat("acc-", w.netname, "-cnt-fired"), a.(accuracy_cnt_fired[i-1]));
-
- PlayerStats_Event(p, strcat("acc-", w.netname, "-frags"), a.(accuracy_frags[i-1]));
- }
-}
-
void PlayerStats_EndMatch(float finished)
{
entity p, winner;