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