]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge remote branch 'origin/master' into samual/hud_updates
authorSamual <samual@xonotic.org>
Mon, 3 Oct 2011 17:12:19 +0000 (13:12 -0400)
committerSamual <samual@xonotic.org>
Mon, 3 Oct 2011 17:12:19 +0000 (13:12 -0400)
qcsrc/common/urllib.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/playerstats.qc
qcsrc/server/playerstats.qh

index 0ab17f34a4eebed25e7dee028c104c7d5fb25602..d23873e74c81eea11a1f877c43a9ce44252a1380 100644 (file)
@@ -1,5 +1,7 @@
-// files (-1 for URL)
+// files
 .float url_fh;
+#define URL_FH_CURL   -1
+#define URL_FH_STDOUT -2
 
 // URLs
 .string url_url;
@@ -35,7 +37,7 @@ float url_URI_Get_Callback(float id, float status, string data)
        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)
@@ -93,7 +95,7 @@ void url_fopen(string url, float mode, url_ready_func rdy, entity pass)
                                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)
                                {
@@ -142,7 +144,7 @@ void url_fopen(string url, float mode, url_ready_func rdy, entity pass)
                                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;
@@ -155,6 +157,23 @@ void url_fopen(string url, float mode, url_ready_func rdy, entity pass)
                                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;
@@ -182,7 +201,7 @@ void url_fclose(entity e, url_ready_func rdy, entity pass)
 {
        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)
@@ -246,6 +265,11 @@ void url_fclose(entity e, url_ready_func rdy, entity pass)
                        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
@@ -258,7 +282,7 @@ void url_fclose(entity e, url_ready_func rdy, entity pass)
 // 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");
@@ -268,6 +292,11 @@ string url_fgets(entity e)
                e.url_rbufpos += 1;
                return s;
        }
+       else if(e.url_fh == URL_FH_STDOUT)
+       {
+               // stdout
+               return string_null;
+       }
        else
        {
                // file
@@ -278,7 +307,7 @@ string url_fgets(entity e)
 // 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");
@@ -286,6 +315,11 @@ void url_fputs(entity e, string s)
                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
index 19465d09dd1a156e397abb29ca4fac14d7633ae8..b0b1aa3e0dcb3afd67e17a60c685b59d32cb05da 100644 (file)
@@ -2043,7 +2043,6 @@ float MAX_IPBAN_URIS           = 16;
 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)
 {
@@ -2064,10 +2063,6 @@ 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");
index 35ad9b6185fc8d6b5471079c26b09b99ce867d4d..a15c2b1341588b896c2beae564c3dcbe0ea4fa10 100644 (file)
@@ -154,12 +154,6 @@ void PlayerStats_TeamScore(float t, string event_id, float value) // TODO: doesn
        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:
 
@@ -283,8 +277,8 @@ void PlayerStats_Shutdown()
        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
        {
@@ -295,6 +289,26 @@ void PlayerStats_Shutdown()
 }
 //#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)
@@ -321,30 +335,12 @@ void PlayerStats_AddGlobalInfo(entity p)
        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;
index f546e560590025c124a4615905e07a2c15252a3e..b99366434b9e214bbeff607a333dc81f1d6271b6 100644 (file)
@@ -44,9 +44,6 @@ void PlayerStats_TeamScore(float t, string event_id, float value);
 // call at game over
 void PlayerStats_Shutdown(); // send stats to the server
 
-// URI GET callback
-void PlayerStats_Sent_URI_Get_Callback(float id, float status, string data);
-
 // call this whenever a player leaves
 void PlayerStats_AddGlobalInfo(entity p);