Store 99 time records in the server database. Send g_cts_send_rankings_cnt records...
authorNick Savchenko <nsavch@gmail.com>
Mon, 4 Jun 2018 20:51:42 +0000 (23:51 +0300)
committerNick Savchenko <nsavch@gmail.com>
Mon, 4 Jun 2018 20:51:42 +0000 (23:51 +0300)
gamemodes-server.cfg
qcsrc/client/main.qc
qcsrc/common/constants.qh
qcsrc/common/net_linked.qh
qcsrc/server/mutators/mutator/gamemode_ctf.qc
qcsrc/server/mutators/mutator/gamemode_cts.qc
qcsrc/server/mutators/mutator/gamemode_race.qc
qcsrc/server/race.qc
qcsrc/server/race.qh

index 6790a3b..7319cba 100644 (file)
@@ -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"
 
 
 // ==========================
index 37027d2..9f1061d 100644 (file)
@@ -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();
index 8afe47b..675b75c 100644 (file)
@@ -1,6 +1,6 @@
 #pragma once
 
-const int RANKINGS_CNT = 100;
+const int RANKINGS_CNT = 99;
 
 ///////////////////////////
 // keys pressed
index 657e761..6651c6c 100644 (file)
@@ -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
index e0d25e9..1847473 100644 (file)
@@ -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);
                }
index 1363411..87830db 100644 (file)
@@ -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);
                }
index e4109b7..65541fc 100644 (file)
@@ -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);
                }
index 743d02d..da86f76 100644 (file)
@@ -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);
index 472827e..32edca7 100644 (file)
@@ -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);