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/stats.qh>
9 #include <common/util.qh>
10 #include <common/weapons/_all.qh>
11 #include <common/wepent.qh>
12 #include <server/command/getreplies.qh>
13 #include <server/intermission.qh>
14 #include <server/main.qh>
15 #include <server/mutators/_mod.qh>
16 #include <server/race.qh>
17 #include <server/world.qh>
19 // =========================================================
20 // Reply messages for common commands, re-worked by Samual
21 // Last updated: December 30th, 2011
22 // =========================================================
24 // These strings are set usually during init in world.qc,
25 // or also by some game modes or other functions manually,
26 // and their purpose is to output information to clients
27 // without using any extra processing time.
29 // See common.qc for their proper commands
31 string getrecords(int page) // 50 records per page
35 MUTATOR_CALLHOOK(GetRecords, page, s);
36 s = M_ARGV(1, string);
40 if (s == "" && page == 0)
41 return "No records are available on this server for the current game mode.\n";
53 for (i = 1; i <= RANKINGS_CNT; ++i)
55 t = race_readTime(map, i);
59 n = race_readName(map, i);
61 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
66 if (s == "") return strcat("No records are available for the map: ", map, "\n");
67 else return strcat("Records for ", map, ":\n", s);
72 int i, j, k, uidcnt = 0, thiscnt;
73 string s, temp_s, rr, myuid, thisuid;
75 rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
77 for (k = 0; k < MapInfo_count; ++k)
79 if (MapInfo_Get_ByID(k))
81 for (i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award
83 if (i == 0) // speed award
85 if (stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) continue;
87 myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp"));
89 else // normal record, if it exists (else break)
91 if (race_readTime(MapInfo_Map_bspname, i) == 0) continue;
93 myuid = race_readUID(MapInfo_Map_bspname, i);
97 // arg 0 = # of speed recs
98 // arg 1 = # of 1st place recs
99 // arg 2 = # of 2nd place recs
101 // LADDER_CNT+1 = total points
103 temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
107 db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
110 for (j = 0; j <= LADDER_CNT + 1; ++j)
112 if (j != LADDER_CNT + 1) temp_s = strcat(temp_s, "0 ");
113 else temp_s = strcat(temp_s, "0");
117 tokenize_console(temp_s);
120 if (i == 0) // speed award
122 for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
124 if (j == 0) // speed award
125 s = strcat(s, ftos(stof(argv(j)) + 1)); // add 1 to speed rec count and write
126 else s = strcat(s, " ", argv(j)); // just copy over everything else
131 for (j = 0; j <= LADDER_CNT; ++j) // loop over each arg in the string
133 if (j == 0) s = strcat(s, argv(j)); // speed award, dont prefix with " "
134 else if (j == i) // wanted rec!
135 s = strcat(s, " ", ftos(stof(argv(j)) + 1)); // update argv(j)
136 else s = strcat(s, " ", argv(j)); // just copy over everything else
140 // total points are (by default) calculated like this:
141 // speedrec = floor(100 / 10) = 10 points
142 // 1st place = floor(100 / 1) = 100 points
143 // 2nd place = floor(100 / 2) = 50 points
144 // 3rd place = floor(100 / 3) = 33 points
145 // 4th place = floor(100 / 4) = 25 points
146 // 5th place = floor(100 / 5) = 20 points
149 if (i == 0) s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
150 else s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + floor(LADDER_FIRSTPOINT / i))); // record, add LADDER_FIRSTPOINT / i points
152 db_put(TemporaryDB, strcat("ladder", myuid), s);
157 for (i = 0; i <= uidcnt; ++i) // for each known uid
159 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
160 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
161 tokenize_console(temp_s);
162 thiscnt = stof(argv(LADDER_CNT + 1));
164 if (thiscnt > top_scores[LADDER_SIZE - 1])
166 for (j = 0; j < LADDER_SIZE; ++j) // for each place in ladder
168 if (thiscnt > top_scores[j])
170 for (k = LADDER_SIZE - 1; k >= j; --k)
172 top_uids[k] = top_uids[k - 1];
173 top_scores[k] = top_scores[k - 1];
176 top_uids[j] = thisuid;
177 top_scores[j] = thiscnt;
184 s = "^3-----------------------\n\n";
186 s = strcat(s, "Pos ^3|");
187 s = strcat(s, " ^7Total ^3|");
189 for (i = 1; i <= LADDER_CNT; ++i)
190 s = strcat(s, " ^7", count_ordinal(i), " ^3|");
191 s = strcat(s, " ^7Speed awards ^3| ^7Name");
192 s = strcat(s, "\n^3----+--------");
194 for (i = 1; i <= min(9, LADDER_CNT); ++i)
195 s = strcat(s, "+-----");
197 for (i = 1; i <= LADDER_CNT - 9; ++i)
198 s = strcat(s, "+------");
201 s = strcat(s, "+--------------+--------------------\n");
203 for (i = 0; i < LADDER_SIZE; ++i)
205 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
206 tokenize_console(temp_s);
208 if (argv(LADDER_CNT + 1) == "") // total is 0, skip
211 s = strcat(s, strpad(4, count_ordinal(i + 1)), "^3| ^7"); // pos
212 s = strcat(s, strpad(7, argv(LADDER_CNT + 1)), "^3| ^7"); // total
214 for (j = 1; j <= min(9, LADDER_CNT); ++j)
215 s = strcat(s, strpad(4, argv(j)), "^3| ^7"); // 1st, 2nd, 3rd etc cnt
218 for (j = 10; j <= LADDER_CNT; ++j)
219 s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt
222 s = strcat(s, strpad(13, argv(0)), "^3| ^7"); // speed award cnt
223 s = strcat(s, uid2name(top_uids[i]), "\n"); // name
226 MapInfo_ClearTemps();
228 if (s == "") return "No ladder on this server!\n";
229 else return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
234 string maplist = "", col;
237 argc = tokenize_console(autocvar_g_maplist);
238 for (i = 0; i < argc; ++i)
240 if (MapInfo_CheckMap(argv(i)))
242 if (i % 2) col = "^2"; else col = "^3";
243 maplist = sprintf("%s%s%s ", maplist, col, argv(i));
247 MapInfo_ClearTemps();
248 return sprintf("^7Maps in list: %s\n", maplist);
251 const int LSMAPS_MAX = 250;
254 string lsmaps = "", col;
255 bool newmaps = false;
258 for (int i = 0; i < MapInfo_count; ++i)
260 if ((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags()))
264 if(added > LSMAPS_MAX)
265 continue; // we still get the added count, but skip the actual processing
267 // todo: Check by play count of maps for other game types?
268 if((g_race || g_cts) && !race_readTime(MapInfo_Map_bspname, 1))
271 if (i % 2) col = "^4*"; else col = "^5*";
275 if (i % 2) col = "^2"; else col = "^3";
278 lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname);
282 if(added > LSMAPS_MAX)
283 lsmaps = sprintf("%s^7(%d not listed)", lsmaps, added - LSMAPS_MAX);
285 MapInfo_ClearTemps();
286 return sprintf("^7Maps available (%d)%s: %s\n", added, (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps);
289 string getmonsterlist()
291 string monsterlist = "";
293 FOREACH(Monsters, it != MON_Null && !(it.spawnflags & MON_FLAG_HIDDEN),
295 string col = ((i % 2) ? "^2" : "^3");
296 monsterlist = sprintf("%s%s%s ", monsterlist, col, it.netname);
299 return sprintf("^7Monsters available: %s\n", monsterlist);
308 >0: receives a cvar from name=argv(f) value=argv(f+1)
310 void GetCvars_handleString(entity this, entity store, string thisname, float f, .string field, string name)
314 strfree(store.(field));
318 if (thisname == name)
320 strcpy(store.(field), argv(f + 1));
324 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
326 void GetCvars_handleString_Fixup(entity this, entity store, string thisname, float f, .string field, string name, string(entity, string) func)
328 GetCvars_handleString(this, store, thisname, f, field, name);
329 if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
330 if (thisname == name)
332 string s = func(this, strcat1(store.(field)));
333 if (s != store.(field))
335 strcpy(store.(field), s);
339 void GetCvars_handleFloat(entity this, entity store, string thisname, float f, .float field, string name)
346 if (thisname == name)
347 store.(field) = stof(argv(f + 1));
350 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
352 void GetCvars_handleFloatOnce(entity this, entity store, string thisname, float f, .float field, string name)
359 if (thisname == name)
363 store.(field) = stof(argv(f + 1));
372 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
375 string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo)
377 string o = W_FixWeaponOrder_ForceComplete(wo);
378 strcpy(CS(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o));
383 * @param f -1: cleanup, 0: request, 1: receive
385 void GetCvars(entity this, entity store, int f)
387 string s = string_null;
390 LOG_INFO("Warning: requesting cvar values is deprecated. Client should send them automatically using REPLICATE.\n");
393 s = strcat1(argv(f));
397 MUTATOR_CALLHOOK(GetCvars);
399 Notification_GetCvars(this);
401 ReplicateVars(this, store, s, f);
403 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
404 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
405 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
406 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
407 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
408 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
409 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
410 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
411 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
412 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
413 GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
415 GetCvars_handleFloat(this, store, s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
417 // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
420 if (s == "cl_weaponpriority")
422 for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
424 .entity weaponentity = weaponentities[slot];
425 if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0))
426 this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity);
429 if (s == "cl_allow_uidtracking")
430 PlayerStats_GameReport_AddPlayer(this);
431 //if (s == "cl_gunalign")
432 //W_ResetGunAlign(this, store.cvar_cl_gunalign);