]> icculus.org git repositories - divverent/darkplaces.git/blob - host_cmd.c
fixed a critical bug with Vile and other midnight mods (dlights were being controlled...
[divverent/darkplaces.git] / host_cmd.c
1 /*
2 Copyright (C) 1996-1997 Id Software, Inc.
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
13 See the GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
18
19 */
20
21 #include "quakedef.h"
22
23 int current_skill;
24 cvar_t sv_cheats = {0, "sv_cheats", "0"};
25 qboolean allowcheats = false;
26
27 mfunction_t *ED_FindFunction (char *name);
28
29 /*
30 ==================
31 Host_Quit_f
32 ==================
33 */
34
35 void Host_Quit_f (void)
36 {
37         Sys_Quit ();
38 }
39
40
41 /*
42 ==================
43 Host_Status_f
44 ==================
45 */
46 void Host_Status_f (void)
47 {
48         const char *protocolname;
49         client_t *client;
50         int seconds, minutes, hours = 0, j, players;
51         void (*print) (const char *fmt, ...);
52
53         if (cmd_source == src_command)
54         {
55                 if (!sv.active)
56                 {
57                         Cmd_ForwardToServer ();
58                         return;
59                 }
60                 print = Con_Printf;
61         }
62         else
63                 print = SV_ClientPrintf;
64
65         for (players = 0, j = 0;j < svs.maxclients;j++)
66                 if (svs.clients[j].active)
67                         players++;
68         print ("host:    %s\n", Cvar_VariableString ("hostname"));
69         print ("version: %s build %s\n", gamename, buildstring);
70         switch(sv.protocol)
71         {
72                 case PROTOCOL_QUAKE: protocolname = sv.netquakecompatible ? "QUAKE" : "QUAKEDP";break;
73                 case PROTOCOL_DARKPLACES1: protocolname = "PROTOCOL_DARKPLACES1";break;
74                 case PROTOCOL_DARKPLACES2: protocolname = "PROTOCOL_DARKPLACES2";break;
75                 case PROTOCOL_DARKPLACES3: protocolname = "PROTOCOL_DARKPLACES3";break;
76                 case PROTOCOL_DARKPLACES4: protocolname = "PROTOCOL_DARKPLACES4";break;
77                 case PROTOCOL_DARKPLACES5: protocolname = "PROTOCOL_DARKPLACES5";break;
78                 default: protocolname = "PROTOCOL_UNKNOWN";break;
79         }
80         print ("protocol: %i (%s)\n", sv.protocol, protocolname);
81         print ("map:     %s\n", sv.name);
82         print ("players: %i active (%i max)\n\n", players, svs.maxclients);
83         for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
84         {
85                 if (!client->active)
86                         continue;
87                 seconds = (int)(realtime - client->connecttime);
88                 minutes = seconds / 60;
89                 if (minutes)
90                 {
91                         seconds -= (minutes * 60);
92                         hours = minutes / 60;
93                         if (hours)
94                                 minutes -= (hours * 60);
95                 }
96                 else
97                         hours = 0;
98                 print ("#%-2u %-16.16s  %3i  %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->v->frags, hours, minutes, seconds);
99                 print ("   %s\n", client->netconnection ? client->netconnection->address : "botclient");
100         }
101 }
102
103
104 /*
105 ==================
106 Host_God_f
107
108 Sets client to godmode
109 ==================
110 */
111 void Host_God_f (void)
112 {
113         if (cmd_source == src_command)
114         {
115                 Cmd_ForwardToServer ();
116                 return;
117         }
118
119         if (!allowcheats)
120         {
121                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
122                 return;
123         }
124
125         host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_GODMODE;
126         if (!((int)host_client->edict->v->flags & FL_GODMODE) )
127                 SV_ClientPrint("godmode OFF\n");
128         else
129                 SV_ClientPrint("godmode ON\n");
130 }
131
132 void Host_Notarget_f (void)
133 {
134         if (cmd_source == src_command)
135         {
136                 Cmd_ForwardToServer ();
137                 return;
138         }
139
140         if (!allowcheats)
141         {
142                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
143                 return;
144         }
145
146         host_client->edict->v->flags = (int)host_client->edict->v->flags ^ FL_NOTARGET;
147         if (!((int)host_client->edict->v->flags & FL_NOTARGET) )
148                 SV_ClientPrint("notarget OFF\n");
149         else
150                 SV_ClientPrint("notarget ON\n");
151 }
152
153 qboolean noclip_anglehack;
154
155 void Host_Noclip_f (void)
156 {
157         if (cmd_source == src_command)
158         {
159                 Cmd_ForwardToServer ();
160                 return;
161         }
162
163         if (!allowcheats)
164         {
165                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
166                 return;
167         }
168
169         if (host_client->edict->v->movetype != MOVETYPE_NOCLIP)
170         {
171                 noclip_anglehack = true;
172                 host_client->edict->v->movetype = MOVETYPE_NOCLIP;
173                 SV_ClientPrint("noclip ON\n");
174         }
175         else
176         {
177                 noclip_anglehack = false;
178                 host_client->edict->v->movetype = MOVETYPE_WALK;
179                 SV_ClientPrint("noclip OFF\n");
180         }
181 }
182
183 /*
184 ==================
185 Host_Fly_f
186
187 Sets client to flymode
188 ==================
189 */
190 void Host_Fly_f (void)
191 {
192         if (cmd_source == src_command)
193         {
194                 Cmd_ForwardToServer ();
195                 return;
196         }
197
198         if (!allowcheats)
199         {
200                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
201                 return;
202         }
203
204         if (host_client->edict->v->movetype != MOVETYPE_FLY)
205         {
206                 host_client->edict->v->movetype = MOVETYPE_FLY;
207                 SV_ClientPrint("flymode ON\n");
208         }
209         else
210         {
211                 host_client->edict->v->movetype = MOVETYPE_WALK;
212                 SV_ClientPrint("flymode OFF\n");
213         }
214 }
215
216
217 /*
218 ==================
219 Host_Ping_f
220
221 ==================
222 */
223 void Host_Ping_f (void)
224 {
225         int             i, j;
226         float   total;
227         client_t        *client;
228
229         if (cmd_source == src_command)
230         {
231                 Cmd_ForwardToServer ();
232                 return;
233         }
234
235         SV_ClientPrint("Client ping times:\n");
236         for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
237         {
238                 if (!client->active)
239                         continue;
240                 total = 0;
241                 for (j=0 ; j<NUM_PING_TIMES ; j++)
242                         total+=client->ping_times[j];
243                 total /= NUM_PING_TIMES;
244                 SV_ClientPrintf("%4i %s\n", (int)(total*1000), client->name);
245         }
246 }
247
248 /*
249 ===============================================================================
250
251 SERVER TRANSITIONS
252
253 ===============================================================================
254 */
255
256 /*
257 ======================
258 Host_Map_f
259
260 handle a
261 map <servername>
262 command from the console.  Active clients are kicked off.
263 ======================
264 */
265 void Host_Map_f (void)
266 {
267         char level[MAX_QPATH];
268
269         if (Cmd_Argc() != 2)
270         {
271                 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
272                 return;
273         }
274
275         if (cmd_source != src_command)
276                 return;
277
278         SCR_BeginLoadingPlaque ();
279         cls.demonum = -1;               // stop demo loop in case this fails
280
281         CL_Disconnect ();
282         Host_ShutdownServer(false);
283
284         // remove console or menu
285         key_dest = key_game;
286         key_consoleactive = 0;
287
288         svs.serverflags = 0;                    // haven't completed an episode yet
289         allowcheats = sv_cheats.integer != 0;
290         strcpy(level, Cmd_Argv(1));
291         SV_SpawnServer(level);
292         if (sv.active && cls.state == ca_disconnected)
293                 CL_EstablishConnection("local:1");
294 }
295
296 /*
297 ==================
298 Host_Changelevel_f
299
300 Goes to a new map, taking all clients along
301 ==================
302 */
303 void Host_Changelevel_f (void)
304 {
305         char level[MAX_QPATH];
306         
307         if (Cmd_Argc() != 2)
308         {
309                 Con_Print("changelevel <levelname> : continue game on a new level\n");
310                 return;
311         }
312         if (!sv.active || cls.demoplayback)
313         {
314                 Con_Print("Only the server may changelevel\n");
315                 return;
316         }
317         if (cmd_source != src_command)
318                 return;
319
320         // remove console or menu
321         key_dest = key_game;
322         key_consoleactive = 0;
323
324         SV_SaveSpawnparms ();
325         SCR_BeginLoadingPlaque();
326         allowcheats = sv_cheats.integer != 0;
327         strcpy(level, Cmd_Argv(1));
328         SV_SpawnServer(level);
329         if (sv.active && cls.state == ca_disconnected)
330                 CL_EstablishConnection("local:1");
331 }
332
333 /*
334 ==================
335 Host_Restart_f
336
337 Restarts the current server for a dead player
338 ==================
339 */
340 void Host_Restart_f (void)
341 {
342         char mapname[MAX_QPATH];
343         
344         if (Cmd_Argc() != 1)
345         {
346                 Con_Print("restart : restart current level\n");
347                 return;
348         }
349         if (!sv.active || cls.demoplayback)
350         {
351                 Con_Print("Only the server may restart\n");
352                 return;
353         }
354         if (cmd_source != src_command)
355                 return;
356
357         // remove console or menu
358         key_dest = key_game;
359         key_consoleactive = 0;
360
361         SCR_BeginLoadingPlaque();
362         allowcheats = sv_cheats.integer != 0;
363         strcpy(mapname, sv.name);
364         SV_SpawnServer(mapname);
365         if (sv.active && cls.state == ca_disconnected)
366                 CL_EstablishConnection("local:1");
367 }
368
369 /*
370 ==================
371 Host_Reconnect_f
372
373 This command causes the client to wait for the signon messages again.
374 This is sent just before a server changes levels
375 ==================
376 */
377 void Host_Reconnect_f (void)
378 {
379         if (Cmd_Argc() != 1)
380         {
381                 Con_Print("reconnect : wait for signon messages again\n");
382                 return;
383         }
384         if (!cls.signon)
385         {
386                 //Con_Print("reconnect: no signon, ignoring reconnect\n");
387                 return;
388         }
389         SCR_BeginLoadingPlaque();
390         cls.signon = 0;         // need new connection messages
391 }
392
393 /*
394 =====================
395 Host_Connect_f
396
397 User command to connect to server
398 =====================
399 */
400 void Host_Connect_f (void)
401 {
402         if (Cmd_Argc() != 2)
403         {
404                 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
405                 return;
406         }
407         CL_EstablishConnection(Cmd_Argv(1));
408 }
409
410
411 /*
412 ===============================================================================
413
414 LOAD / SAVE GAME
415
416 ===============================================================================
417 */
418
419 #define SAVEGAME_VERSION        5
420
421 /*
422 ===============
423 Host_SavegameComment
424
425 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
426 ===============
427 */
428 void Host_SavegameComment (char *text)
429 {
430         int             i;
431         char    kills[20];
432
433         for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
434                 text[i] = ' ';
435         memcpy (text, cl.levelname, strlen(cl.levelname));
436         sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
437         memcpy (text+22, kills, strlen(kills));
438 // convert space to _ to make stdio happy
439         for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
440                 if (text[i] == ' ')
441                         text[i] = '_';
442         text[SAVEGAME_COMMENT_LENGTH] = '\0';
443 }
444
445
446 /*
447 ===============
448 Host_Savegame_f
449 ===============
450 */
451 void Host_Savegame_f (void)
452 {
453         char    name[256];
454         qfile_t *f;
455         int             i;
456         char    comment[SAVEGAME_COMMENT_LENGTH+1];
457
458         if (cmd_source != src_command)
459                 return;
460
461         if (cls.state != ca_connected || !sv.active)
462         {
463                 Con_Print("Not playing a local game.\n");
464                 return;
465         }
466
467         if (cl.intermission)
468         {
469                 Con_Print("Can't save in intermission.\n");
470                 return;
471         }
472
473         for (i = 0;i < svs.maxclients;i++)
474         {
475                 if (svs.clients[i].active)
476                 {
477                         if (i > 0)
478                         {
479                                 Con_Print("Can't save multiplayer games.\n");
480                                 return;
481                         }
482                         if (svs.clients[i].edict->v->deadflag)
483                         {
484                                 Con_Print("Can't savegame with a dead player\n");
485                                 return;
486                         }
487                 }
488         }
489
490         if (Cmd_Argc() != 2)
491         {
492                 Con_Print("save <savename> : save a game\n");
493                 return;
494         }
495
496         if (strstr(Cmd_Argv(1), ".."))
497         {
498                 Con_Print("Relative pathnames are not allowed.\n");
499                 return;
500         }
501
502         strlcpy (name, Cmd_Argv(1), sizeof (name));
503         FS_DefaultExtension (name, ".sav", sizeof (name));
504
505         Con_Printf("Saving game to %s...\n", name);
506         f = FS_Open (name, "w", false);
507         if (!f)
508         {
509                 Con_Print("ERROR: couldn't open.\n");
510                 return;
511         }
512
513         FS_Printf(f, "%i\n", SAVEGAME_VERSION);
514         Host_SavegameComment (comment);
515         FS_Printf(f, "%s\n", comment);
516         for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
517                 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
518         FS_Printf(f, "%d\n", current_skill);
519         FS_Printf(f, "%s\n", sv.name);
520         FS_Printf(f, "%f\n",sv.time);
521
522 // write the light styles
523
524         for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
525         {
526                 if (sv.lightstyles[i])
527                         FS_Printf(f, "%s\n", sv.lightstyles[i]);
528                 else
529                         FS_Print(f,"m\n");
530         }
531
532
533         ED_WriteGlobals (f);
534         for (i=0 ; i<sv.num_edicts ; i++)
535         {
536                 ED_Write (f, EDICT_NUM(i));
537                 FS_Flush (f);
538         }
539         FS_Close (f);
540         Con_Print("done.\n");
541 }
542
543
544 extern mempool_t *edictstring_mempool;
545
546 /*
547 ===============
548 Host_Loadgame_f
549 ===============
550 */
551 void Host_Loadgame_f (void)
552 {
553         qfile_t *f;
554         char filename[MAX_QPATH];
555         char mapname[MAX_QPATH];
556         float time, tfloat;
557         char buf[32768];
558         const char *start;
559         char *str;
560         int i, r;
561         edict_t *ent;
562         int entnum;
563         int version;
564         float spawn_parms[NUM_SPAWN_PARMS];
565
566         if (cmd_source != src_command)
567                 return;
568
569         if (Cmd_Argc() != 2)
570         {
571                 Con_Print("load <savename> : load a game\n");
572                 return;
573         }
574
575         strcpy (filename, Cmd_Argv(1));
576         FS_DefaultExtension (filename, ".sav", sizeof (filename));
577
578         Con_Printf("Loading game from %s...\n", filename);
579
580         cls.demonum = -1;               // stop demo loop in case this fails
581
582         f = FS_Open (filename, "r", false);
583         if (!f)
584         {
585                 Con_Print("ERROR: couldn't open.\n");
586                 return;
587         }
588
589         str = FS_Getline (f);
590         sscanf (str, "%i\n", &version);
591         if (version != SAVEGAME_VERSION)
592         {
593                 FS_Close (f);
594                 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
595                 return;
596         }
597
598         SCR_BeginLoadingPlaque ();
599
600         str = FS_Getline (f);
601         for (i = 0;i < NUM_SPAWN_PARMS;i++)
602         {
603                 str = FS_Getline (f);
604                 sscanf (str, "%f\n", &spawn_parms[i]);
605         }
606 // this silliness is so we can load 1.06 save files, which have float skill values
607         str = FS_Getline (f);
608         sscanf (str, "%f\n", &tfloat);
609         current_skill = (int)(tfloat + 0.1);
610         Cvar_SetValue ("skill", (float)current_skill);
611
612         strcpy (mapname, FS_Getline (f));
613
614         str = FS_Getline (f);
615         sscanf (str, "%f\n",&time);
616
617         allowcheats = sv_cheats.integer != 0;
618         SV_SpawnServer (mapname);
619         if (!sv.active)
620         {
621                 Con_Print("Couldn't load map\n");
622                 return;
623         }
624         sv.paused = true;               // pause until all clients connect
625         sv.loadgame = true;
626
627 // load the light styles
628
629         for (i = 0;i < MAX_LIGHTSTYLES;i++)
630         {
631                 str = FS_Getline (f);
632                 sv.lightstyles[i] = Mem_Alloc(edictstring_mempool, strlen(str)+1);
633                 strcpy (sv.lightstyles[i], str);
634         }
635
636 // load the edicts out of the savegame file
637         // -1 is the globals
638         entnum = -1;
639         for (;;)
640         {
641                 r = EOF;
642                 for (i = 0;i < (int)sizeof(buf) - 1;i++)
643                 {
644                         r = FS_Getc (f);
645                         if (r == EOF || !r)
646                                 break;
647                         buf[i] = r;
648                         if (r == '}')
649                         {
650                                 i++;
651                                 break;
652                         }
653                 }
654                 if (r == EOF)
655                         break;
656                 if (i == sizeof(buf)-1)
657                         Host_Error ("Loadgame buffer overflow");
658                 buf[i] = 0;
659                 start = buf;
660                 if (!COM_ParseToken(&start, false))
661                 {
662                         // end of file
663                         break;
664                 }
665                 if (strcmp(com_token,"{"))
666                         Host_Error ("First token isn't a brace");
667
668                 if (entnum == -1)
669                 {
670                         // parse the global vars
671                         ED_ParseGlobals (start);
672                 }
673                 else
674                 {
675                         // parse an edict
676                         if (entnum >= MAX_EDICTS)
677                                 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)\n", MAX_EDICTS);
678                         while (entnum >= sv.max_edicts)
679                                 SV_IncreaseEdicts();
680                         ent = EDICT_NUM(entnum);
681                         memset (ent->v, 0, progs->entityfields * 4);
682                         ent->e->free = false;
683                         ED_ParseEdict (start, ent);
684
685                         // link it into the bsp tree
686                         if (!ent->e->free)
687                                 SV_LinkEdict (ent, false);
688                 }
689
690                 entnum++;
691         }
692
693         sv.num_edicts = entnum;
694         sv.time = time;
695
696         FS_Close (f);
697
698         for (i = 0;i < NUM_SPAWN_PARMS;i++)
699                 svs.clients[0].spawn_parms[i] = spawn_parms[i];
700
701         // make sure we're connected to loopback
702         if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
703                 CL_EstablishConnection("local:1");
704 }
705
706 //============================================================================
707
708 /*
709 ======================
710 Host_Name_f
711 ======================
712 */
713 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
714 void Host_Name_f (void)
715 {
716         int i, j;
717         char newName[sizeof(host_client->name)];
718
719         if (Cmd_Argc () == 1)
720         {
721                 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
722                 return;
723         }
724
725         if (Cmd_Argc () == 2)
726                 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
727         else
728                 strlcpy (newName, Cmd_Args(), sizeof (newName));
729
730         for (i = 0, j = 0;newName[i];i++)
731                 if (newName[i] != '\r' && newName[i] != '\n')
732                         newName[j++] = newName[i];
733         newName[j] = 0;
734
735         if (cmd_source == src_command)
736         {
737                 Cvar_Set ("_cl_name", newName);
738                 if (cls.state == ca_connected)
739                         Cmd_ForwardToServer ();
740                 return;
741         }
742
743         if (sv.time < host_client->nametime)
744         {
745                 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
746                 return;
747         }
748         
749         host_client->nametime = sv.time + 5;
750
751         // point the string back at updateclient->name to keep it safe
752         strlcpy (host_client->name, newName, sizeof (host_client->name));
753         host_client->edict->v->netname = PR_SetString(host_client->name);
754         if (strcmp(host_client->old_name, host_client->name))
755         {
756                 if (host_client->spawned)
757                         SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
758                 strcpy(host_client->old_name, host_client->name);
759                 // send notification to all clients
760                 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
761                 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
762                 MSG_WriteString (&sv.reliable_datagram, host_client->name);
763         }
764 }
765
766
767 void Host_Version_f (void)
768 {
769         Con_Printf("Version: %s build %s\n", gamename, buildstring);
770 }
771
772 void Host_Say(qboolean teamonly)
773 {
774         client_t *save;
775         int j, quoted;
776         const char *p1;
777         char *p2;
778         // LordHavoc: 256 char say messages
779         unsigned char text[256];
780         qboolean fromServer = false;
781
782         if (cmd_source == src_command)
783         {
784                 if (cls.state == ca_dedicated)
785                 {
786                         fromServer = true;
787                         teamonly = false;
788                 }
789                 else
790                 {
791                         Cmd_ForwardToServer ();
792                         return;
793                 }
794         }
795
796         if (Cmd_Argc () < 2)
797                 return;
798
799         if (!teamplay.integer)
800                 teamonly = false;
801
802 // turn on color set 1
803         p1 = Cmd_Args();
804         quoted = false;
805         if (*p1 == '\"')
806         {
807                 quoted = true;
808                 p1++;
809         }
810         if (!fromServer)
811                 snprintf (text, sizeof(text), "%c%s: %s", 1, host_client->name, p1);
812         else
813                 snprintf (text, sizeof(text), "%c<%s> %s", 1, hostname.string, p1);
814         p2 = text + strlen(text);
815         while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
816         {
817                 if (p2[-1] == '\"' && quoted)
818                         quoted = false;
819                 p2[-1] = 0;
820                 p2--;
821         }
822         strlcat(text, "\n", sizeof(text));
823
824         // note: save is not a valid edict if fromServer is true
825         save = host_client;
826         for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
827                 if (host_client->spawned && (!teamonly || host_client->edict->v->team == save->edict->v->team))
828                         SV_ClientPrint(text);
829         host_client = save;
830
831         Sys_Print(&text[1]);
832 }
833
834
835 void Host_Say_f(void)
836 {
837         Host_Say(false);
838 }
839
840
841 void Host_Say_Team_f(void)
842 {
843         Host_Say(true);
844 }
845
846
847 void Host_Tell_f(void)
848 {
849         client_t *save;
850         int j;
851         const char *p1, *p2;
852         char text[1024]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
853         qboolean fromServer = false;
854
855         if (cmd_source == src_command)
856         {
857                 if (cls.state == ca_dedicated)
858                         fromServer = true;
859                 else
860                 {
861                         Cmd_ForwardToServer ();
862                         return;
863                 }
864         }
865
866         if (Cmd_Argc () < 3)
867                 return;
868
869         if (!fromServer)
870                 sprintf (text, "%s: ", host_client->name);
871         else
872                 sprintf (text, "<%s> ", hostname.string);
873
874         p1 = Cmd_Args();
875         p2 = p1 + strlen(p1);
876         // remove the target name
877         while (p1 < p2 && *p1 != ' ')
878                 p1++;
879         while (p1 < p2 && *p1 == ' ')
880                 p1++;
881         // remove trailing newlines
882         while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
883                 p2--;
884         // remove quotes if present
885         if (*p1 == '"')
886         {
887                 p1++;
888                 if (p2[-1] == '"')
889                         p2--;
890                 else if (fromServer)
891                         Con_Print("Host_Tell: missing end quote\n");
892                 else
893                         SV_ClientPrint("Host_Tell: missing end quote\n");
894         }
895         while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
896                 p2--;
897         for (j = strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
898                 text[j++] = *p1++;
899         text[j++] = '\n';
900         text[j++] = 0;
901
902         save = host_client;
903         for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
904                 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
905                         SV_ClientPrint(text);
906         host_client = save;
907 }
908
909
910 /*
911 ==================
912 Host_Color_f
913 ==================
914 */
915 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
916 void Host_Color_f(void)
917 {
918         int             top, bottom;
919         int             playercolor;
920         mfunction_t *f;
921         func_t  SV_ChangeTeam;
922
923         if (Cmd_Argc() == 1)
924         {
925                 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
926                 Con_Print("color <0-15> [0-15]\n");
927                 return;
928         }
929
930         if (Cmd_Argc() == 2)
931                 top = bottom = atoi(Cmd_Argv(1));
932         else
933         {
934                 top = atoi(Cmd_Argv(1));
935                 bottom = atoi(Cmd_Argv(2));
936         }
937
938         top &= 15;
939         // LordHavoc: allow skin colormaps 14 and 15 (was 13)
940         if (top > 15)
941                 top = 15;
942         bottom &= 15;
943         // LordHavoc: allow skin colormaps 14 and 15 (was 13)
944         if (bottom > 15)
945                 bottom = 15;
946
947         playercolor = top*16 + bottom;
948
949         if (cmd_source == src_command)
950         {
951                 Cvar_SetValue ("_cl_color", playercolor);
952                 if (cls.state == ca_connected)
953                         Cmd_ForwardToServer ();
954                 return;
955         }
956
957         if (host_client->edict && (f = ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - pr_functions)))
958         {
959                 Con_DPrint("Calling SV_ChangeTeam\n");
960                 pr_global_struct->time = sv.time;
961                 pr_globals[OFS_PARM0] = playercolor;
962                 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
963                 PR_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
964         }
965         else
966         {
967                 eval_t *val;
968                 if (host_client->edict)
969                 {
970                         if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
971                                 val->_float = playercolor;
972                         host_client->edict->v->team = bottom + 1;
973                 }
974                 host_client->colors = playercolor;
975                 if (host_client->old_colors != host_client->colors)
976                 {
977                         host_client->old_colors = host_client->colors;
978                         // send notification to all clients
979                         MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
980                         MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
981                         MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
982                 }
983         }
984 }
985
986 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000"};
987 void Host_Rate_f(void)
988 {
989         int rate;
990
991         if (Cmd_Argc() != 2)
992         {
993                 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
994                 Con_Print("rate <500-25000>\n");
995                 return;
996         }
997
998         rate = atoi(Cmd_Argv(1));
999
1000         if (cmd_source == src_command)
1001         {
1002                 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1003                 if (cls.state == ca_connected)
1004                         Cmd_ForwardToServer ();
1005                 return;
1006         }
1007
1008         host_client->rate = rate;
1009 }
1010
1011 /*
1012 ==================
1013 Host_Kill_f
1014 ==================
1015 */
1016 void Host_Kill_f (void)
1017 {
1018         if (cmd_source == src_command)
1019         {
1020                 Cmd_ForwardToServer ();
1021                 return;
1022         }
1023
1024         if (host_client->edict->v->health <= 0)
1025         {
1026                 SV_ClientPrint("Can't suicide -- already dead!\n");
1027                 return;
1028         }
1029
1030         pr_global_struct->time = sv.time;
1031         pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1032         PR_ExecuteProgram (pr_global_struct->ClientKill, "QC function ClientKill is missing");
1033 }
1034
1035
1036 /*
1037 ==================
1038 Host_Pause_f
1039 ==================
1040 */
1041 void Host_Pause_f (void)
1042 {
1043
1044         if (cmd_source == src_command)
1045         {
1046                 Cmd_ForwardToServer ();
1047                 return;
1048         }
1049         if (!pausable.integer)
1050                 SV_ClientPrint("Pause not allowed.\n");
1051         else
1052         {
1053                 sv.paused ^= 1;
1054                 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1055                 // send notification to all clients
1056                 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1057                 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1058         }
1059 }
1060
1061 /*
1062 ======================
1063 Host_PModel_f
1064 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1065 ======================
1066 */
1067 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
1068 static void Host_PModel_f (void)
1069 {
1070         int i;
1071         eval_t *val;
1072
1073         if (Cmd_Argc () == 1)
1074         {
1075                 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1076                 return;
1077         }
1078         i = atoi(Cmd_Argv(1));
1079
1080         if (cmd_source == src_command)
1081         {
1082                 if (cl_pmodel.integer == i)
1083                         return;
1084                 Cvar_SetValue ("_cl_pmodel", i);
1085                 if (cls.state == ca_connected)
1086                         Cmd_ForwardToServer ();
1087                 return;
1088         }
1089
1090         if (host_client->edict && (val = GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1091                 val->_float = i;
1092 }
1093
1094 //===========================================================================
1095
1096
1097 /*
1098 ==================
1099 Host_PreSpawn_f
1100 ==================
1101 */
1102 void Host_PreSpawn_f (void)
1103 {
1104         if (cmd_source == src_command)
1105         {
1106                 Con_Print("prespawn is not valid from the console\n");
1107                 return;
1108         }
1109
1110         if (host_client->spawned)
1111         {
1112                 Con_Print("prespawn not valid -- already spawned\n");
1113                 return;
1114         }
1115
1116         SZ_Write (&host_client->message, sv.signon.data, sv.signon.cursize);
1117         MSG_WriteByte (&host_client->message, svc_signonnum);
1118         MSG_WriteByte (&host_client->message, 2);
1119         host_client->sendsignon = true;
1120
1121         // reset the name change timer because the client will send name soon
1122         host_client->nametime = 0;
1123 }
1124
1125 /*
1126 ==================
1127 Host_Spawn_f
1128 ==================
1129 */
1130 void Host_Spawn_f (void)
1131 {
1132         int i;
1133         client_t *client;
1134         func_t RestoreGame;
1135         mfunction_t *f;
1136
1137         if (cmd_source == src_command)
1138         {
1139                 Con_Print("spawn is not valid from the console\n");
1140                 return;
1141         }
1142
1143         if (host_client->spawned)
1144         {
1145                 Con_Print("Spawn not valid -- already spawned\n");
1146                 return;
1147         }
1148
1149         // reset name change timer again because they might want to change name
1150         // again in the first 5 seconds after connecting
1151         host_client->nametime = 0;
1152
1153         // LordHavoc: moved this above the QC calls at FrikaC's request
1154         // send all current names, colors, and frag counts
1155         SZ_Clear (&host_client->message);
1156
1157         // run the entrance script
1158         if (sv.loadgame)
1159         {
1160                 // loaded games are fully initialized already
1161                 // if this is the last client to be connected, unpause
1162                 sv.paused = false;
1163
1164                 if ((f = ED_FindFunction ("RestoreGame")))
1165                 if ((RestoreGame = (func_t)(f - pr_functions)))
1166                 {
1167                         Con_DPrint("Calling RestoreGame\n");
1168                         pr_global_struct->time = sv.time;
1169                         pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1170                         PR_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1171                 }
1172         }
1173         else
1174         {
1175                 // set up the edict
1176                 ED_ClearEdict(host_client->edict);
1177
1178                 //Con_Printf("Host_Spawn_f: host_client->edict->netname = %s, host_client->edict->netname = %s, host_client->name = %s\n", PR_GetString(host_client->edict->v->netname), PR_GetString(host_client->edict->v->netname), host_client->name);
1179
1180                 // copy spawn parms out of the client_t
1181                 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1182                         (&pr_global_struct->parm1)[i] = host_client->spawn_parms[i];
1183
1184                 // call the spawn function
1185                 pr_global_struct->time = sv.time;
1186                 pr_global_struct->self = EDICT_TO_PROG(host_client->edict);
1187                 PR_ExecuteProgram (pr_global_struct->ClientConnect, "QC function ClientConnect is missing");
1188
1189                 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1190                         Sys_Printf("%s entered the game\n", host_client->name);
1191
1192                 PR_ExecuteProgram (pr_global_struct->PutClientInServer, "QC function PutClientInServer is missing");
1193         }
1194
1195
1196         // send time of update
1197         MSG_WriteByte (&host_client->message, svc_time);
1198         MSG_WriteFloat (&host_client->message, sv.time);
1199
1200         for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1201         {
1202                 if (!client->active)
1203                         continue;
1204                 MSG_WriteByte (&host_client->message, svc_updatename);
1205                 MSG_WriteByte (&host_client->message, i);
1206                 MSG_WriteString (&host_client->message, client->name);
1207                 MSG_WriteByte (&host_client->message, svc_updatefrags);
1208                 MSG_WriteByte (&host_client->message, i);
1209                 MSG_WriteShort (&host_client->message, client->frags);
1210                 MSG_WriteByte (&host_client->message, svc_updatecolors);
1211                 MSG_WriteByte (&host_client->message, i);
1212                 MSG_WriteByte (&host_client->message, client->colors);
1213         }
1214
1215         // send all current light styles
1216         for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1217         {
1218                 MSG_WriteByte (&host_client->message, svc_lightstyle);
1219                 MSG_WriteByte (&host_client->message, (char)i);
1220                 MSG_WriteString (&host_client->message, sv.lightstyles[i]);
1221         }
1222
1223         // send some stats
1224         MSG_WriteByte (&host_client->message, svc_updatestat);
1225         MSG_WriteByte (&host_client->message, STAT_TOTALSECRETS);
1226         MSG_WriteLong (&host_client->message, pr_global_struct->total_secrets);
1227
1228         MSG_WriteByte (&host_client->message, svc_updatestat);
1229         MSG_WriteByte (&host_client->message, STAT_TOTALMONSTERS);
1230         MSG_WriteLong (&host_client->message, pr_global_struct->total_monsters);
1231
1232         MSG_WriteByte (&host_client->message, svc_updatestat);
1233         MSG_WriteByte (&host_client->message, STAT_SECRETS);
1234         MSG_WriteLong (&host_client->message, pr_global_struct->found_secrets);
1235
1236         MSG_WriteByte (&host_client->message, svc_updatestat);
1237         MSG_WriteByte (&host_client->message, STAT_MONSTERS);
1238         MSG_WriteLong (&host_client->message, pr_global_struct->killed_monsters);
1239
1240         // send a fixangle
1241         // Never send a roll angle, because savegames can catch the server
1242         // in a state where it is expecting the client to correct the angle
1243         // and it won't happen if the game was just loaded, so you wind up
1244         // with a permanent head tilt
1245         MSG_WriteByte (&host_client->message, svc_setangle);
1246         MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[0], sv.protocol);
1247         MSG_WriteAngle (&host_client->message, host_client->edict->v->angles[1], sv.protocol);
1248         MSG_WriteAngle (&host_client->message, 0, sv.protocol);
1249
1250         SV_WriteClientdataToMessage (host_client->edict, &host_client->message);
1251
1252         MSG_WriteByte (&host_client->message, svc_signonnum);
1253         MSG_WriteByte (&host_client->message, 3);
1254         host_client->sendsignon = true;
1255 }
1256
1257 /*
1258 ==================
1259 Host_Begin_f
1260 ==================
1261 */
1262 void Host_Begin_f (void)
1263 {
1264         if (cmd_source == src_command)
1265         {
1266                 Con_Print("begin is not valid from the console\n");
1267                 return;
1268         }
1269
1270         host_client->spawned = true;
1271 }
1272
1273 //===========================================================================
1274
1275
1276 /*
1277 ==================
1278 Host_Kick_f
1279
1280 Kicks a user off of the server
1281 ==================
1282 */
1283 void Host_Kick_f (void)
1284 {
1285         char *who;
1286         const char *message = NULL;
1287         client_t *save;
1288         int i;
1289         qboolean byNumber = false;
1290
1291         if (cmd_source != src_command || !sv.active)
1292                 return;
1293
1294         save = host_client;
1295
1296         if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1297         {
1298                 i = atof(Cmd_Argv(2)) - 1;
1299                 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1300                         return;
1301                 byNumber = true;
1302         }
1303         else
1304         {
1305                 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1306                 {
1307                         if (!host_client->active)
1308                                 continue;
1309                         if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1310                                 break;
1311                 }
1312         }
1313
1314         if (i < svs.maxclients)
1315         {
1316                 if (cmd_source == src_command)
1317                 {
1318                         if (cls.state == ca_dedicated)
1319                                 who = "Console";
1320                         else
1321                                 who = cl_name.string;
1322                 }
1323                 else
1324                         who = save->name;
1325
1326                 // can't kick yourself!
1327                 if (host_client == save)
1328                         return;
1329
1330                 if (Cmd_Argc() > 2)
1331                 {
1332                         message = Cmd_Args();
1333                         COM_ParseToken(&message, false);
1334                         if (byNumber)
1335                         {
1336                                 message++;                                                      // skip the #
1337                                 while (*message == ' ')                         // skip white space
1338                                         message++;
1339                                 message += strlen(Cmd_Argv(2)); // skip the number
1340                         }
1341                         while (*message && *message == ' ')
1342                                 message++;
1343                 }
1344                 if (message)
1345                         SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1346                 else
1347                         SV_ClientPrintf("Kicked by %s\n", who);
1348                 SV_DropClient (false); // kicked
1349         }
1350
1351         host_client = save;
1352 }
1353
1354 /*
1355 ===============================================================================
1356
1357 DEBUGGING TOOLS
1358
1359 ===============================================================================
1360 */
1361
1362 /*
1363 ==================
1364 Host_Give_f
1365 ==================
1366 */
1367 void Host_Give_f (void)
1368 {
1369         const char *t;
1370         int v;
1371         eval_t *val;
1372
1373         if (cmd_source == src_command)
1374         {
1375                 Cmd_ForwardToServer ();
1376                 return;
1377         }
1378
1379         if (!allowcheats)
1380         {
1381                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1382                 return;
1383         }
1384
1385         t = Cmd_Argv(1);
1386         v = atoi (Cmd_Argv(2));
1387
1388         switch (t[0])
1389         {
1390         case '0':
1391         case '1':
1392         case '2':
1393         case '3':
1394         case '4':
1395         case '5':
1396         case '6':
1397         case '7':
1398         case '8':
1399         case '9':
1400                 // MED 01/04/97 added hipnotic give stuff
1401                 if (gamemode == GAME_HIPNOTIC)
1402                 {
1403                         if (t[0] == '6')
1404                         {
1405                                 if (t[1] == 'a')
1406                                         host_client->edict->v->items = (int)host_client->edict->v->items | HIT_PROXIMITY_GUN;
1407                                 else
1408                                         host_client->edict->v->items = (int)host_client->edict->v->items | IT_GRENADE_LAUNCHER;
1409                         }
1410                         else if (t[0] == '9')
1411                                 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_LASER_CANNON;
1412                         else if (t[0] == '0')
1413                                 host_client->edict->v->items = (int)host_client->edict->v->items | HIT_MJOLNIR;
1414                         else if (t[0] >= '2')
1415                                 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1416                 }
1417                 else
1418                 {
1419                         if (t[0] >= '2')
1420                                 host_client->edict->v->items = (int)host_client->edict->v->items | (IT_SHOTGUN << (t[0] - '2'));
1421                 }
1422                 break;
1423
1424         case 's':
1425                 if (gamemode == GAME_ROGUE && (val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1426                         val->_float = v;
1427
1428                 host_client->edict->v->ammo_shells = v;
1429                 break;
1430         case 'n':
1431                 if (gamemode == GAME_ROGUE)
1432                 {
1433                         if ((val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1434                         {
1435                                 val->_float = v;
1436                                 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1437                                         host_client->edict->v->ammo_nails = v;
1438                         }
1439                 }
1440                 else
1441                 {
1442                         host_client->edict->v->ammo_nails = v;
1443                 }
1444                 break;
1445         case 'l':
1446                 if (gamemode == GAME_ROGUE)
1447                 {
1448                         val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1449                         if (val)
1450                         {
1451                                 val->_float = v;
1452                                 if (host_client->edict->v->weapon > IT_LIGHTNING)
1453                                         host_client->edict->v->ammo_nails = v;
1454                         }
1455                 }
1456                 break;
1457         case 'r':
1458                 if (gamemode == GAME_ROGUE)
1459                 {
1460                         val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1461                         if (val)
1462                         {
1463                                 val->_float = v;
1464                                 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1465                                         host_client->edict->v->ammo_rockets = v;
1466                         }
1467                 }
1468                 else
1469                 {
1470                         host_client->edict->v->ammo_rockets = v;
1471                 }
1472                 break;
1473         case 'm':
1474                 if (gamemode == GAME_ROGUE)
1475                 {
1476                         val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1477                         if (val)
1478                         {
1479                                 val->_float = v;
1480                                 if (host_client->edict->v->weapon > IT_LIGHTNING)
1481                                         host_client->edict->v->ammo_rockets = v;
1482                         }
1483                 }
1484                 break;
1485         case 'h':
1486                 host_client->edict->v->health = v;
1487                 break;
1488         case 'c':
1489                 if (gamemode == GAME_ROGUE)
1490                 {
1491                         val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1492                         if (val)
1493                         {
1494                                 val->_float = v;
1495                                 if (host_client->edict->v->weapon <= IT_LIGHTNING)
1496                                         host_client->edict->v->ammo_cells = v;
1497                         }
1498                 }
1499                 else
1500                 {
1501                         host_client->edict->v->ammo_cells = v;
1502                 }
1503                 break;
1504         case 'p':
1505                 if (gamemode == GAME_ROGUE)
1506                 {
1507                         val = GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1508                         if (val)
1509                         {
1510                                 val->_float = v;
1511                                 if (host_client->edict->v->weapon > IT_LIGHTNING)
1512                                         host_client->edict->v->ammo_cells = v;
1513                         }
1514                 }
1515                 break;
1516         }
1517 }
1518
1519 edict_t *FindViewthing (void)
1520 {
1521         int             i;
1522         edict_t *e;
1523
1524         for (i=0 ; i<sv.num_edicts ; i++)
1525         {
1526                 e = EDICT_NUM(i);
1527                 if (!strcmp (PR_GetString(e->v->classname), "viewthing"))
1528                         return e;
1529         }
1530         Con_Print("No viewthing on map\n");
1531         return NULL;
1532 }
1533
1534 /*
1535 ==================
1536 Host_Viewmodel_f
1537 ==================
1538 */
1539 void Host_Viewmodel_f (void)
1540 {
1541         edict_t *e;
1542         model_t *m;
1543
1544         e = FindViewthing ();
1545         if (!e)
1546                 return;
1547
1548         m = Mod_ForName (Cmd_Argv(1), false, true, false);
1549         if (!m)
1550         {
1551                 Con_Printf("Can't load %s\n", Cmd_Argv(1));
1552                 return;
1553         }
1554
1555         e->v->frame = 0;
1556         cl.model_precache[(int)e->v->modelindex] = m;
1557 }
1558
1559 /*
1560 ==================
1561 Host_Viewframe_f
1562 ==================
1563 */
1564 void Host_Viewframe_f (void)
1565 {
1566         edict_t *e;
1567         int             f;
1568         model_t *m;
1569
1570         e = FindViewthing ();
1571         if (!e)
1572                 return;
1573         m = cl.model_precache[(int)e->v->modelindex];
1574
1575         f = atoi(Cmd_Argv(1));
1576         if (f >= m->numframes)
1577                 f = m->numframes-1;
1578
1579         e->v->frame = f;
1580 }
1581
1582
1583 void PrintFrameName (model_t *m, int frame)
1584 {
1585         if (m->animscenes)
1586                 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1587         else
1588                 Con_Printf("frame %i\n", frame);
1589 }
1590
1591 /*
1592 ==================
1593 Host_Viewnext_f
1594 ==================
1595 */
1596 void Host_Viewnext_f (void)
1597 {
1598         edict_t *e;
1599         model_t *m;
1600
1601         e = FindViewthing ();
1602         if (!e)
1603                 return;
1604         m = cl.model_precache[(int)e->v->modelindex];
1605
1606         e->v->frame = e->v->frame + 1;
1607         if (e->v->frame >= m->numframes)
1608                 e->v->frame = m->numframes - 1;
1609
1610         PrintFrameName (m, e->v->frame);
1611 }
1612
1613 /*
1614 ==================
1615 Host_Viewprev_f
1616 ==================
1617 */
1618 void Host_Viewprev_f (void)
1619 {
1620         edict_t *e;
1621         model_t *m;
1622
1623         e = FindViewthing ();
1624         if (!e)
1625                 return;
1626
1627         m = cl.model_precache[(int)e->v->modelindex];
1628
1629         e->v->frame = e->v->frame - 1;
1630         if (e->v->frame < 0)
1631                 e->v->frame = 0;
1632
1633         PrintFrameName (m, e->v->frame);
1634 }
1635
1636 /*
1637 ===============================================================================
1638
1639 DEMO LOOP CONTROL
1640
1641 ===============================================================================
1642 */
1643
1644
1645 /*
1646 ==================
1647 Host_Startdemos_f
1648 ==================
1649 */
1650 void Host_Startdemos_f (void)
1651 {
1652         int             i, c;
1653
1654         if (cls.state == ca_dedicated || COM_CheckParm("-listen"))
1655                 return;
1656
1657         c = Cmd_Argc() - 1;
1658         if (c > MAX_DEMOS)
1659         {
1660                 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1661                 c = MAX_DEMOS;
1662         }
1663         Con_DPrintf("%i demo(s) in loop\n", c);
1664
1665         for (i=1 ; i<c+1 ; i++)
1666                 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1667
1668         // LordHavoc: clear the remaining slots
1669         for (;i <= MAX_DEMOS;i++)
1670                 cls.demos[i-1][0] = 0;
1671
1672         if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1673         {
1674                 cls.demonum = 0;
1675                 CL_NextDemo ();
1676         }
1677         else
1678                 cls.demonum = -1;
1679 }
1680
1681
1682 /*
1683 ==================
1684 Host_Demos_f
1685
1686 Return to looping demos
1687 ==================
1688 */
1689 void Host_Demos_f (void)
1690 {
1691         if (cls.state == ca_dedicated)
1692                 return;
1693         if (cls.demonum == -1)
1694                 cls.demonum = 1;
1695         CL_Disconnect_f ();
1696         CL_NextDemo ();
1697 }
1698
1699 /*
1700 ==================
1701 Host_Stopdemo_f
1702
1703 Return to looping demos
1704 ==================
1705 */
1706 void Host_Stopdemo_f (void)
1707 {
1708         if (!cls.demoplayback)
1709                 return;
1710         CL_Disconnect ();
1711         Host_ShutdownServer (false);
1712 }
1713
1714 static void MaxPlayers_f(void)
1715 {
1716         int n;
1717
1718         if (Cmd_Argc() != 2)
1719         {
1720                 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1721                 return;
1722         }
1723
1724         if (sv.active)
1725         {
1726                 Con_Print("maxplayers can not be changed while a server is running.\n");
1727                 return;
1728         }
1729
1730         n = atoi(Cmd_Argv(1));
1731         n = bound(1, n, MAX_SCOREBOARD);
1732         Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1733
1734         if (svs.clients)
1735                 Mem_Free(svs.clients);
1736         svs.maxclients = n;
1737         svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
1738         if (n == 1)
1739                 Cvar_Set ("deathmatch", "0");
1740         else
1741                 Cvar_Set ("deathmatch", "1");
1742 }
1743
1744 //=============================================================================
1745
1746 /*
1747 ==================
1748 Host_InitCommands
1749 ==================
1750 */
1751 void Host_InitCommands (void)
1752 {
1753         Cmd_AddCommand ("status", Host_Status_f);
1754         Cmd_AddCommand ("quit", Host_Quit_f);
1755         if (gamemode == GAME_NEHAHRA)
1756         {
1757                 Cmd_AddCommand ("max", Host_God_f);
1758                 Cmd_AddCommand ("monster", Host_Notarget_f);
1759                 Cmd_AddCommand ("scrag", Host_Fly_f);
1760                 Cmd_AddCommand ("wraith", Host_Noclip_f);
1761                 Cmd_AddCommand ("gimme", Host_Give_f);
1762         }
1763         else
1764         {
1765                 Cmd_AddCommand ("god", Host_God_f);
1766                 Cmd_AddCommand ("notarget", Host_Notarget_f);
1767                 Cmd_AddCommand ("fly", Host_Fly_f);
1768                 Cmd_AddCommand ("noclip", Host_Noclip_f);
1769                 Cmd_AddCommand ("give", Host_Give_f);
1770         }
1771         Cmd_AddCommand ("map", Host_Map_f);
1772         Cmd_AddCommand ("restart", Host_Restart_f);
1773         Cmd_AddCommand ("changelevel", Host_Changelevel_f);
1774         Cmd_AddCommand ("connect", Host_Connect_f);
1775         Cmd_AddCommand ("reconnect", Host_Reconnect_f);
1776         Cmd_AddCommand ("version", Host_Version_f);
1777         Cmd_AddCommand ("say", Host_Say_f);
1778         Cmd_AddCommand ("say_team", Host_Say_Team_f);
1779         Cmd_AddCommand ("tell", Host_Tell_f);
1780         Cmd_AddCommand ("kill", Host_Kill_f);
1781         Cmd_AddCommand ("pause", Host_Pause_f);
1782         Cmd_AddCommand ("kick", Host_Kick_f);
1783         Cmd_AddCommand ("ping", Host_Ping_f);
1784         Cmd_AddCommand ("load", Host_Loadgame_f);
1785         Cmd_AddCommand ("save", Host_Savegame_f);
1786
1787         Cmd_AddCommand ("startdemos", Host_Startdemos_f);
1788         Cmd_AddCommand ("demos", Host_Demos_f);
1789         Cmd_AddCommand ("stopdemo", Host_Stopdemo_f);
1790
1791         Cmd_AddCommand ("viewmodel", Host_Viewmodel_f);
1792         Cmd_AddCommand ("viewframe", Host_Viewframe_f);
1793         Cmd_AddCommand ("viewnext", Host_Viewnext_f);
1794         Cmd_AddCommand ("viewprev", Host_Viewprev_f);
1795
1796         Cvar_RegisterVariable (&cl_name);
1797         Cmd_AddCommand ("name", Host_Name_f);
1798         Cvar_RegisterVariable (&cl_color);
1799         Cmd_AddCommand ("color", Host_Color_f);
1800         Cvar_RegisterVariable (&cl_rate);
1801         Cmd_AddCommand ("rate", Host_Rate_f);
1802         if (gamemode == GAME_NEHAHRA)
1803         {
1804                 Cvar_RegisterVariable (&cl_pmodel);
1805                 Cmd_AddCommand ("pmodel", Host_PModel_f);
1806         }
1807         Cmd_AddCommand ("prespawn", Host_PreSpawn_f);
1808         Cmd_AddCommand ("spawn", Host_Spawn_f);
1809         Cmd_AddCommand ("begin", Host_Begin_f);
1810         Cmd_AddCommand ("maxplayers", MaxPlayers_f);
1811
1812         Cvar_RegisterVariable(&sv_cheats);
1813 }
1814