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