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