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