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