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