X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Fserver%2Fcommand%2Fgetreplies.qc;h=5017e81aba03014d4d325c3ddbb56fe0b9e36e2e;hp=aa8efd6d69a15934416371d6066b76c419bfc212;hb=b0a563c3658ec620ddb9037b9417b743a47002a5;hpb=e921ae9f86a09d0a20cd4c72b44e6d71d25975ea diff --git a/qcsrc/server/command/getreplies.qc b/qcsrc/server/command/getreplies.qc index aa8efd6d69..5017e81aba 100644 --- a/qcsrc/server/command/getreplies.qc +++ b/qcsrc/server/command/getreplies.qc @@ -1,17 +1,15 @@ -#if defined(CSQC) -#elif defined(MENUQC) -#elif defined(SVQC) - #include "../../dpdefs/progsdefs.qh" - #include "../../dpdefs/dpextensions.qh" - #include "../../common/constants.qh" - #include "../../common/util.qh" - #include "../../common/counting.qh" - #include "../../common/monsters/monsters.qh" - #include "../defs.qh" - #include "../../common/mapinfo.qh" - #include "getreplies.qh" - #include "../race.qh" -#endif +#include "getreplies.qh" +#include +#include "getreplies.qh" + +#include "../race.qh" + +#include +#include +#include +#include + +#include // ========================================================= // Reply messages for common commands, re-worked by Samual @@ -25,74 +23,17 @@ // See common.qc for their proper commands -string getrecords(float page) // 50 records per page +string getrecords(int page) // 50 records per page { - float rec = 0, r, i; - string h, s; - - 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) - 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); + string s = ""; - if (!r) - 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) - 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; - } - } - } + MUTATOR_CALLHOOK(GetRecords, page, s); + s = M_ARGV(1, string); 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() @@ -107,8 +48,7 @@ string getrankings() { t = race_readTime(map, i); - if (t == 0) - continue; + if (t == 0) continue; n = race_readName(map, i); p = count_ordinal(i); @@ -117,10 +57,8 @@ string getrankings() 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() @@ -130,23 +68,21 @@ string getladder() rr = (g_cts) ? CTS_RECORD : RACE_RECORD; - for(k = 0; k < MapInfo_count; ++k) + for (k = 0; k < MapInfo_count; ++k) { - if(MapInfo_Get_ByID(k)) + if (MapInfo_Get_ByID(k)) { - for(i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award + for (i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award { - if(i == 0) // speed award + if (i == 0) // speed award { - if(stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) - continue; + 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) + else // normal record, if it exists (else break) { - if(race_readTime(MapInfo_Map_bspname, i) == 0) - continue; + if (race_readTime(MapInfo_Map_bspname, i) == 0) continue; myuid = race_readUID(MapInfo_Map_bspname, i); } @@ -160,43 +96,38 @@ string getladder() temp_s = db_get(TemporaryDB, strcat("ladder", myuid)); - if(temp_s == "") + if (temp_s == "") { db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid); ++uidcnt; - for(j = 0; j <= LADDER_CNT + 1; ++j) + 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"); + 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 + if (i == 0) // speed award { - for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string + 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 + 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 + else // record { - for(j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string + 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 + 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 } } @@ -209,33 +140,31 @@ string getladder() // 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 + 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); } } } - for(i = 0; i <= uidcnt; ++i) // for each known uid + 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)); + thiscnt = stof(argv(LADDER_CNT + 1)); - if(thiscnt > top_scores[LADDER_SIZE-1]) + if (thiscnt > top_scores[LADDER_SIZE - 1]) { - for(j = 0; j < LADDER_SIZE; ++j) // for each place in ladder + for (j = 0; j < LADDER_SIZE; ++j) // for each place in ladder { - if(thiscnt > top_scores[j]) + if (thiscnt > top_scores[j]) { - for(k = LADDER_SIZE-1; k >= j; --k) + for (k = LADDER_SIZE - 1; k >= j; --k) { - top_uids[k] = top_uids[k-1]; - top_scores[k] = top_scores[k-1]; + top_uids[k] = top_uids[k - 1]; + top_scores[k] = top_scores[k - 1]; } top_uids[j] = thisuid; @@ -251,51 +180,47 @@ string getladder() s = strcat(s, "Pos ^3|"); s = strcat(s, " ^7Total ^3|"); - for(i = 1; i <= LADDER_CNT; ++i) - { s = strcat(s, " ^7", count_ordinal(i), " ^3|"); } - + for (i = 1; i <= LADDER_CNT; ++i) + s = strcat(s, " ^7", count_ordinal(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 + 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) + 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 + if (argv(LADDER_CNT + 1) == "") // total is 0, skip continue; - s = strcat(s, strpad(4, count_ordinal(i+1)), "^3| ^7"); // pos - s = strcat(s, strpad(7, argv(LADDER_CNT+1)), "^3| ^7"); // total + s = strcat(s, strpad(4, count_ordinal(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 + 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 +#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 + 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); + if (s == "") return "No ladder on this server!\n"; + else return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s); } string getmaplist() @@ -304,12 +229,11 @@ string getmaplist() int i, argc; argc = tokenize_console(autocvar_g_maplist); - for(i = 0; i < argc; ++i) + for (i = 0; i < argc; ++i) { - if(MapInfo_CheckMap(argv(i))) + if (MapInfo_CheckMap(argv(i))) { - if(i % 2) { col = "^2"; } - else { col = "^3"; } + if (i % 2) col = "^2"; else col = "^3"; maplist = sprintf("%s%s%s ", maplist, col, argv(i)); } } @@ -324,25 +248,23 @@ string getlsmaps() string lsmaps = "", col; float i, newmaps = 0; - for(i = 0; i < MapInfo_count; ++i) + for (i = 0; i < MapInfo_count; ++i) { - if((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags())) + if ((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags())) { // todo: Check by play count of maps for other game types? - if( - (g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time")))) - || - (g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time")))) - ) + if ( + (g_race && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, RACE_RECORD, "time")))) + || + (g_cts && !stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, CTS_RECORD, "time")))) + ) { newmaps = true; - if(i % 2) { col = "^4*"; } - else { col = "^5*"; } + if (i % 2) col = "^4*"; else col = "^5*"; } else { - if(i % 2) { col = "^2"; } - else { col = "^3"; } + if (i % 2) col = "^2"; else col = "^3"; } lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname); @@ -357,10 +279,9 @@ string getmonsterlist() { string monsterlist = "", col; - for(int i = MON_FIRST; i <= MON_LAST; ++i) + for (int i = MON_FIRST; i <= MON_LAST; ++i) { - if(i % 2) { col = "^2"; } - else { col = "^3"; } + if (i % 2) col = "^2"; else col = "^3"; monsterlist = sprintf("%s%s%s ", monsterlist, col, (get_monsterinfo(i)).netname); }