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