]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/getreplies.qc
GameCommand_moveplayer: fix wrong team name in a message
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / getreplies.qc
1 #include "getreplies.qh"
2
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/mapvoting.qh>
18 #include <server/mutators/_mod.qh>
19 #include <server/race.qh>
20 #include <server/weapons/selection.qh>
21 #include <server/world.qh>
22
23 // =========================================================
24 //  Reply messages for common commands, re-worked by Samual
25 //  Last updated: December 30th, 2011
26 // =========================================================
27
28 // These strings are set usually during init in world.qc,
29 // or also by some game modes or other functions manually,
30 // and their purpose is to output information to clients
31 // without using any extra processing time.
32
33 // See common.qc for their proper commands
34
35 string getrecords(int page)
36 {
37         string s = "";
38
39         MUTATOR_CALLHOOK(GetRecords, page, s);
40         s = M_ARGV(1, string);
41
42         MapInfo_ClearTemps();
43         return s;
44 }
45
46 string getrankings()
47 {
48         float t, i;
49         string n, s, p, map;
50
51         map = GetMapname();
52
53         s = "";
54         for (i = 1; i <= RANKINGS_CNT; ++i)
55         {
56                 t = race_readTime(map, i);
57
58                 if (t == 0) continue;
59
60                 n = race_readName(map, i);
61                 p = count_ordinal(i);
62                 s = strcat(s, strpad(8, p), " ", strpad(-8, TIME_ENCODED_TOSTRING(t)), " ", n, "\n");
63         }
64
65         MapInfo_ClearTemps();
66
67         if (s == "") return strcat("No records are available for the map: ", map, "\n");
68         else return strcat("Records for ", map, ":\n", s);
69 }
70
71 string getladder()
72 {
73         int i, j, k, uidcnt = 0, thiscnt;
74         string s, temp_s, rr, myuid, thisuid;
75
76         rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
77
78         for (k = 0; k < MapInfo_count; ++k)
79         {
80                 if (MapInfo_Get_ByID(k))
81                 {
82                         for (i = 0; i <= LADDER_CNT; ++i) // i = 0 because it is the speed award
83                         {
84                                 if (i == 0)                   // speed award
85                                 {
86                                         if (stof(db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/speed"))) == 0) continue;
87
88                                         myuid = db_get(ServerProgsDB, strcat(MapInfo_Map_bspname, rr, "speed/crypto_idfp"));
89                                 }
90                                 else  // normal record, if it exists (else break)
91                                 {
92                                         if (race_readTime(MapInfo_Map_bspname, i) == 0) continue;
93
94                                         myuid = race_readUID(MapInfo_Map_bspname, i);
95                                 }
96
97                                 // string s contains:
98                                 // arg 0 = # of speed recs
99                                 // arg 1 = # of 1st place recs
100                                 // arg 2 = # of 2nd place recs
101                                 // ... etc
102                                 // LADDER_CNT+1 = total points
103
104                                 temp_s = db_get(TemporaryDB, strcat("ladder", myuid));
105
106                                 if (temp_s == "")
107                                 {
108                                         db_put(TemporaryDB, strcat("uid", ftos(uidcnt)), myuid);
109                                         ++uidcnt;
110
111                                         for (j = 0; j <= LADDER_CNT + 1; ++j)
112                                         {
113                                                 if (j != LADDER_CNT + 1) temp_s = strcat(temp_s, "0 ");
114                                                 else temp_s = strcat(temp_s, "0");
115                                         }
116                                 }
117
118                                 tokenize_console(temp_s);
119                                 s = "";
120
121                                 if (i == 0)                                         // speed award
122                                 {
123                                         for (j = 0; j <= LADDER_CNT; ++j)               // loop over each arg in the string
124                                         {
125                                                 if (j == 0)                                 // speed award
126                                                         s = strcat(s, ftos(stof(argv(j)) + 1)); // add 1 to speed rec count and write
127                                                 else s = strcat(s, " ", argv(j));           // just copy over everything else
128                                         }
129                                 }
130                                 else  // record
131                                 {
132                                         for (j = 0; j <= LADDER_CNT; ++j)                    // loop over each arg in the string
133                                         {
134                                                 if (j == 0) s = strcat(s, argv(j));              // speed award, dont prefix with " "
135                                                 else if (j == i)                                 // wanted rec!
136                                                         s = strcat(s, " ", ftos(stof(argv(j)) + 1)); // update argv(j)
137                                                 else s = strcat(s, " ", argv(j));                // just copy over everything else
138                                         }
139                                 }
140
141                                 // total points are (by default) calculated like this:
142                                 // speedrec = floor(100 / 10) = 10 points
143                                 // 1st place = floor(100 / 1) = 100 points
144                                 // 2nd place = floor(100 / 2) = 50 points
145                                 // 3rd place = floor(100 / 3) = 33 points
146                                 // 4th place = floor(100 / 4) = 25 points
147                                 // 5th place = floor(100 / 5) = 20 points
148                                 // ... etc
149
150                                 if (i == 0) s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + LADDER_FIRSTPOINT / 10)); // speed award, add LADDER_FIRSTPOINT / 10 points
151                                 else s = strcat(s, " ", ftos(stof(argv(LADDER_CNT + 1)) + floor(LADDER_FIRSTPOINT / i)));  // record, add LADDER_FIRSTPOINT / i points
152
153                                 db_put(TemporaryDB, strcat("ladder", myuid), s);
154                         }
155                 }
156         }
157
158         for (i = 0; i <= uidcnt; ++i)  // for each known uid
159         {
160                 thisuid = db_get(TemporaryDB, strcat("uid", ftos(i)));
161                 temp_s = db_get(TemporaryDB, strcat("ladder", thisuid));
162                 tokenize_console(temp_s);
163                 thiscnt = stof(argv(LADDER_CNT + 1));
164
165                 if (thiscnt > top_scores[LADDER_SIZE - 1])
166                 {
167                         for (j = 0; j < LADDER_SIZE; ++j)  // for each place in ladder
168                         {
169                                 if (thiscnt > top_scores[j])
170                                 {
171                                         for (k = LADDER_SIZE - 1; k >= j; --k)
172                                         {
173                                                 top_uids[k] = top_uids[k - 1];
174                                                 top_scores[k] = top_scores[k - 1];
175                                         }
176
177                                         top_uids[j] = thisuid;
178                                         top_scores[j] = thiscnt;
179                                         break;
180                                 }
181                         }
182                 }
183         }
184
185         s = "^3-----------------------\n\n";
186
187         s = strcat(s, "Pos ^3|");
188         s = strcat(s, " ^7Total  ^3|");
189
190         for (i = 1; i <= LADDER_CNT; ++i)
191                 s = strcat(s, " ^7", count_ordinal(i), " ^3|");
192         s = strcat(s, " ^7Speed awards ^3| ^7Name");
193         s = strcat(s, "\n^3----+--------");
194
195         for (i = 1; i <= min(9, LADDER_CNT); ++i)
196                 s = strcat(s, "+-----");
197 #if LADDER_CNT > 9
198                 for (i = 1; i <= LADDER_CNT - 9; ++i)
199                         s = strcat(s, "+------");
200 #endif
201
202         s = strcat(s, "+--------------+--------------------\n");
203
204         for (i = 0; i < LADDER_SIZE; ++i)
205         {
206                 temp_s = db_get(TemporaryDB, strcat("ladder", top_uids[i]));
207                 tokenize_console(temp_s);
208
209                 if (argv(LADDER_CNT + 1) == "")                           // total is 0, skip
210                         continue;
211
212                 s = strcat(s, strpad(4, count_ordinal(i + 1)), "^3| ^7"); // pos
213                 s = strcat(s, strpad(7, argv(LADDER_CNT + 1)), "^3| ^7"); // total
214
215                 for (j = 1; j <= min(9, LADDER_CNT); ++j)
216                         s = strcat(s, strpad(4, argv(j)), "^3| ^7");          // 1st, 2nd, 3rd etc cnt
217
218 #if LADDER_CNT > 9
219                         for (j = 10; j <= LADDER_CNT; ++j)
220                                 s = strcat(s, strpad(4, argv(j)), " ^3| ^7"); // 1st, 2nd, 3rd etc cnt
221 #endif
222
223                 s = strcat(s, strpad(13, argv(0)), "^3| ^7");         // speed award cnt
224                 s = strcat(s, uid2name(top_uids[i]), "\n");           // name
225         }
226
227         MapInfo_ClearTemps();
228
229         if (s == "") return "No ladder on this server!\n";
230         else return strcat("Top ", ftos(LADDER_SIZE), " ladder rankings:\n", s);
231 }
232
233 string getmaplist()
234 {
235         string maplist = "", col;
236         int i, argc;
237
238         argc = tokenize_console(autocvar_g_maplist);
239         for (i = 0; i < argc; ++i)
240         {
241                 if (MapInfo_CheckMap(argv(i)))
242                 {
243                         if (i % 2) col = "^2"; else col = "^3";
244                         maplist = sprintf("%s%s%s ", maplist, col, argv(i));
245                 }
246         }
247
248         MapInfo_ClearTemps();
249         return sprintf("^7Maps in list: %s\n", maplist);
250 }
251
252 const int LSMAPS_MAX = 250;
253 string getlsmaps()
254 {
255         string lsmaps = "", col;
256         bool newmaps = false;
257         int added = 0;
258
259         for (int i = 0; i < MapInfo_count; ++i)
260         {
261                 if ((MapInfo_Get_ByID(i)) && !(MapInfo_Map_flags & MapInfo_ForbiddenFlags()))
262                 {
263                         ++added;
264
265                         if(added > LSMAPS_MAX)
266                                 continue; // we still get the added count, but skip the actual processing
267
268                         // todo: Check by play count of maps for other game types?
269                         if((g_race || g_cts) && !race_readTime(MapInfo_Map_bspname, 1))
270                         {
271                                 newmaps = true;
272                                 if (i % 2) col = "^4*"; else col = "^5*";
273                         }
274                         else
275                         {
276                                 if (i % 2) col = "^2"; else col = "^3";
277                         }
278
279                         lsmaps = sprintf("%s%s%s ", lsmaps, col, MapInfo_Map_bspname);
280                 }
281         }
282
283         if(added > LSMAPS_MAX)
284                 lsmaps = sprintf("%s^7(%d not listed)", lsmaps, added - LSMAPS_MAX);
285
286         MapInfo_ClearTemps();
287         return sprintf("^7Maps available (%d)%s: %s\n", added, (newmaps ? " (New maps have asterisks marked in blue)" : ""), lsmaps);
288 }
289
290 string getmonsterlist()
291 {
292         string monsterlist = "";
293
294         FOREACH(Monsters, it != MON_Null && !(it.spawnflags & MON_FLAG_HIDDEN),
295         {
296                 string col = ((i % 2) ? "^2" : "^3");
297                 monsterlist = sprintf("%s%s%s ", monsterlist, col, it.netname);
298         });
299
300         return sprintf("^7Monsters available: %s\n", monsterlist);
301 }
302
303 /*
304 =============
305 GetCvars
306 =============
307 Called with:
308   0:  sends the request
309   >0: receives a cvar from name=argv(f) value=argv(f+1)
310 */
311 void GetCvars_handleString(entity this, entity store, string thisname, float f, .string field, string name)
312 {
313         if (f < 0)
314         {
315                 strfree(store.(field));
316         }
317         else if (f > 0)
318         {
319                 if (thisname == name)
320                 {
321                         strcpy(store.(field), argv(f + 1));
322                 }
323         }
324         else
325                 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
326 }
327 void GetCvars_handleString_Fixup(entity this, entity store, string thisname, float f, .string field, string name, string(entity, string) func)
328 {
329         GetCvars_handleString(this, store, thisname, f, field, name);
330         if (f >= 0) // also initialize to the fitting value for "" when sending cvars out
331                 if (thisname == name)
332                 {
333                         string s = func(this, strcat1(store.(field)));
334                         if (s != store.(field))
335                         {
336                                 strcpy(store.(field), s);
337                         }
338                 }
339 }
340 void GetCvars_handleFloat(entity this, entity store, string thisname, float f, .float field, string name)
341 {
342         if (f < 0)
343         {
344         }
345         else if (f > 0)
346         {
347                 if (thisname == name)
348                         store.(field) = stof(argv(f + 1));
349         }
350         else
351                 stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
352 }
353 void GetCvars_handleFloatOnce(entity this, entity store, string thisname, float f, .float field, string name)
354 {
355         if (f < 0)
356         {
357         }
358         else if (f > 0)
359         {
360                 if (thisname == name)
361                 {
362                         if (!store.(field))
363                         {
364                                 store.(field) = stof(argv(f + 1));
365                                 if (!store.(field))
366                                         store.(field) = -1;
367                         }
368                 }
369         }
370         else
371         {
372                 if (!store.(field))
373                         stuffcmd(this, strcat("cl_cmd sendcvar ", name, "\n"));
374         }
375 }
376 string W_FixWeaponOrder_ForceComplete_AndBuildImpulseList(entity this, string wo)
377 {
378         string o = W_FixWeaponOrder_ForceComplete(wo);
379         strcpy(CS_CVAR(this).weaponorder_byimpulse, W_FixWeaponOrder_BuildImpulseList(o));
380         return o;
381 }
382
383 /**
384  * @param f -1: cleanup, 0: request, 1: receive
385  */
386 void GetCvars(entity this, entity store, int f)
387 {
388         string s = string_null;
389
390         if (f == 0)
391                 LOG_INFO("Warning: requesting cvar values is deprecated. Client should send them automatically using REPLICATE.\n");
392
393         if (f > 0)
394                 s = strcat1(argv(f));
395
396         get_cvars_f = f;
397         get_cvars_s = s;
398         MUTATOR_CALLHOOK(GetCvars);
399
400         Notification_GetCvars(this, store);
401
402         ReplicateVars(this, store, s, f);
403
404         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriority, "cl_weaponpriority", W_FixWeaponOrder_ForceComplete_AndBuildImpulseList);
405         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[0], "cl_weaponpriority0", W_FixWeaponOrder_AllowIncomplete);
406         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[1], "cl_weaponpriority1", W_FixWeaponOrder_AllowIncomplete);
407         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[2], "cl_weaponpriority2", W_FixWeaponOrder_AllowIncomplete);
408         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[3], "cl_weaponpriority3", W_FixWeaponOrder_AllowIncomplete);
409         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[4], "cl_weaponpriority4", W_FixWeaponOrder_AllowIncomplete);
410         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[5], "cl_weaponpriority5", W_FixWeaponOrder_AllowIncomplete);
411         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[6], "cl_weaponpriority6", W_FixWeaponOrder_AllowIncomplete);
412         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[7], "cl_weaponpriority7", W_FixWeaponOrder_AllowIncomplete);
413         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[8], "cl_weaponpriority8", W_FixWeaponOrder_AllowIncomplete);
414         GetCvars_handleString_Fixup(this, store, s, f, cvar_cl_weaponpriorities[9], "cl_weaponpriority9", W_FixWeaponOrder_AllowIncomplete);
415
416         GetCvars_handleFloat(this, store, s, f, cvar_cl_allow_uidtracking, "cl_allow_uidtracking");
417
418         // fixup of switchweapon (needed for LMS or when spectating is disabled, as PutClientInServer comes too early)
419         if (f > 0)
420         {
421                 if (s == "cl_weaponpriority")
422                 {
423                         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
424                         {
425                                 .entity weaponentity = weaponentities[slot];
426                                 if (this.(weaponentity) && (this.(weaponentity).m_weapon != WEP_Null || slot == 0))
427                                         this.(weaponentity).m_switchweapon = w_getbestweapon(this, weaponentity);
428                         }
429                 }
430                 if (s == "cl_allow_uidtracking")
431                         PlayerStats_GameReport_AddPlayer(this);
432                 //if (s == "cl_gunalign")
433                         //W_ResetGunAlign(this, store.cvar_cl_gunalign);
434         }
435 }