]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/gamecommand.qc
Add gettaginfo command plus add a warning for using incorrect parameters for a command
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / gamecommand.qc
1 string GotoMap(string m);
2 void race_deleteTime(string map, float pos);
3
4 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
5 {
6         vector c;
7         float white, black;
8
9         white = 0.001;
10         black = 0.001;
11
12         c = a;
13
14         float n, m;
15         n = m = 0;
16
17         while(vlen(c - b) > 1)
18         {
19                 ++m;
20
21                 tracebox(c, mi, ma, b, MOVE_WORLDONLY, world);
22                 ++n;
23
24                 if(!trace_startsolid)
25                 {
26                         black += vlen(trace_endpos - c);
27                         c = trace_endpos;
28                 }
29
30                 n += tracebox_inverted(c, mi, ma, b, MOVE_WORLDONLY, world);
31
32                 white += vlen(trace_endpos - c);
33                 c = trace_endpos;
34         }
35
36         if(n > 200)
37                 dprint("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations\n");
38
39         return white / (black + white);
40 }
41
42 float RadarMapAtPoint_Trace(float x, float y, float w, float h, float zmin, float zsize, float q)
43 {
44         vector a, b, mi, ma;
45
46         mi = '0 0 0';
47         ma = '1 0 0' * w + '0 1 0' * h;
48         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
49         b = '1 0 0' * x + '0 1 0' * y + '0 0 1' * (zsize + zmin);
50
51         return FullTraceFraction(a, mi, ma, b);
52 }
53 float RadarMapAtPoint_LineBlock(float x, float y, float w, float h, float zmin, float zsize, float q)
54 {
55         vector o, mi, ma;
56         float i, r;
57         vector dz;
58
59         q = 256 * q - 1;
60         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
61
62         mi = '0 0 0';
63         dz = (zsize / q) * '0 0 1';
64         ma = '1 0 0' * w + '0 1 0' * h + dz;
65         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
66
67         if(x < world.absmin_x - w)
68                 return 0;
69         if(y < world.absmin_y - h)
70                 return 0;
71         if(x > world.absmax_x)
72                 return 0;
73         if(y > world.absmax_y)
74                 return 0;
75
76         r = 0;
77         for(i = 0; i < q; ++i)
78         {
79                 vector v1, v2;
80                 v1 = v2 = o + dz * i + mi;
81                 v1_x += random() * (ma_x - mi_x);
82                 v1_y += random() * (ma_y - mi_y);
83                 v1_z += random() * (ma_z - mi_z);
84                 v2_x += random() * (ma_x - mi_x);
85                 v2_y += random() * (ma_y - mi_y);
86                 v2_z += random() * (ma_z - mi_z);
87                 traceline(v1, v2, MOVE_WORLDONLY, world);
88                 if(trace_startsolid || trace_fraction < 1)
89                         ++r;
90         }
91         return r / q;
92 }
93 float RadarMapAtPoint_Block(float x, float y, float w, float h, float zmin, float zsize, float q)
94 {
95         vector o, mi, ma;
96         float i, r;
97         vector dz;
98
99         q = 256 * q - 1;
100         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
101
102         mi = '0 0 0';
103         dz = (zsize / q) * '0 0 1';
104         ma = '1 0 0' * w + '0 1 0' * h + dz;
105         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
106
107         if(x < world.absmin_x - w)
108                 return 0;
109         if(y < world.absmin_y - h)
110                 return 0;
111         if(x > world.absmax_x)
112                 return 0;
113         if(y > world.absmax_y)
114                 return 0;
115
116         r = 0;
117         for(i = 0; i < q; ++i)
118         {
119                 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
120                 if(trace_startsolid)
121                         ++r;
122         }
123         return r / q;
124 }
125 float RadarMapAtPoint_Sample(float x, float y, float w, float h, float zmin, float zsize, float q)
126 {
127         vector a, b, mi, ma;
128
129         q *= 4; // choose q so it matches the regular algorithm in speed
130
131         q = 256 * q - 1;
132         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
133
134         mi = '0 0 0';
135         ma = '1 0 0' * w + '0 1 0' * h;
136         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
137         b = '1 0 0' * w + '0 1 0' * h + '0 0 1' * zsize;
138
139         float c, i;
140         c = 0;
141
142         for(i = 0; i < q; ++i)
143         {
144                 vector v;
145                 v_x = a_x + random() * b_x;
146                 v_y = a_y + random() * b_y;
147                 v_z = a_z + random() * b_z;
148                 traceline(v, v, MOVE_WORLDONLY, world);
149                 if(trace_startsolid)
150                         ++c;
151         }
152
153         return c / q;
154 }
155
156 // FF is contained twice, to map 256 to FF too
157 // removes the need to bound()
158 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFFFF";
159
160 float RADAR_WIDTH_MAX = 512;
161 float RADAR_HEIGHT_MAX = 512;
162 float sharpen_buffer[RADAR_WIDTH_MAX * 3];
163
164 void sharpen_set(float x, float v)
165 {
166         sharpen_buffer[x + 2 * RADAR_WIDTH_MAX] = v;
167 }
168
169 float sharpen_getpixel(float x, float y)
170 {
171         if(x < 0)
172                 return 0;
173         if(x >= RADAR_WIDTH_MAX)
174                 return 0;
175         if(y < 0)
176                 return 0;
177         if(y > 2)
178                 return 0;
179         return sharpen_buffer[x + y * RADAR_WIDTH_MAX];
180 }
181
182 float sharpen_get(float x, float a)
183 {
184         float sum;
185         sum = sharpen_getpixel(x, 1);
186         if(a == 0)
187                 return sum;
188         sum *= (8 + 1/a);
189         sum -= sharpen_getpixel(x - 1, 0);
190         sum -= sharpen_getpixel(x - 1, 1);
191         sum -= sharpen_getpixel(x - 1, 2);
192         sum -= sharpen_getpixel(x + 1, 0);
193         sum -= sharpen_getpixel(x + 1, 1);
194         sum -= sharpen_getpixel(x + 1, 2);
195         sum -= sharpen_getpixel(x, 0);
196         sum -= sharpen_getpixel(x, 2);
197         return bound(0, sum * a, 1);
198 }
199
200 void sharpen_shift(float w)
201 {
202         float i;
203         for(i = 0; i < w; ++i)
204         {
205                 sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX];
206                 sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX];
207                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
208         }
209 }
210
211 void sharpen_init(float w)
212 {
213         float i;
214         for(i = 0; i < w; ++i)
215         {
216                 sharpen_buffer[i] = 0;
217                 sharpen_buffer[i + RADAR_WIDTH_MAX] = 0;
218                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
219         }
220 }
221
222 entity radarmapper;
223 void RadarMap_Next()
224 {
225         if(radarmapper.count & 4)
226         {
227                 localcmd("quit\n");
228         }
229         else if(radarmapper.count & 2)
230         {
231                 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"));
232                 GotoNextMap();
233         }
234         remove(radarmapper);
235         radarmapper = world;
236 }
237
238 // rough map entity
239 //   cnt: current line
240 //   size: pixel width/height
241 //   maxs: cell width/height
242 //   frame: counter
243 void RadarMap_Think()
244 {
245         float i, x, l;
246         string si;
247
248         if(self.frame == 0)
249         {
250                 // initialize
251                 get_mi_min_max_texcoords(1);
252                 self.mins = mi_picmin;
253                 self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
254                 self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
255                 self.maxs_z = mi_max_z - mi_min_z;
256                 print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
257                 self.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm"));
258                 if(!(self.count & 1))
259                 {
260                         self.cnt = fopen(self.netname, FILE_READ);
261                         if(self.cnt < 0)
262                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ);
263                         if(self.cnt < 0)
264                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ);
265                         if(self.cnt < 0)
266                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ);
267                         if(self.cnt < 0)
268                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ);
269                         if(self.cnt < 0)
270                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ);
271                         if(self.cnt < 0)
272                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ);
273                         if(self.cnt >= 0)
274                         {
275                                 fclose(self.cnt);
276
277                                 print(self.netname, " already exists, aborting (you may want to specify --force)\n");
278                                 RadarMap_Next();
279                                 return;
280                         }
281                 }
282                 self.cnt = fopen(self.netname, FILE_WRITE);
283                 if(self.cnt < 0)
284                 {
285                         print("Error writing ", self.netname, "\n");
286                         remove(self);
287                         radarmapper = world;
288                         return;
289                 }
290                 print("Writing to ", self.netname, "...\n");
291                 fputs(self.cnt, "/* XPM */\n");
292                 fputs(self.cnt, "static char *RadarMap[] = {\n");
293                 fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
294                 fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
295                 for(i = 0; i < 256; ++i)
296                 {
297                         si = substring(doublehex, i*2, 2);
298                         fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
299                 }
300                 self.frame += 1;
301                 self.nextthink = time;
302                 sharpen_init(self.size_x);
303         }
304         else if(self.frame <= self.size_y)
305         {
306                 // fill the sharpen buffer with this line
307                 sharpen_shift(self.size_x);
308                 i = self.count & 24;
309
310                 switch(i)
311                 {
312                         case 0:
313                         default:
314                                 for(x = 0; x < self.size_x; ++x)
315                                 {
316                                         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);
317                                         sharpen_set(x, l);
318                                 }
319                                 break;
320                         case 8:
321                                 for(x = 0; x < self.size_x; ++x)
322                                 {
323                                         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);
324                                         sharpen_set(x, l);
325                                 }
326                                 break;
327                         case 16:
328                                 for(x = 0; x < self.size_x; ++x)
329                                 {
330                                         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);
331                                         sharpen_set(x, l);
332                                 }
333                                 break;
334                         case 24:
335                                 for(x = 0; x < self.size_x; ++x)
336                                 {
337                                         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);
338                                         sharpen_set(x, l);
339                                 }
340                                 break;
341                 }
342
343                 // do we have enough lines?
344                 if(self.frame >= 2)
345                 {
346                         // write a pixel line
347                         fputs(self.cnt, "\"");
348                         for(x = 0; x < self.size_x; ++x)
349                         {
350                                 l = sharpen_get(x, self.ltime);
351                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
352                         }
353                         if(self.frame == self.size_y)
354                                 fputs(self.cnt, "\"\n");
355                         else
356                         {
357                                 fputs(self.cnt, "\",\n");
358                                 print(ftos(self.size_y - self.frame), " lines left\n");
359                         }
360                 }
361
362                 // is this the last line? then write back the missing line
363                 if(self.frame == self.size_y)
364                 {
365                         sharpen_shift(self.size_x);
366                         // write a pixel line
367                         fputs(self.cnt, "\"");
368                         for(x = 0; x < self.size_x; ++x)
369                         {
370                                 l = sharpen_get(x, self.ltime);
371                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
372                         }
373                         if(self.frame == self.size_y)
374                                 fputs(self.cnt, "\"\n");
375                         else
376                         {
377                                 fputs(self.cnt, "\",\n");
378                                 print(ftos(self.size_y - self.frame), " lines left\n");
379                         }
380                 }
381
382                 self.frame += 1;
383                 self.nextthink = time;
384         }
385         else
386         {
387                 // close the file
388                 fputs(self.cnt, "};\n");
389                 fclose(self.cnt);
390                 print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the gfx folder.\n");
391                 RadarMap_Next();
392         }
393 }
394
395 void RadarMap(float argc)
396 {
397         if(radarmapper)
398                 return;
399         float i;
400         radarmapper = spawn();
401         radarmapper.classname = "radarmapper";
402         radarmapper.think = RadarMap_Think;
403         radarmapper.nextthink = time;
404         radarmapper.count = 8; // default to the --trace method, as it is faster now
405         radarmapper.ltime = 1;
406         radarmapper.size_x = 512;
407         radarmapper.size_y = 512;
408         radarmapper.size_z = 1;
409
410         for(i = 1; i < argc; ++i)
411         {
412                 if(argv(i) == "--force")
413                         radarmapper.count |= 1;
414                 else if(argv(i) == "--loop")
415                         radarmapper.count |= 2;
416                 else if(argv(i) == "--quit")
417                         radarmapper.count |= 4;
418                 else if(argv(i) == "--block")
419                 {
420                         radarmapper.count &~= 24;
421                 }
422                 else if(argv(i) == "--trace")
423                 {
424                         radarmapper.count &~= 24;
425                         radarmapper.count |= 8;
426                 }
427                 else if(argv(i) == "--sample")
428                 {
429                         radarmapper.count &~= 24;
430                         radarmapper.count |= 16;
431                 }
432                 else if(argv(i) == "--lineblock")
433                 {
434                         radarmapper.count |= 24;
435                 }
436                 else if(argv(i) == "--flags") // for the recursive call
437                 {
438                         ++i;
439                         radarmapper.count = stof(argv(i));
440                 }
441                 else if(argv(i) == "--sharpen") // for the recursive call
442                 {
443                         ++i;
444                         radarmapper.ltime = stof(argv(i));
445                 }
446                 else if(argv(i) == "--res") // resolution
447                 {
448                         ++i;
449                         radarmapper.size_x = stof(argv(i));
450                         ++i;
451                         radarmapper.size_y = stof(argv(i));
452                 }
453                 else if(argv(i) == "--qual") // quality multiplier
454                 {
455                         ++i;
456                         radarmapper.size_z = stof(argv(i));
457                 }
458                 else
459                 {
460                         remove(radarmapper);
461                         radarmapper = world;
462                         print("Usage: sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]\n");
463                         print("The quality factor Q is roughly proportional to the time taken.\n");
464                         print("--trace supports no quality factor; its result should look like --block with infinite quality factor.\n");
465                         print("--block \n");
466                         return;
467                 }
468         }
469
470         print("Radarmap entity spawned.\n");
471 }
472
473 void make_mapinfo_Think()
474 {
475         if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
476         {
477                 print("Done rebuiling mapinfos.\n");
478                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
479                 remove(self);
480         }
481         else
482         {
483                 self.think = make_mapinfo_Think;
484                 self.nextthink = time;
485         }
486 }
487
488 void changematchtime(float delta, float mi, float ma)
489 {
490         float cur;
491         float new;
492         float lim;
493
494         if(delta == 0)
495                 return;
496         if(autocvar_timelimit < 0)
497                 return;
498
499         if(mi <= 10)
500                 mi = 10; // at least ten sec in the future
501         cur = time - game_starttime;
502         if(cur > 0)
503                 mi += cur; // from current time!
504
505         lim = autocvar_timelimit * 60;
506
507         if(delta > 0)
508         {
509                 if(lim == 0)
510                         return; // cannot increase any further
511                 else if(lim < ma)
512                         new = min(ma, lim + delta);
513                 else // already above maximum: FAIL
514                         return;
515         }
516         else
517         {
518                 if(lim == 0) // infinite: try reducing to max, if we are allowed to
519                         new = max(mi, ma);
520                 else if(lim > mi) // above minimum: decrease
521                         new = max(mi, lim + delta);
522                 else // already below minimum: FAIL
523                         return;
524         }
525
526         cvar_set("timelimit", ftos(new / 60));
527 }
528
529 float g_clientmodel_genericsendentity (entity to, float sf);
530 void modelbug_make_svqc();
531 void modelbug_make_csqc()
532 {
533         Net_LinkEntity(self, TRUE, 0, g_clientmodel_genericsendentity);
534         self.think = modelbug_make_svqc;
535         self.nextthink = time + 1;
536         setorigin(self, self.origin - '0 0 8');
537 }
538 void modelbug_make_svqc()
539 {
540         self.SendEntity = func_null;
541         self.think = modelbug_make_csqc;
542         self.nextthink = time + 1;
543         setorigin(self, self.origin + '0 0 8');
544 }
545
546 void modelbug()
547 {
548         entity e;
549         e = spawn();
550         setorigin(e, nextent(world).origin);
551         precache_model("models_portal.md3");
552         setmodel(e, "models/portal.md3");
553         e.think = modelbug_make_svqc;
554         e.nextthink = time + 1;
555 }
556
557 // ===================
558 //  Command Functions
559 // ===================
560 #define GC_REQUEST_HELP 1
561 #define GC_REQUEST_COMMAND 2
562 #define GC_REQUEST_USAGE 3
563
564 void GameCommand_adminmsg(float request, string command)
565 {
566         entity client;
567         float argc = tokenize_console(command);
568         float entno = stof(argv(1)); 
569         float n, i;
570         string s;
571         
572         switch(request)
573         {
574                 case GC_REQUEST_HELP:
575                         print("  adminmsg - Send an admin message to a client directly\n");
576                         return;
577                         
578                 case GC_REQUEST_COMMAND:
579                         if(argc >= 3 && argc <= 4) {
580                                 if((entno < 0) | (entno > maxclients)) {
581                                         print("Player ", argv(1), " doesn't exist\n");
582                                         return;
583                                 }
584                                 n = 0;
585                                 for(i = (entno ? entno : 1); i <= (entno ? entno : maxclients); ++i)
586                                 {
587                                         client = edict_num(i);
588                                         if(client.flags & FL_CLIENT)
589                                         {
590                                                 if(argc == 4)
591                                                 {
592                                                         s = argv(2);
593                                                         s = strreplace("\n", "", s);
594                                                         s = strreplace("\\", "\\\\", s);
595                                                         s = strreplace("$", "$$", s);
596                                                         s = strreplace("\"", "\\\"", s);
597                                                         stuffcmd(client, sprintf("\ninfobar %f \"%s\"\n", stof(argv(3)), s));
598                                                 }
599                                                 else
600                                                 {
601                                                         centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
602                                                         sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
603                                                 }
604                                                 dprint("Message sent to ", client.netname, "\n");
605                                                 ++n;
606                                         }
607                                 }
608                                 if(!n) { print("Client not found\n"); } 
609                                 return;
610                         } 
611                         
612                 default:
613                         print("Incorrect parameters for \"adminmsg\"\n");
614                 case GC_REQUEST_USAGE:
615                         print("\nUsage: sv_cmd adminmsg clientnumber \"message\" [infobartime]\n");
616                         print("  If infobartime is provided, the message will be sent to infobar.\n");
617                         print("  Otherwise, it will just be sent as a centerprint message.\n");
618                         print("Examples: adminmsg 4 \"this message will last for ten seconds\" 10\n");
619                         print("          adminmsg 2 \"this message will be a centerprint\"\n");
620                         return;
621         }
622 }
623
624 void GameCommand_allready(float request)
625 {
626         switch(request)
627         {
628                 case GC_REQUEST_HELP:
629                         print("  allready - Restart the server and reset the players\n");
630                         return;
631                         
632                 case GC_REQUEST_COMMAND:
633                         ReadyRestart();
634                         return;
635                         
636                 default:
637                 case GC_REQUEST_USAGE:
638                         print("\nUsage: sv_cmd allready\n");
639                         print("  No arguments required.\n");
640                         return;
641         }
642 }
643
644 void GameCommand_allspec(float request) // todo: Add ability to provide a reason string
645 {
646         entity client;
647         float i;
648         switch(request)
649         {
650                 case GC_REQUEST_HELP:
651                         print("  allspec - Force all players to spectate\n");
652                         return;
653                         
654                 case GC_REQUEST_COMMAND:
655                         FOR_EACH_PLAYER(client)
656                         {
657                                 PutObserverInServer();
658                                 ++i;
659                         }
660                         if(i) { bprint(strcat("Successfully forced all players to spectate (", ftos(i), ")\n")); } // should a message be added if no players were found? 
661                         return;
662                         
663                 default:
664                 case GC_REQUEST_USAGE:
665                         print("\nUsage: sv_cmd allspec\n");
666                         print("  No arguments required.\n");
667                         return;
668         }
669 }
670
671 void GameCommand_anticheat(float request, string command) // FIXME: player entity is never found
672 {
673         entity client;
674         float argc = tokenize_console(command);
675         float entno = stof(argv(1)); 
676         
677         switch(request)
678         {
679                 case GC_REQUEST_HELP:
680                         print("  anticheat - Create an anticheat report for a client\n");
681                         return;
682                         
683                 case GC_REQUEST_COMMAND:
684                         if((entno < 1) | (entno > maxclients)) {
685                                 print("Player ", argv(1), " doesn't exist\n");
686                                 return;
687                         }
688                         client = edict_num(entno);
689                         if(clienttype(client) != CLIENTTYPE_REAL && clienttype(client) != CLIENTTYPE_BOT) {
690                                 print("Player ", client.netname, " is not active\n");
691                                 return;
692                         }
693                         self = client;
694                         anticheat_report();
695                         return;
696                         
697                 default:
698                         print("Incorrect parameters for \"anticheat\"\n");
699                 case GC_REQUEST_USAGE:
700                         print("\nUsage: sv_cmd anticheat clientnumber\n");
701                         print("  where clientnumber is player entity number.\n");
702                         return;
703         }
704 }
705
706 void GameCommand_bbox(float request)
707 {
708         switch(request)
709         {
710                 case GC_REQUEST_HELP:
711                         print("  bbox - Print detailed information about world size\n");
712                         return;
713                         
714                 case GC_REQUEST_COMMAND:
715                         print("Original size: ", ftos(world.absmin_x), " ", ftos(world.absmin_y), " ", ftos(world.absmin_z));
716                         print(" ", ftos(world.absmax_x), " ", ftos(world.absmax_y), " ", ftos(world.absmax_z), "\n");
717                         print("Currently set size: ", ftos(world.mins_x), " ", ftos(world.mins_y), " ", ftos(world.mins_z));
718                         print(" ", ftos(world.maxs_x), " ", ftos(world.maxs_y), " ", ftos(world.maxs_z), "\n");
719                         print("Solid bounding box size:");
720
721                         tracebox('1 0 0' * world.absmin_x,
722                                                         '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
723                                                         '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
724                                                         '1 0 0' * world.absmax_x,
725                                         MOVE_WORLDONLY,
726                                         world);
727                         if(trace_startsolid)
728                                 print(" ", ftos(world.absmin_x));
729                         else
730                                 print(" ", ftos(trace_endpos_x));
731
732                         tracebox('0 1 0' * world.absmin_y,
733                                                         '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
734                                                         '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
735                                                         '0 1 0' * world.absmax_y,
736                                         MOVE_WORLDONLY,
737                                         world);
738                         if(trace_startsolid)
739                                 print(" ", ftos(world.absmin_y));
740                         else
741                                 print(" ", ftos(trace_endpos_y));
742
743                         tracebox('0 0 1' * world.absmin_z,
744                                                         '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
745                                                         '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
746                                                         '0 0 1' * world.absmax_z,
747                                         MOVE_WORLDONLY,
748                                         world);
749                         if(trace_startsolid)
750                                 print(" ", ftos(world.absmin_z));
751                         else
752                                 print(" ", ftos(trace_endpos_z));
753
754                         tracebox('1 0 0' * world.absmax_x,
755                                                         '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
756                                                         '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
757                                                         '1 0 0' * world.absmin_x,
758                                         MOVE_WORLDONLY,
759                                         world);
760                         if(trace_startsolid)
761                                 print(" ", ftos(world.absmax_x));
762                         else
763                                 print(" ", ftos(trace_endpos_x));
764
765                         tracebox('0 1 0' * world.absmax_y,
766                                                         '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
767                                                         '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
768                                                         '0 1 0' * world.absmin_y,
769                                         MOVE_WORLDONLY,
770                                         world);
771                         if(trace_startsolid)
772                                 print(" ", ftos(world.absmax_y));
773                         else
774                                 print(" ", ftos(trace_endpos_y));
775
776                         tracebox('0 0 1' * world.absmax_z,
777                                                         '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
778                                                         '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
779                                                         '0 0 1' * world.absmin_z,
780                                         MOVE_WORLDONLY,
781                                         world);
782                         if(trace_startsolid)
783                                 print(" ", ftos(world.absmax_z));
784                         else
785                                 print(" ", ftos(trace_endpos_z));
786                                 
787                         print("\n");
788                         return;
789                         
790                 default:
791                 case GC_REQUEST_USAGE:
792                         print("\nUsage: sv_cmd bbox\n");
793                         print("  No arguments required.\n");
794                         return;
795         }
796 }
797
798 void GameCommand_bot_cmd(float request, string command) // what a mess... old old code.
799 {
800         entity bot;
801         float argc = tokenize_console(command);
802         
803         switch(request)
804         {
805                 case GC_REQUEST_HELP:
806                         print("  bot_cmd - Control and send commands to bots\n");
807                         return;
808                         
809                 case GC_REQUEST_COMMAND:
810                         if(argv(1) == "reset")
811                         {
812                                 bot_resetqueues();
813                                 return;
814                         }
815                         else if(argv(1) == "load" && argc == 3)
816                         {
817                                 float fh, i;
818                                 string s;
819                                 fh = fopen(argv(2), FILE_READ);
820                                 if(fh < 0)
821                                 {
822                                         print("cannot open the file\n");
823                                         return;
824                                 }
825
826                                 i = 0;
827                                 while((s = fgets(fh)))
828                                 {
829                                         argc = tokenize_console(s);
830
831                                         if(argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
832                                         {
833                                                 // let's start at token 2 so we can skip sv_cmd bot_cmd
834                                                 bot = find_bot_by_number(stof(argv(2)));
835                                                 if(bot == world)
836                                                         bot = find_bot_by_name(argv(2));
837                                                 if(bot)
838                                                         bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
839                                         }
840                                         else
841                                                 localcmd(strcat(s, "\n"));
842
843                                         ++i;
844                                 }
845                                 print(ftos(i), " commands read\n");
846                                 fclose(fh);
847                                 return;
848                         }
849                         else if(argv(1) == "help")
850                         {
851                                 if(argv(2))
852                                         bot_cmdhelp(argv(2));
853                                 else
854                                         bot_list_commands();
855                                 return;
856                         }
857                         else if(argc >= 3) // this comes last
858                         {
859                                 bot = find_bot_by_number(stof(argv(1)));
860                                 if(bot == world)
861                                         bot = find_bot_by_name(argv(1));
862                                 if(bot)
863                                 {
864                                         print(strcat("Command '", (argv(2), " ", argv(3)), "' sent to bot ", bot.netname, "\n"));
865                                         bot_queuecommand(bot, strcat(argv(2), " ", argv(3)));
866                                         return;
867                                 }
868                                 else
869                                         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
870                         }
871                         
872                 default:
873                         print("Incorrect parameters for \"bot_cmd\"\n");
874                 case GC_REQUEST_USAGE:
875                         print("\nUsage: sv_cmd bot_cmd client command [argument]\n");
876                         print("  'client' can be either the name or entity id of the bot\n");
877                         print("  For full list of commands, see bot_cmd help [command].\n");
878                         print("Examples: bot_cmd <id> cc \"say something\"\n");
879                         print("          bot_cmd <id> presskey jump\n");
880                         return;
881         }
882 }
883
884 void GameCommand_cointoss(float request) // todo: Perhaps add the ability to give your own arguments to pick between? (Like player names)
885 {
886         entity client;
887         float choice = (random() > 0.5);
888         
889         switch(request)
890         {
891                 case GC_REQUEST_HELP:
892                         print("  cointoss - Flip a virtual coin and give random result\n");
893                         return;
894                         
895                 case GC_REQUEST_COMMAND:
896                         FOR_EACH_CLIENT(client)
897                                 centerprint(client, strcat("^3Throwing coin... Result: ", (choice ? "^1HEADS^3!\n" : "^4TAILS^3!\n")));
898                         bprint(strcat("^3Throwing coin... Result: ", (choice ? "^1HEADS^3!\n" : "^4TAILS^3!\n")));
899                         return;
900                         
901                 default:
902                 case GC_REQUEST_USAGE:
903                         print("\nUsage: sv_cmd cointoss\n");
904                         print("  No arguments required.\n");
905                         return;
906         }
907 }
908
909 void GameCommand_cvar_changes(float request)
910 {
911         switch(request)
912         {
913                 case GC_REQUEST_HELP:
914                         print("  cvar_changes - Prints a list of all changed server cvars\n");
915                         return;
916                         
917                 case GC_REQUEST_COMMAND:
918                         print(cvar_changes);
919                         return;
920                         
921                 default:
922                 case GC_REQUEST_USAGE:
923                         print("\nUsage: sv_cmd \n");
924                         print("  No arguments required.\n");
925                         return;
926         }
927 }
928
929 void GameCommand_cvar_purechanges(float request)
930 {
931         switch(request)
932         {
933                 case GC_REQUEST_HELP:
934                         print("  cvar_purechanges - Prints a list of all changed gameplay cvars\n");
935                         return;
936                         
937                 case GC_REQUEST_COMMAND:
938                         print(cvar_purechanges);
939                         return;
940                         
941                 default:
942                 case GC_REQUEST_USAGE:
943                         print("\nUsage: sv_cmd cvar_purechanges\n");
944                         print("  No arguments required.\n");
945                         return;
946         }
947 }
948
949 void GameCommand_database(float request, string command)
950 {
951         float argc = tokenize_console(command);
952         
953         switch(request)
954         {
955                 case GC_REQUEST_HELP:
956                         print("  database - Extra controls of the serverprogs database\n");
957                         return;
958                         
959                 case GC_REQUEST_COMMAND:
960                         if(argc == 3)
961                         {
962                                 if(argv(1) == "save")
963                                 {
964                                         db_save(ServerProgsDB, argv(2));
965                                         print(strcat("Copied serverprogs database to '", argv(2), "' in the data directory.\n"));
966                                         return;
967                                 }
968                                 else if(argv(1) == "dump")
969                                 {
970                                         db_dump(ServerProgsDB, argv(2));
971                                         print("DB dumped.\n"); // wtf does this do?
972                                         return;
973                                 }
974                                 else if(argv(1) == "load")
975                                 {
976                                         db_close(ServerProgsDB);
977                                         ServerProgsDB = db_load(argv(2));
978                                         print(strcat("Loaded '", argv(2), "' as new serverprogs database.\n"));
979                                         return;
980                                 }
981                         }
982                         
983                 default:
984                         print("Incorrect parameters for \"database\"\n");
985                 case GC_REQUEST_USAGE:
986                         print("\nUsage: sv_cmd database action filename\n");
987                         print("  Where action is the command to complete,\n");
988                         print("  and filename is what it acts upon.\n");
989                         print("  Full list of commands here: \"save, dump, load.\"\n");
990                         return;
991         }
992 }
993
994 void GameCommand_defer_clear(float request, string command)
995 {
996         entity client;
997         float argc = tokenize_console(command);
998         float entno = stof(argv(1));
999         
1000         switch(request)
1001         {
1002                 case GC_REQUEST_HELP:
1003                         print("  defer_clear - Clear all queued defer commands for client\n");
1004                         return;
1005                         
1006                 case GC_REQUEST_COMMAND:
1007                         if(argc == 2)
1008                         {
1009                                 // player_id is out of range
1010                                 if((entno < 1) | (entno > maxclients)) {
1011                                         print("Player ", argv(1), " doesn't exist\n");
1012                                         return;
1013                                 }
1014                                 client = edict_num(entno);
1015                                 if not(client.flags & FL_CLIENT) {
1016                                         print("Player ", argv(1), " doesn't exist\n");
1017                                         return;
1018                                 }
1019                                 if(clienttype(client) == CLIENTTYPE_BOT) {
1020                                         print("Player ", argv(1), " (", client.netname, ") is a bot\n");
1021                                         return;
1022                                 }
1023                                 stuffcmd(client, "defer clear\n");
1024                                 print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
1025                                 return;
1026                         }
1027                 
1028                 default:
1029                         print("Incorrect parameters for \"defer_clear\"\n");
1030                 case GC_REQUEST_USAGE:
1031                         print("\nUsage: sv_cmd defer_clear clientnumber\n");
1032                         print("  where clientnumber is player entity number.\n");
1033                         return;
1034         }
1035 }
1036
1037 void GameCommand_defer_clear_all(float request)
1038 {
1039         entity client;
1040         float i;
1041         
1042         switch(request)
1043         {
1044                 case GC_REQUEST_HELP:
1045                         print("  defer_clear_all - Clear all queued defer commands for all clients\n");
1046                         return;
1047                         
1048                 case GC_REQUEST_COMMAND:
1049                         FOR_EACH_CLIENT(client)
1050                         {
1051                                 GameCommand_defer_clear(GC_REQUEST_COMMAND, strcat("defer_clear ", ftos(num_for_edict(client))));       
1052                                 ++i;
1053                         }
1054                         if(i) { bprint(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); } // should a message be added if no players were found? 
1055                         return;
1056                 
1057                 default:
1058                 case GC_REQUEST_USAGE:
1059                         print("\nUsage: sv_cmd defer_clear_all\n");
1060                         print("  No arguments required.\n");
1061                         return;
1062         }
1063 }
1064
1065 void GameCommand_delrec(float request, string command) // UNTESTED
1066 {
1067         float argc = tokenize_console(command);
1068
1069         switch(request)
1070         {
1071                 case GC_REQUEST_HELP:
1072                         print("  delrec - Delete race time record for a map\n");
1073                         return;
1074                         
1075                 case GC_REQUEST_COMMAND:
1076                         if(argv(1))
1077                         {
1078                                 if(argv(2))
1079                                         race_deleteTime(argv(2), stof(argv(1)));
1080                                 else
1081                                         race_deleteTime(GetMapname(), stof(argv(1)));
1082                                 return;
1083                         }
1084                         
1085                 default:
1086                         print("Incorrect parameters for \"delrec\"\n");
1087                 case GC_REQUEST_USAGE:
1088                         print("\nUsage: sv_cmd delrec ranking [map]\n");
1089                         print("  ranking is which ranking level to clear up to, \n");
1090                         print("  it will clear all records up to nth place.\n");
1091                         print("  if map is not provided it will use current map.\n");
1092                         return;
1093         }
1094 }
1095
1096 void GameCommand_effectindexdump(float request)
1097 {
1098         float fh, d;
1099         string s;
1100         
1101         switch(request)
1102         {
1103                 case GC_REQUEST_HELP:
1104                         print("  effectindexdump - Dump list of effects from code and effectinfo.txt\n");
1105                         return;
1106                         
1107                 case GC_REQUEST_COMMAND:
1108                         d = db_create();
1109                         print("begin of effects list\n");
1110                         db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
1111                         db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
1112                         db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
1113                         db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
1114                         db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
1115                         db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
1116                         db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
1117                         db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
1118                         db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
1119                         db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
1120                         db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
1121                         db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
1122                         db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
1123                         db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
1124                         db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
1125                         db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
1126                         db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
1127                         db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
1128                         db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
1129                         db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
1130                         db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
1131                         db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
1132                         db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
1133                         db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
1134                         db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
1135                         db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
1136                         db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
1137                         db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
1138                         db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
1139                         db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
1140                         db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
1141                         db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
1142                         db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
1143                         db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
1144                         db_put(d, "TR_SEEKER", "1"); print("effect TR_SEEKER is ", ftos(particleeffectnum("TR_SEEKER")), "\n");
1145                         db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
1146
1147                         fh = fopen("effectinfo.txt", FILE_READ);
1148                         while((s = fgets(fh)))
1149                         {
1150                                 tokenize(s); // tokenize_console would hit the loop counter :(
1151                                 if(argv(0) == "effect")
1152                                 {
1153                                         if(db_get(d, argv(1)) != "1")
1154                                         {
1155                                                 if(particleeffectnum(argv(1)) >= 0)
1156                                                         print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
1157                                                 db_put(d, argv(1), "1");
1158                                         }
1159                                 }
1160                         }
1161                         print("end of effects list\n");
1162
1163                         db_close(d);
1164                         return;
1165                         
1166                 default:
1167                 case GC_REQUEST_USAGE:
1168                         print("\nUsage: sv_cmd effectindexdump\n");
1169                         print("  No arguments required.\n");
1170                         return;
1171         }
1172 }
1173
1174 void GameCommand_extendmatchtime(float request) // todo: Perhaps allows the user to send a specific time to extend it.
1175 {
1176         switch(request)
1177         {
1178                 case GC_REQUEST_HELP:
1179                         print("  extendmatchtime - Increase the timelimit value incrementally\n");
1180                         return;
1181                         
1182                 case GC_REQUEST_COMMAND:
1183                         changematchtime(autocvar_timelimit_increment* 60, autocvar_timelimit_min*60, autocvar_timelimit_max*60);
1184                         return;
1185                         
1186                 default:
1187                 case GC_REQUEST_USAGE:
1188                         print("\nUsage: sv_cmd extendmatchtime\n");
1189                         print("  No arguments required.\n");
1190                         return;
1191         }
1192 }
1193
1194 void GameCommand_find(float request, string command)
1195 {
1196         entity client;
1197         float argc = tokenize_console(command);
1198         
1199         switch(request)
1200         {
1201                 case GC_REQUEST_HELP:
1202                         print("  find - Search through entities for matching classname\n");
1203                         return;
1204                         
1205                 case GC_REQUEST_COMMAND:
1206                         for(client = world; (client = find(client, classname, argv(1))); )
1207                                 print(etos(client), "\n");
1208                         return;
1209                         
1210                 default:
1211                         print("Incorrect parameters for \"find\"\n");
1212                 case GC_REQUEST_USAGE:
1213                         print("\nUsage: sv_cmd find classname\n");
1214                         print("  Where classname is the classname to search for.\n");
1215                         return;
1216         }
1217 }
1218
1219 void GameCommand_gametype(float request, string command)
1220 {
1221         float argc = tokenize_console(command);
1222         string s = argv(1);
1223         float t = MapInfo_Type_FromString(s), tsave = MapInfo_CurrentGametype();
1224         
1225         switch(request)
1226         {
1227                 case GC_REQUEST_HELP:
1228                         print("  gametype - Simple command to change the active gametype\n");
1229                         return;
1230                         
1231                 case GC_REQUEST_COMMAND:
1232                         if(t)
1233                         {
1234                                 MapInfo_SwitchGameType(t);
1235                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
1236                                 if(MapInfo_count > 0)
1237                                         bprint("Game type successfully switched to ", s, "\n");
1238                                 else
1239                                 {
1240                                         bprint("Cannot use this game type: no map for it found\n");
1241                                         MapInfo_SwitchGameType(tsave);
1242                                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
1243                                 }
1244                         }
1245                         else
1246                                 bprint("Game type switch to ", s, " failed: this type does not exist!\n");
1247                         return;
1248                         
1249                 default:
1250                         print("Incorrect parameters for \"gametype\"\n");
1251                 case GC_REQUEST_USAGE:
1252                         print("\nUsage: sv_cmd gametype mode\n");
1253                         print("  Where mode is the gametype mode to switch to.\n");
1254                         return;
1255         }
1256 }
1257
1258 void GameCommand_gettaginfo(float request, string command) // UNTESTED // todo: finish usage description for it (but, must first learn this shit)
1259 {
1260         entity tmp_entity;
1261         float argc = tokenize_console(command), i;
1262         vector v;
1263         switch(request)
1264         {
1265                 case GC_REQUEST_HELP:
1266                         print("  gettaginfo - Get specific information about a weapon model\n");
1267                         return;
1268                         
1269                 case GC_REQUEST_COMMAND:
1270                         if(argc >= 4)
1271                         {
1272                                 tmp_entity = spawn();
1273                                 if(argv(1) == "w")
1274                                         setmodel(tmp_entity, (nextent(world)).weaponentity.model);
1275                                 else
1276                                 {
1277                                         precache_model(argv(1));
1278                                         setmodel(tmp_entity, argv(1));
1279                                 }
1280                                 tmp_entity.frame = stof(argv(2));
1281                                 if(substring(argv(3), 0, 1) == "#")
1282                                         i = stof(substring(argv(3), 1, -1));
1283                                 else
1284                                         i = gettagindex(tmp_entity, argv(3));
1285                                 if(i)
1286                                 {
1287                                         v = gettaginfo(tmp_entity, i);
1288                                         print("model ", tmp_entity.model, " frame ", ftos(tmp_entity.frame), " tag ", gettaginfo_name);
1289                                         print(" index ", ftos(i), " parent ", ftos(gettaginfo_parent), "\n");
1290                                         print(" vector = ", ftos(v_x), " ", ftos(v_y), " ", ftos(v_z), "\n");
1291                                         print(" offset = ", ftos(gettaginfo_offset_x), " ", ftos(gettaginfo_offset_y), " ", ftos(gettaginfo_offset_z), "\n");
1292                                         print(" forward = ", ftos(gettaginfo_forward_x), " ", ftos(gettaginfo_forward_y), " ", ftos(gettaginfo_forward_z), "\n");
1293                                         print(" right = ", ftos(gettaginfo_right_x), " ", ftos(gettaginfo_right_y), " ", ftos(gettaginfo_right_z), "\n");
1294                                         print(" up = ", ftos(gettaginfo_up_x), " ", ftos(gettaginfo_up_y), " ", ftos(gettaginfo_up_z), "\n");
1295                                         if(argc >= 6)
1296                                         {
1297                                                 v_y = -v_y;
1298                                                 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
1299                                         }
1300                                 }
1301                                 else
1302                                         print("bone not found\n");
1303                                         
1304                                 remove(tmp_entity);
1305                                 return;
1306                         }
1307                         
1308                 default:
1309                         print("Incorrect parameters for \"gettaginfo\"\n");
1310                 case GC_REQUEST_USAGE:
1311                         print("\nUsage: sv_cmd gettaginfo\n");
1312                         print("  No arguments required.\n");
1313                         return;
1314         }
1315 }
1316
1317 void GameCommand_gotomap(float request, string command)
1318 {
1319         float argc = tokenize_console(command);
1320         
1321         switch(request)
1322         {
1323                 case GC_REQUEST_HELP:
1324                         print("  gotomap - Simple command to switch to another map\n");
1325                         return;
1326                         
1327                 case GC_REQUEST_COMMAND:
1328                         if(argc == 2)
1329                         {
1330                                 print(GotoMap(argv(1)), "\n");
1331                                 return;
1332                         }
1333                         
1334                 default:
1335                 case GC_REQUEST_USAGE:
1336                         print("\nUsage: sv_cmd gotomap map\n");
1337                         print("  Where map is the *.bsp file to change to.\n");
1338                         return;
1339         }
1340 }
1341
1342 void GameCommand(string command)
1343 {
1344         // ===== TODO list =====
1345         
1346         // Finish adding the rest of the commands
1347         
1348         // Add ifdef to stuffto so that is can only be used when the game code is compiled for it 
1349         //(this way it's more obscure and harder to abuse on normal servers)
1350
1351         float search_request_type;
1352         float argc = tokenize_console(command);
1353
1354         if(argv(0) == "help") 
1355         {
1356                 if(argc == 1) 
1357                 {
1358                         print("\nUsage: sv_cmd COMMAND..., where possible commands are:\n");
1359                         GameCommand_adminmsg(GC_REQUEST_HELP, "");
1360                         GameCommand_allready(GC_REQUEST_HELP);
1361                         GameCommand_allspec(GC_REQUEST_HELP);
1362                         GameCommand_anticheat(GC_REQUEST_HELP, "");
1363                         GameCommand_bbox(GC_REQUEST_HELP);
1364                         GameCommand_bot_cmd(GC_REQUEST_HELP, "");
1365                         GameCommand_cointoss(GC_REQUEST_HELP);
1366                         GameCommand_cvar_changes(GC_REQUEST_HELP);
1367                         GameCommand_cvar_purechanges(GC_REQUEST_HELP);
1368                         GameCommand_database(GC_REQUEST_HELP, "");
1369                         GameCommand_defer_clear(GC_REQUEST_HELP, "");
1370                         GameCommand_defer_clear_all(GC_REQUEST_HELP);
1371                         GameCommand_delrec(GC_REQUEST_HELP, "");
1372                         GameCommand_effectindexdump(GC_REQUEST_HELP);
1373                         GameCommand_extendmatchtime(GC_REQUEST_HELP);
1374                         GameCommand_find(GC_REQUEST_HELP, "");
1375                         GameCommand_gametype(GC_REQUEST_HELP, "");
1376                         GameCommand_gettaginfo(GC_REQUEST_HELP, "");
1377                         GameCommand_gotomap(GC_REQUEST_HELP, "");
1378                         print("  teamstatus\n");
1379                         print("  printstats\n");
1380                         print("  make_mapinfo\n");
1381                         print("  radarmap [--force] [--quit | --loop] [sharpness]\n");
1382                         print("  reducematchtime\n");
1383                         GameCommand_Vote("help", world);
1384                         GameCommand_Ban("help");
1385                         GameCommand_Generic("help");
1386                         print("For help about specific commands, type sv_cmd help COMMAND\n");
1387                         return;
1388                 } 
1389                 else
1390                         search_request_type = GC_REQUEST_USAGE; // Instead of trying to call a command, we're going to see detailed information about it
1391         } 
1392         else if(GameCommand_Vote(command, world)) 
1393         {
1394                 return; // handled by server/vote.qc 
1395         }
1396         else if(GameCommand_Ban(command)) 
1397         {
1398                 return; // handled by server/ipban.qc
1399         }
1400         else if(GameCommand_Generic(command)) 
1401         {
1402                 return; // handled by common/gamecommand.qc
1403         }
1404         else
1405                 search_request_type = GC_REQUEST_COMMAND; // continue as usual and scan for normal commands
1406                 
1407         switch( ((argv(0) == "help") ? argv(1) : argv(0)) ) // if first argument is help, then search for the second argument. Else, search for first. 
1408         {
1409                 case "adminmsg": GameCommand_adminmsg(search_request_type, command); break;
1410                 case "allready": GameCommand_allready(search_request_type); break;
1411                 case "allspec": GameCommand_allspec(search_request_type); break;
1412                 case "anticheat": GameCommand_anticheat(search_request_type, command); break;
1413                 case "bbox": GameCommand_bbox(search_request_type); break;
1414                 case "bot_cmd": GameCommand_bot_cmd(search_request_type, command); break;
1415                 case "cointoss": GameCommand_cointoss(search_request_type); break; 
1416                 case "cvar_changes": GameCommand_cvar_changes(search_request_type); break; 
1417                 case "cvar_purechanges": GameCommand_cvar_purechanges(search_request_type); break; 
1418                 case "database": GameCommand_database(search_request_type, command); break;
1419                 case "defer_clear": GameCommand_defer_clear(search_request_type, command); break;
1420                 case "defer_clear_all": GameCommand_defer_clear_all(search_request_type); break;
1421                 case "delrec": GameCommand_delrec(search_request_type, command); break;
1422                 case "effectindexdump": GameCommand_effectindexdump(search_request_type); break;
1423                 case "extendmatchtime": GameCommand_extendmatchtime(search_request_type); break;
1424                 case "find": GameCommand_find(search_request_type, command); break; 
1425                 case "gametype": GameCommand_gametype(search_request_type, command); break;
1426                 case "gettaginfo": GameCommand_gettaginfo(search_request_type, command); break;
1427                 case "gotomap": GameCommand_gotomap(search_request_type, command); break;
1428                 
1429                 default:
1430                         print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
1431         }
1432 }
1433