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