]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Scoreboard ELO: show "..." when loading, "N/A" when missing
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 6 Aug 2016 07:51:41 +0000 (17:51 +1000)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 6 Aug 2016 07:51:41 +0000 (17:51 +1000)
qcsrc/client/scoreboard.qc
qcsrc/common/playerstats.qc
qcsrc/common/state.qc

index 91f3e9556ec4c87e566fac5cdcdd6cbe45bcc65e..f32873cba740f67e933f2a630538d42e08bda92c 100644 (file)
@@ -411,6 +411,7 @@ void Cmd_HUD_SetFields(int argc)
                        case "sum": case "diff": case "k-d": hud_field[hud_num_fields] = SP_SUM; break;
                        case "name": case "nick": hud_field[hud_num_fields] = SP_NAME; have_name = true; break;
                        case "|": hud_field[hud_num_fields] = SP_SEPARATOR; have_separator = true; break;
+                       case "elo": hud_field[hud_num_fields] = SP_ELO; break;
                        case "dmg": hud_field[hud_num_fields] = SP_DMG; break;
                        case "dmgtaken": hud_field[hud_num_fields] = SP_DMGTAKEN; break;
                        default:
@@ -620,6 +621,16 @@ string HUD_GetField(entity pl, PlayerScoreField field)
                        }
                        return ftos(f);
 
+               case SP_ELO:
+               {
+                       float elo = pl.(scores(SP_ELO));
+                       switch (elo) {
+                               case -1: return "...";
+                               case -2: return _("N/A");
+                               default: return ftos(elo);
+                       }
+               }
+
                case SP_DMG:
                        num = pl.(scores(SP_DMG));
                        denom = 1000;
index fdb71fe782093400dc45b1bc3f76fb9344f5a8f0..b00bdcf8d55c7ee5df9522fa69d3e03e689b4884 100644 (file)
@@ -416,12 +416,14 @@ void PlayerStats_GameReport_Handler(entity fh, entity pass, float status)
 
 void PlayerStats_PlayerBasic(entity joiningplayer, float newrequest)
 {
+       PlayerScore_Add(joiningplayer, SP_ELO, -1);
        // http://stats.xonotic.org/player/GgXRw6piDtFIbMArMuiAi8JG4tiin8VLjZgsKB60Uds=/elo.txt
        if(autocvar_g_playerstats_playerbasic_uri != "")
        {
                string uri = autocvar_g_playerstats_playerbasic_uri;
-               if(joiningplayer.crypto_idfp != "")
-               {
+               if (joiningplayer.crypto_idfp == "") {
+                       PlayerScore_Add(joiningplayer, SP_ELO, -1);
+               } else {
                        // create the database if it doesn't already exist
                        if(PS_B_IN_DB < 0)
                                PS_B_IN_DB = db_create();
@@ -452,6 +454,7 @@ void PlayerStats_PlayerBasic(entity joiningplayer, float newrequest)
        else
        {
                // server has this disabled, kill the DB and set status to idle
+               PlayerScore_Add(joiningplayer, SP_ELO, -1);
                if(PS_B_IN_DB >= 0)
                {
                        db_close(PS_B_IN_DB);
@@ -466,12 +469,10 @@ void PlayerStats_PlayerBasic_CheckUpdate(entity joiningplayer)
 {
        // determine whether we should retrieve playerbasic information again
 
-       #if 0
-       LOG_INFOF("PlayerStats_PlayerBasic_CheckUpdate('%s'): %f\n",
+       LOG_TRACEF("PlayerStats_PlayerBasic_CheckUpdate('%s'): %f\n",
                joiningplayer.netname,
                time
        );
-       #endif
 
        // TODO: check to see if this playerid is inside the database already somehow...
        // for now we'll just check the field, but this won't work for players who disconnect and reconnect properly
@@ -503,11 +504,12 @@ void PlayerStats_PlayerBasic_Handler(entity fh, entity p, float status)
                        url_fputs(fh, sprintf("m %s %s\n", cvar_string("_cl_playermodel"), cvar_string("_cl_playerskin"))); // model/skin
                        */url_fputs(fh, "\n");
                        url_fclose(fh);
-                       break;
+                       return;
                }
 
                case URL_READY_CANREAD:
                {
+                       bool handled = false;
                        string gt = string_null;
                        for (string s = ""; (s = url_fgets(fh)); ) {
                                int n = tokenizebyseparator(s, " "); // key value? data
@@ -551,8 +553,9 @@ void PlayerStats_PlayerBasic_Handler(entity fh, entity p, float status)
                         LOG_TRACE("G: ", gt);
                         LOG_TRACE("e: ", data);
                         if (gt == GetGametype()) {
+                            handled = true;
                             float e = stof(data);
-                            PlayerScore_Add(p, SP_ELO, e);
+                            PlayerScore_Add(p, SP_ELO, +1 + e);
                         }
                         if (gt == "") {
                             // PlayerInfo_AddItem(p, value, data);
@@ -563,13 +566,14 @@ void PlayerStats_PlayerBasic_Handler(entity fh, entity p, float status)
                 }
                        }
                        url_fclose(fh);
+                       if (handled) return;
                        break;
                }
                case URL_READY_CLOSED:
                {
                        // url_fclose has finished
                        LOG_INFO("Player stats synchronized with server\n");
-                       break;
+                       return;
                }
 
                case URL_READY_ERROR:
@@ -579,6 +583,7 @@ void PlayerStats_PlayerBasic_Handler(entity fh, entity p, float status)
                        break;
                }
        }
+       PlayerScore_Add(p, SP_ELO, -1);
 }
 #endif // SVQC
 
index e73bfa24fd481eacec76cc216f84f3693c9a25e7..eaa96892f64aba3e9e1cb38f5b2e34af51358ed3 100644 (file)
@@ -45,13 +45,12 @@ void ClientState_attach(entity this)
 
     GetCvars(this, 0);  // get other cvars from player
 
-       if (IS_REAL_CLIENT(this)) { PlayerStats_PlayerBasic_CheckUpdate(this); }
-
        // TODO: fold all of these into ClientState
 
        DecodeLevelParms(this);
 
        PlayerScore_Attach(this);
+       PlayerStats_PlayerBasic_CheckUpdate(this);
        ClientData_Attach(this);
        accuracy_init(this);
        entcs_attach(this);