1 // =====================================================
2 // Server side game commands code, reworked by Samual
3 // Last updated: July 13th, 2011
4 // =====================================================
6 #define GC_REQUEST_HELP 1
7 #define GC_REQUEST_COMMAND 2
8 #define GC_REQUEST_USAGE 3
12 float RADAR_WIDTH_MAX = 512;
13 float RADAR_HEIGHT_MAX = 512;
14 float sharpen_buffer[RADAR_WIDTH_MAX * 3];
16 string GotoMap(string m);
17 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFFFF";
18 // FF is contained twice, to map 256 to FF too
19 // removes the need to bound()
21 void race_deleteTime(string map, float pos);
24 // ============================
25 // Misc. Supporting Functions
26 // ============================
28 // used by GameCommand_radarmap()
29 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
42 while(vlen(c - b) > 1)
46 tracebox(c, mi, ma, b, MOVE_WORLDONLY, world);
51 black += vlen(trace_endpos - c);
55 n += tracebox_inverted(c, mi, ma, b, MOVE_WORLDONLY, world);
57 white += vlen(trace_endpos - c);
62 dprint("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations\n");
64 return white / (black + white);
66 float RadarMapAtPoint_Trace(float x, float y, float w, float h, float zmin, float zsize, float q)
71 ma = '1 0 0' * w + '0 1 0' * h;
72 a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
73 b = '1 0 0' * x + '0 1 0' * y + '0 0 1' * (zsize + zmin);
75 return FullTraceFraction(a, mi, ma, b);
77 float RadarMapAtPoint_LineBlock(float x, float y, float w, float h, float zmin, float zsize, float q)
84 // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
87 dz = (zsize / q) * '0 0 1';
88 ma = '1 0 0' * w + '0 1 0' * h + dz;
89 o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
91 if(x < world.absmin_x - w)
93 if(y < world.absmin_y - h)
95 if(x > world.absmax_x)
97 if(y > world.absmax_y)
101 for(i = 0; i < q; ++i)
104 v1 = v2 = o + dz * i + mi;
105 v1_x += random() * (ma_x - mi_x);
106 v1_y += random() * (ma_y - mi_y);
107 v1_z += random() * (ma_z - mi_z);
108 v2_x += random() * (ma_x - mi_x);
109 v2_y += random() * (ma_y - mi_y);
110 v2_z += random() * (ma_z - mi_z);
111 traceline(v1, v2, MOVE_WORLDONLY, world);
112 if(trace_startsolid || trace_fraction < 1)
117 float RadarMapAtPoint_Block(float x, float y, float w, float h, float zmin, float zsize, float q)
124 // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
127 dz = (zsize / q) * '0 0 1';
128 ma = '1 0 0' * w + '0 1 0' * h + dz;
129 o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
131 if(x < world.absmin_x - w)
133 if(y < world.absmin_y - h)
135 if(x > world.absmax_x)
137 if(y > world.absmax_y)
141 for(i = 0; i < q; ++i)
143 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
149 float RadarMapAtPoint_Sample(float x, float y, float w, float h, float zmin, float zsize, float q)
153 q *= 4; // choose q so it matches the regular algorithm in speed
156 // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
159 ma = '1 0 0' * w + '0 1 0' * h;
160 a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
161 b = '1 0 0' * w + '0 1 0' * h + '0 0 1' * zsize;
166 for(i = 0; i < q; ++i)
169 v_x = a_x + random() * b_x;
170 v_y = a_y + random() * b_y;
171 v_z = a_z + random() * b_z;
172 traceline(v, v, MOVE_WORLDONLY, world);
179 void sharpen_set(float x, float v)
181 sharpen_buffer[x + 2 * RADAR_WIDTH_MAX] = v;
183 float sharpen_getpixel(float x, float y)
187 if(x >= RADAR_WIDTH_MAX)
193 return sharpen_buffer[x + y * RADAR_WIDTH_MAX];
195 float sharpen_get(float x, float a)
198 sum = sharpen_getpixel(x, 1);
202 sum -= sharpen_getpixel(x - 1, 0);
203 sum -= sharpen_getpixel(x - 1, 1);
204 sum -= sharpen_getpixel(x - 1, 2);
205 sum -= sharpen_getpixel(x + 1, 0);
206 sum -= sharpen_getpixel(x + 1, 1);
207 sum -= sharpen_getpixel(x + 1, 2);
208 sum -= sharpen_getpixel(x, 0);
209 sum -= sharpen_getpixel(x, 2);
210 return bound(0, sum * a, 1);
212 void sharpen_shift(float w)
215 for(i = 0; i < w; ++i)
217 sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX];
218 sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX];
219 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
222 void sharpen_init(float w)
225 for(i = 0; i < w; ++i)
227 sharpen_buffer[i] = 0;
228 sharpen_buffer[i + RADAR_WIDTH_MAX] = 0;
229 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
234 if(radarmapper.count & 4)
238 else if(radarmapper.count & 2)
240 localcmd(strcat("defer 1 \"sv_cmd radarmap --flags ", ftos(radarmapper.count), strcat(" --res ", ftos(radarmapper.size_x), " ", ftos(radarmapper.size_y), " --sharpen ", ftos(radarmapper.ltime), " --qual ", ftos(radarmapper.size_z)), "\"\n"));
246 void RadarMap_Think()
250 // size: pixel width/height
251 // maxs: cell width/height
260 get_mi_min_max_texcoords(1);
261 self.mins = mi_picmin;
262 self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
263 self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
264 self.maxs_z = mi_max_z - mi_min_z;
265 print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
266 self.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm"));
267 if(!(self.count & 1))
269 self.cnt = fopen(self.netname, FILE_READ);
271 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ);
273 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ);
275 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ);
277 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ);
279 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ);
281 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ);
286 print(self.netname, " already exists, aborting (you may want to specify --force)\n");
291 self.cnt = fopen(self.netname, FILE_WRITE);
294 print("Error writing ", self.netname, "\n");
299 print("Writing to ", self.netname, "...\n");
300 fputs(self.cnt, "/* XPM */\n");
301 fputs(self.cnt, "static char *RadarMap[] = {\n");
302 fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
303 fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
304 for(i = 0; i < 256; ++i)
306 si = substring(doublehex, i*2, 2);
307 fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
310 self.nextthink = time;
311 sharpen_init(self.size_x);
313 else if(self.frame <= self.size_y)
315 // fill the sharpen buffer with this line
316 sharpen_shift(self.size_x);
323 for(x = 0; x < self.size_x; ++x)
325 l = RadarMapAtPoint_Block(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
330 for(x = 0; x < self.size_x; ++x)
332 l = RadarMapAtPoint_Trace(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
337 for(x = 0; x < self.size_x; ++x)
339 l = RadarMapAtPoint_Sample(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
344 for(x = 0; x < self.size_x; ++x)
346 l = RadarMapAtPoint_LineBlock(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
352 // do we have enough lines?
355 // write a pixel line
356 fputs(self.cnt, "\"");
357 for(x = 0; x < self.size_x; ++x)
359 l = sharpen_get(x, self.ltime);
360 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
362 if(self.frame == self.size_y)
363 fputs(self.cnt, "\"\n");
366 fputs(self.cnt, "\",\n");
367 print(ftos(self.size_y - self.frame), " lines left\n");
371 // is this the last line? then write back the missing line
372 if(self.frame == self.size_y)
374 sharpen_shift(self.size_x);
375 // write a pixel line
376 fputs(self.cnt, "\"");
377 for(x = 0; x < self.size_x; ++x)
379 l = sharpen_get(x, self.ltime);
380 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
382 if(self.frame == self.size_y)
383 fputs(self.cnt, "\"\n");
386 fputs(self.cnt, "\",\n");
387 print(ftos(self.size_y - self.frame), " lines left\n");
392 self.nextthink = time;
397 fputs(self.cnt, "};\n");
399 print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the gfx folder.\n");
404 // used by GameCommand_make_mapinfo()
405 void make_mapinfo_Think()
407 if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
409 print("Done rebuiling mapinfos.\n");
410 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
415 self.think = make_mapinfo_Think;
416 self.nextthink = time;
420 // used by GameCommand_extendmatchtime() and GameCommand_reducematchtime()
421 void changematchtime(float delta, float mi, float ma)
429 if(autocvar_timelimit < 0)
433 mi = 10; // at least ten sec in the future
434 cur = time - game_starttime;
436 mi += cur; // from current time!
438 lim = autocvar_timelimit * 60;
443 return; // cannot increase any further
445 new = min(ma, lim + delta);
446 else // already above maximum: FAIL
451 if(lim == 0) // infinite: try reducing to max, if we are allowed to
453 else if(lim > mi) // above minimum: decrease
454 new = max(mi, lim + delta);
455 else // already below minimum: FAIL
459 cvar_set("timelimit", ftos(new / 60));
462 // used by GameCommand_modelbug() // TODO: is this even needed?
463 float g_clientmodel_genericsendentity (entity to, float sf);
464 void modelbug_make_svqc();
465 void modelbug_make_csqc()
467 Net_LinkEntity(self, TRUE, 0, g_clientmodel_genericsendentity);
468 self.think = modelbug_make_svqc;
469 self.nextthink = time + 1;
470 setorigin(self, self.origin - '0 0 8');
472 void modelbug_make_svqc()
474 self.SendEntity = func_null;
475 self.think = modelbug_make_csqc;
476 self.nextthink = time + 1;
477 setorigin(self, self.origin + '0 0 8');
483 setorigin(e, nextent(world).origin);
484 precache_model("models_portal.md3");
485 setmodel(e, "models/portal.md3");
486 e.think = modelbug_make_svqc;
487 e.nextthink = time + 1;
491 // =======================
492 // Command Sub-Functions
493 // =======================
495 void GameCommand_adminmsg(float request, float argc)
498 float entno = stof(argv(1));
504 case GC_REQUEST_HELP:
505 print(" ^2adminmsg^7: Send an admin message to a client directly\n");
508 case GC_REQUEST_COMMAND:
509 if(argc >= 3 && argc <= 4) {
510 if((entno < 0) | (entno > maxclients)) {
511 print("Player ", argv(1), " doesn't exist\n");
515 for(i = (entno ? entno : 1); i <= (entno ? entno : maxclients); ++i)
517 client = edict_num(i);
518 if(client.flags & FL_CLIENT)
522 // make the string console safe
524 s = strreplace("\n", "", s);
525 s = strreplace("\\", "\\\\", s);
526 s = strreplace("$", "$$", s);
527 s = strreplace("\"", "\\\"", s);
528 stuffcmd(client, sprintf("\ninfobar %f \"%s\"\n", stof(argv(3)), s));
532 centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
533 sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
535 dprint("Message sent to ", client.netname, "\n");
539 if(!n) { print(strcat("Client (", argv(1) ,") not found.\n")); }
544 print("Incorrect parameters for ^2adminmsg^7\n");
545 case GC_REQUEST_USAGE:
546 print("\nUsage:^3 sv_cmd adminmsg clientnumber \"message\" [infobartime]\n");
547 print(" If infobartime is provided, the message will be sent to infobar.\n");
548 print(" Otherwise, it will just be sent as a centerprint message.\n");
549 print("Examples: adminmsg 4 \"this infomessage will last for ten seconds\" 10\n");
550 print(" adminmsg 2 \"this message will be a centerprint\"\n");
555 void GameCommand_allready(float request)
559 case GC_REQUEST_HELP:
560 print(" ^2allready^7: Restart the server and reset the players\n");
563 case GC_REQUEST_COMMAND:
568 case GC_REQUEST_USAGE:
569 print("\nUsage:^3 sv_cmd allready\n");
570 print(" No arguments required.\n");
575 void GameCommand_allspec(float request, float argc)
582 case GC_REQUEST_HELP:
583 print(" ^2allspec^7: Force all players to spectate\n");
586 case GC_REQUEST_COMMAND:
587 FOR_EACH_PLAYER(client)
590 PutObserverInServer();
593 if(i) { bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (argv(1) ? strcat(" for reason: '", argv(1), "'") : ""), ".\n")); }
594 else { print("No players found to spectate.\n"); }
598 case GC_REQUEST_USAGE:
599 print("\nUsage:^3 sv_cmd allspec [reason]\n");
600 print(" Where 'reason' is an optional argument for explanation of allspec command.\n");
601 print("See also: ^2moveplayer^7\n");
606 void GameCommand_anticheat(float request, float argc) // FIXME: player entity is never found
609 float entno = stof(argv(1));
613 case GC_REQUEST_HELP:
614 print(" ^2anticheat^7: Create an anticheat report for a client\n");
617 case GC_REQUEST_COMMAND:
618 if((entno < 1) | (entno > maxclients)) {
619 print("Player ", argv(1), " doesn't exist\n");
622 client = edict_num(entno);
623 if(clienttype(client) != CLIENTTYPE_REAL && clienttype(client) != CLIENTTYPE_BOT) {
624 print("Player ", client.netname, " is not active\n");
632 print("Incorrect parameters for ^2anticheat^7\n");
633 case GC_REQUEST_USAGE:
634 print("\nUsage:^3 sv_cmd anticheat clientnumber\n");
635 print(" where clientnumber is player entity number.\n");
640 void GameCommand_bbox(float request)
644 case GC_REQUEST_HELP:
645 print(" ^2bbox^7: Print detailed information about world size\n");
648 case GC_REQUEST_COMMAND:
649 print("Original size: ", ftos(world.absmin_x), " ", ftos(world.absmin_y), " ", ftos(world.absmin_z));
650 print(" ", ftos(world.absmax_x), " ", ftos(world.absmax_y), " ", ftos(world.absmax_z), "\n");
651 print("Currently set size: ", ftos(world.mins_x), " ", ftos(world.mins_y), " ", ftos(world.mins_z));
652 print(" ", ftos(world.maxs_x), " ", ftos(world.maxs_y), " ", ftos(world.maxs_z), "\n");
653 print("Solid bounding box size:");
655 tracebox('1 0 0' * world.absmin_x,
656 '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
657 '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
658 '1 0 0' * world.absmax_x,
662 print(" ", ftos(world.absmin_x));
664 print(" ", ftos(trace_endpos_x));
666 tracebox('0 1 0' * world.absmin_y,
667 '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
668 '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
669 '0 1 0' * world.absmax_y,
673 print(" ", ftos(world.absmin_y));
675 print(" ", ftos(trace_endpos_y));
677 tracebox('0 0 1' * world.absmin_z,
678 '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
679 '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
680 '0 0 1' * world.absmax_z,
684 print(" ", ftos(world.absmin_z));
686 print(" ", ftos(trace_endpos_z));
688 tracebox('1 0 0' * world.absmax_x,
689 '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
690 '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
691 '1 0 0' * world.absmin_x,
695 print(" ", ftos(world.absmax_x));
697 print(" ", ftos(trace_endpos_x));
699 tracebox('0 1 0' * world.absmax_y,
700 '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
701 '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
702 '0 1 0' * world.absmin_y,
706 print(" ", ftos(world.absmax_y));
708 print(" ", ftos(trace_endpos_y));
710 tracebox('0 0 1' * world.absmax_z,
711 '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
712 '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
713 '0 0 1' * world.absmin_z,
717 print(" ", ftos(world.absmax_z));
719 print(" ", ftos(trace_endpos_z));
725 case GC_REQUEST_USAGE:
726 print("\nUsage:^3 sv_cmd bbox\n");
727 print(" No arguments required.\n");
728 print("See also: ^2gettaginfo^7\n");
733 void GameCommand_bot_cmd(float request, float argc) // what a mess... old old code.
739 case GC_REQUEST_HELP:
740 print(" ^2bot_cmd^7: Control and send commands to bots\n");
743 case GC_REQUEST_COMMAND:
744 if(argv(1) == "reset")
749 else if(argv(1) == "load" && argc == 3)
753 fh = fopen(argv(2), FILE_READ);
756 print("cannot open the file\n");
761 while((s = fgets(fh)))
763 argc = tokenize_console(s);
765 if(argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
767 // let's start at token 2 so we can skip sv_cmd bot_cmd
768 bot = find_bot_by_number(stof(argv(2)));
770 bot = find_bot_by_name(argv(2));
772 bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
775 localcmd(strcat(s, "\n"));
779 print(ftos(i), " commands read\n");
783 else if(argv(1) == "help")
786 bot_cmdhelp(argv(2));
791 else if(argc >= 3) // this comes last
793 bot = find_bot_by_number(stof(argv(1)));
795 bot = find_bot_by_name(argv(1));
798 print(strcat("Command '", (argv(2), " ", argv(3)), "' sent to bot ", bot.netname, "\n"));
799 bot_queuecommand(bot, strcat(argv(2), " ", argv(3)));
803 print(strcat("Error: Can't find bot with the name or id '", argv(1),"' - Did you mistype the command?\n")); // don't return so that usage is shown
807 print("Incorrect parameters for ^2bot_cmd^7\n");
808 case GC_REQUEST_USAGE:
809 print("\nUsage:^3 sv_cmd bot_cmd client command [argument]\n");
810 print(" 'client' can be either the name or entity id of the bot\n");
811 print(" For full list of commands, see bot_cmd help [command].\n");
812 print("Examples: bot_cmd <id> cc \"say something\"\n");
813 print(" bot_cmd <id> presskey jump\n");
818 void GameCommand_cointoss(float request, float argc)
821 string result1 = (argv(2) ? strcat("^7", argv(1), "^3!\n") : "^1HEADS^3!\n");
822 string result2 = (argv(2) ? strcat("^7", argv(2), "^3!\n") : "^4TAILS^3!\n");
823 string choice = ((random() > 0.5) ? result1 : result2);
827 case GC_REQUEST_HELP:
828 print(" ^2cointoss^7: Flip a virtual coin and give random result\n");
831 case GC_REQUEST_COMMAND:
832 FOR_EACH_CLIENT(client)
833 centerprint(client, strcat("^3Throwing coin... Result: ", choice));
834 bprint(strcat("^3Throwing coin... Result: ", choice));
838 case GC_REQUEST_USAGE:
839 print("\nUsage:^3 sv_cmd cointoss [result1 result2]\n");
840 print(" Where 'result1' and 'result2' are user created options.\n");
845 void GameCommand_cvar_changes(float request)
849 case GC_REQUEST_HELP:
850 print(" ^2cvar_changes^7: Prints a list of all changed server cvars\n");
853 case GC_REQUEST_COMMAND:
858 case GC_REQUEST_USAGE:
859 print("\nUsage:^3 sv_cmd \n");
860 print(" No arguments required.\n");
861 print("See also: ^2cvar_purechanges^7\n");
866 void GameCommand_cvar_purechanges(float request)
870 case GC_REQUEST_HELP:
871 print(" ^2cvar_purechanges^7: Prints a list of all changed gameplay cvars\n");
874 case GC_REQUEST_COMMAND:
875 print(cvar_purechanges);
879 case GC_REQUEST_USAGE:
880 print("\nUsage:^3 sv_cmd cvar_purechanges\n");
881 print(" No arguments required.\n");
882 print("See also: ^2cvar_changes^7\n");
887 void GameCommand_database(float request, float argc)
891 case GC_REQUEST_HELP:
892 print(" ^2database^7: Extra controls of the serverprogs database\n");
895 case GC_REQUEST_COMMAND:
898 if(argv(1) == "save")
900 db_save(ServerProgsDB, argv(2));
901 print(strcat("Copied serverprogs database to '", argv(2), "' in the data directory.\n"));
904 else if(argv(1) == "dump")
906 db_dump(ServerProgsDB, argv(2));
907 print("DB dumped.\n"); // wtf does this do?
910 else if(argv(1) == "load")
912 db_close(ServerProgsDB);
913 ServerProgsDB = db_load(argv(2));
914 print(strcat("Loaded '", argv(2), "' as new serverprogs database.\n"));
920 print("Incorrect parameters for ^2database^7\n");
921 case GC_REQUEST_USAGE:
922 print("\nUsage:^3 sv_cmd database action filename\n");
923 print(" Where 'action' is the command to complete,\n");
924 print(" and 'filename' is what it acts upon.\n");
925 print(" Full list of commands here: \"save, dump, load.\"\n");
930 void GameCommand_defer_clear(float request, float argc)
933 float entno = stof(argv(1));
937 case GC_REQUEST_HELP:
938 print(" ^2defer_clear^7: Clear all queued defer commands for client\n");
941 case GC_REQUEST_COMMAND:
944 // player_id is out of range
945 if((entno < 1) | (entno > maxclients)) {
946 print("Player ", argv(1), " doesn't exist\n");
949 client = edict_num(entno);
950 if not(client.flags & FL_CLIENT) {
951 print("Player ", argv(1), " doesn't exist\n");
954 if(clienttype(client) == CLIENTTYPE_BOT) {
955 print("Player ", argv(1), " (", client.netname, ") is a bot\n");
958 stuffcmd(client, "defer clear\n");
959 print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
964 print("Incorrect parameters for ^2defer_clear^7\n");
965 case GC_REQUEST_USAGE:
966 print("\nUsage:^3 sv_cmd defer_clear clientnumber\n");
967 print(" where 'clientnumber' is player entity number.\n");
968 print("See also: ^2defer_clear_all^7\n");
973 void GameCommand_defer_clear_all(float request)
981 case GC_REQUEST_HELP:
982 print(" ^2defer_clear_all^7: Clear all queued defer commands for all clients\n");
985 case GC_REQUEST_COMMAND:
986 FOR_EACH_CLIENT(client)
988 argc = tokenize_console(strcat("defer_clear ", ftos(num_for_edict(client))));
989 GameCommand_defer_clear(GC_REQUEST_COMMAND, argc);
992 if(i) { bprint(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); } // should a message be added if no players were found?
996 case GC_REQUEST_USAGE:
997 print("\nUsage:^3 sv_cmd defer_clear_all\n");
998 print(" No arguments required.\n");
999 print("See also: ^2defer_clear^7\n");
1004 void GameCommand_delrec(float request, float argc) // UNTESTED // perhaps merge later with records and printstats and such?
1008 case GC_REQUEST_HELP:
1009 print(" ^2delrec^7: Delete race time record for a map\n");
1012 case GC_REQUEST_COMMAND:
1016 race_deleteTime(argv(2), stof(argv(1)));
1018 race_deleteTime(GetMapname(), stof(argv(1)));
1023 print("Incorrect parameters for ^2delrec^7\n");
1024 case GC_REQUEST_USAGE:
1025 print("\nUsage:^3 sv_cmd delrec ranking [map]\n");
1026 print(" 'ranking' is which ranking level to clear up to, \n");
1027 print(" it will clear all records up to nth place.\n");
1028 print(" if 'map' is not provided it will use current map.\n");
1033 void GameCommand_effectindexdump(float request)
1040 case GC_REQUEST_HELP:
1041 print(" ^2effectindexdump^7: Dump list of effects from code and effectinfo.txt\n");
1044 case GC_REQUEST_COMMAND:
1046 print("begin of effects list\n");
1047 db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
1048 db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
1049 db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
1050 db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
1051 db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
1052 db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
1053 db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
1054 db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
1055 db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
1056 db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
1057 db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
1058 db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
1059 db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
1060 db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
1061 db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
1062 db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
1063 db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
1064 db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
1065 db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
1066 db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
1067 db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
1068 db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
1069 db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
1070 db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
1071 db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
1072 db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
1073 db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
1074 db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
1075 db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
1076 db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
1077 db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
1078 db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
1079 db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
1080 db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
1081 db_put(d, "TR_SEEKER", "1"); print("effect TR_SEEKER is ", ftos(particleeffectnum("TR_SEEKER")), "\n");
1082 db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
1084 fh = fopen("effectinfo.txt", FILE_READ);
1085 while((s = fgets(fh)))
1087 tokenize(s); // tokenize_console would hit the loop counter :(
1088 if(argv(0) == "effect")
1090 if(db_get(d, argv(1)) != "1")
1092 if(particleeffectnum(argv(1)) >= 0)
1093 print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
1094 db_put(d, argv(1), "1");
1098 print("end of effects list\n");
1104 case GC_REQUEST_USAGE:
1105 print("\nUsage:^3 sv_cmd effectindexdump\n");
1106 print(" No arguments required.\n");
1111 void GameCommand_extendmatchtime(float request) // todo: Perhaps allows the user to send a specific time to extend it.
1115 case GC_REQUEST_HELP:
1116 print(" ^2extendmatchtime^7: Increase the timelimit value incrementally\n");
1119 case GC_REQUEST_COMMAND:
1120 changematchtime(autocvar_timelimit_increment* 60, autocvar_timelimit_min*60, autocvar_timelimit_max*60);
1124 case GC_REQUEST_USAGE:
1125 print("\nUsage:^3 sv_cmd extendmatchtime\n");
1126 print(" No arguments required.\n");
1127 print("See also: ^2reducematchtime^7\n");
1132 void GameCommand_find(float request, float argc)
1138 case GC_REQUEST_HELP:
1139 print(" ^2find^7: Search through entities for matching classname\n");
1142 case GC_REQUEST_COMMAND:
1143 for(client = world; (client = find(client, classname, argv(1))); )
1144 print(etos(client), "\n");
1148 print("Incorrect parameters for ^2find^7\n");
1149 case GC_REQUEST_USAGE:
1150 print("\nUsage:^3 sv_cmd find classname\n");
1151 print(" Where 'classname' is the classname to search for.\n");
1156 void GameCommand_gametype(float request, float argc)
1159 float t = MapInfo_Type_FromString(s), tsave = MapInfo_CurrentGametype();
1163 case GC_REQUEST_HELP:
1164 print(" ^2gametype^7: Simple command to change the active gametype\n");
1167 case GC_REQUEST_COMMAND:
1170 MapInfo_SwitchGameType(t);
1171 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
1172 if(MapInfo_count > 0)
1173 bprint("Game type successfully switched to ", s, "\n");
1176 bprint("Cannot use this game type: no map for it found\n");
1177 MapInfo_SwitchGameType(tsave);
1178 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
1182 bprint("Game type switch to ", s, " failed: this type does not exist!\n");
1186 print("Incorrect parameters for ^2gametype^7\n");
1187 case GC_REQUEST_USAGE:
1188 print("\nUsage:^3 sv_cmd gametype mode\n");
1189 print(" Where 'mode' is the gametype mode to switch to.\n");
1190 print("See also: ^2gotomap^7\n");
1195 void GameCommand_gettaginfo(float request, float argc) // UNTESTED // todo: finish usage description for it (but, must first learn this shit)
1203 case GC_REQUEST_HELP:
1204 print(" ^2gettaginfo^7: Get specific information about a weapon model\n");
1207 case GC_REQUEST_COMMAND:
1210 tmp_entity = spawn();
1212 setmodel(tmp_entity, (nextent(world)).weaponentity.model);
1215 precache_model(argv(1));
1216 setmodel(tmp_entity, argv(1));
1218 tmp_entity.frame = stof(argv(2));
1219 if(substring(argv(3), 0, 1) == "#")
1220 i = stof(substring(argv(3), 1, -1));
1222 i = gettagindex(tmp_entity, argv(3));
1225 v = gettaginfo(tmp_entity, i);
1226 print("model ", tmp_entity.model, " frame ", ftos(tmp_entity.frame), " tag ", gettaginfo_name);
1227 print(" index ", ftos(i), " parent ", ftos(gettaginfo_parent), "\n");
1228 print(" vector = ", ftos(v_x), " ", ftos(v_y), " ", ftos(v_z), "\n");
1229 print(" offset = ", ftos(gettaginfo_offset_x), " ", ftos(gettaginfo_offset_y), " ", ftos(gettaginfo_offset_z), "\n");
1230 print(" forward = ", ftos(gettaginfo_forward_x), " ", ftos(gettaginfo_forward_y), " ", ftos(gettaginfo_forward_z), "\n");
1231 print(" right = ", ftos(gettaginfo_right_x), " ", ftos(gettaginfo_right_y), " ", ftos(gettaginfo_right_z), "\n");
1232 print(" up = ", ftos(gettaginfo_up_x), " ", ftos(gettaginfo_up_y), " ", ftos(gettaginfo_up_z), "\n");
1236 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
1240 print("bone not found\n");
1247 print("Incorrect parameters for ^2gettaginfo^7\n");
1248 case GC_REQUEST_USAGE:
1249 print("\nUsage:^3 sv_cmd gettaginfo\n");
1250 print(" FIXME: Arguments currently unknown\n");
1251 print("See also: ^2bbox^7\n");
1256 void GameCommand_gotomap(float request, float argc)
1260 case GC_REQUEST_HELP:
1261 print(" ^2gotomap^7: Simple command to switch to another map\n");
1264 case GC_REQUEST_COMMAND:
1267 print(GotoMap(argv(1)), "\n");
1272 print("Incorrect parameters for ^2gotomap^7\n");
1273 case GC_REQUEST_USAGE:
1274 print("\nUsage:^3 sv_cmd gotomap map\n");
1275 print(" Where 'map' is the *.bsp file to change to.\n");
1276 print("See also: ^2gametype^7\n");
1281 void GameCommand_ladder(float request)
1285 case GC_REQUEST_HELP:
1286 print(" ^2ladder^7: Get information about top players if supported\n");
1289 case GC_REQUEST_COMMAND:
1290 print(ladder_reply);
1294 case GC_REQUEST_USAGE:
1295 print("\nUsage:^3 sv_cmd ladder\n");
1296 print(" No arguments required.\n");
1301 void GameCommand_lockteams(float request)
1305 case GC_REQUEST_HELP:
1306 print(" ^2lockteams^7: Disable the ability for players to switch or enter teams\n");
1309 case GC_REQUEST_COMMAND:
1313 bprint("^1The teams are now locked.\n");
1316 bprint("That command can only be used in a team-based gamemode.\n");
1320 case GC_REQUEST_USAGE:
1321 print("\nUsage:^3 sv_cmd lockteams\n");
1322 print(" No arguments required.\n");
1323 print("See also: ^2unlockteams^7\n");
1328 void GameCommand_make_mapinfo(float request) // UNTESTED
1334 case GC_REQUEST_HELP:
1335 print(" ^2make_mapinfo^7: Automatically rebuild mapinfo files\n");
1338 case GC_REQUEST_COMMAND:
1339 tmp_entity = spawn();
1340 tmp_entity.classname = "make_mapinfo";
1341 tmp_entity.think = make_mapinfo_Think;
1342 tmp_entity.nextthink = time; // this sucks... todo: re-write this -- Use initializeentity later
1343 MapInfo_Enumerate();
1347 case GC_REQUEST_USAGE:
1348 print("\nUsage:^3 sv_cmd make_mapinfo\n");
1349 print(" No arguments required.\n");
1354 void GameCommand_modelbug(float request) // UNTESTED // is this even needed anymore?
1358 case GC_REQUEST_HELP:
1359 print(" ^2modelbug^7: foobar\n");
1362 case GC_REQUEST_COMMAND:
1367 case GC_REQUEST_USAGE:
1368 print("\nUsage:^3 sv_cmd modelbug\n");
1369 print(" No arguments required.\n");
1374 void GameCommand_moveplayer(float request, float argc)
1377 string targets = argv(1);
1378 string destination = argv(2);
1379 string notify = argv(3);
1381 argc = tokenizebyseparator(targets, ","); // re-use argc for the targets
1385 case GC_REQUEST_HELP:
1386 print(" ^2moveplayer^7: Change the team/status of a player\n");
1389 case GC_REQUEST_COMMAND:
1390 // lets see if the target(s) even actually exist.
1391 if((targets) && (destination))
1393 for(i = 0; i < argc; ++i)
1395 // Check to see if the player is a valid target
1396 if((stof(argv(i)) < 1) | (stof(argv(i)) > maxclients)) // player_id is out of range
1398 print(strcat("Player ", argv(i), " doesn't exist", (((i + 1) < argc) ? ", skipping to next player.\n" : ".\n")));
1401 client = edict_num(stof(argv(i)));
1402 if not(client.flags & FL_CLIENT) // player entity is not a client
1404 print(strcat("Player ", argv(i), " doesn't exist", (((i + 1) < argc) ? ", skipping to next player.\n" : ".\n")));
1408 // Where are we putting this player?
1409 if(destination == "spec" || destination == "spectator")
1411 if(client.classname != "spectator" && client.classname != "observer")
1414 PutObserverInServer();
1418 print("Player ", argv(i), " (", client.netname, ") is already spectating.\n");
1424 if(client.classname != "spectator" && client.classname != "observer")
1430 float save = client.team_forced;
1431 client.team_forced = 0;
1433 // find the team to move the player to
1434 team_color = ColourToNumber(destination);
1435 if(team_color == client.team) // already on the destination team
1437 // keep the forcing undone
1438 print("Player ", argv(i), " (", client.netname, ") is already on the ", ColoredTeamName(client.team), ".\n");
1441 else if(team_color == 0) // auto team
1443 team_color = NumberToTeamNumber(FindSmallestTeam(client, FALSE));
1447 CheckAllowedTeams(client);
1449 client.team_forced = save;
1451 // Check to see if the destination team is even available
1456 print("Sorry, can't move player to red team if it doesn't exist.\n");
1463 print("Sorry, can't move player to blue team if it doesn't exist.\n");
1470 print("Sorry, can't move player to yellow team if it doesn't exist.\n");
1477 print("Sorry, can't move player to pink team if it doesn't exist.\n");
1483 print("Sorry, can't move player here if team ", destination, " doesn't exist.\n");
1487 // If so, lets continue and finally move the player
1488 client.team_forced = 0;
1489 MoveToTeam(client, team_color, 6, stof(notify));
1490 print("Player ", argv(i), " (", client.netname, ") has been moved to the ", ColoredTeamName(team_color), ".\n");
1495 print("Can't change teams when currently not playing a team game.\n");
1501 print("Can't change teams if the player isn't in the game.\n"); // well technically we could, but should we allow that? :P
1506 print("No acceptable players given, aborting.\n");
1507 return; // still correct parameters so return to avoid usage print
1511 print("Incorrect parameters for ^2moveplayer^7\n");
1512 case GC_REQUEST_USAGE:
1513 print("\nUsage:^3 sv_cmd moveplayer clientnumbers destination [notify]\n");
1514 print(" 'clientnumbers' is a list (separated by commas) of player entity ID's\n");
1515 print(" 'destination' is what to send the player to, be it team or spectating\n");
1516 print(" Full list of destinations here: \"spec, spectator, red, blue, yellow, pink, auto.\"\n");
1517 print(" 'notify' is whether or not to send messages notifying of the move. Detail below.\n");
1518 print(" 0 (00) automove centerprint, admin message; 1 (01) automove centerprint, no admin message\n");
1519 print(" 2 (10) no centerprint, admin message; 3 (11) no centerprint, no admin message\n");
1520 print("Examples: moveplayer 1,3,5 red 3\n");
1521 print(" moveplayer 2 spec \n");
1522 print("See also: ^2allspec^7\n");
1527 void GameCommand_nospectators(float request)
1531 case GC_REQUEST_HELP:
1532 print(" ^2nospectators^7: Automatically remove spectators from a match\n");
1535 case GC_REQUEST_COMMAND:
1536 blockSpectators = 1;
1538 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
1540 if(plr.classname == "spectator" || plr.classname == "observer")
1542 plr.spectatortime = time;
1543 sprint(plr, strcat("^7You have to become a player within the next ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
1546 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n"));
1550 case GC_REQUEST_USAGE:
1551 print("\nUsage:^3 sv_cmd nospectators\n");
1552 print(" No arguments required.\n");
1557 void GameCommand_onslaught_updatelinks(float request) // UNTESTED // should this be here? Perhaps some mutatorhook call instead....
1561 case GC_REQUEST_HELP:
1562 print(" ^2onslaught_updatelinks^7: Refresh link status for onslaught\n");
1565 case GC_REQUEST_COMMAND:
1566 onslaught_updatelinks();
1567 print("ONS links updated\n");
1571 case GC_REQUEST_USAGE:
1572 print("\nUsage:^3 sv_cmd onslaught_updatelinks\n");
1573 print(" No arguments required.\n");
1578 void GameCommand_playerdemo(float request, float argc) // UNTESTED // TODO: change the if statements for sub arguments to switches
1586 case GC_REQUEST_HELP:
1587 print(" ^2playerdemo^7: Control the ability to save demos of players\n");
1590 case GC_REQUEST_COMMAND:
1591 if(argv(1) == "read")
1593 // TODO: Create a general command for looking this up, save a lot of space everywhere in this file
1594 entno = stof(argv(2));
1595 if((entno < 1) | (entno > maxclients)) {
1596 print("Player ", argv(2), " doesn't exist\n");
1599 client = edict_num(entno);
1600 if(clienttype(client) != CLIENTTYPE_BOT) {
1601 print("Player ", client.netname, " is not a bot\n");
1605 playerdemo_open_read(argv(3));
1608 else if(argv(1) == "write")
1610 entno = stof(argv(2));
1611 if((entno < 1) | (entno > maxclients)) {
1612 print("Player ", argv(2), " doesn't exist\n");
1615 client = edict_num(entno);
1617 playerdemo_open_write(argv(3));
1620 else if(argv(1) == "auto_read_and_write")
1624 cvar_set("bot_number", ftos(n));
1625 localcmd("wait; wait; wait\n");
1626 for(i = 0; i < n; ++i)
1627 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1628 localcmd("sv_cmd playerdemo write 1 ", ftos(n+1), "\n");
1631 else if(argv(1) == "auto_read")
1635 cvar_set("bot_number", ftos(n));
1636 localcmd("wait; wait; wait\n");
1637 for(i = 0; i < n; ++i)
1638 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1644 print("Incorrect parameters for ^2radarmap^7\n");
1645 case GC_REQUEST_USAGE:
1646 print("\nUsage:^3 sv_cmd \n");
1647 print(" FIXME: Arguments currently unknown\n");
1652 void GameCommand_printstats(float request)
1656 case GC_REQUEST_HELP:
1657 print(" ^2printstats^7: foobar\n");
1660 case GC_REQUEST_COMMAND:
1662 print("stats dumped.\n");
1666 case GC_REQUEST_USAGE:
1667 print("\nUsage:^3 sv_cmd printstats\n");
1668 print(" No arguments required.\n");
1673 void GameCommand_radarmap(float request, float argc)
1679 case GC_REQUEST_HELP:
1680 print(" ^2radarmap^7: Generate a radar image of the map\n");
1683 case GC_REQUEST_COMMAND:
1686 radarmapper = spawn();
1687 radarmapper.classname = "radarmapper";
1688 radarmapper.think = RadarMap_Think;
1689 radarmapper.nextthink = time;
1690 radarmapper.count = 8; // default to the --trace method, as it is faster now
1691 radarmapper.ltime = 1;
1692 radarmapper.size = '512 512 1';
1694 for(i = 1; i < argc; ++i)
1698 case "--force": { radarmapper.count |= 1; break; }
1699 case "--loop": { radarmapper.count |= 2; break; }
1700 case "--quit": { radarmapper.count |= 4; break; }
1701 case "--block": { radarmapper.count &~= 24; break; }
1702 case "--trace": { radarmapper.count &~= 24; radarmapper.count |= 8; break; }
1703 case "--sample": { radarmapper.count &~= 24; radarmapper.count |= 16; break; }
1704 case "--lineblock": { radarmapper.count |= 24; break; }
1705 case "--flags": { ++i; radarmapper.count = stof(argv(i)); break; } // for the recursive call
1706 case "--sharpen": { ++i; radarmapper.ltime = stof(argv(i)); break; } // for the recursive call
1707 case "--res": // minor alias
1708 case "--resolution": { ++i; radarmapper.size_x = stof(argv(i)); ++i; radarmapper.size_y = stof(argv(i)); break; }
1709 case "--qual": // minor alias
1710 case "--quality": { ++i; radarmapper.size_z = stof(argv(i)); break; }
1714 remove(radarmapper);
1715 radarmapper = world;
1720 if(radarmapper) // after doing the arguments, see if we successfully went forward.
1722 print("Radarmap entity spawned.\n");
1723 return; // if so, don't print usage.
1728 print("Incorrect parameters for ^2radarmap^7\n");
1729 case GC_REQUEST_USAGE:
1730 print("\nUsage:^3 sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]\n");
1731 print(" The quality factor Q is roughly proportional to the time taken.\n");
1732 print(" trace supports no quality factor; its result should look like --block with infinite quality factor.\n");
1737 void GameCommand_rankings(float request) // this is OLD.... jeez.
1741 case GC_REQUEST_HELP:
1742 print(" ^2rankings^7: Print information about rankings\n");
1745 case GC_REQUEST_COMMAND:
1746 strunzone(rankings_reply);
1747 rankings_reply = strzone(getrankings());
1748 print(rankings_reply);
1752 case GC_REQUEST_USAGE:
1753 print("\nUsage:^3 sv_cmd rankings\n");
1754 print(" No arguments required.\n");
1759 void GameCommand_records(float request)
1765 case GC_REQUEST_HELP:
1766 print(" ^2records^7: List top 10 records for the current map\n");
1769 case GC_REQUEST_COMMAND:
1770 for (i = 0; i < 10; ++i)
1771 print(records_reply[i]);
1775 case GC_REQUEST_USAGE:
1776 print("\nUsage:^3 sv_cmd records\n");
1777 print(" No arguments required.\n");
1782 void GameCommand_reducematchtime(float request) // todo: Perhaps allows the user to send a specific time to reduce it.
1786 case GC_REQUEST_HELP:
1787 print(" ^2reducematchtime^7: Decrease the timelimit value incrementally\n");
1790 case GC_REQUEST_COMMAND:
1791 changematchtime(autocvar_timelimit_decrement*-60, autocvar_timelimit_min*60, autocvar_timelimit_max*60);
1795 case GC_REQUEST_USAGE:
1796 print("\nUsage:^3 sv_cmd reducematchtime\n");
1797 print(" No arguments required.\n");
1798 print("See also: ^2extendmatchtime^7\n");
1803 void GameCommand_stuffto(float request, float argc)
1805 // This... is a fairly dangerous and powerful command... - It allows any arguments to be sent to a client via rcon.
1806 // Because of this, it is disabled by default and must be enabled by the server owner when doing compilation. That way,
1807 // we can be certain they understand the risks of it... So to enable, compile server with -DSTUFFTO_ENABLED argument.
1812 #ifdef STUFFTO_ENABLED
1815 case GC_REQUEST_HELP:
1816 print(" ^2stuffto^7: Send a command to be executed on a client\n");
1819 case GC_REQUEST_COMMAND:
1822 entno = stof(argv(1));
1824 if(entno <= maxclients)
1825 client = edict_num(entno);
1826 if(client.flags & FL_CLIENT)
1828 stuffcmd(client, strcat("\n", argv(2), "\n"));
1829 print(strcat("Command: \"", argv(2), "\" sent to ", client.netname, " (", argv(1) ,").\n"));
1832 print(strcat("Client (", argv(1) ,") not found.\n"));
1838 print("Incorrect parameters for ^2stuffto^7\n");
1839 case GC_REQUEST_USAGE:
1840 print("\nUsage:^3 sv_cmd stuffto clientnumber command\n");
1841 print(" FIXME: Arguments currently unknown\n");
1844 #else // give the response for missing command to fake them out ;3
1845 if(request == GC_REQUEST_COMMAND)
1847 print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
1853 void GameCommand_teamstatus(float request)
1857 case GC_REQUEST_HELP:
1858 print(" ^2teamstatus^7: Show information about player and team scores\n");
1861 case GC_REQUEST_COMMAND:
1862 Score_NicePrint(world);
1866 case GC_REQUEST_USAGE:
1867 print("\nUsage:^3 sv_cmd teamstatus\n");
1868 print(" No arguments required.\n");
1873 void GameCommand_time(float request)
1877 case GC_REQUEST_HELP:
1878 print(" ^2time^7: Print different formats/readouts of time\n");
1881 case GC_REQUEST_COMMAND:
1882 print("time = ", ftos(time), "\n");
1883 print("frame start = ", ftos(gettime(GETTIME_FRAMESTART)), "\n");
1884 print("realtime = ", ftos(gettime(GETTIME_REALTIME)), "\n");
1885 print("hires = ", ftos(gettime(GETTIME_HIRES)), "\n");
1886 print("uptime = ", ftos(gettime(GETTIME_UPTIME)), "\n");
1887 print("localtime = ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n"); // FIXME: Why is strftime broken? is engine problem, I think.
1888 print("gmtime = ", strftime(FALSE, "%a %b %e %H:%M:%S %Z %Y"), "\n");
1892 case GC_REQUEST_USAGE:
1893 print("\nUsage:^3 sv_cmd time\n");
1894 print(" No arguments required.\n");
1899 void GameCommand_trace(float request, float argc)
1902 vector org, delta, start, end, p, q, q0, pos, vv, dv;
1903 float i, f, safe, unsafe, dq, dqf;
1905 // TODO: Clean up all of these variables and merge the code below to use only a few
1909 case GC_REQUEST_HELP:
1910 print(" ^2trace^7: Various debugging tools with tracing\n");
1913 case GC_REQUEST_COMMAND:
1917 print("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.\n");
1921 delta = world.maxs - world.mins;
1923 start_x = org_x + random() * delta_x;
1924 start_y = org_y + random() * delta_y;
1925 start_z = org_z + random() * delta_z;
1927 end_x = org_x + random() * delta_x;
1928 end_y = org_y + random() * delta_y;
1929 end_z = org_z + random() * delta_z;
1931 start = stov(vtos(start));
1932 end = stov(vtos(end));
1934 tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1935 if(!trace_startsolid)
1938 tracebox(p, PL_MIN, PL_MAX, p, MOVE_NOMONSTERS, world);
1939 if(trace_startsolid || trace_fraction == 1)
1941 rint(42); // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
1942 tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1943 tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1945 if(trace_startsolid)
1947 // how much do we need to back off?
1952 pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
1953 tracebox(pos, PL_MIN, PL_MAX, pos, MOVE_NOMONSTERS, world);
1954 if(trace_startsolid)
1956 if((safe + unsafe) * 0.5 == unsafe)
1958 unsafe = (safe + unsafe) * 0.5;
1962 if((safe + unsafe) * 0.5 == safe)
1964 safe = (safe + unsafe) * 0.5;
1968 print("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu\n");
1969 print("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu\n");
1971 tracebox(p, PL_MIN + '0.1 0.1 0.1', PL_MAX - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, world);
1972 if(trace_startsolid)
1973 print("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1975 print("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1984 q = p + normalize(end - p) * (dq + dqf);
1987 tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1988 if(trace_startsolid)
1989 error("THIS ONE cannot happen");
1990 if(trace_fraction > 0)
1991 dq += dqf * trace_fraction;
1997 print("trace_endpos still before solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1998 print("could go ", ftos(dq), " units further to ", vtos(q), "\n");
2008 tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
2010 if(trace_fraction == 1)
2012 print("not above ground, aborting\n");
2016 for(i = 0; i < 100000; ++i)
2021 tracebox(vv, e.mins, e.maxs, vv + dv, MOVE_NORMAL, e);
2022 if(trace_startsolid)
2024 if(trace_fraction == 1)
2027 print("bug 2: ", ftos(dv_x), " ", ftos(dv_y), " ", ftos(dv_z));
2028 print(" (", ftos(asin(dv_z / vlen(dv)) * 180 / M_PI), " degrees)\n");
2032 print("highest possible dist: ", ftos(f), "\n");
2039 if(tracewalk(e, stov(argv(1)), e.mins, e.maxs, stov(argv(2)), MOVE_NORMAL))
2040 print("can walk\n");
2042 print("cannot walk\n");
2051 traceline(vv, dv, MOVE_NORMAL, world);
2052 trailparticles(world, particleeffectnum("TR_NEXUIZPLASMA"), vv, trace_endpos);
2053 trailparticles(world, particleeffectnum("TR_CRYLINKPLASMA"), trace_endpos, dv);
2057 // no default case, just go straight to "invalid arguments"
2061 case GC_REQUEST_USAGE:
2062 print("\nUsage:^3 sv_cmd trace command [arguments]\n");
2063 print(" FIXME: Arguments currently unknown\n");
2068 void GameCommand_unlockteams(float request)
2072 case GC_REQUEST_HELP:
2073 print(" ^2unlockteams^7: Enable the ability for players to switch or enter teams\n");
2076 case GC_REQUEST_COMMAND:
2080 bprint("^1The teams are now unlocked.\n");
2083 bprint("That command can only be used in a team-based gamemode.\n");
2087 case GC_REQUEST_USAGE:
2088 print("\nUsage:^3 sv_cmd unlockteams\n");
2089 print(" No arguments required.\n");
2090 print("See also: ^2lockteams^7\n");
2096 // =========================================
2097 // Main Function Called By Engine (sv_cmd)
2098 // =========================================
2100 void GameCommand(string command)
2102 // ===== TODO list =====
2103 // find all FIXME's and TODO'S and UNTESTED'S and finish them :P
2105 float search_request_type;
2106 float argc = tokenize_console(command);
2108 if(argv(0) == "help")
2112 print("\nUsage:^3 sv_cmd COMMAND...^7, where possible commands are:\n");
2113 GameCommand_adminmsg(GC_REQUEST_HELP, 0);
2114 GameCommand_allready(GC_REQUEST_HELP);
2115 GameCommand_allspec(GC_REQUEST_HELP, 0);
2116 GameCommand_anticheat(GC_REQUEST_HELP, 0);
2117 GameCommand_bbox(GC_REQUEST_HELP);
2118 GameCommand_bot_cmd(GC_REQUEST_HELP, 0);
2119 GameCommand_cointoss(GC_REQUEST_HELP, 0);
2120 GameCommand_cvar_changes(GC_REQUEST_HELP);
2121 GameCommand_cvar_purechanges(GC_REQUEST_HELP);
2122 GameCommand_database(GC_REQUEST_HELP, 0);
2123 GameCommand_defer_clear(GC_REQUEST_HELP, 0);
2124 GameCommand_defer_clear_all(GC_REQUEST_HELP);
2125 GameCommand_delrec(GC_REQUEST_HELP, 0);
2126 GameCommand_effectindexdump(GC_REQUEST_HELP);
2127 GameCommand_extendmatchtime(GC_REQUEST_HELP);
2128 GameCommand_find(GC_REQUEST_HELP, 0);
2129 GameCommand_gametype(GC_REQUEST_HELP, 0);
2130 GameCommand_gettaginfo(GC_REQUEST_HELP, 0);
2131 GameCommand_gotomap(GC_REQUEST_HELP, 0);
2132 GameCommand_ladder(GC_REQUEST_HELP);
2133 GameCommand_lockteams(GC_REQUEST_HELP);
2134 GameCommand_make_mapinfo(GC_REQUEST_HELP);
2135 GameCommand_modelbug(GC_REQUEST_HELP);
2136 GameCommand_moveplayer(GC_REQUEST_HELP, 0);
2137 GameCommand_nospectators(GC_REQUEST_HELP);
2138 GameCommand_onslaught_updatelinks(GC_REQUEST_HELP);
2139 GameCommand_playerdemo(GC_REQUEST_HELP, 0);
2140 GameCommand_printstats(GC_REQUEST_HELP);
2141 GameCommand_radarmap(GC_REQUEST_HELP, 0);
2142 GameCommand_rankings(GC_REQUEST_HELP);
2143 GameCommand_records(GC_REQUEST_HELP);
2144 GameCommand_reducematchtime(GC_REQUEST_HELP);
2145 GameCommand_stuffto(GC_REQUEST_HELP, 0);
2146 GameCommand_teamstatus(GC_REQUEST_HELP);
2147 GameCommand_time(GC_REQUEST_HELP);
2148 GameCommand_trace(GC_REQUEST_HELP, 0);
2149 GameCommand_unlockteams(GC_REQUEST_HELP);
2150 GameCommand_Vote("help", world);
2151 GameCommand_Ban("help");
2152 GameCommand_Generic("help");
2153 print("For help about specific commands, type sv_cmd help COMMAND\n");
2157 search_request_type = GC_REQUEST_USAGE; // Instead of trying to call a command, we're going to see detailed information about it
2159 else if(GameCommand_Vote(command, world))
2161 return; // handled by server/vote.qc
2163 else if(GameCommand_Ban(command))
2165 return; // handled by server/ipban.qc
2167 else if(GameCommand_Generic(command))
2169 return; // handled by common/gamecommand.qc
2172 search_request_type = GC_REQUEST_COMMAND; // continue as usual and scan for normal commands
2174 switch( ((argv(0) == "help") ? argv(1) : argv(0)) ) // if first argument is help, then search for the second argument. Else, search for first.
2176 // Do not hard code aliases for these, instead create them in defaultXonotic.cfg
2177 // also: keep in alphabetical order, please ;)
2179 case "adminmsg": GameCommand_adminmsg(search_request_type, argc); break;
2180 case "allready": GameCommand_allready(search_request_type); break;
2181 case "allspec": GameCommand_allspec(search_request_type, argc); break;
2182 case "anticheat": GameCommand_anticheat(search_request_type, argc); break;
2183 case "bbox": GameCommand_bbox(search_request_type); break;
2184 case "bot_cmd": GameCommand_bot_cmd(search_request_type, argc); break;
2185 case "cointoss": GameCommand_cointoss(search_request_type, argc); break;
2186 case "cvar_changes": GameCommand_cvar_changes(search_request_type); break;
2187 case "cvar_purechanges": GameCommand_cvar_purechanges(search_request_type); break;
2188 case "database": GameCommand_database(search_request_type, argc); break;
2189 case "defer_clear": GameCommand_defer_clear(search_request_type, argc); break;
2190 case "defer_clear_all": GameCommand_defer_clear_all(search_request_type); break;
2191 case "delrec": GameCommand_delrec(search_request_type, argc); break;
2192 case "effectindexdump": GameCommand_effectindexdump(search_request_type); break;
2193 case "extendmatchtime": GameCommand_extendmatchtime(search_request_type); break;
2194 case "find": GameCommand_find(search_request_type, argc); break;
2195 case "gametype": GameCommand_gametype(search_request_type, argc); break;
2196 case "gettaginfo": GameCommand_gettaginfo(search_request_type, argc); break;
2197 case "gotomap": GameCommand_gotomap(search_request_type, argc); break;
2198 case "ladder": GameCommand_ladder(search_request_type); break;
2199 case "lockteams": GameCommand_lockteams(search_request_type); break;
2200 case "make_mapinfo": GameCommand_make_mapinfo(search_request_type); break;
2201 case "modelbug": GameCommand_modelbug(search_request_type); break;
2202 case "moveplayer": GameCommand_moveplayer(search_request_type, argc); break;
2203 case "nospectators": GameCommand_nospectators(search_request_type); break;
2204 case "onslaught_updatelinks": GameCommand_onslaught_updatelinks(search_request_type); break;
2205 case "playerdemo": GameCommand_playerdemo(search_request_type, argc); break;
2206 case "printstats": GameCommand_printstats(search_request_type); break;
2207 case "radarmap": GameCommand_radarmap(search_request_type, argc); break;
2208 case "rankings": GameCommand_rankings(search_request_type); break;
2209 case "records": GameCommand_records(search_request_type); break;
2210 case "reducematchtime": GameCommand_reducematchtime(search_request_type); break;
2211 case "stuffto": GameCommand_stuffto(search_request_type, argc); break;
2212 case "teamstatus": GameCommand_teamstatus(search_request_type); break;
2213 case "time": GameCommand_time(search_request_type); break;
2214 case "trace": GameCommand_trace(search_request_type, argc); break;
2215 case "unlockteams": GameCommand_unlockteams(search_request_type); break;
2218 print("Invalid command. For a list of supported commands, try sv_cmd help.\n");