From: Nick Savchenko Date: Mon, 4 Jun 2018 20:51:42 +0000 (+0300) Subject: Store 99 time records in the server database. Send g_cts_send_rankings_cnt records... X-Git-Tag: xonotic-v0.8.5~2100^2~3 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=7530a8fe25423d8545e3622c8e36b4f82090b55d;p=xonotic%2Fxonotic-data.pk3dir.git Store 99 time records in the server database. Send g_cts_send_rankings_cnt records to the client (default 15) --- diff --git a/gamemodes-server.cfg b/gamemodes-server.cfg index 6790a3b4f..7319cba4e 100644 --- a/gamemodes-server.cfg +++ b/gamemodes-server.cfg @@ -308,6 +308,7 @@ exec ctfscoring-samual.cfg set g_cts 0 "CTS: complete the stage" set g_cts_selfdamage 1 "0 = disable all selfdamage and falldamage in cts" set g_cts_finish_kill_delay 10 "prevent cheating by running back to the start line, and starting out with more speed than otherwise possible" +set g_cts_send_rankings_cnt 15 "send this number of map records to clients" // ========================== diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 37027d25c..9f1061dc9 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -1144,6 +1144,9 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) strcpy(race_speedaward_alltimebest_holder, ReadString()); strcpy(race_speedaward_alltimebest_unit, GetSpeedUnit(autocvar_hud_panel_physics_speed_unit)); break; + case RACE_NET_RANKINGS_CNT: + RANKINGS_RECEIVED_CNT = ReadByte(); + break; case RACE_NET_SERVER_RANKINGS: float prevpos, del; int pos = ReadShort(); @@ -1153,13 +1156,14 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) // move other rankings out of the way int i; if (prevpos) { - for (i=prevpos-1;i>pos-1;--i) { + int m = min(prevpos, RANKINGS_RECEIVED_CNT); + for (i=m-1; i>pos-1; --i) { grecordtime[i] = grecordtime[i-1]; strcpy(grecordholder[i], grecordholder[i-1]); } } else if (del) { // a record has been deleted by the admin - for (i=pos-1; i<= RANKINGS_CNT-1; ++i) { - if (i == RANKINGS_CNT-1) { // clear out last record + for (i=pos-1; i<= RANKINGS_RECEIVED_CNT-1; ++i) { + if (i == RANKINGS_RECEIVED_CNT-1) { // clear out last record grecordtime[i] = 0; strfree(grecordholder[i]); } @@ -1169,12 +1173,18 @@ NET_HANDLE(TE_CSQC_RACE, bool isNew) } } } else { // player has no ranked record yet - for (i=RANKINGS_CNT-1;i>pos-1;--i) { + for (i=RANKINGS_RECEIVED_CNT-1;i>pos-1;--i) { grecordtime[i] = grecordtime[i-1]; strcpy(grecordholder[i], grecordholder[i-1]); } } + if (grecordtime[RANKINGS_RECEIVED_CNT]) { + // kick off the player who fell from the last displayed position + grecordtime[RANKINGS_RECEIVED_CNT] = 0; + strfree(grecordholder[RANKINGS_RECEIVED_CNT]); + } + // store new ranking strcpy(grecordholder[pos-1], ReadString()); grecordtime[pos-1] = ReadInt24_t(); diff --git a/qcsrc/common/constants.qh b/qcsrc/common/constants.qh index 8afe47bde..675b75c0a 100644 --- a/qcsrc/common/constants.qh +++ b/qcsrc/common/constants.qh @@ -1,6 +1,6 @@ #pragma once -const int RANKINGS_CNT = 100; +const int RANKINGS_CNT = 99; /////////////////////////// // keys pressed diff --git a/qcsrc/common/net_linked.qh b/qcsrc/common/net_linked.qh index 657e76171..6651c6cb9 100644 --- a/qcsrc/common/net_linked.qh +++ b/qcsrc/common/net_linked.qh @@ -22,6 +22,7 @@ const int RACE_NET_SERVER_RANKINGS = 11; const int RACE_NET_SERVER_STATUS = 12; const int RACE_NET_CHECKPOINT_HIT_SELF_QUALIFYING = 13; // byte checkpoint, short time, short recordtime const int RACE_NET_CHECKPOINT_NEXT_SELF_QUALIFYING = 14; // byte nextcheckpoint, short recordtime +const int RACE_NET_RANKINGS_CNT = 15; REGISTER_NET_LINKED(_ENT_CLIENT_INIT) #ifdef CSQC diff --git a/qcsrc/server/mutators/mutator/gamemode_ctf.qc b/qcsrc/server/mutators/mutator/gamemode_ctf.qc index e0d25e9e8..1847473cf 100644 --- a/qcsrc/server/mutators/mutator/gamemode_ctf.qc +++ b/qcsrc/server/mutators/mutator/gamemode_ctf.qc @@ -2228,7 +2228,9 @@ MUTATOR_HOOKFUNCTION(ctf, ClientConnect) if(IS_REAL_CLIENT(player)) { - for(int i = 1; i <= RANKINGS_CNT; ++i) + int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); + race_send_rankings_cnt(MSG_ONE); + for (int i = 1; i <= m; ++i) { race_SendRankings(i, 0, 0, MSG_ONE); } diff --git a/qcsrc/server/mutators/mutator/gamemode_cts.qc b/qcsrc/server/mutators/mutator/gamemode_cts.qc index 1363411aa..87830db48 100644 --- a/qcsrc/server/mutators/mutator/gamemode_cts.qc +++ b/qcsrc/server/mutators/mutator/gamemode_cts.qc @@ -199,7 +199,9 @@ MUTATOR_HOOKFUNCTION(cts, ClientConnect) race_send_speedaward_alltimebest(MSG_ONE); float i; - for (i = 1; i <= RANKINGS_CNT; ++i) + int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); + race_send_rankings_cnt(MSG_ONE); + for (i = 1; i <= m; ++i) { race_SendRankings(i, 0, 0, MSG_ONE); } diff --git a/qcsrc/server/mutators/mutator/gamemode_race.qc b/qcsrc/server/mutators/mutator/gamemode_race.qc index e4109b72a..65541fc08 100644 --- a/qcsrc/server/mutators/mutator/gamemode_race.qc +++ b/qcsrc/server/mutators/mutator/gamemode_race.qc @@ -245,7 +245,9 @@ MUTATOR_HOOKFUNCTION(rc, ClientConnect) race_send_speedaward_alltimebest(MSG_ONE); float i; - for (i = 1; i <= RANKINGS_CNT; ++i) + int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); + race_send_rankings_cnt(MSG_ONE); + for (i = 1; i <= m; ++i) { race_SendRankings(i, 0, 0, MSG_ONE); } diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index 743d02d03..da86f76f0 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -224,6 +224,14 @@ void race_send_speedaward_alltimebest(float msg) WriteString(msg, speedaward_alltimebest_holder); } +void race_send_rankings_cnt(float msg) +{ + WriteHeader(msg, TE_CSQC_RACE); + WriteByte(msg, RACE_NET_RANKINGS_CNT); + int m = min(RANKINGS_CNT, autocvar_g_cts_send_rankings_cnt); + WriteByte(msg, m); +} + void race_SendRankings(float pos, float prevpos, float del, float msg) { WriteHeader(msg, TE_CSQC_RACE); diff --git a/qcsrc/server/race.qh b/qcsrc/server/race.qh index 472827efa..32edca781 100644 --- a/qcsrc/server/race.qh +++ b/qcsrc/server/race.qh @@ -5,6 +5,8 @@ float race_teams; // scores const float ST_RACE_LAPS = 1; +int autocvar_g_cts_send_rankings_cnt = 15; + bool g_race_qualifying; float speedaward_lastsent; @@ -61,6 +63,8 @@ void race_send_speedaward(float msg); void race_send_speedaward_alltimebest(float msg); +void race_send_rankings_cnt(float msg); + void race_SendRankings(float pos, float prevpos, float del, float msg); void race_RetractPlayer(entity this);