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