]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/command/sv_cmd.qc
Add printplayer and ircmsg commands
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / command / sv_cmd.qc
1 #include "sv_cmd.qh"
2
3 #include <common/constants.qh>
4 #include <common/effects/all.qh>
5 #include <common/gamemodes/_mod.qh>
6 #include <common/mapinfo.qh>
7 #include <common/monsters/sv_monsters.qh>
8 #include <common/net_linked.qh>
9 #include <common/notifications/all.qh>
10 #include <common/teams.qh>
11 #include <common/util.qh>
12 #include <server/anticheat.qh>
13 #include <server/bot/api.qh>
14 #include <server/campaign.qh>
15 #include <server/client.qh>
16 #include <server/command/_mod.qh>
17 #include <server/command/banning.qh>
18 #include <server/command/cmd.qh>
19 #include <server/command/common.qh>
20 #include <server/command/getreplies.qh>
21 #include <server/command/radarmap.qh>
22 #include <server/intermission.qh>
23 #include <server/ipban.qh>
24 #include <server/mutators/_mod.qh>
25 #include <server/player.qh>
26 #include <server/scores_rules.qh>
27 #include <server/teamplay.qh>
28 #include <server/world.qh>
29 #include <lib/misc.qh>
30
31 //  used by GameCommand_make_mapinfo()
32 void make_mapinfo_Think(entity this)
33 {
34         if (_MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
35         {
36                 LOG_INFO("Done rebuiling mapinfos.");
37                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
38                 delete(this);
39         }
40         else
41         {
42                 setthink(this, make_mapinfo_Think);
43                 this.nextthink = time;
44         }
45 }
46
47 //  used by GameCommand_extendmatchtime() and GameCommand_reducematchtime()
48 void changematchtime(float delta, float mi, float ma)
49 {
50         float cur;
51         float update;
52         float lim;
53
54         if (delta == 0) return;
55         if (autocvar_timelimit < 0) return;
56
57         if (mi <= 10) mi = 10;  // at least ten sec in the future
58         cur = time - game_starttime;
59         if (cur > 0) mi += cur; // from current time!
60
61         lim = autocvar_timelimit * 60;
62
63         if (delta > 0)
64         {
65                 if (lim == 0) return; // cannot increase any further
66                 else if (lim < ma) update = min(ma, lim + delta);
67                 else                  // already above maximum: FAIL
68                         return;
69         }
70         else
71         {
72                 if (lim == 0)      // infinite: try reducing to max, if we are allowed to
73                         update = max(mi, ma);
74                 else if (lim > mi) // above minimum: decrease
75                         update = max(mi, lim + delta);
76                 else               // already below minimum: FAIL
77                         return;
78         }
79
80         cvar_set("timelimit", ftos(update / 60));
81 }
82
83
84 // =======================
85 //  Command Sub-Functions
86 // =======================
87
88 void GameCommand_adminmsg(int request, int argc)
89 {
90         switch (request)
91         {
92                 case CMD_REQUEST_COMMAND:
93                 {
94                         entity client;
95                         float accepted;
96
97                         string targets = strreplace(",", " ", argv(1));
98                         string original_targets = strreplace(" ", ", ", targets);
99                         string admin_message = argv(2);
100                         float infobartime = stof(argv(3));
101
102                         string successful, t;
103                         successful = string_null;
104
105                         if ((targets) && (admin_message))
106                         {
107                                 for ( ; targets; )
108                                 {
109                                         t = car(targets);
110                                         targets = cdr(targets);
111
112                                         // Check to see if the player is a valid target
113                                         client = GetFilteredEntity(t);
114                                         accepted = VerifyClientEntity(client, true, false);
115
116                                         if (accepted <= 0)
117                                         {
118                                                 LOG_INFO("adminmsg: ", GetClientErrorString(accepted, t), (targets ? ", skipping to next player.\n" : "."));
119                                                 continue;
120                                         }
121
122                                         // send the centerprint/console print or infomessage
123                                         if (infobartime)
124                                         {
125                                                 stuffcmd(client, sprintf("\ninfobar %f \"%s\"\n", infobartime, MakeConsoleSafe(admin_message)));
126                                         }
127                                         else
128                                         {
129                                                 centerprint(client, strcat("^3", GetCallerName(NULL), ":\n^7", admin_message));
130                                                 sprint(client, strcat("\{1}\{13}^3", GetCallerName(NULL), "^7: ", admin_message, "\n"));
131                                         }
132
133                                         successful = strcat(successful, (successful ? ", " : ""), playername(client.netname, client.team, false));
134                                         LOG_TRACE("Message sent to ", playername(client.netname, client.team, false));
135                                         continue;
136                                 }
137
138                                 if (successful) bprint("Successfully sent message '", admin_message, "' to ", successful, ".\n");
139                                 else LOG_INFO("No players given (", original_targets, ") could receive the message.");
140
141                                 return;
142                         }
143                 }
144
145                 default:
146                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
147                 case CMD_REQUEST_USAGE:
148                 {
149                         LOG_HELP("Usage:^3 sv_cmd adminmsg <clients> \"<message>\" [<infobartime>]");
150                         LOG_HELP("  <clients> is a list (separated by commas) of player entity ID's or nicknames");
151                         LOG_HELP("  If <infobartime> is provided, the message will be sent to infobar.");
152                         LOG_HELP("  Otherwise, it will just be sent as a centerprint message.");
153                         LOG_HELP("Examples: adminmsg 2,4 \"this infomessage will last for ten seconds\" 10");
154                         LOG_HELP("          adminmsg 2,5 \"this message will be a centerprint\"");
155                         return;
156                 }
157         }
158 }
159
160 void GameCommand_allready(int request)
161 {
162         switch (request)
163         {
164                 case CMD_REQUEST_COMMAND:
165                 {
166                         if(warmup_stage)
167                         {
168                                 ReadyRestart(true);
169                         }
170                         else
171                                 LOG_INFO("Not in warmup.");
172
173                         return;
174                 }
175
176                 default:
177                 case CMD_REQUEST_USAGE:
178                 {
179                         LOG_HELP("Usage:^3 sv_cmd allready");
180                         LOG_HELP("  No arguments required.");
181                         return;
182                 }
183         }
184 }
185
186 void GameCommand_allspec(int request, int argc)
187 {
188         switch (request)
189         {
190                 case CMD_REQUEST_COMMAND:
191                 {
192                         string reason = argv(1);
193                         int n = 0;
194                         FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
195                                 PutObserverInServer(it, true, true);
196                                 ++n;
197                         });
198                         if (n)   bprint(strcat("Successfully forced all (", ftos(n), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n"));
199                         else   LOG_INFO("No players found to spectate.");
200                         return;
201                 }
202
203                 default:
204                 case CMD_REQUEST_USAGE:
205                 {
206                         LOG_HELP("Usage:^3 sv_cmd allspec [<reason>]");
207                         LOG_HELP("  Where <reason> is an optional argument for explanation of allspec command.");
208                         LOG_HELP("See also: ^2moveplayer, shuffleteams^7");
209                         return;
210                 }
211         }
212 }
213
214 void GameCommand_anticheat(int request, int argc)
215 {
216         switch (request)
217         {
218                 case CMD_REQUEST_COMMAND:
219                 {
220                         entity client = GetIndexedEntity(argc, 1);
221                         float accepted = VerifyClientEntity(client, false, false);
222
223                         if (accepted > 0)
224                         {
225                                 anticheat_report_to_eventlog(client);
226                                 return;
227                         }
228                         else
229                         {
230                                 LOG_INFO("anticheat: ", GetClientErrorString(accepted, argv(1)), ".");
231                         }
232                 }
233
234                 default:
235                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
236                 case CMD_REQUEST_USAGE:
237                 {
238                         LOG_HELP("Usage:^3 sv_cmd anticheat <client>");
239                         LOG_HELP("  <client> is the entity number or name of the player.");
240                         return;
241                 }
242         }
243 }
244
245 void GameCommand_bbox(int request)
246 {
247         switch (request)
248         {
249                 case CMD_REQUEST_COMMAND:
250                 {
251                         vector size_min = '0 0 0';
252                         vector size_max = '0 0 0';
253                         tracebox('1 0 0' * world.absmin.x,
254                                 '0 1 0' * world.absmin.y + '0 0 1' * world.absmin.z,
255                                 '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z,
256                                 '1 0 0' * world.absmax.x,
257                                 MOVE_WORLDONLY,
258                                 NULL);
259                         size_min.x = (trace_startsolid) ? world.absmin.x : trace_endpos.x;
260
261                         tracebox('0 1 0' * world.absmin.y,
262                                 '1 0 0' * world.absmin.x + '0 0 1' * world.absmin.z,
263                                 '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z,
264                                 '0 1 0' * world.absmax.y,
265                                 MOVE_WORLDONLY,
266                                 NULL);
267                         size_min.y = (trace_startsolid) ? world.absmin.y : trace_endpos.y;
268
269                         tracebox('0 0 1' * world.absmin.z,
270                                 '1 0 0' * world.absmin.x + '0 1 0' * world.absmin.y,
271                                 '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y,
272                                 '0 0 1' * world.absmax.z,
273                                 MOVE_WORLDONLY,
274                                 NULL);
275                         size_min.z = (trace_startsolid) ? world.absmin.z : trace_endpos.z;
276
277                         tracebox('1 0 0' * world.absmax.x,
278                                 '0 1 0' * world.absmin.y + '0 0 1' * world.absmin.z,
279                                 '0 1 0' * world.absmax.y + '0 0 1' * world.absmax.z,
280                                 '1 0 0' * world.absmin.x,
281                                 MOVE_WORLDONLY,
282                                 NULL);
283                         size_max.x = (trace_startsolid) ? world.absmax.x : trace_endpos.x;
284
285                         tracebox('0 1 0' * world.absmax.y,
286                                 '1 0 0' * world.absmin.x + '0 0 1' * world.absmin.z,
287                                 '1 0 0' * world.absmax.x + '0 0 1' * world.absmax.z,
288                                 '0 1 0' * world.absmin.y,
289                                 MOVE_WORLDONLY,
290                                 NULL);
291                         size_max.y = (trace_startsolid) ? world.absmax.y : trace_endpos.y;
292
293                         tracebox('0 0 1' * world.absmax.z,
294                                 '1 0 0' * world.absmin.x + '0 1 0' * world.absmin.y,
295                                 '1 0 0' * world.absmax.x + '0 1 0' * world.absmax.y,
296                                 '0 0 1' * world.absmin.z,
297                                 MOVE_WORLDONLY,
298                                 NULL);
299                         size_max.z = (trace_startsolid) ? world.absmax.z : trace_endpos.z;
300
301                         LOG_INFOF("Original size: %v %v", world.absmin, world.absmax);
302                         LOG_INFOF("Currently set size: %v %v", world.mins, world.maxs);
303                         LOG_INFOF("Solid bounding box size: %v %v", size_min, size_max);
304                         return;
305                 }
306
307                 default:
308                 case CMD_REQUEST_USAGE:
309                 {
310                         LOG_HELP("Usage:^3 sv_cmd bbox");
311                         LOG_HELP("  No arguments required.");
312                         LOG_HELP("See also: ^2gettaginfo, trace^7");
313                         return;
314                 }
315         }
316 }
317
318 void GameCommand_bot_cmd(int request, int argc, string command)
319 {
320         switch (request)
321         {
322                 case CMD_REQUEST_COMMAND:
323                 {
324                         entity bot;
325
326                         if (argv(1) == "reset")
327                         {
328                                 bot_resetqueues();
329                                 return;
330                         }
331                         else if (argv(1) == "setbots")
332                         {
333                                 cvar_settemp("bot_vs_human", "0");
334                                 cvar_settemp("minplayers", "0");
335                                 cvar_settemp("minplayers_per_team", "0");
336                                 cvar_settemp("bot_number", "0");
337                                 bot_fixcount(false);  // Kill all bots.
338                                 cvar_settemp("bot_number", argv(2));
339                                 if (!bot_fixcount(true)) LOG_INFO("Sorry, could not set requested bot count");
340                                 return;
341                         }
342                         else if (argv(1) == "load" && argc == 3)
343                         {
344                                 float fh, i;
345                                 string s;
346                                 fh = fopen(argv(2), FILE_READ);
347                                 if (fh < 0)
348                                 {
349                                         LOG_INFO("cannot open the file");
350                                         return;
351                                 }
352
353                                 i = 0;
354                                 while ((s = fgets(fh)))
355                                 {
356                                         argc = tokenize_console(s);
357
358                                         if (argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
359                                         {
360                                                 if (argv(2) == "reset")
361                                                 {
362                                                         bot_resetqueues();
363                                                 }
364                                                 else if (argv(2) == "setbots")
365                                                 {
366                                                         cvar_settemp("bot_vs_human", "0");
367                                                         cvar_settemp("minplayers", "0");
368                                                         cvar_settemp("minplayers_per_team", "0");
369                                                         cvar_settemp("bot_number", "0");
370                                                         bot_fixcount(false);  // Kill all bots.
371                                                         cvar_settemp("bot_number", argv(3));
372                                                         if (!bot_fixcount(true)) LOG_INFO("Sorry, could not set requested bot count");
373                                                 }
374                                                 else
375                                                 {
376                                                         if(argv(2) == "*" || argv(2) == "all")
377                                                                 FOREACH_CLIENT(IS_BOT_CLIENT(it), {
378                                                                         bot_queuecommand(it, substring(s, argv_start_index(3), -1));
379                                                                 });
380                                                         else
381                                                         {
382                                                                 bot = find_bot_by_number(stof(argv(2)));
383                                                                 if (bot == NULL) bot = find_bot_by_name(argv(2));
384                                                                 if (bot) bot_queuecommand(bot, substring(s, argv_start_index(3), -1));
385                                                         }
386                                                 }
387                                         }
388                                         else
389                                         {
390                                                 localcmd(strcat(s, "\n"));
391                                         }
392
393                                         ++i;
394                                 }
395                                 LOG_INFO(ftos(i), " commands read");
396                                 fclose(fh);
397                                 return;
398                         }
399                         else if (argv(1) == "help")
400                         {
401                                 if (argv(2)) bot_cmdhelp(argv(2));
402                                 else bot_list_commands();
403                                 return;
404                         }
405                         else if (argc >= 3)  // this comes last
406                         {
407                                 if(argv(1) == "*" || argv(1) == "all")
408                                 {
409                                         int bot_num = 0;
410                                         FOREACH_CLIENT(IS_BOT_CLIENT(it), {
411                                                 bot_queuecommand(it, substring(command, argv_start_index(2), -1));
412                                                 bot_num++;
413                                         });
414                                         if(bot_num)
415                                                 LOG_INFO("Command '", substring(command, argv_start_index(2), -1), "' sent to all bots (", ftos(bot_num), ")");
416                                         return;
417                                 }
418                                 else
419                                 {
420                                         bot = find_bot_by_number(stof(argv(1)));
421                                         if (bot == NULL) bot = find_bot_by_name(argv(1));
422                                         if (bot)
423                                         {
424                                                 LOG_INFO("Command '", substring(command, argv_start_index(2), -1), "' sent to bot ", bot.netname);
425                                                 bot_queuecommand(bot, substring(command, argv_start_index(2), -1));
426                                                 return;
427                                         }
428                                         else
429                                         {
430                                                 LOG_INFO("Error: Can't find bot with the name or id '", argv(1), "' - Did you mistype the command?");  // don't return so that usage is shown
431                                         }
432                                 }
433                         }
434                 }
435
436                 default:
437                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
438                 case CMD_REQUEST_USAGE:
439                 {
440                         LOG_HELP("Usage:^3 sv_cmd bot_cmd <client> <command> [<arguments>]");
441                         LOG_HELP("  <client> can be either the name of the bot or a progressive number (not the entity number!)");
442                         LOG_HELP("           can also be '*' or 'all' to allow sending the command to all the bots");
443                         LOG_HELP("  For full list of commands, see bot_cmd help [<command>].");
444                         LOG_HELP("Examples: sv_cmd bot_cmd 1 cc \"say something\"");
445                         LOG_HELP("          sv_cmd bot_cmd 1 presskey jump");
446                         LOG_HELP("          sv_cmd bot_cmd * pause");
447                         return;
448                 }
449         }
450 }
451
452 void GameCommand_cointoss(int request, int argc)
453 {
454         switch (request)
455         {
456                 case CMD_REQUEST_COMMAND:
457                 {
458                         string result1 = (argv(2) ? strcat("^7", argv(1)) : "^1HEADS");
459                         string result2 = (argv(2) ? strcat("^7", argv(2)) : "^4TAILS");
460                         string choice = ((random() > 0.5) ? result1 : result2);
461
462                         Send_Notification(NOTIF_ALL, NULL, MSG_MULTI, MULTI_COINTOSS, choice);
463                         return;
464                 }
465
466                 default:
467                 case CMD_REQUEST_USAGE:
468                 {
469                         LOG_HELP("Usage:^3 sv_cmd cointoss [<result1> <result2>]");
470                         LOG_HELP("  Where <result1> and <result2> are user created options.");
471                         return;
472                 }
473         }
474 }
475
476 void GameCommand_database(int request, int argc)
477 {
478         switch (request)
479         {
480                 case CMD_REQUEST_COMMAND:
481                 {
482                         if (argc == 3)
483                         {
484                                 if (argv(1) == "save")
485                                 {
486                                         db_save(ServerProgsDB, argv(2));
487                                         LOG_INFO("Copied serverprogs database to '", argv(2), "' in the data directory.");
488                                         return;
489                                 }
490                                 else if (argv(1) == "dump")
491                                 {
492                                         db_dump(ServerProgsDB, argv(2));
493                                         LOG_INFO("DB dumped.");  // wtf does this do?
494                                         return;
495                                 }
496                                 else if (argv(1) == "load")
497                                 {
498                                         db_close(ServerProgsDB);
499                                         ServerProgsDB = db_load(argv(2));
500                                         LOG_INFO("Loaded '", argv(2), "' as new serverprogs database.");
501                                         return;
502                                 }
503                         }
504                 }
505
506                 default:
507                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
508                 case CMD_REQUEST_USAGE:
509                 {
510                         LOG_HELP("Usage:^3 sv_cmd database <action> <filename>");
511                         LOG_HELP("  Where <action> is the command to complete,");
512                         LOG_HELP("  and <filename> is what it acts upon.");
513                         LOG_HELP("  Full list of commands here: save, dump, load.");
514                         return;
515                 }
516         }
517 }
518
519 void GameCommand_defer_clear(int request, int argc)
520 {
521         switch (request)
522         {
523                 case CMD_REQUEST_COMMAND:
524                 {
525                         entity client;
526                         float accepted;
527
528                         if (argc >= 2)
529                         {
530                                 client = GetIndexedEntity(argc, 1);
531                                 accepted = VerifyClientEntity(client, true, false);
532
533                                 if (accepted > 0)
534                                 {
535                                         stuffcmd(client, "defer clear\n");
536                                         LOG_INFO("defer clear stuffed to ", playername(client.netname, client.team, false));
537                                 }
538                                 else { LOG_INFO("defer_clear: ", GetClientErrorString(accepted, argv(1)), "."); }
539
540                                 return;
541                         }
542                 }
543
544                 default:
545                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
546                 case CMD_REQUEST_USAGE:
547                 {
548                         LOG_HELP("Usage:^3 sv_cmd defer_clear <client>");
549                         LOG_HELP("  <client> is the entity number or name of the player.");
550                         LOG_HELP("See also: ^2defer_clear_all^7");
551                         return;
552                 }
553         }
554 }
555
556 void GameCommand_defer_clear_all(int request)
557 {
558         switch (request)
559         {
560                 case CMD_REQUEST_COMMAND:
561                 {
562                         int n = 0;
563                         int argc;
564
565                         FOREACH_CLIENT(true, {
566                                 argc = tokenize_console(strcat("defer_clear ", ftos(etof(it))));
567                                 GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc);
568                                 ++n;
569                         });
570                         if (n)   LOG_INFO("Successfully stuffed defer clear to all clients (", ftos(n), ")");  // should a message be added if no players were found?
571                         return;
572                 }
573
574                 default:
575                 case CMD_REQUEST_USAGE:
576                 {
577                         LOG_HELP("Usage:^3 sv_cmd defer_clear_all");
578                         LOG_HELP("  No arguments required.");
579                         LOG_HELP("See also: ^2defer_clear^7");
580                         return;
581                 }
582         }
583 }
584
585 void GameCommand_delrec(int request, int argc)  // perhaps merge later with records and printstats and such?
586 {
587         switch (request)
588         {
589                 case CMD_REQUEST_COMMAND:
590                 {
591                         if (argv(1))
592                         {
593                                 if (argv(2)) race_deleteTime(argv(2), stof(argv(1)));
594                                 else race_deleteTime(GetMapname(), stof(argv(1)));
595                                 return;
596                         }
597                 }
598
599                 default:
600                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
601                 case CMD_REQUEST_USAGE:
602                 {
603                         LOG_HELP("Usage:^3 sv_cmd delrec <ranking> [<map>]");
604                         LOG_HELP("  <ranking> is which ranking level to clear up to, ");
605                         LOG_HELP("  it will clear all records up to nth place.");
606                         LOG_HELP("  if <map> is not provided it will use current map.");
607                         return;
608                 }
609         }
610 }
611
612 void print_Effect_Index(int d, string effect_name)
613
614         // this is inside a function to avoid expanding it on compilation everytime
615         LOG_INFO("effect ", effect_name, " is ", ftos(_particleeffectnum(effect_name)), "\n");
616         db_put(d, effect_name, "1");
617 }
618
619 void GameCommand_effectindexdump(int request)
620 {
621         switch (request)
622         {
623                 case CMD_REQUEST_COMMAND:
624                 {
625                         float fh, d;
626                         string s;
627
628                         d = db_create();
629                         LOG_INFO("begin of effects list");
630
631                         print_Effect_Index(d, "TE_GUNSHOT");
632                         print_Effect_Index(d, "TE_GUNSHOTQUAD");
633                         print_Effect_Index(d, "TE_SPIKE");
634                         print_Effect_Index(d, "TE_SPIKEQUAD");
635                         print_Effect_Index(d, "TE_SUPERSPIKE");
636                         print_Effect_Index(d, "TE_SUPERSPIKEQUAD");
637                         print_Effect_Index(d, "TE_WIZSPIKE");
638                         print_Effect_Index(d, "TE_KNIGHTSPIKE");
639                         print_Effect_Index(d, "TE_EXPLOSION");
640                         print_Effect_Index(d, "TE_EXPLOSIONQUAD");
641                         print_Effect_Index(d, "TE_TAREXPLOSION");
642                         print_Effect_Index(d, "TE_TELEPORT");
643                         print_Effect_Index(d, "TE_LAVASPLASH");
644                         print_Effect_Index(d, "TE_SMALLFLASH");
645                         print_Effect_Index(d, "TE_FLAMEJET");
646                         print_Effect_Index(d, "EF_FLAME");
647                         print_Effect_Index(d, "TE_BLOOD");
648                         print_Effect_Index(d, "TE_SPARK");
649                         print_Effect_Index(d, "TE_PLASMABURN");
650                         print_Effect_Index(d, "TE_TEI_G3");
651                         print_Effect_Index(d, "TE_TEI_SMOKE");
652                         print_Effect_Index(d, "TE_TEI_BIGEXPLOSION");
653                         print_Effect_Index(d, "TE_TEI_PLASMAHIT");
654                         print_Effect_Index(d, "EF_STARDUST");
655                         print_Effect_Index(d, "TR_ROCKET");
656                         print_Effect_Index(d, "TR_GRENADE");
657                         print_Effect_Index(d, "TR_BLOOD");
658                         print_Effect_Index(d, "TR_WIZSPIKE");
659                         print_Effect_Index(d, "TR_SLIGHTBLOOD");
660                         print_Effect_Index(d, "TR_KNIGHTSPIKE");
661                         print_Effect_Index(d, "TR_VORESPIKE");
662                         print_Effect_Index(d, "TR_NEHAHRASMOKE");
663                         print_Effect_Index(d, "TR_NEXUIZPLASMA");
664                         print_Effect_Index(d, "TR_GLOWTRAIL");
665                         print_Effect_Index(d, "TR_SEEKER");
666                         print_Effect_Index(d, "SVC_PARTICLE");
667
668                         fh = fopen("effectinfo.txt", FILE_READ);
669                         while ((s = fgets(fh)))
670                         {
671                                 tokenize_console(s);
672                                 if (argv(0) == "effect")
673                                 {
674                                         if (db_get(d, argv(1)) != "1")
675                                         {
676                                                 int i = _particleeffectnum(argv(1));
677                                                 if (i >= 0) LOG_INFO("effect ", argv(1), " is ", ftos(i));
678                                                 db_put(d, argv(1), "1");
679                                         }
680                                 }
681                         }
682                         LOG_INFO("end of effects list");
683
684                         db_close(d);
685                         return;
686                 }
687
688                 default:
689                 case CMD_REQUEST_USAGE:
690                 {
691                         LOG_HELP("Usage:^3 sv_cmd effectindexdump");
692                         LOG_HELP("  No arguments required.");
693                         return;
694                 }
695         }
696 }
697
698 void GameCommand_extendmatchtime(int request)
699 {
700         switch (request)
701         {
702                 case CMD_REQUEST_COMMAND:
703                 {
704                         changematchtime(autocvar_timelimit_increment * 60, autocvar_timelimit_min * 60, autocvar_timelimit_max * 60);
705                         return;
706                 }
707
708                 default:
709                 case CMD_REQUEST_USAGE:
710                 {
711                         LOG_HELP("Usage:^3 sv_cmd extendmatchtime");
712                         LOG_HELP("  No arguments required.");
713                         LOG_HELP("See also: ^2reducematchtime^7");
714                         return;
715                 }
716         }
717 }
718
719 void GameCommand_gametype(int request, int argc)
720 {
721         switch (request)
722         {
723                 case CMD_REQUEST_COMMAND:
724                 {
725                         if (!world_initialized)
726                         {
727                                 LOG_INFOF("This command works only when the server is running.");
728                                 return;
729                         }
730                         if (argv(1) != "")
731                         {
732                                 string s = argv(1);
733                                 Gametype t = MapInfo_Type_FromString(s, false), tsave = MapInfo_CurrentGametype();
734
735                                 if (t)
736                                 {
737                                         MapInfo_SwitchGameType(t);
738                                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
739                                         if (MapInfo_count > 0)
740                                         {
741                                                 // update lsmaps in case the gametype changed, this way people can easily list maps for it
742                                                 if (lsmaps_reply != "")   strunzone(lsmaps_reply);
743                                                 lsmaps_reply = strzone(getlsmaps());
744                                                 bprint("Game type successfully switched to ", s, "\n");
745                                         }
746                                         else
747                                         {
748                                                 bprint("Cannot use this game type: no map for it found\n");
749                                                 MapInfo_SwitchGameType(tsave);
750                                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
751                                         }
752                                 }
753                                 else
754                                 {
755                                         bprint("Failed to switch to ", s, ": this game type does not exist!\n");
756                                 }
757
758                                 return;
759                         }
760                 }
761
762                 default:
763                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
764                 case CMD_REQUEST_USAGE:
765                 {
766                         LOG_HELP("Usage:^3 sv_cmd gametype <mode>");
767                         LOG_HELP("  Where <mode> is the gametype mode to switch to.");
768                         LOG_HELP("See also: ^2gotomap^7");
769                         return;
770                 }
771         }
772 }
773
774 void GameCommand_gettaginfo(int request, int argc)
775 {
776         switch (request)
777         {
778                 case CMD_REQUEST_COMMAND:
779                 {
780                         entity tmp_entity;
781                         float i;
782                         vector v;
783
784                         if (argc >= 4)
785                         {
786                                 tmp_entity = spawn();
787                                 if (argv(1) == "w")
788                                 {
789                                         .entity weaponentity = weaponentities[0];
790                                         _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
791                                 }
792                                 else
793                                 {
794                                         precache_model(argv(1));
795                                         _setmodel(tmp_entity, argv(1));
796                                 }
797                                 tmp_entity.frame = stof(argv(2));
798                                 if (substring(argv(3), 0, 1) == "#") i = stof(substring(argv(3), 1, -1));
799                                 else i = gettagindex(tmp_entity, argv(3));
800                                 if (i)
801                                 {
802                                         v = gettaginfo(tmp_entity, i);
803                                         LOG_HELPF("model %s frame %s tag %s index %s parent %s",
804                                                 tmp_entity.model, ftos(tmp_entity.frame), gettaginfo_name, ftos(i), ftos(gettaginfo_parent)
805                                         );
806                                         LOG_HELPF(" vector = %s %s %s", ftos(v.x), ftos(v.y), ftos(v.z));
807                                         LOG_HELPF(" offset = %s %s %s", ftos(gettaginfo_offset.x), ftos(gettaginfo_offset.y), ftos(gettaginfo_offset.z));
808                                         LOG_HELPF(" forward = %s %s %s", ftos(gettaginfo_forward.x), ftos(gettaginfo_forward.y), ftos(gettaginfo_forward.z));
809                                         LOG_HELPF(" right = %s %s %s", ftos(gettaginfo_right.x), ftos(gettaginfo_right.y), ftos(gettaginfo_right.z));
810                                         LOG_HELPF(" up = %s %s %s", ftos(gettaginfo_up.x), ftos(gettaginfo_up.y), ftos(gettaginfo_up.z));
811                                         if (argc >= 6)
812                                         {
813                                                 v.y = -v.y;
814                                                 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
815                                         }
816                                 }
817                                 else
818                                 {
819                                         LOG_INFO("bone not found");
820                                 }
821
822                                 delete(tmp_entity);
823                                 return;
824                         }
825                 }
826
827                 default:
828                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
829                 case CMD_REQUEST_USAGE:
830                 {
831                         LOG_HELP("Usage:^3 sv_cmd gettaginfo <model> <frame> <index> [<command1>] [<command2>]");
832                         LOG_HELP("See also: ^2bbox, trace^7");
833                         return;
834                 }
835         }
836 }
837
838 void GameCommand_animbench(int request, int argc)
839 {
840         switch (request)
841         {
842                 case CMD_REQUEST_COMMAND:
843                 {
844                         entity tmp_entity;
845
846                         if (argc >= 4)
847                         {
848                                 tmp_entity = spawn();
849                                 if (argv(1) == "w")
850                                 {
851                                         .entity weaponentity = weaponentities[0];
852                                         _setmodel(tmp_entity, (nextent(NULL)).(weaponentity).model);
853                                 }
854                                 else
855                                 {
856                                         precache_model(argv(1));
857                                         _setmodel(tmp_entity, argv(1));
858                                 }
859                                 float f1 = stof(argv(2));
860                                 float f2 = stof(argv(3));
861                                 float t0;
862                                 float t1 = 0;
863                                 float t2 = 0;
864                                 float n = 0;
865
866                                 while (t1 + t2 < 1)
867                                 {
868                                         tmp_entity.frame = f1;
869                                         t0 = gettime(GETTIME_HIRES);
870                                         getsurfacepoint(tmp_entity, 0, 0);
871                                         t1 += gettime(GETTIME_HIRES) - t0;
872                                         tmp_entity.frame = f2;
873                                         t0 = gettime(GETTIME_HIRES);
874                                         getsurfacepoint(tmp_entity, 0, 0);
875                                         t2 += gettime(GETTIME_HIRES) - t0;
876                                         n += 1;
877                                 }
878                                 LOG_INFO("model ", tmp_entity.model, " frame ", ftos(f1), " animtime ", ftos(n / t1), "/s");
879                                 LOG_INFO("model ", tmp_entity.model, " frame ", ftos(f2), " animtime ", ftos(n / t2), "/s");
880
881                                 delete(tmp_entity);
882                                 return;
883                         }
884                 }
885
886                 default:
887                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
888                 case CMD_REQUEST_USAGE:
889                 {
890                         LOG_HELP("Usage:^3 sv_cmd animbench <model> <frame1> <frame2>");
891                         LOG_HELP("See also: ^2bbox, trace^7");
892                         return;
893                 }
894         }
895 }
896
897 void GameCommand_gotomap(int request, int argc)
898 {
899         switch (request)
900         {
901                 case CMD_REQUEST_COMMAND:
902                 {
903                         if (!world_initialized)
904                         {
905                                 LOG_INFOF("This command works only when the server is running.");
906                                 return;
907                         }
908                         if (argv(1))
909                         {
910                                 LOG_INFO(GotoMap(argv(1)));
911                                 return;
912                         }
913                 }
914
915                 default:
916                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
917                 case CMD_REQUEST_USAGE:
918                 {
919                         LOG_HELP("Usage:^3 sv_cmd gotomap <map>");
920                         LOG_HELP("  Where <map> is the *.bsp file to change to.");
921                         LOG_HELP("See also: ^2gametype^7");
922                         return;
923                 }
924         }
925 }
926
927 void GameCommand_lockteams(int request)
928 {
929         switch (request)
930         {
931                 case CMD_REQUEST_COMMAND:
932                 {
933                         if (teamplay)
934                         {
935                                 lockteams = 1;
936                                 bprint("^1The teams are now locked.\n");
937                         }
938                         else
939                         {
940                                 bprint("lockteams command can only be used in a team-based gamemode.\n");
941                         }
942                         return;
943                 }
944
945                 default:
946                 case CMD_REQUEST_USAGE:
947                 {
948                         LOG_HELP("Usage:^3 sv_cmd lockteams");
949                         LOG_HELP("  No arguments required.");
950                         LOG_HELP("See also: ^2unlockteams^7");
951                         return;
952                 }
953         }
954 }
955
956 void GameCommand_make_mapinfo(int request)
957 {
958         switch (request)
959         {
960                 case CMD_REQUEST_COMMAND:
961                 {
962                         entity tmp_entity;
963
964                         tmp_entity = new(make_mapinfo);
965                         setthink(tmp_entity, make_mapinfo_Think);
966                         tmp_entity.nextthink = time;
967                         MapInfo_Enumerate();
968                         return;
969                 }
970
971                 default:
972                 case CMD_REQUEST_USAGE:
973                 {
974                         LOG_HELP("Usage:^3 sv_cmd make_mapinfo");
975                         LOG_HELP("  No arguments required.");
976                         LOG_HELP("See also: ^2radarmap^7");
977                         return;
978                 }
979         }
980 }
981
982 void GameCommand_moveplayer(int request, int argc)
983 {
984         switch (request)
985         {
986                 case CMD_REQUEST_COMMAND:
987                 {
988                         float accepted;
989                         entity client;
990
991                         string targets = strreplace(",", " ", argv(1));
992                         string original_targets = strreplace(" ", ", ", targets);
993                         string destination = argv(2);
994                         if (destination == "spec")
995                                 destination = "spectator";
996
997                         if ((targets) && (destination))
998                         {
999                                 string successful = string_null;
1000                                 string t;
1001                                 for ( ; targets; )
1002                                 {
1003                                         t = car(targets);
1004                                         targets = cdr(targets);
1005
1006                                         // Check to see if the player is a valid target
1007                                         client = GetFilteredEntity(t);
1008                                         accepted = VerifyClientEntity(client, false, false);
1009                                         string client_num_str = ftos(etof(client));
1010
1011                                         if (accepted <= 0)
1012                                         {
1013                                                 LOG_INFO("moveplayer: ", GetClientErrorString(accepted, t), ".");
1014                                         }
1015                                         else if (destination == "spectator")
1016                                         {
1017                                                 string pl_name = playername(client.netname, client.team, false);
1018                                                 if (!IS_SPEC(client) && !IS_OBSERVER(client))
1019                                                 {
1020                                                         PutObserverInServer(client, true, true);
1021
1022                                                         successful = strcat(successful, (successful ? ", " : ""), pl_name);
1023                                                 }
1024                                                 else
1025                                                 {
1026                                                         LOG_INFO("Player #", client_num_str, " (", pl_name, ") is already spectating.");
1027                                                 }
1028                                         }
1029                                         else
1030                                         {
1031                                                 if (!teamplay)
1032                                                 {
1033                                                         LOG_INFO("Can't change teams when currently not playing a team game.");
1034                                                         return;
1035                                                 }
1036
1037                                                 string pl_name = playername(client.netname, client.team, false);
1038                                                 if (IS_SPEC(client) || IS_OBSERVER(client))
1039                                                 {
1040                                                         // well technically we could, but should we allow that? :P
1041                                                         LOG_INFO("Player #", client_num_str, " (", pl_name, ") is not in the game.");
1042                                                         continue;
1043                                                 }
1044
1045                                                 // set up
1046                                                 int save = Player_GetForcedTeamIndex(client);
1047                                                 Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
1048
1049                                                 // find the team to move the player to
1050                                                 int team_num = Team_ColorToTeam(destination);
1051                                                 entity balance;
1052                                                 if (team_num == client.team)  // already on the destination team
1053                                                 {
1054                                                         // keep the forcing undone
1055                                                         LOG_INFO("Player #", client_num_str, " (", pl_name, ") is already on the ", Team_ColoredFullName(team_num), "^7.");
1056                                                         continue;
1057                                                 }
1058                                                 else if (team_num == 0)  // auto team
1059                                                 {
1060                                                         balance = TeamBalance_CheckAllowedTeams(client);
1061                                                         team_num = Team_IndexToTeam(TeamBalance_FindBestTeam(balance, client, false));
1062                                                 }
1063                                                 else
1064                                                 {
1065                                                         balance = TeamBalance_CheckAllowedTeams(client);
1066                                                 }
1067                                                 Player_SetForcedTeamIndex(client, save);
1068
1069                                                 // Check to see if the destination team is even available
1070                                                 int team_id = Team_TeamToIndex(team_num);
1071                                                 if (team_id == -1)
1072                                                 {
1073                                                         LOG_INFO("Can't move player to ", destination, " team because it doesn't exist.");
1074                                                         TeamBalance_Destroy(balance);
1075                                                         return;
1076                                                 }
1077                                                 if (!IsTeamAvailable(team_num))
1078                                                 {
1079                                                         LOG_INFO("Can't move player to ", destination, " team because it isn't available.");
1080                                                         TeamBalance_Destroy(balance);
1081                                                         return;
1082                                                 }
1083                                                 if (!TeamBalance_IsTeamAllowed(balance, team_id))
1084                                                 {
1085                                                         LOG_INFO("Player #", client_num_str, " (", pl_name, ") is not allowed to join the ", Team_ColoredFullName(team_num), "^7.");
1086                                                         TeamBalance_Destroy(balance);
1087                                                         continue;
1088                                                 }
1089                                                 TeamBalance_Destroy(balance);
1090
1091                                                 // If so, lets continue and finally move the player
1092                                                 Player_SetForcedTeamIndex(client, TEAM_FORCE_DEFAULT);
1093                                                 if (MoveToTeam(client, team_id, 6))
1094                                                 {
1095                                                         successful = strcat(successful, (successful ? ", " : ""), pl_name);
1096                                                         LOG_INFO("Player #", client_num_str, " (", pl_name, ") has been moved to the ", Team_ColoredFullName(team_num), "^7.");
1097                                                 }
1098                                                 else
1099                                                 {
1100                                                         LOG_INFO("Unable to move player #", client_num_str, " (", pl_name, ")");
1101                                                 }
1102                                         }
1103                                 } // loop end
1104
1105                                 if (successful) bprint("Successfully moved players ", successful, " to destination ", destination, ".\n");
1106                                 else LOG_INFO("No players given (", original_targets, ") are able to move.");
1107
1108                                 return;  // still correct parameters so return to avoid usage print
1109                         }
1110                 }
1111
1112                 default:
1113                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1114                 case CMD_REQUEST_USAGE:
1115                 {
1116                         LOG_HELP("Usage:^3 sv_cmd moveplayer <clients> <destination>");
1117                         LOG_HELP("  <clients> is a list (separated by commas) of player entity ID's or nicknames");
1118                         LOG_HELP("  <destination> is what to send the player to, be it team or spectating");
1119                         LOG_HELP("  Full list of destinations here: spec, spectator, red, blue, yellow, pink, auto.");
1120                         LOG_HELP("Examples: sv_cmd moveplayer 1,3,5 red");
1121                         LOG_HELP("          sv_cmd moveplayer 2 spec");
1122                         LOG_HELP("See also: ^2allspec, shuffleteams^7");
1123                         return;
1124                 }
1125         }
1126 }
1127
1128 void GameCommand_nospectators(int request)
1129 {
1130         switch (request)
1131         {
1132                 case CMD_REQUEST_COMMAND:
1133                 {
1134                         blockSpectators = 1;
1135                         // give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
1136                         FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !INGAME(it), {
1137                                 CS(it).spectatortime = time;
1138                                 Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime);
1139                         });
1140                         bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n"));
1141                         return;
1142                 }
1143
1144                 default:
1145                 case CMD_REQUEST_USAGE:
1146                 {
1147                         LOG_HELP("Usage:^3 sv_cmd nospectators");
1148                         LOG_HELP("  No arguments required.");
1149                         return;
1150                 }
1151         }
1152 }
1153
1154 void GameCommand_printplayer(int request, int argc)
1155 {
1156         switch (request)
1157         {
1158                 case CMD_REQUEST_COMMAND:
1159                 {
1160                         entity player = GetIndexedEntity(argc, 1);
1161                         if (player.playerid)
1162                         {
1163                                 GameLogEcho(strcat(
1164                                                    strcat(
1165                                                           ":playerinfo:", ftos(player.playerid),
1166                                                           ":", ftos(etof(player)),
1167                                                           ":", ftos(CS_CVAR(player).cvar_cl_allow_uidtracking),
1168                                                           ":", ftos(CS_CVAR(player).cvar_cl_allow_uid2name)),
1169                                                    strcat(
1170                                                           ":", ftos(CS_CVAR(player).cvar_cl_allow_uidranking),
1171                                                           ":", ((IS_REAL_CLIENT(player)) ? GameLog_ProcessIP(player.netaddress) : "bot"),
1172                                                           ":", player.crypto_idfp,
1173                                                           ":", playername(player.netname, player.team, false))));
1174                         }
1175                         return;
1176                 }
1177                 default:
1178                 case CMD_REQUEST_USAGE:
1179                 {
1180                         LOG_HELP("Usage:^3 sv_cmd printplayer <player_entity_id>");
1181                         return;
1182                 }
1183         }
1184 }
1185
1186 void GameCommand_printstats(int request)
1187 {
1188         switch (request)
1189         {
1190                 case CMD_REQUEST_COMMAND:
1191                 {
1192                         DumpStats(false);
1193                         LOG_INFO("stats dumped.");
1194                         return;
1195                 }
1196
1197                 default:
1198                 case CMD_REQUEST_USAGE:
1199                 {
1200                         LOG_HELP("Usage:^3 sv_cmd printstats");
1201                         LOG_HELP("  No arguments required.");
1202                         return;
1203                 }
1204         }
1205 }
1206
1207 void GameCommand_radarmap(int request, int argc)
1208 {
1209         switch (request)
1210         {
1211                 case CMD_REQUEST_COMMAND:
1212                 {
1213                         if (RadarMap_Make(argc)) return;
1214                 }
1215
1216                 default:
1217                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1218                 case CMD_REQUEST_USAGE:
1219                 {
1220                         LOG_HELP("Usage:^3 sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]");
1221                         LOG_HELP("  The quality factor Q is roughly proportional to the time taken.");
1222                         LOG_HELP("  trace supports no quality factor; its result should look like --block with infinite quality factor.");
1223                         LOG_HELP("See also: ^2make_mapinfo^7");
1224                         return;
1225                 }
1226         }
1227 }
1228
1229 void GameCommand_reducematchtime(int request)
1230 {
1231         switch (request)
1232         {
1233                 case CMD_REQUEST_COMMAND:
1234                 {
1235                         changematchtime(autocvar_timelimit_decrement * -60, autocvar_timelimit_min * 60, autocvar_timelimit_max * 60);
1236                         return;
1237                 }
1238
1239                 default:
1240                 case CMD_REQUEST_USAGE:
1241                 {
1242                         LOG_HELP("Usage:^3 sv_cmd reducematchtime");
1243                         LOG_HELP("  No arguments required.");
1244                         LOG_HELP("See also: ^2extendmatchtime^7");
1245                         return;
1246                 }
1247         }
1248 }
1249
1250 void GameCommand_setbots(int request, int argc)
1251 {
1252         switch (request)
1253         {
1254                 case CMD_REQUEST_COMMAND:
1255                 {
1256                         if (argc >= 2)
1257                         {
1258                                 cvar_settemp("minplayers", "0");
1259                                 cvar_settemp("minplayers_per_team", "0");
1260                                 cvar_settemp("bot_number", argv(1));
1261                                 bot_fixcount(true);
1262                                 return;
1263                         }
1264                 }
1265
1266                 default:
1267                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1268                 case CMD_REQUEST_USAGE:
1269                 {
1270                         LOG_HELP("Usage:^3 sv_cmd setbots <botnumber>");
1271                         LOG_HELP("  Where <botnumber> is the amount of bots to set bot_number cvar to.");
1272                         LOG_HELP("See also: ^2bot_cmd^7");
1273                         return;
1274                 }
1275         }
1276 }
1277
1278 void shuffleteams()
1279 {
1280         if (!teamplay)
1281         {
1282                 LOG_INFO("Can't shuffle teams when currently not playing a team game.");
1283                 return;
1284         }
1285
1286         FOREACH_CLIENT(IS_PLAYER(it) || INGAME(it), {
1287                 if (Player_HasRealForcedTeam(it)) {
1288                         // we could theoretically assign forced players to their teams
1289                         // and shuffle the rest to fill the empty spots but in practise
1290                         // either all players or none are gonna have forced teams
1291                         LOG_INFO("Can't shuffle teams because at least one player has a forced team.");
1292                         return;
1293                 }
1294         });
1295
1296         int number_of_teams = 0;
1297         entity balance = TeamBalance_CheckAllowedTeams(NULL);
1298         for (int i = 1; i <= NUM_TEAMS; ++i)
1299         {
1300                 if (TeamBalance_IsTeamAllowed(balance, i))
1301                 {
1302                         number_of_teams = max(i, number_of_teams);
1303                 }
1304         }
1305         TeamBalance_Destroy(balance);
1306
1307         int team_index = 0;
1308         FOREACH_CLIENT_RANDOM(IS_PLAYER(it) || INGAME(it), {
1309                 int target_team_index = team_index + 1;
1310                 if (Entity_GetTeamIndex(it) != target_team_index)
1311                 {
1312                         MoveToTeam(it, target_team_index, 6);
1313                 }
1314                 team_index = (team_index + 1) % number_of_teams;
1315         });
1316
1317         bprint("Successfully shuffled the players around randomly.\n");
1318 }
1319
1320 void GameCommand_shuffleteams(int request)
1321 {
1322         switch (request)
1323         {
1324                 case CMD_REQUEST_COMMAND:
1325                 {
1326                         if (shuffleteams_on_reset_map)
1327                         {
1328                                 bprint("Players will be shuffled when this round is over.\n");
1329                                 shuffleteams_on_reset_map = true;
1330                         }
1331                         else
1332                                 shuffleteams();
1333                         return;
1334                 }
1335
1336                 default:
1337                 case CMD_REQUEST_USAGE:
1338                 {
1339                         LOG_HELP("Usage:^3 sv_cmd shuffleteams");
1340                         LOG_HELP("  No arguments required.");
1341                         LOG_HELP("See also: ^2moveplayer, allspec^7");
1342                         return;
1343                 }
1344         }
1345 }
1346
1347 void GameCommand_resetmatch(int request)
1348 {
1349         switch (request)
1350         {
1351                 case CMD_REQUEST_COMMAND:
1352                 {
1353                         ReadyRestart(false);
1354                         return;
1355                 }
1356
1357                 default:
1358                 case CMD_REQUEST_USAGE:
1359                 {
1360                         LOG_HELP("Usage:^3 sv_cmd resetmatch");
1361                         LOG_HELP("  No arguments required.");
1362                         return;
1363                 }
1364         }
1365 }
1366
1367 void GameCommand_stuffto(int request, int argc)
1368 {
1369         // This... is a fairly dangerous and powerful command... - It allows any arguments to be sent to a client via rcon.
1370         // Because of this, it is disabled by default and must be enabled by the server owner when doing compilation. That way,
1371         // we can be certain they understand the risks of it... So to enable, compile server with -DSTUFFTO_ENABLED argument.
1372
1373 #ifdef STUFFTO_ENABLED
1374                 switch (request)
1375                 {
1376                         case CMD_REQUEST_COMMAND:
1377                         {
1378                                 if (argv(2))
1379                                 {
1380                                         entity client = GetIndexedEntity(argc, 1);
1381                                         float accepted = VerifyClientEntity(client, true, false);
1382
1383                                         if (accepted > 0)
1384                                         {
1385                                                 stuffcmd(client, strcat("\n", argv(next_token), "\n"));
1386                                                 LOG_INFO("Command: \"", argv(next_token), "\" sent to ", GetCallerName(client), " (", argv(1), ").");
1387                                         }
1388                                         else
1389                                         {
1390                                                 LOG_INFO("stuffto: ", GetClientErrorString(accepted, argv(1)), ".");
1391                                         }
1392
1393                                         return;
1394                                 }
1395                         }
1396
1397                         default:
1398                                 LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1399                         case CMD_REQUEST_USAGE:
1400                         {
1401                                 LOG_HELP("Usage:^3 sv_cmd stuffto <client> \"<command>\"");
1402                                 LOG_HELP("  <client> is the entity number or name of the player,");
1403                                 LOG_HELP("  and <command> is the command to be sent to that player.");
1404                                 return;
1405                         }
1406                 }
1407 #else
1408                 if (request)
1409                 {
1410                         LOG_HELP("stuffto command is not enabled on this server.");
1411                         return;
1412                 }
1413 #endif
1414 }
1415
1416 void GameCommand_trace(int request, int argc)
1417 {
1418         switch (request)
1419         {
1420                 case CMD_REQUEST_COMMAND:
1421                 {
1422                         entity e;
1423                         vector org, delta, start, end, p, q, q0, pos, vv, dv;
1424                         float i, f, safe, unsafe, dq, dqf;
1425
1426                         switch (argv(1))
1427                         {
1428                                 case "debug":
1429                                 {
1430                                         float hitcount = 0;
1431                                         LOG_INFO("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.");
1432                                         float worst_endpos_bug = 0;
1433                                         for ( ; ; )
1434                                         {
1435                                                 org = world.mins;
1436                                                 delta = world.maxs - world.mins;
1437
1438                                                 start.x = org.x + random() * delta.x;
1439                                                 start.y = org.y + random() * delta.y;
1440                                                 start.z = org.z + random() * delta.z;
1441
1442                                                 end.x = org.x + random() * delta.x;
1443                                                 end.y = org.y + random() * delta.y;
1444                                                 end.z = org.z + random() * delta.z;
1445
1446                                                 start = stov(vtos(start));
1447                                                 end = stov(vtos(end));
1448
1449                                                 tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
1450                                                 if (!trace_startsolid && trace_fraction < 1)
1451                                                 {
1452                                                         p = trace_endpos;
1453                                                         tracebox(p, PL_MIN_CONST, PL_MAX_CONST, p, MOVE_NOMONSTERS, NULL);
1454                                                         if (trace_startsolid)
1455                                                         {
1456                                                                 rint(42);  // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
1457                                                                 tracebox(start, PL_MIN_CONST, PL_MAX_CONST, end, MOVE_NOMONSTERS, NULL);
1458
1459                                                                 // how much do we need to back off?
1460                                                                 safe = 1;
1461                                                                 unsafe = 0;
1462                                                                 for ( ; ; )
1463                                                                 {
1464                                                                         pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
1465                                                                         tracebox(pos, PL_MIN_CONST, PL_MAX_CONST, pos, MOVE_NOMONSTERS, NULL);
1466                                                                         if (trace_startsolid)
1467                                                                         {
1468                                                                                 if ((safe + unsafe) * 0.5 == unsafe) break;
1469                                                                                 unsafe = (safe + unsafe) * 0.5;
1470                                                                         }
1471                                                                         else
1472                                                                         {
1473                                                                                 if ((safe + unsafe) * 0.5 == safe) break;
1474                                                                                 safe = (safe + unsafe) * 0.5;
1475                                                                         }
1476                                                                 }
1477
1478                                                                 LOG_INFO("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu");
1479                                                                 LOG_INFO("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu");
1480
1481                                                                 tracebox(p, PL_MIN_CONST + '0.1 0.1 0.1', PL_MAX_CONST - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, NULL);
1482                                                                 if (trace_startsolid) LOG_INFO("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1483                                                                 else LOG_INFO("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1484                                                                 if (++hitcount >= 10) break;
1485                                                         }
1486                                                         else
1487                                                         {
1488                                                                 q0 = p;
1489                                                                 dq = 0;
1490                                                                 dqf = 1;
1491                                                                 for ( ; ; )
1492                                                                 {
1493                                                                         q = p + normalize(end - p) * (dq + dqf);
1494                                                                         if (q == q0) break;
1495                                                                         tracebox(p, PL_MIN_CONST, PL_MAX_CONST, q, MOVE_NOMONSTERS, NULL);
1496                                                                         if (trace_startsolid) error("THIS ONE cannot happen");
1497                                                                         if (trace_fraction > 0) dq += dqf * trace_fraction;
1498                                                                         dqf *= 0.5;
1499                                                                         q0 = q;
1500                                                                 }
1501                                                                 if (dq > worst_endpos_bug)
1502                                                                 {
1503                                                                         worst_endpos_bug = dq;
1504                                                                         LOG_INFO("trace_endpos still before solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p));
1505                                                                         LOG_INFO("could go ", ftos(dq), " units further to ", vtos(q));
1506                                                                         if (++hitcount >= 10) break;
1507                                                                 }
1508                                                         }
1509                                                 }
1510                                         }
1511                                         return;
1512                                 }
1513
1514                                 case "debug2":
1515                                 {
1516                                         e = nextent(NULL);
1517                                         tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
1518                                         vv = trace_endpos;
1519                                         if (trace_fraction == 1)
1520                                         {
1521                                                 LOG_INFO("not above ground, aborting");
1522                                                 return;
1523                                         }
1524                                         f = 0;
1525                                         for (i = 0; i < 100000; ++i)
1526                                         {
1527                                                 dv = randomvec();
1528                                                 if (dv.z > 0) dv = -1 * dv;
1529                                                 tracebox(vv, e.mins, e.maxs, vv + dv, MOVE_NORMAL, e);
1530                                                 if (trace_startsolid) LOG_INFO("bug 1");
1531                                                 if (trace_fraction == 1)
1532                                                 {
1533                                                         if (dv.z < f)
1534                                                         {
1535                                                                 LOG_INFO("bug 2: ", ftos(dv.x), " ", ftos(dv.y), " ", ftos(dv.z));
1536                                                                 LOG_INFO(" (", ftos(asin(dv.z / vlen(dv)) * 180 / M_PI), " degrees)");
1537                                                                 f = dv.z;
1538                                                         }
1539                                                 }
1540                                         }
1541                                         LOG_INFO("highest possible dist: ", ftos(f));
1542                                         return;
1543                                 }
1544
1545                                 case "walk":
1546                                 {
1547                                         if (argc == 4 || argc == 5)
1548                                         {
1549                                                 e = nextent(NULL);
1550                                                 int dphitcontentsmask_save = e.dphitcontentsmask;
1551                                                 e.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_PLAYERCLIP | DPCONTENTS_BOTCLIP;
1552                                                 if (tracewalk(e, stov(argv(2)), e.mins, e.maxs, stov(argv(3)), stof(argv(4)), MOVE_NORMAL))
1553                                                         LOG_INFO("can walk");
1554                                                 else
1555                                                         LOG_INFO("cannot walk");
1556                                                 e.dphitcontentsmask = dphitcontentsmask_save;
1557                                                 return;
1558                                         }
1559                                 }
1560
1561                                 case "showline":
1562                                 {
1563                                         if (argc == 4)
1564                                         {
1565                                                 vv = stov(argv(2));
1566                                                 dv = stov(argv(3));
1567                                                 traceline(vv, dv, MOVE_NORMAL, NULL);
1568                                                 __trailparticles(NULL, particleeffectnum(EFFECT_TR_NEXUIZPLASMA), vv, trace_endpos);
1569                                                 __trailparticles(NULL, particleeffectnum(EFFECT_TR_CRYLINKPLASMA), trace_endpos, dv);
1570                                                 return;
1571                                         }
1572                                 }
1573
1574                                 // no default case, just go straight to invalid
1575                         }
1576                 }
1577
1578                 default:
1579                         LOG_INFOF("Incorrect parameters for ^2%s^7", argv(0));
1580                 case CMD_REQUEST_USAGE:
1581                 {
1582                         LOG_HELP("Usage:^3 sv_cmd trace <command> [<startpos> <endpos>] [<endpos_height>]");
1583                         LOG_HELP("  Where <startpos> and <endpos> are parameters for the 'walk' and 'showline' commands,");
1584                         LOG_HELP("  <endpos_height> is an optional parameter for the 'walk' command,");
1585                         LOG_HELP("  Full list of commands here: debug, debug2, walk, showline.");
1586                         LOG_HELP("See also: ^2bbox, gettaginfo^7");
1587                         return;
1588                 }
1589         }
1590 }
1591
1592 void GameCommand_unlockteams(int request)
1593 {
1594         switch (request)
1595         {
1596                 case CMD_REQUEST_COMMAND:
1597                 {
1598                         if (teamplay)
1599                         {
1600                                 lockteams = 0;
1601                                 bprint("^1The teams are now unlocked.\n");
1602                         }
1603                         else
1604                         {
1605                                 bprint("unlockteams command can only be used in a team-based gamemode.\n");
1606                         }
1607                         return;
1608                 }
1609
1610                 default:
1611                 case CMD_REQUEST_USAGE:
1612                 {
1613                         LOG_HELP("Usage:^3 sv_cmd unlockteams");
1614                         LOG_HELP("  No arguments required.");
1615                         LOG_HELP("See also: ^2lockteams^7");
1616                         return;
1617                 }
1618         }
1619 }
1620
1621 void GameCommand_warp(int request, int argc)
1622 {
1623         switch (request)
1624         {
1625                 case CMD_REQUEST_COMMAND:
1626                 {
1627                         if (autocvar_g_campaign)
1628                         {
1629                                 if (argc >= 2)
1630                                 {
1631                                         CampaignLevelWarp(stof(argv(1)));
1632                                         LOG_INFO("Successfully warped to campaign level ", argv(1), ".");
1633                                 }
1634                                 else
1635                                 {
1636                                         CampaignLevelWarp(-1);
1637                                         LOG_INFO("Successfully warped to next campaign level.");
1638                                 }
1639                         }
1640                         else
1641                         {
1642                                 LOG_INFO("Not in campaign, can't level warp");
1643                         }
1644                         return;
1645                 }
1646
1647                 default:
1648                 case CMD_REQUEST_USAGE:
1649                 {
1650                         LOG_HELP("Usage:^3 sv_cmd warp [<level>]");
1651                         LOG_HELP("  <level> is the level to change campaign mode to.");
1652                         LOG_HELP("  if <level> is not provided it will change to the next level.");
1653                         return;
1654                 }
1655         }
1656 }
1657
1658 void IRCSay(string msgstr)
1659 {
1660         if(msgstr == "")
1661                 return;
1662
1663         string prefix;
1664         if(substring(msgstr, 0, 3) == "^4*") // actions
1665                 prefix = "\{3}";
1666         else
1667                 prefix = "\{1}";
1668
1669         msgstr = strcat(prefix, strreplace("\n", " ", msgstr), "\n"); // newlines only are good for centerprint
1670
1671         FOREACH_CLIENTSLOT(true,
1672         {
1673                 if(!intermission_running)
1674                 if((autocvar_g_chat_nospectators == 1) || (autocvar_g_chat_nospectators == 2 && !(warmup_stage || game_stopped)))
1675                 if(IS_PLAYER(it))
1676                         continue;
1677                 if(IS_REAL_CLIENT(it))
1678                         sprint(it, msgstr);
1679         });
1680 }
1681
1682 void GameCommand_ircmsg(int request, int argc, string command)
1683 {
1684         IRCSay(substring(command, strlen(argv(0))+1, strlen(command)));
1685         return;
1686 }
1687
1688 /* use this when creating a new command, making sure to place it in alphabetical order... also,
1689 ** ADD ALL NEW COMMANDS TO commands.cfg WITH PROPER ALIASES IN THE SAME FASHION!
1690 void GameCommand_(int request)
1691 {
1692     switch(request)
1693     {
1694         case CMD_REQUEST_COMMAND:
1695         {
1696
1697             return;
1698         }
1699
1700         default:
1701         case CMD_REQUEST_USAGE:
1702         {
1703             LOG_HELP("Usage:^3 sv_cmd ");
1704             LOG_HELP("  No arguments required.");
1705             return;
1706         }
1707     }
1708 }
1709 */
1710
1711
1712 // ==================================
1713 //  Macro system for server commands
1714 // ==================================
1715
1716 // Do not hard code aliases for these, instead create them in commands.cfg... also: keep in alphabetical order, please ;)
1717 SERVER_COMMAND(adminmsg, "Send an admin message to a client directly") { GameCommand_adminmsg(request, arguments); }
1718 SERVER_COMMAND(allready, "Ends warmup and starts the match") { GameCommand_allready(request); }
1719 SERVER_COMMAND(allspec, "Force all players to spectate") { GameCommand_allspec(request, arguments); }
1720 SERVER_COMMAND(anticheat, "Create an anticheat report for a client") { GameCommand_anticheat(request, arguments); }
1721 SERVER_COMMAND(animbench, "Benchmark model animation (LAGS)") { GameCommand_animbench(request, arguments); }
1722 SERVER_COMMAND(bbox, "Print detailed information about world size") { GameCommand_bbox(request); }
1723 SERVER_COMMAND(bot_cmd, "Control and send commands to bots") { GameCommand_bot_cmd(request, arguments, command); }
1724 SERVER_COMMAND(cointoss, "Flip a virtual coin and give random result") { GameCommand_cointoss(request, arguments); }
1725 SERVER_COMMAND(database, "Extra controls of the serverprogs database") { GameCommand_database(request, arguments); }
1726 SERVER_COMMAND(defer_clear, "Clear all queued defer commands for a specific client") { GameCommand_defer_clear(request, arguments); }
1727 SERVER_COMMAND(defer_clear_all, "Clear all queued defer commands for all clients") { GameCommand_defer_clear_all(request); }
1728 SERVER_COMMAND(delrec, "Delete race time record for a map") { GameCommand_delrec(request, arguments); }
1729 SERVER_COMMAND(effectindexdump, "Dump list of effects from code and effectinfo.txt") { GameCommand_effectindexdump(request); }
1730 SERVER_COMMAND(extendmatchtime, "Increase the timelimit value incrementally") { GameCommand_extendmatchtime(request); }
1731 SERVER_COMMAND(gametype, "Simple command to change the active gametype") { GameCommand_gametype(request, arguments); }
1732 SERVER_COMMAND(gettaginfo, "Get specific information about a weapon model") { GameCommand_gettaginfo(request, arguments); }
1733 SERVER_COMMAND(gotomap, "Simple command to switch to another map") { GameCommand_gotomap(request, arguments); }
1734 SERVER_COMMAND(ircmsg, "Utility function to forward chat messages from IRC/discord/whatever") { GameCommand_ircmsg(request, arguments, command); }
1735 SERVER_COMMAND(lockteams, "Disable the ability for players to switch or enter teams") { GameCommand_lockteams(request); }
1736 SERVER_COMMAND(make_mapinfo, "Automatically rebuild mapinfo files") { GameCommand_make_mapinfo(request); }
1737 SERVER_COMMAND(moveplayer, "Change the team/status of a player") { GameCommand_moveplayer(request, arguments); }
1738 SERVER_COMMAND(nospectators, "Automatically remove spectators from a match") { GameCommand_nospectators(request); }
1739 SERVER_COMMAND(printplayer, "Print information about a player") { GameCommand_printplayer(request, arguments); }
1740 SERVER_COMMAND(printstats, "Dump eventlog player stats and other score information") { GameCommand_printstats(request); }
1741 SERVER_COMMAND(radarmap, "Generate a radar image of the map") { GameCommand_radarmap(request, arguments); }
1742 SERVER_COMMAND(reducematchtime, "Decrease the timelimit value incrementally") { GameCommand_reducematchtime(request); }
1743 SERVER_COMMAND(resetmatch, "Soft restart the game without changing teams; goes back to warmup if enabled") { GameCommand_resetmatch(request); }
1744 SERVER_COMMAND(setbots, "Adjust how many bots are in the match") { GameCommand_setbots(request, arguments); }
1745 SERVER_COMMAND(shuffleteams, "Randomly move players to different teams") { GameCommand_shuffleteams(request); }
1746 SERVER_COMMAND(stuffto, "Send a command to be executed on a client") { GameCommand_stuffto(request, arguments); }
1747 SERVER_COMMAND(trace, "Various debugging tools with tracing") { GameCommand_trace(request, arguments); }
1748 SERVER_COMMAND(unlockteams, "Enable the ability for players to switch or enter teams") { GameCommand_unlockteams(request); }
1749 SERVER_COMMAND(warp, "Choose different level in campaign") { GameCommand_warp(request, arguments); }
1750
1751 void GameCommand_macro_help()
1752 {
1753         FOREACH(SERVER_COMMANDS, true, { LOG_HELPF("  ^2%s^7: %s", it.m_name, it.m_description); });
1754 }
1755
1756 float GameCommand_macro_command(int argc, string command)
1757 {
1758         string c = strtolower(argv(0));
1759         FOREACH(SERVER_COMMANDS, it.m_name == c, {
1760                 it.m_invokecmd(it, CMD_REQUEST_COMMAND, NULL, argc, command);
1761                 return true;
1762         });
1763         return false;
1764 }
1765
1766 float GameCommand_macro_usage(int argc)
1767 {
1768         string c = strtolower(argv(1));
1769         FOREACH(SERVER_COMMANDS, it.m_name == c, {
1770                 it.m_invokecmd(it, CMD_REQUEST_USAGE, NULL, argc, "");
1771                 return true;
1772         });
1773         return false;
1774 }
1775
1776 void GameCommand_macro_write_aliases(float fh)
1777 {
1778         FOREACH(SERVER_COMMANDS, true, { CMD_Write_Alias("qc_cmd_sv", it.m_name, it.m_description); });
1779 }
1780
1781
1782 // =========================================
1783 //  Main Function Called By Engine (sv_cmd)
1784 // =========================================
1785 // If this function exists, game code handles gamecommand instead of the engine code.
1786
1787 void GameCommand(string command)
1788 {
1789         int argc = tokenize_console(command);
1790
1791         // Guide for working with argc arguments by example:
1792         // argc:   1    - 2      - 3     - 4
1793         // argv:   0    - 1      - 2     - 3
1794         // cmd     vote - master - login - password
1795
1796         if (strtolower(argv(0)) == "help")
1797         {
1798                 if (argc == 1)
1799                 {
1800                         LOG_HELP("Server console commands:");
1801                         GameCommand_macro_help();
1802
1803                         LOG_HELP("\nBanning commands:");
1804                         BanCommand_macro_help();
1805
1806                         LOG_HELP("\nCommon networked commands:");
1807                         CommonCommand_macro_help(NULL);
1808
1809                         LOG_HELP("\nGeneric commands shared by all programs:");
1810                         GenericCommand_macro_help();
1811
1812                         LOG_HELP("\nUsage:^3 sv_cmd <command>^7, where possible commands are listed above.\n"
1813                                 "For help about a specific command, type sv_cmd help <command>");
1814
1815                         return;
1816                 }
1817                 else if (BanCommand_macro_usage(argc))  // Instead of trying to call a command, we're going to see detailed information about it
1818                 {
1819                         return;
1820                 }
1821                 else if (CommonCommand_macro_usage(argc, NULL))  // same here, but for common commands instead
1822                 {
1823                         return;
1824                 }
1825                 else if (GenericCommand_macro_usage(argc))  // same here, but for generic commands instead
1826                 {
1827                         return;
1828                 }
1829                 else if (GameCommand_macro_usage(argc))  // finally try for normal commands too
1830                 {
1831                         return;
1832                 }
1833         }
1834         else if (MUTATOR_CALLHOOK(SV_ParseServerCommand, strtolower(argv(0)), argc, command))
1835         {
1836                 return;  // handled by a mutator
1837         }
1838         else if (BanCommand(command))
1839         {
1840                 return;  // handled by server/command/ipban.qc
1841         }
1842         else if (CommonCommand_macro_command(argc, NULL, command))
1843         {
1844                 return;  // handled by server/command/common.qc
1845         }
1846         else if (GenericCommand(command))
1847         {
1848                 return;                                        // handled by common/command/generic.qc
1849         }
1850         else if (GameCommand_macro_command(argc, command)) // continue as usual and scan for normal commands
1851         {
1852                 return;                                        // handled by one of the above GameCommand_* functions
1853         }
1854
1855         // nothing above caught the command, must be invalid
1856         LOG_INFO(((command != "") ? strcat("Unknown server command \"", command, "\"") : "No command provided"), ". For a list of supported commands, try sv_cmd help.");
1857 }