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