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