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