Merge branch 'master' into fruitiex/racefixes
authorFruitieX <rasse@rasse-laptop.(none)>
Tue, 26 Oct 2010 11:02:13 +0000 (14:02 +0300)
committerFruitieX <rasse@rasse-laptop.(none)>
Tue, 26 Oct 2010 11:02:13 +0000 (14:02 +0300)
defaultXonotic.cfg
qcsrc/common/gamecommand.qc
qcsrc/common/util.qh
qcsrc/server/cl_client.qc
qcsrc/server/cl_physics.qc
qcsrc/server/clientcommands.qc
qcsrc/server/g_world.qc
qcsrc/server/gamecommand.qc
qcsrc/server/miscfunctions.qc
qcsrc/server/race.qc
qcsrc/server/t_quake3.qc

index 3ac447e864691b3229548c392f10a53241b31fbe..50a7ed8a9f49fad3522be4c1c1e273eb1cccc544 100644 (file)
@@ -626,6 +626,7 @@ set g_rc_respawn_delay 0
 set g_cts_respawn_waves 0
 set g_cts_respawn_delay 0
 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"
 
 // overtime
 seta timelimit_overtime 2 "duration in minutes of one added overtime, added to the timelimit"
index be2f5e78c202bfed5398a7260041bfea1bb7cfda..f6b54f155b842e6ff683ad236bfb7463f8d785ae 100644 (file)
@@ -831,6 +831,10 @@ float GameCommand_Generic(string command)
                print(records_reply);
                return TRUE;
        }
+       else if(argv(0) == "ladder") {
+               print(ladder_reply);
+               return TRUE;
+       }
        else if(argv(0) == "rankings") {
                print(rankings_reply);
                return TRUE;
index 77b3e03202817a61ef6325761c764ce0de357aff..65bede381e453829e834ca5e330b42e58034e7ed 100644 (file)
@@ -162,7 +162,7 @@ void check_unacceptable_compiler_bugs();
 float compressShotOrigin(vector v);
 vector decompressShotOrigin(float f);
 
-string rankings_reply, lsmaps_reply, lsnewmaps_reply, maplist_reply; // cached replies
+string rankings_reply, ladder_reply, lsmaps_reply, lsnewmaps_reply, maplist_reply; // cached replies
 string records_reply[10];
 
 float RandomSelection_totalweight;
index df6c8d4b2a3f41e0793e271d8aae9a9b54512692..b4f9e2da0fc59161530882ca6d97ef57993882b9 100644 (file)
@@ -1308,6 +1308,22 @@ void ClientKill (void)
        ClientKill_TeamChange(0);
 }
 
+void CTS_ClientKill_Think (void)
+{
+       self = self.owner; // set self to the player to be killed
+       sprint(self, "^1You were killed in order to prevent cheating!");
+       ClientKill_Now();
+}
+
+void CTS_ClientKill (float t) // silent version of ClientKill
+{
+       entity e;
+       e = spawn();
+       e.owner = self;
+       e.think = CTS_ClientKill_Think;
+       e.nextthink = t;
+}
+
 void DoTeamChange(float destteam)
 {
        float t, c0;
index b005dd5f3f20c575914e76107a7891ffd4198d07..376e54f24eac3a1ce9682e23b2c5e60c767db204 100644 (file)
@@ -673,6 +673,7 @@ void SpecialCommand()
 
 float speedaward_speed;
 string speedaward_holder;
+string speedaward_uid;
 void race_send_speedaward(float msg)
 {
        // send the best speed of the round
@@ -685,6 +686,7 @@ void race_send_speedaward(float msg)
 
 float speedaward_alltimebest;
 string speedaward_alltimebest_holder;
+string speedaward_alltimebest_uid;
 void race_send_speedaward_alltimebest(float msg)
 {
        // send the best speed
@@ -1306,6 +1308,9 @@ void SV_PlayerPhysics()
                if(vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed) {
                        speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
                        speedaward_holder = self.netname;
+                       if(speedaward_uid)
+                               strunzone(speedaward_uid);
+                       speedaward_uid = strzone(self.crypto_idfp);
                        speedaward_lastupdate = time;
                }
                if(speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1) {
@@ -1321,6 +1326,7 @@ void SV_PlayerPhysics()
                                speedaward_alltimebest_holder = speedaward_holder;
                                db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
                                db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/netname"), speedaward_alltimebest_holder);
+                               db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_holder);
                                race_send_speedaward_alltimebest(MSG_ALL);
                        }
                }
index a9fd886bfe9c331e34b7651faf4c4bca063703c5..a11ab82f9955577b47ebe4275e0aebc4b0fc207c 100644 (file)
@@ -303,6 +303,8 @@ void SV_ParseClientCommand(string s) {
        } else if(cmd == "records") {
                for(i = 0; i < 10; ++i)
                        sprint(self, records_reply[i]);
+       } else if(cmd == "ladder") {
+               sprint(self, ladder_reply);
        } else if(cmd == "rankings") {
                sprint(self, rankings_reply);
        } else if(cmd == "voice") {
index 08329a29d7e61a76a2f1e3097b307a93fa0fff78..053ed5124b134adc2d4d1837bef9b117bf1d4eb9 100644 (file)
@@ -697,6 +697,8 @@ void spawnfunc_worldspawn (void)
        {
                records_reply[i] = strzone(getrecords(i));
        }
+       if(g_cts)
+               ladder_reply = strzone(getladder());
 
        rankings_reply = strzone(getrankings());
 
index b5c68ca79bcbb84f2ce8aa11bb8627d26e9106ec..0d7e0295f9d26b82ee65617fb03b126f9bcc0ba9 100644 (file)
@@ -1,5 +1,5 @@
 string GotoMap(string m);
-void race_DeleteTime(float pos);
+void race_deleteTime(string map, float pos);
 
 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
 {
@@ -924,6 +924,11 @@ void GameCommand(string command)
                        print(records_reply[i]);
                return;
        }
+       if (argv(0) == "ladder")
+       {
+               print(ladder_reply);
+               return;
+       }
        if (argv(0) == "rankings")
        {
                strunzone(rankings_reply);
@@ -1340,7 +1345,11 @@ void GameCommand(string command)
        }
        if(argv(0) == "delrec")
        {
-               race_DeleteTime(stof(argv(1)));
+               if(argv(2) != "")
+                       race_deleteTime(argv(2), stof(argv(1)));
+               else
+                       race_deleteTime(GetMapname(), stof(argv(1)));
+
                return;
        }
 
index 05f297746c5243812b1a0e61d811002c8aa422c9..b277bb6271c1c98aa2525e5cfa9d042c885b51d3 100644 (file)
@@ -16,9 +16,6 @@ void WarpZone_crosshair_trace(entity pl)
 
 void() spawnfunc_info_player_deathmatch; // needed for the other spawnpoints
 void() spawnpoint_use;
-float race_GetTime(float pos);
-string race_GetName(float pos);
-string race_PlaceName(float pos);
 string GetMapname();
 string ColoredTeamName(float t);
 
@@ -2069,6 +2066,93 @@ void print_to(entity e, string s)
         print(s, "\n");
 }
 
+string uid2name(string myuid) {
+       // TODO TODO TODO!
+       // store uid in separate uid2name db IF CLIENT ALLOWS THIS
+       // - make it global for all mods
+       // perhaps show 10 first digits here if missing name?
+       string s;
+       s = db_get(ServerProgsDB, strcat("uid2name", myuid));
+       
+       if(s == "")
+               s = "^1Unregistered Player";
+       return s;
+}
+
+float race_readTime(string map, float pos)
+{
+       string rr;
+       if(g_cts)
+               rr = CTS_RECORD;
+       else
+               rr = RACE_RECORD;
+
+       return stof(db_get(ServerProgsDB, strcat(map, rr, "time", ftos(pos))));
+}
+
+string race_readUID(string map, float pos)
+{
+       string rr;
+       if(g_cts)
+               rr = CTS_RECORD;
+       else
+               rr = RACE_RECORD;
+
+       return db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)));
+}
+
+float race_readPos(string map, float t) {
+       float i;
+       for (i = 1; i <= RANKINGS_CNT; ++i)
+               if (race_readTime(map, i) == 0 || race_readTime(map, i) > t)
+                       return i;
+
+       return 0; // pos is zero if unranked
+}
+
+void race_writeTime(string map, float t, string myuid)
+{
+       string rr;
+       if(g_cts)
+               rr = CTS_RECORD;
+       else
+               rr = RACE_RECORD;
+
+       float pos;
+       pos = race_readPos(map, t);
+
+       if(pos) { // don't even ALLOW writing unranked times into the db, less stuff to worry about in other code then :-)
+               db_put(ServerProgsDB, strcat(map, rr, "time", ftos(pos)), ftos(t));
+               db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos)), myuid);
+       }
+}
+
+string race_readName(string map, float pos)
+{
+       string rr;
+       if(g_cts)
+               rr = CTS_RECORD;
+       else
+               rr = RACE_RECORD;
+
+       return uid2name(db_get(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(pos))));
+}
+
+string race_placeName(float pos) {
+       if(floor((mod(pos, 100))/10) * 10 != 10) // examples: 12th, 111th, 213th will not execute this block
+       {
+               if(mod(pos, 10) == 1)
+                       return strcat(ftos(pos), "st");
+               else if(mod(pos, 10) == 2)
+                       return strcat(ftos(pos), "nd");
+               else if(mod(pos, 10) == 3)
+                       return strcat(ftos(pos), "rd");
+               else
+                       return strcat(ftos(pos), "th");
+       }
+       else
+               return strcat(ftos(pos), "th");
+}
 string getrecords(float page) // 50 records per page
 {
     float rec;
@@ -2090,6 +2174,7 @@ string getrecords(float page) // 50 records per page
                 r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/time")));
                 if (r == 0)
                     continue;
+               // TODO: uid2name
                 h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, "/captimerecord/netname"));
                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-6, ftos_decimals(r, 2)), " ", h, "\n");
                 ++rec;
@@ -2103,10 +2188,10 @@ string getrecords(float page) // 50 records per page
         {
             if (MapInfo_Get_ByID(i))
             {
-                r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time")));
+               r = race_readTime(MapInfo_Map_bspname, 1);
                 if (r == 0)
                     continue;
-                h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "netname"));
+               h = race_readName(MapInfo_Map_bspname, 1);
                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
                 ++rec;
             }
@@ -2119,10 +2204,10 @@ string getrecords(float page) // 50 records per page
         {
             if (MapInfo_Get_ByID(i))
             {
-                r = stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time")));
+               r = race_readTime(MapInfo_Map_bspname, 1);
                 if (r == 0)
                     continue;
-                h = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "netname"));
+               h = race_readName(MapInfo_Map_bspname, 1);
                 s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n");
                 ++rec;
             }
@@ -2152,11 +2237,11 @@ string getrankings()
 
     for (i = 1; i <= RANKINGS_CNT; ++i)
     {
-        t = race_GetTime(i);
+        t = race_readTime(map, i);
        if (t == 0)
            continue;
-       n = race_GetName(i);
-       p = race_PlaceName(i);
+       n = race_readName(map, i);
+       p = race_placeName(i);
         s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
     }
 
@@ -2168,6 +2253,162 @@ string getrankings()
         return strcat("Records for ", map, ":\n", s);
 }
 
+const float LADDER_FIRSTPOINT = 100;
+const float LADDER_CNT = 10; // position X still gives LADDER_FIRSTPOINT/X points
+const float LADDER_SIZE = 30; // ladder shows the top X players
+string top_uids[LADDER_SIZE];
+float top_scores[LADDER_SIZE];
+float UIDCNT;
+string getladder()
+{
+    float i, j, k;
+    string s, temp_s;
+
+    s = "";
+    temp_s = "";
+
+    string myuid;
+
+    for (k = 0; k < MapInfo_count; ++k)
+    {
+        if (MapInfo_Get_ByID(k))
+       {
+               for (i = 0; i <= LADDER_CNT; ++i) { // i = 0 because it is the speed award
+                       if(race_readTime(GetMapname(), i) == 0)
+                           break;
+
+                       myuid = race_readUID(GetMapname(), i);
+
+                       // string s contains:
+                       // arg 0 = # of speed recs
+                       // arg 1 = # of 1st place recs
+                       // arg 2 = # of 2nd place recs
+                       // ... etc
+                       // LADDER_CNT+1 = total points
+
+                       temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
+                       if (temp_s == "")
+                       {
+                           db_put(TemporaryDB, strcat("uid", ftos(UIDCNT)), myuid);
+                           ++UIDCNT;
+                           for (j = 0; j <= LADDER_CNT + 1; ++j)
+                           {
+                               if(j != LADDER_CNT + 1)
+                                   temp_s = strcat(temp_s, "0 ");
+                               else
+                                   temp_s = strcat(temp_s, "0");
+                           }
+                       }
+
+                       tokenize_console(temp_s);
+                       s = "";
+
+                       if(i == 0) // speed award
+                           for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
+                           {
+                               if(j == 0) // speed award
+                                   s = strcat(s, ftos(stof(argv(j)) +1)); // add 1 to speed rec count and write
+                               else
+                                   s = strcat(s, " ", argv(j)); // just copy over everything else
+                           }
+                       else // record
+                           for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
+                           {
+                               if(j == 0)
+                                   s = strcat(s, argv(j)); // speed award, dont prefix with " "
+                               else if(j == i) // wanted rec!
+                                   s = strcat(s, " ", ftos(stof(argv(j)) +1)); // update argv(j)
+                               else
+                                   s = strcat(s, " ", argv(j)); // just copy over everything else
+                           }
+
+                       // total points are (by default) calculated like this:
+                       // speedrec = floor(100 / 10) = 10 points
+                       // 1st place = floor(100 / 1) = 100 points
+                       // 2nd place = floor(100 / 2) = 50 points
+                       // 3rd place = floor(100 / 3) = 33 points
+                       // 4th place = floor(100 / 4) = 25 points
+                       // 5th place = floor(100 / 5) = 20 points
+                       // ... etc
+
+                       if(i == 0)
+                           s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
+                       else
+                           s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points
+
+                       db_put(TemporaryDB, strcat("ladder", myuid), s);
+               }
+       }
+    }
+
+    float thiscnt;
+    string thisuid;
+    for (i = 0; i <= UIDCNT; ++i) // for each known uid
+    {
+       thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
+       temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
+       tokenize_console(temp_s);
+        thiscnt = stof(argv(LADDER_CNT+1));
+
+       if(thiscnt > top_scores[LADDER_SIZE-1])
+       for (j = 0; j < LADDER_SIZE; ++j) // for each place in ladder
+       {
+           if(thiscnt > top_scores[j])
+           {
+               for (k = LADDER_SIZE-1; k >= j; --k)
+               {
+                   top_uids[k] = top_uids[k-1];
+                   top_scores[k] = top_scores[k-1];
+               }
+               top_uids[j] = thisuid;
+               top_scores[j] = thiscnt;
+               break;
+           }
+       }
+    }
+
+    s = "^3-----------------------\n\n";
+
+    s = strcat(s, "Pos ^3|");
+    s = strcat(s, " ^7Total  ^3|");
+    for (i = 1; i <= LADDER_CNT; ++i)
+    {
+       s = strcat(s, " ^7", race_placeName(i), " ^3|");
+    }
+    s = strcat(s, " ^7Speed awards ^3| ^7Name");
+
+    s = strcat(s, "\n^3----+--------");
+    for (i = 1; i <= LADDER_CNT; ++i)
+    {
+       s = strcat(s, "+-----");
+    }
+    s = strcat(s, "+--------------+--------------------\n");
+
+    for (i = 0; i < LADDER_SIZE; ++i)
+    {
+       temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
+       tokenize_console(temp_s);
+       if (argv(LADDER_CNT+1) == "") // total is 0, skip
+           continue;
+       s = strcat(s, strpad(4, race_placeName(i+1)), "^3| ^7"); // pos
+       s = strcat(s, strpad(7, argv(LADDER_CNT+1)), "^3| ^7"); // total
+       for (j = 1; j <= LADDER_CNT; ++j)
+       {
+           s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt
+       }
+       s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt
+       s = strcat(s, uid2name(top_uids[i]), "\n"); // name
+    }
+
+    MapInfo_ClearTemps();
+
+    if (s == "")
+       return "No ladder on this server!\n";
+    else
+        return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
+}
+
+
 float MoveToRandomMapLocation(entity e, float goodcontents, float badcontents, float badsurfaceflags, float attempts, float maxaboveground, float minviewdistance)
 {
     float m, i;
index 2f158898198aafe3b45aeedbe4a1a04979fbf6b8..19995d7d058cebfd82626d849b460155906777ac 100644 (file)
@@ -98,75 +98,13 @@ void race_InitSpectator()
                        race_SendNextCheckpoint(msg_entity.enemy, 1);
 }
 
-string rr;
-float grecordtime[RANKINGS_CNT];
-string grecordholder[RANKINGS_CNT];
-string grecorduid[RANKINGS_CNT];
-float worst_time; // last ranked time
-float have_recs; // have we already read the records from the database before?
-float race_GetTime(float pos) {
-       if(g_cts)
-               rr = CTS_RECORD;
-       else
-               rr = RACE_RECORD;
-
-       if (!have_recs) { // I guess this is better than checking if the first array item is empty, rumor has it that arrays are slow
-               float i;
-               for(i=0;i<RANKINGS_CNT;++i) {
-                       grecordtime[i] = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time", ftos(i))));
-                       grecordholder[i] = strzone(db_get(ServerProgsDB, strcat(GetMapname(), rr, "netname", ftos(i))));
-                       grecorduid[i] = strzone(db_get(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp", ftos(i))));
-               }
-               grecordtime[0] = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, "time")));
-               grecordholder[0] = strzone(db_get(ServerProgsDB, strcat(GetMapname(), rr, "netname")));
-               grecorduid[0] = strzone(db_get(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp")));
-               worst_time = stof(db_get(ServerProgsDB, strcat(GetMapname(), rr, strcat("time", ftos(RANKINGS_CNT-1)))));
-               have_recs = 1;
-       }
-
-       return grecordtime[pos-1];
-}
-
-string race_GetName(float pos) { // these other functions assume that race_GetTime has been called >= once before
-       return grecordholder[pos-1];
-}
-
-float race_CheckUID(string myuid, string net_name) { // return existing UID or player name ranking pos, else 0
-       float i;
-       if(myuid)
-       {
-               for (i=RANKINGS_CNT-1;i>=0;--i)
-                       if(grecorduid[i] == myuid)
-                               return i+1;
-       }
-       for (i=RANKINGS_CNT-1;i>=0;--i)
-               if(!grecorduid[i])
-                       if(grecordholder[i] == net_name)
-                               return i+1;
-       return 0;
-}
-
-float race_GetPos(float t) {
-       float i;
-
-       if(worst_time == 0)
-       for (i=0;i<RANKINGS_CNT;++i)
-               if (grecordtime[i] == 0 || grecordtime[i] > t)
-                       return i+1;
-
-       for (i=0;i<RANKINGS_CNT;++i)
-               if (grecordtime[i] > t)
-                       return i+1;
-       return 0;
-}
-
 void race_send_recordtime(float msg)
 {
        // send the server best time
        WriteByte(msg, SVC_TEMPENTITY);
        WriteByte(msg, TE_CSQC_RACE);
        WriteByte(msg, RACE_NET_SERVER_RECORD);
-       WriteInt24_t(msg, race_GetTime(1));
+       WriteInt24_t(msg, race_readTime(MapInfo_Map_bspname, 1));
 }
 
 void race_SendRankings(float pos, float prevpos, float del, float msg)
@@ -177,8 +115,8 @@ void race_SendRankings(float pos, float prevpos, float del, float msg)
        WriteShort(msg, pos);
        WriteShort(msg, prevpos);
        WriteShort(msg, del);
-       WriteString(msg, race_GetName(pos));
-       WriteInt24_t(msg, race_GetTime(pos));
+       WriteString(msg, race_readName(MapInfo_Map_bspname, pos));
+       WriteInt24_t(msg, race_readTime(MapInfo_Map_bspname, pos));
 }
 
 void race_SendStatus(float id, entity e)
@@ -198,179 +136,104 @@ void race_SendStatus(float id, entity e)
        });
 }
 
-string race_PlaceName(float pos) {
-       if(pos == 1)
-               return "1st";
-       else if(pos == 2)
-               return "2nd";
-       else if(pos == 3)
-               return "3rd";
-       else
-               return strcat(ftos(pos), "th");
-}
+void race_setTime(string map, float t, string myuid, string mynetname, entity e) { // netname only used TEMPORARILY for printing
+       float newpos, player_prevpos;
+       newpos = race_readPos(map, t);
 
-void race_SetTime(entity e, float t, float match_rec) {
-       float pos, prevpos;
-       pos = race_GetPos(t);
-       prevpos = race_CheckUID(e.crypto_idfp, e.netname);
+       float i;
+       for(i = 1; i <= RANKINGS_CNT; ++i)
+       {
+               if(race_readUID(map, i) == myuid)
+                       player_prevpos = i;
+       }
 
        float oldrec;
-       string recorddifference;
-       if (prevpos && (prevpos < pos || !pos))
+       string recorddifference, oldrec_holder;
+       if (player_prevpos && (player_prevpos < newpos || !newpos))
        {
-               oldrec = race_GetTime(prevpos);
+               oldrec = race_readTime(MapInfo_Map_bspname, player_prevpos);
                recorddifference = strcat(" ^1[+", TIME_ENCODED_TOSTRING(t - oldrec), "]");
-               bprint(e.netname, "^7 couldn't break their ", race_PlaceName(prevpos), " place record of ", TIME_ENCODED_TOSTRING(oldrec), recorddifference, "\n");
+               bprint(mynetname, "^7 couldn't break their ", race_placeName(player_prevpos), " place record of ", TIME_ENCODED_TOSTRING(oldrec), recorddifference, "\n");
                race_SendStatus(0, e); // "fail"
                return;
-       } else if (!pos) { // no ranking, time worse than the worst ranked
-               recorddifference = strcat(" ^1[+", TIME_ENCODED_TOSTRING(t - grecordtime[RANKINGS_CNT-1]), "]");
-               bprint(e.netname, "^7 couldn't break the ", race_PlaceName(RANKINGS_CNT), " place record of ", TIME_ENCODED_TOSTRING(grecordtime[RANKINGS_CNT-1]), recorddifference, "\n");
+       } else if (!newpos) { // no ranking, time worse than the worst ranked
+               recorddifference = strcat(" ^1[+", TIME_ENCODED_TOSTRING(t - race_readTime(MapInfo_Map_bspname, RANKINGS_CNT)), "]");
+               bprint(mynetname, "^7 couldn't break the ", race_placeName(RANKINGS_CNT), " place record of ", TIME_ENCODED_TOSTRING(race_readTime(MapInfo_Map_bspname, RANKINGS_CNT)), recorddifference, "\n");
                race_SendStatus(0, e); // "fail"
                return;
        }
 
-       oldrec = grecordtime[pos-1];
+       // if we didn't hit a return yet, we have a new record!
+
+       oldrec = race_readTime(MapInfo_Map_bspname, newpos);
+       oldrec_holder = race_readName(MapInfo_Map_bspname, newpos);
 
        // move other rankings out of the way
-       float i;
-       if (prevpos) { // player improved his existing record
-               for (i=prevpos-1;i>pos-1;--i) {
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "time", ftos(i)), ftos(grecordtime[i-1]));
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname", ftos(i)), grecordholder[i-1]);
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp", ftos(i)), grecorduid[i-1]);
-                       grecordtime[i] = grecordtime[i-1];
-
-                       if (grecordholder[i])
-                               strunzone(grecordholder[i]);
-                       grecordholder[i] = strzone(grecordholder[i-1]);
-                       if (grecorduid[i])
-                               strunzone(grecorduid[i]);
-                       grecorduid[i] = strzone(grecorduid[i-1]);
+       if (player_prevpos) { // player improved his existing record, only have to iterate on ranks between new and old recs
+               for (i = player_prevpos; i > newpos; --i) {
+                       race_writeTime(GetMapname(), race_readTime(GetMapname(), newpos-1), race_readUID(GetMapname(), newpos-1));
                }
        } else { // player has no ranked record yet
-               for (i=RANKINGS_CNT-1;i>pos-1;--i) {
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "time", ftos(i)), ftos(grecordtime[i-1]));
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname", ftos(i)), grecordholder[i-1]);
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp", ftos(i)), grecorduid[i-1]);
-                       grecordtime[i] = grecordtime[i-1];
-
-                       if (grecordholder[i])
-                               strunzone(grecordholder[i]);
-                       grecordholder[i] = strzone(grecordholder[i-1]);
-                       if (grecorduid[i])
-                               strunzone(grecorduid[i]);
-                       grecorduid[i] = strzone(grecorduid[i-1]);
+               for (i = RANKINGS_CNT; i > newpos; --i) {
+                       race_writeTime(GetMapname(), race_readTime(GetMapname(), newpos-1), race_readUID(GetMapname(), newpos-1));
                }
        }
        
        // store new ranking
-       if (pos == 1) {
-               db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(t));
-               db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), e.netname);
-               db_put(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp"), e.crypto_idfp);
-
-               grecordtime[0] = t;
-
-               if (grecordholder[0])
-                       strunzone(grecordholder[0]);
-               grecordholder[0] = strzone(e.netname);
-               if (grecorduid[0])
-                       strunzone(grecorduid[0]);
-               grecorduid[0] = strzone(e.crypto_idfp);
+       race_writeTime(GetMapname(), t, myuid);
+
+       if (newpos == 1) {
                write_recordmarker(e, time - TIME_DECODE(t), TIME_DECODE(t));
                race_send_recordtime(MSG_ALL);
-       } else {
-               db_put(ServerProgsDB, strcat(GetMapname(), rr, "time", ftos(pos-1)), ftos(t));
-               db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname", ftos(pos-1)), e.netname);
-               db_put(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp", ftos(pos-1)), e.crypto_idfp);
-
-               grecordtime[pos-1] = t;
-
-               if (grecordholder[pos-1])
-                       strunzone(grecordholder[pos-1]);
-               grecordholder[pos-1] = strzone(e.netname);
-               if (grecorduid[pos-1])
-                       strunzone(grecorduid[pos-1]);
-               grecorduid[pos-1] = strzone(e.crypto_idfp);
        }
 
-       if (pos == RANKINGS_CNT)
-               worst_time = t;
-
-       race_SendRankings(pos, prevpos, 0, MSG_ALL);
+       race_SendRankings(newpos, player_prevpos, 0, MSG_ALL);
        if(rankings_reply)
                strunzone(rankings_reply);
        rankings_reply = strzone(getrankings());
-       if(pos == 1) {
-               if(pos == prevpos) {
+       if(newpos == 1) {
+               if(newpos == player_prevpos) {
                        recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-                       bprint(e.netname, "^1 improved their 1st place record with ", TIME_ENCODED_TOSTRING(t), recorddifference, "\n");
+                       bprint(mynetname, "^1 improved their 1st place record with ", TIME_ENCODED_TOSTRING(t), recorddifference, "\n");
                } else if (oldrec == 0) {
-                       bprint(e.netname, "^1 set the 1st place record with ", TIME_ENCODED_TOSTRING(t), "\n");
+                       bprint(mynetname, "^1 set the 1st place record with ", TIME_ENCODED_TOSTRING(t), "\n");
                } else {
                        recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-                       bprint(e.netname, "^1 broke ", grecordholder[pos], "^1's 1st place record with ", strcat(TIME_ENCODED_TOSTRING(t), recorddifference, "\n"));
+                       bprint(mynetname, "^1 broke ", oldrec_holder, "^1's 1st place record with ", strcat(TIME_ENCODED_TOSTRING(t), recorddifference, "\n"));
                }
                race_SendStatus(3, e); // "new server record"
        } else {
-               if(pos == prevpos) {
+               if(newpos == player_prevpos) {
                        recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-                       bprint(e.netname, "^5 improved their ", race_PlaceName(pos), " ^5place record with ", TIME_ENCODED_TOSTRING(t), recorddifference, "\n");
+                       bprint(mynetname, "^5 improved their ", race_placeName(newpos), " ^5place record with ", TIME_ENCODED_TOSTRING(t), recorddifference, "\n");
                        race_SendStatus(1, e); // "new time"
                } else if (oldrec == 0) {
-                       bprint(e.netname, "^2 set the ", race_PlaceName(pos), " ^2place record with ", TIME_ENCODED_TOSTRING(t), "\n");
+                       bprint(mynetname, "^2 set the ", race_placeName(newpos), " ^2place record with ", TIME_ENCODED_TOSTRING(t), "\n");
                        race_SendStatus(2, e); // "new rank"
                } else {
                        recorddifference = strcat(" ^2[-", TIME_ENCODED_TOSTRING(oldrec - t), "]");
-                       bprint(e.netname, "^2 broke ", grecordholder[pos], "^2's ", race_PlaceName(pos), " ^2place record with ", strcat(TIME_ENCODED_TOSTRING(t), recorddifference, "\n"));
+                       bprint(mynetname, "^2 broke ", oldrec_holder, "^2's ", race_placeName(newpos), " ^2place record with ", strcat(TIME_ENCODED_TOSTRING(t), recorddifference, "\n"));
                        race_SendStatus(2, e); // "new rank"
                }
        }
 }
 
-void race_DeleteTime(float pos) {
-       float i;
+void race_deleteTime(string map, float pos) {
+       string rr;
+       if(g_cts)
+               rr = CTS_RECORD;
+       else
+               rr = RACE_RECORD;
 
-       for (i = pos-1; i <= RANKINGS_CNT-1; ++i) {
-               if (i == 0) {
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "time"), ftos(grecordtime[1]));
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname"), grecordholder[1]);
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp"), grecorduid[1]);
-                       grecordtime[0] = grecordtime[1];
-                       if (grecordholder[i])
-                               strunzone(grecordholder[0]);
-                       grecordholder[0] = strzone(grecordholder[1]);
-
-                       if (grecorduid[i])
-                               strunzone(grecorduid[0]);
-                       grecorduid[0] = strzone(grecorduid[1]);
-               }
-               else if (i == RANKINGS_CNT-1) {
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "time", ftos(i)), string_null);
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname", ftos(i)), string_null);
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp", ftos(i)), string_null);
-                       grecordtime[i] = 0;
-                       if (grecordholder[i])
-                               strunzone(grecordholder[i]);
-                       grecordholder[i] = string_null;
-
-                       if (grecorduid[i])
-                               strunzone(grecorduid[i]);
-                       grecorduid[i] = string_null;
+       float i;
+       for (i = pos; i <= RANKINGS_CNT; ++i) {
+               if (i == RANKINGS_CNT) {
+                       db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), string_null);
+                       db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), string_null);
                }
                else {
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "time", ftos(i)), ftos(grecordtime[i+1]));
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "netname", ftos(i)), grecordholder[i+1]);
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "crypto_idfp", ftos(i)), grecorduid[i+1]);
-                       grecordtime[i] = grecordtime[i+1];
-                       if (grecordholder[i])
-                               strunzone(grecordholder[i]);
-                       grecordholder[i] = strzone(grecordholder[i+1]);
-
-                       if (grecorduid[i])
-                               strunzone(grecorduid[i]);
-                       grecorduid[i] = strzone(grecorduid[i+1]);
+                       db_put(ServerProgsDB, strcat(map, rr, "time", ftos(i)), ftos(race_readTime(GetMapname(), i+1)));
+                       db_put(ServerProgsDB, strcat(map, rr, "crypto_idfp", ftos(i)), race_readUID(GetMapname(), i+1));
                }
        }
 
@@ -381,8 +244,6 @@ void race_DeleteTime(float pos) {
        if(rankings_reply)
                strunzone(rankings_reply);
        rankings_reply = strzone(getrankings());
-
-       worst_time = 0;
 }
 
 void race_SendTime(entity e, float cp, float t, float tvalid)
@@ -441,8 +302,13 @@ void race_SendTime(entity e, float cp, float t, float tvalid)
 
                        if(t != 0) {
                                if(cp == race_timed_checkpoint)
-                                       race_SetTime(e, t, recordtime);
-
+                               {
+                                       race_setTime(MapInfo_Map_bspname, t, e.crypto_idfp, e.netname, e);
+                                       if(g_cts && cvar("g_cts_finish_kill_delay"))
+                                       {
+                                               CTS_ClientKill(cvar("g_cts_finish_kill_delay"));
+                                       }
+                               }
                                if(t < recordtime || recordtime == 0)
                                {
                                        race_checkpoint_records[cp] = t;
index cffe88bd7fff5acfe21bc2ca98f26af4ffe99bcf..3d3f1d626ec0f43c99ea5839e5d5315f66beaab5 100644 (file)
@@ -39,12 +39,29 @@ void spawnfunc_item_armor_combat()   { spawnfunc_item_armor_big();      }
 void spawnfunc_item_armor_shard()    { spawnfunc_item_armor_small();    }
 void spawnfunc_item_enviro()         { spawnfunc_item_invincible();     }
 
-// weapon remove ent from defrag
+// weapon remove ent from df
+void target_init_verify()
+{
+       entity trigger, targ;
+       for(trigger = world; (trigger = find(trigger, classname, "trigger_multiple")); )
+               for(targ = world; (targ = find(targ, targetname, trigger.target)); )
+                       if (targ.classname == "target_init" || targ.classname == "target_give" || targ.classname == "target_items")
+                       {
+                               targ.wait = -2;
+                               targ.delay = 0;
+
+                               setsize(targ, trigger.mins, trigger.maxs);
+                               setorigin(targ, trigger.origin);
+                               //remove(trigger);
+                       }
+}
+
 void spawnfunc_target_init()
 {
        self.spawnflags = 0; // remove all weapons except the ones listed below
        self.netname = "laser uzi"; // keep these weapons through the remove trigger
        spawnfunc_target_items();
+       InitializeEntity(self, target_init_verify, INITPRIO_FINDTARGET);
 }
 
 // weapon give ent from defrag
@@ -85,6 +102,7 @@ void target_give_init()
        }
        self.spawnflags = 2;
        spawnfunc_target_items();
+       InitializeEntity(self, target_init_verify, INITPRIO_FINDTARGET);
 }
 
 void spawnfunc_target_give()