From bc6239385f21a0dcfab1d07cd738dca6cdb05182 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 6 Aug 2016 17:51:41 +1000 Subject: [PATCH] Scoreboard ELO: show "..." when loading, "N/A" when missing --- qcsrc/client/scoreboard.qc | 11 +++++++++++ qcsrc/common/playerstats.qc | 21 +++++++++++++-------- qcsrc/common/state.qc | 3 +-- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/qcsrc/client/scoreboard.qc b/qcsrc/client/scoreboard.qc index 91f3e9556..f32873cba 100644 --- a/qcsrc/client/scoreboard.qc +++ b/qcsrc/client/scoreboard.qc @@ -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; diff --git a/qcsrc/common/playerstats.qc b/qcsrc/common/playerstats.qc index fdb71fe78..b00bdcf8d 100644 --- a/qcsrc/common/playerstats.qc +++ b/qcsrc/common/playerstats.qc @@ -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 diff --git a/qcsrc/common/state.qc b/qcsrc/common/state.qc index e73bfa24f..eaa96892f 100644 --- a/qcsrc/common/state.qc +++ b/qcsrc/common/state.qc @@ -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); -- 2.39.2