1 #include "getreplies.qh"
3 #include <common/command/_mod.qh>
4 #include <common/constants.qh>
5 #include <common/gamemodes/_mod.qh>
6 #include <common/monsters/_mod.qh>
7 #include <common/net_linked.qh>
8 #include <common/notifications/all.qh>
9 #include <common/playerstats.qh>
10 #include <common/stats.qh>
11 #include <common/util.qh>
12 #include <common/weapons/_all.qh>
13 #include <common/wepent.qh>
14 #include <server/command/getreplies.qh>
15 #include <server/intermission.qh>
16 #include <server/main.qh>
17 #include <server/mutators/_mod.qh>
18 #include <server/race.qh>
19 #include <server/weapons/selection.qh>
20 #include <server/world.qh>
22 // =========================================================
23 // Reply messages for common commands, re-worked by Samual
24 // Last updated: December 30th, 2011
25 // =========================================================
27 // These strings are set usually during init in world.qc,
28 // or also by some game modes or other functions manually,
29 // and their purpose is to output information to clients
30 // without using any extra processing time.
32 // See common.qc for their proper commands
34 string getrecords(int page) // 50 records per page
38 MUTATOR_CALLHOOK(GetRecords, page, s);
39 s = M_ARGV(1, string);
43 if (s == "" && page == 0)
44 return "No records are available on this server for the current game mode.\n";
56 for (i = 1; i <= RANKINGS_CNT; ++i)
58 t = race_readTime(map, i);
62 n = race_readName(map, i);
64 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
69 if (s == "") return strcat("No records are available for the map: ", map, "\n");
70 else return strcat("Records for ", map, ":\n", s);
75 int i, j, k, uidcnt = 0, thiscnt;
76 string s, temp_s, rr, myuid, thisuid;
78 rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
80 for (k = 0; k < MapInfo_count; ++k)
82 if (MapInfo_Get_ByID(k))
84 for (i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award
86 if (i == 0) // speed award
88 if (stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) continue;
90 myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp"));
92 else // normal record, if it exists (else break)
94 if (race_readTime(MapInfo_Map_bspname, i) == 0) continue;
96 myuid = race_readUID(MapInfo_Map_bspname, i);
100 // arg 0 = # of speed recs
101 // arg 1 = # of 1st place recs
102 // arg 2 = # of 2nd place recs
104 // LADDER_CNT+1 = total points
106 temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
110 db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
113 for (j = 0; j <= LADDER_CNT + 1; ++j)
115 if (j != LADDER_CNT + 1) temp_s = strcat(temp_s, "0 ");
116 else temp_s = strcat(temp_s, "0");
120 tokenize_console(temp_s);
123 if (i == 0) // speed award
125 for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
127 if (j == 0) // speed award
128 s = strcat(s, ftos(stof(argv(j)) + 1)); // add 1 to speed rec count and write
129 else s = strcat(s, " ", argv(j)); // just copy over everything else
134 for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
136 if (j == 0) s = strcat(s, argv(j)); // speed award, dont prefix with " "
137 else if (j == i) // wanted rec!
138 s = strcat(s, " ", ftos(stof(argv(j)) + 1)); // update argv(j)
139 else s = strcat(s, " ", argv(j)); // just copy over everything else
143 // total points are (by default) calculated like this:
144 // speedrec = floor(100 / 10) = 10 points
145 // 1st place = floor(100 / 1) = 100 points
146 // 2nd place = floor(100 / 2) = 50 points
147 // 3rd place = floor(100 / 3) = 33 points
148 // 4th place = floor(100 / 4) = 25 points
149 // 5th place = floor(100 / 5) = 20 points
152 if (i == 0) s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
153 else s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points
155 db_put(TemporaryDB, strcat("ladder", myuid), s);
160 for (i = 0; i <= uidcnt; ++i) // for each known uid
162 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
163 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
164 tokenize_console(temp_s);
165 thiscnt = stof(argv(LADDER_CNT + 1));
167 if (thiscnt > top_scores[LADDER_SIZE - 1])
169 for (j = 0; j < LADDER_SIZE; ++j) // for each place in ladder
171 if (thiscnt > top_scores[j])
173 for (k = LADDER_SIZE - 1; k >= j; --k)
175 top_uids[k] = top_uids[k - 1];
176 top_scores[k] = top_scores[k - 1];
179 top_uids[j] = thisuid;
180 top_scores[j] = thiscnt;
187 s = "^3-----------------------\n\n";
189 s = strcat(s, "Pos ^3|");
190 s = strcat(s, " ^7Total ^3|");
192 for (i = 1; i <= LADDER_CNT; ++i)
193 s = strcat(s, " ^7", count_ordinal(i), " ^3|");
194 s = strcat(s, " ^7Speed awards ^3| ^7Name");
195 s = strcat(s, "\n^3----+--------");
197 for (i = 1; i <= min(9, LADDER_CNT); ++i)
198 s = strcat(s, "+-----");
200 for (i = 1; i <= LADDER_CNT - 9; ++i)
201 s = strcat(s, "+------");
204 s = strcat(s, "+--------------+--------------------\n");
206 for (i = 0; i < LADDER_SIZE; ++i)
208 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
209 tokenize_console(temp_s);
211 if (argv(LADDER_CNT + 1) == "") // total is 0, skip
214 s = strcat(s, strpad(4, count_ordinal(i + 1)), "^3| ^7"); // pos
215 s = strcat(s, strpad(7, argv(LADDER_CNT + 1)), "^3| ^7"); // total
217 for (j = 1; j <= min(9, LADDER_CNT); ++j)
218 s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt
221 for (j = 10; j <= LADDER_CNT; ++j)
222 s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt
225 s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt
226 s = strcat(s, uid2name(top_uids[i]), "\n"); // name
229 MapInfo_ClearTemps();
231 if (s == "") return "No ladder on this server!\n";
232 else return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
237 string maplist = "", col;
240 argc = tokenize_console(autocvar_g_maplist);
241 for (i = 0; i < argc; ++i)
243 if (MapInfo_CheckMap(argv(i)))
245 if (i % 2) col = "^2"; else col = "^3";
246 maplist = sprintf("%s%s%s ", maplist, col, argv(i));
250 MapInfo_ClearTemps();
251 return sprintf("^7Maps in list: %s\n", maplist);
254 const int LSMAPS_MAX = 250;
257 string lsmaps = "", col;
258 bool newmaps = false;
261 for (int i = 0; i < MapInfo_count; ++i)
263 if ((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags()))
267 if(added > LSMAPS_MAX)
268 continue; // we still get the added count, but skip the actual processing
270 // todo: Check by play count of maps for other game types?
271 if((g_race || g_cts) && !race_readTime(MapInfo_Map_bspname, 1))
274 if (i % 2) col = "^4*"; else col = "^5*";
278 if (i % 2) col = "^2"; else col = "^3";
281 lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname);
285 if(added > LSMAPS_MAX)
286 lsmaps = sprintf("%s^7(%d not listed)", lsmaps, added - LSMAPS_MAX);
288 MapInfo_ClearTemps();
289 return sprintf("^7Maps available (%d)%s: %s\n", added, (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps);
292 string getmonsterlist()
294 string monsterlist = "";
296 FOREACH(Monsters, it != MON_Null && !(it.spawnflags & MON_FLAG_HIDDEN),
298 string col = ((i % 2) ? "^2" : "^3");
299 monsterlist = sprintf("%s%s%s ", monsterlist, col, it.netname);
302 return sprintf("^7Monsters available: %s\n", monsterlist);
311 >0: receives a cvar from name=argv(f) value=argv(f+1)
313 void GetCvars_handleString(entity this, entity store, string thisname, float f, .string field, string name)
317 strfree(store.(field));
321 if (thisname == name)
323 strcpy(store.(field), argv(f + 1));
327 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
329 void GetCvars_handleString_Fixup(entity this, entity store, string thisname, float f, .string field, string name, string(entity, string) func)
331 GetCvars_handleString(this, store, thisname, f, field, name);
332 if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
333 if (thisname == name)
335 string s = func(this, strcat1(store.(field)));
336 if (s != store.(field))
338 strcpy(store.(field), s);
342 void GetCvars_handleFloat(entity this, entity store, string thisname, float f, .float field, string name)
349 if (thisname == name)
350 store.(field) = stof(argv(f + 1));
353 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
355 void GetCvars_handleFloatOnce(entity this, entity store, string thisname, float f, .float field, string name)
362 if (thisname == name)
366 store.(field) = stof(argv(f + 1));
375 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
378 string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo)
380 string o = W_FixWeaponOrder_ForceComplete(wo);
381 strcpy(CS(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o));
386 * @param f -1: cleanup, 0: request, 1: receive
388 void GetCvars(entity this, entity store, int f)
390 string s = string_null;
393 LOG_INFO("Warning: requesting cvar values is deprecated. Client should send them automatically using REPLICATE.\n");
396 s = strcat1(argv(f));
400 MUTATOR_CALLHOOK(GetCvars);
402 Notification_GetCvars(this);
404 ReplicateVars(this, store, s, f);
406 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
407 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
408 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
409 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
410 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
411 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
412 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
413 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
414 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
415 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
416 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
418 GetCvars_handleFloat(this, store, s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
420 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
423 if (s == "cl_weaponpriority")
425 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
427 .entity weaponentity = weaponentities[slot];
428 if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0))
429 this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity);
432 if (s == "cl_allow_uidtracking")
433 PlayerStats_GameReport_AddPlayer(this);
434 //if (s == "cl_gunalign")
435 //W_ResetGunAlign(this, store.cvar_cl_gunalign);