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