From: Samual Date: Sat, 31 Dec 2011 06:55:18 +0000 (-0500) Subject: Update the reply code X-Git-Tag: xonotic-v0.6.0~188^2~28^2~11 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=8af589d97a11de85e4f4c20cadc979ae673f6f6a;p=xonotic%2Fxonotic-data.pk3dir.git Update the reply code --- diff --git a/qcsrc/server/command/common.qc b/qcsrc/server/command/common.qc index ce09b4240..842bb5aa8 100644 --- a/qcsrc/server/command/common.qc +++ b/qcsrc/server/command/common.qc @@ -404,30 +404,6 @@ void CommonCommand_printmaplist(float request, entity caller) } } -/* -void GameCommand_rankings(float request) // this is OLD.... jeez. -{ - switch(request) - { - case CMD_REQUEST_COMMAND: - { - strunzone(rankings_reply); - rankings_reply = strzone(getrankings()); - print(rankings_reply); - return; - } - - default: - case CMD_REQUEST_USAGE: - { - print("\nUsage:^3 sv_cmd rankings"); - print(" No arguments required."); - return; - } - } -} -*/ - void CommonCommand_rankings(float request, entity caller) { switch(request) @@ -457,7 +433,8 @@ void CommonCommand_records(float request, entity caller) float i; for(i = 0; i < 10; ++i) - print_to(caller, records_reply[i]); + if(records_reply[i]) + print_to(caller, records_reply[i]); return; // never fall through to usage } diff --git a/qcsrc/server/command/getreplies.qc b/qcsrc/server/command/getreplies.qc index fd468f7d9..e4d5441e1 100644 --- a/qcsrc/server/command/getreplies.qc +++ b/qcsrc/server/command/getreplies.qc @@ -11,282 +11,276 @@ // See common.qc for their proper commands // todo: Re-write this to be more user friendly... I'll probably do it after it is merged. - + string getrecords(float page) // 50 records per page -{ - float rec; - string h; - float r; - float i; - string s; - - rec = 0; - - s = ""; +{ + float rec, r, i; + string h, s; - if (g_ctf) - { - for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i) - { - if (MapInfo_Get_ByID(i)) - { - 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; - } - } - } + if (g_ctf) + { + for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i) + { + if (MapInfo_Get_ByID(i)) + { + 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; + } + } + } - if (g_race) - { - for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i) - { - if (MapInfo_Get_ByID(i)) - { - r = race_readTime(MapInfo_Map_bspname, 1); - if (r == 0) - continue; - h = race_readName(MapInfo_Map_bspname, 1); - s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); - ++rec; - } - } - } + if (g_race) + { + for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i) + { + if (MapInfo_Get_ByID(i)) + { + r = race_readTime(MapInfo_Map_bspname, 1); + + if (r == 0) + continue; + + h = race_readName(MapInfo_Map_bspname, 1); + s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); + ++rec; + } + } + } - if (g_cts) - { - for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i) - { - if (MapInfo_Get_ByID(i)) - { - r = race_readTime(MapInfo_Map_bspname, 1); - if (r == 0) - continue; - h = race_readName(MapInfo_Map_bspname, 1); - s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); - ++rec; - } - } - } + if (g_cts) + { + for (i = page * 200; i < MapInfo_count && i < page * 200 + 200; ++i) + { + if (MapInfo_Get_ByID(i)) + { + r = race_readTime(MapInfo_Map_bspname, 1); + + if (r == 0) + continue; + + h = race_readName(MapInfo_Map_bspname, 1); + s = strcat(s, strpad(32, MapInfo_Map_bspname), " ", strpad(-8, TIME_ENCODED_TOSTRING(r)), " ", h, "\n"); + ++rec; + } + } + } - MapInfo_ClearTemps(); + MapInfo_ClearTemps(); - if (s == "" && page == 0) - return "No records are available on this server.\n"; - else - return s; + if (s == "" && page == 0) + return "No records are available on this server.\n"; + else + return s; } string getrankings() { - string n; - float t; - float i; - string s; - string p; - string map; - - s = ""; + float t, i; + string n, s, p, map; - map = GetMapname(); + map = GetMapname(); - for (i = 1; i <= RANKINGS_CNT; ++i) - { - t = race_readTime(map, i); - if (t == 0) - continue; - n = race_readName(map, i); - p = race_placeName(i); - s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n"); - } + for (i = 1; i <= RANKINGS_CNT; ++i) + { + t = race_readTime(map, i); + + if (t == 0) + continue; + + n = race_readName(map, i); + p = race_placeName(i); + s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n"); + } - MapInfo_ClearTemps(); + MapInfo_ClearTemps(); - if (s == "") - return strcat("No records are available for the map: ", map, "\n"); - else - return strcat("Records for ", map, ":\n", s); + if (s == "") + return strcat("No records are available for the map: ", map, "\n"); + else + return strcat("Records for ", map, ":\n", s); } string getladder() { - float i, j, k, uidcnt; - string s, temp_s; - - s = ""; - temp_s = ""; - - string rr; - if(g_cts) - rr = CTS_RECORD; - else - rr = RACE_RECORD; - - string myuid; - - for (k = 0; k < MapInfo_count; ++k) - { - if (MapInfo_Get_ByID(k)) + float i, j, k, uidcnt, thiscnt; + string s, temp_s, rr, myuid, thisuid; + + if(g_cts) + rr = CTS_RECORD; + else + rr = RACE_RECORD; + + for(k = 0; k < MapInfo_count; ++k) { - for (i = 0; i <= LADDER_CNT; ++i) { // i = 0 because it is the speed award - if(i == 0) // speed award - { - if(stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) - continue; - - myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp")); - } - else // normal record, if it exists (else break) - { - if(race_readTime(MapInfo_Map_bspname, i) == 0) - continue; - - myuid = race_readUID(MapInfo_Map_bspname, 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 == "") + if(MapInfo_Get_ByID(k)) + { + for(i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award { - 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) + if(i == 0) // speed award + { + if(stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) + continue; + + myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp")); + } + else // normal record, if it exists (else break) + { + if(race_readTime(MapInfo_Map_bspname, i) == 0) + continue; + + myuid = race_readUID(MapInfo_Map_bspname, 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, " ", argv(j)); // just copy over everything else - } + s = strcat(s, " ", ftos(stof(argv(LADDER_CNT+1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points - // 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); + 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 + for(i = 0; i <= uidcnt; ++i) // for each known uid { - if(thiscnt > top_scores[j]) - { - for (k = LADDER_SIZE-1; k >= j; --k) + 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]) { - top_uids[k] = top_uids[k-1]; - top_scores[k] = top_scores[k-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; + } + } } - 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 <= min(9, LADDER_CNT); ++i) - { - s = strcat(s, "+-----"); - } -#if LADDER_CNT > 9 - for (i = 1; i <= LADDER_CNT - 9; ++i) - { - s = strcat(s, "+------"); - } -#endif - - 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 <= min(9, LADDER_CNT); ++j) + + 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 <= min(9, LADDER_CNT); ++i) + { s = strcat(s, "+-----"); } + + #if LADDER_CNT > 9 + for(i = 1; i <= LADDER_CNT - 9; ++i) + { s = strcat(s, "+------"); } + #endif + + s = strcat(s, "+--------------+--------------------\n"); + + for(i = 0; i < LADDER_SIZE; ++i) { - s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt + 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 <= min(9, LADDER_CNT); ++j) + { s = strcat(s, strpad(4, argv(j)), "^3| ^7"); } // 1st, 2nd, 3rd etc cnt + + #if LADDER_CNT > 9 + for(j = 10; j <= LADDER_CNT; ++j) + { s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); } // 1st, 2nd, 3rd etc cnt + #endif + + s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt + s = strcat(s, uid2name(top_uids[i]), "\n"); // name } -#if LADDER_CNT > 9 - for (j = 10; j <= LADDER_CNT; ++j) - { - s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt - } -#endif - - s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt - s = strcat(s, uid2name(top_uids[i]), "\n"); // name - } - MapInfo_ClearTemps(); + MapInfo_ClearTemps(); - if (s == "") - return "No ladder on this server!\n"; - else - return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s); + if(s == "") + return "No ladder on this server!\n"; + else + return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s); } \ No newline at end of file