]> icculus.org git repositories - divverent/darkplaces.git/blob - host_cmd.c
allow changelevel to stop demos (necessary for nexuiz menu)
[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", "enables cheat commands in any game, and cheat impulses in dpmod"};
25 cvar_t rcon_password = {0, "rcon_password", "", "password to authenticate rcon commands"};
26 cvar_t rcon_address = {0, "rcon_address", "", "server address to send rcon commands to (when not connected to a server)"};
27 qboolean allowcheats = false;
28
29 /*
30 ==================
31 Host_Quit_f
32 ==================
33 */
34
35 void Host_Quit_f (void)
36 {
37         Sys_Quit ();
38 }
39
40
41 /*
42 ==================
43 Host_Status_f
44 ==================
45 */
46 void Host_Status_f (void)
47 {
48         client_t *client;
49         int seconds, minutes, hours = 0, j, players;
50         void (*print) (const char *fmt, ...);
51
52         if (cmd_source == src_command)
53         {
54                 if (!sv.active)
55                 {
56                         Cmd_ForwardToServer ();
57                         return;
58                 }
59                 print = Con_Printf;
60         }
61         else
62                 print = SV_ClientPrintf;
63
64         for (players = 0, j = 0;j < svs.maxclients;j++)
65                 if (svs.clients[j].active)
66                         players++;
67         print ("host:     %s\n", Cvar_VariableString ("hostname"));
68         print ("version:  %s build %s\n", gamename, buildstring);
69         print ("protocol: %i (%s)\n", Protocol_NumberForEnum(sv.protocol), Protocol_NameForEnum(sv.protocol));
70         print ("map:      %s\n", sv.name);
71         print ("players:  %i active (%i max)\n\n", players, svs.maxclients);
72         for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
73         {
74                 if (!client->active)
75                         continue;
76                 seconds = (int)(realtime - client->connecttime);
77                 minutes = seconds / 60;
78                 if (minutes)
79                 {
80                         seconds -= (minutes * 60);
81                         hours = minutes / 60;
82                         if (hours)
83                                 minutes -= (hours * 60);
84                 }
85                 else
86                         hours = 0;
87                 print ("#%-2u %-16.16s  %3i  %2i:%02i:%02i\n", j+1, client->name, (int)client->edict->fields.server->frags, hours, minutes, seconds);
88                 print ("   %s\n", client->netconnection ? client->netconnection->address : "botclient");
89         }
90 }
91
92
93 /*
94 ==================
95 Host_God_f
96
97 Sets client to godmode
98 ==================
99 */
100 void Host_God_f (void)
101 {
102         if (cmd_source == src_command)
103         {
104                 Cmd_ForwardToServer ();
105                 return;
106         }
107
108         if (!allowcheats)
109         {
110                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
111                 return;
112         }
113
114         host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_GODMODE;
115         if (!((int)host_client->edict->fields.server->flags & FL_GODMODE) )
116                 SV_ClientPrint("godmode OFF\n");
117         else
118                 SV_ClientPrint("godmode ON\n");
119 }
120
121 void Host_Notarget_f (void)
122 {
123         if (cmd_source == src_command)
124         {
125                 Cmd_ForwardToServer ();
126                 return;
127         }
128
129         if (!allowcheats)
130         {
131                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
132                 return;
133         }
134
135         host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_NOTARGET;
136         if (!((int)host_client->edict->fields.server->flags & FL_NOTARGET) )
137                 SV_ClientPrint("notarget OFF\n");
138         else
139                 SV_ClientPrint("notarget ON\n");
140 }
141
142 qboolean noclip_anglehack;
143
144 void Host_Noclip_f (void)
145 {
146         if (cmd_source == src_command)
147         {
148                 Cmd_ForwardToServer ();
149                 return;
150         }
151
152         if (!allowcheats)
153         {
154                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
155                 return;
156         }
157
158         if (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP)
159         {
160                 noclip_anglehack = true;
161                 host_client->edict->fields.server->movetype = MOVETYPE_NOCLIP;
162                 SV_ClientPrint("noclip ON\n");
163         }
164         else
165         {
166                 noclip_anglehack = false;
167                 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
168                 SV_ClientPrint("noclip OFF\n");
169         }
170 }
171
172 /*
173 ==================
174 Host_Fly_f
175
176 Sets client to flymode
177 ==================
178 */
179 void Host_Fly_f (void)
180 {
181         if (cmd_source == src_command)
182         {
183                 Cmd_ForwardToServer ();
184                 return;
185         }
186
187         if (!allowcheats)
188         {
189                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
190                 return;
191         }
192
193         if (host_client->edict->fields.server->movetype != MOVETYPE_FLY)
194         {
195                 host_client->edict->fields.server->movetype = MOVETYPE_FLY;
196                 SV_ClientPrint("flymode ON\n");
197         }
198         else
199         {
200                 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
201                 SV_ClientPrint("flymode OFF\n");
202         }
203 }
204
205
206 /*
207 ==================
208 Host_Ping_f
209
210 ==================
211 */
212 void Host_Ping_f (void)
213 {
214         int i;
215         client_t *client;
216         void (*print) (const char *fmt, ...);
217
218         if (cmd_source == src_command)
219         {
220                 if (!sv.active)
221                 {
222                         Cmd_ForwardToServer ();
223                         return;
224                 }
225                 print = Con_Printf;
226         }
227         else
228                 print = SV_ClientPrintf;
229
230         print("Client ping times:\n");
231         for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
232         {
233                 if (!client->active)
234                         continue;
235                 print("%4i %s\n", (int)floor(client->ping*1000+0.5), client->name);
236         }
237 }
238
239 /*
240 ===============================================================================
241
242 SERVER TRANSITIONS
243
244 ===============================================================================
245 */
246
247 /*
248 ======================
249 Host_Map_f
250
251 handle a
252 map <servername>
253 command from the console.  Active clients are kicked off.
254 ======================
255 */
256 void Host_Map_f (void)
257 {
258         char level[MAX_QPATH];
259
260         if (Cmd_Argc() != 2)
261         {
262                 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
263                 return;
264         }
265
266         if (cmd_source != src_command)
267                 return;
268
269         cls.demonum = -1;               // stop demo loop in case this fails
270
271         CL_Disconnect ();
272         Host_ShutdownServer();
273
274         // remove menu
275         key_dest = key_game;
276
277         svs.serverflags = 0;                    // haven't completed an episode yet
278         allowcheats = sv_cheats.integer != 0;
279         strcpy(level, Cmd_Argv(1));
280         SV_SpawnServer(level);
281         if (sv.active && cls.state == ca_disconnected)
282                 CL_EstablishConnection("local:1");
283
284 // if cl_autodemo is set, automatically start recording a demo if one isn't being recorded already
285         if (cl_autodemo.integer && !cls.demorecording)
286         {
287                 char demofile[MAX_OSPATH];
288
289                 dpsnprintf (demofile, sizeof(demofile), "%s_%s.dem", Sys_TimeString (cl_autodemo_nameformat.string), level);
290
291                 Con_Printf ("Recording to %s.\n", demofile);
292
293                 cls.demofile = FS_Open (demofile, "wb", false, false);
294                 if (cls.demofile)
295                 {
296                         cls.forcetrack = -1;
297                         FS_Printf (cls.demofile, "%i\n", cls.forcetrack);
298                 }
299                 else
300                         Con_Print ("ERROR: couldn't open.\n");
301
302                 cls.demorecording = true;
303         }
304 }
305
306 /*
307 ==================
308 Host_Changelevel_f
309
310 Goes to a new map, taking all clients along
311 ==================
312 */
313 void Host_Changelevel_f (void)
314 {
315         char level[MAX_QPATH];
316
317         if (Cmd_Argc() != 2)
318         {
319                 Con_Print("changelevel <levelname> : continue game on a new level\n");
320                 return;
321         }
322         // HACKHACKHACK
323         if (!sv.active) {
324                 Host_Map_f();
325                 return;
326         }
327         if (cmd_source != src_command)
328                 return;
329
330         // remove menu
331         key_dest = key_game;
332
333         SV_VM_Begin();
334         SV_SaveSpawnparms ();
335         SV_VM_End();
336         allowcheats = sv_cheats.integer != 0;
337         strcpy(level, Cmd_Argv(1));
338         SV_SpawnServer(level);
339         if (sv.active && cls.state == ca_disconnected)
340                 CL_EstablishConnection("local:1");
341 }
342
343 /*
344 ==================
345 Host_Restart_f
346
347 Restarts the current server for a dead player
348 ==================
349 */
350 void Host_Restart_f (void)
351 {
352         char mapname[MAX_QPATH];
353
354         if (Cmd_Argc() != 1)
355         {
356                 Con_Print("restart : restart current level\n");
357                 return;
358         }
359         if (!sv.active)
360         {
361                 Con_Print("Only the server may restart\n");
362                 return;
363         }
364         if (cmd_source != src_command)
365                 return;
366
367         // remove menu
368         key_dest = key_game;
369
370         allowcheats = sv_cheats.integer != 0;
371         strcpy(mapname, sv.name);
372         SV_SpawnServer(mapname);
373         if (sv.active && cls.state == ca_disconnected)
374                 CL_EstablishConnection("local:1");
375 }
376
377 /*
378 ==================
379 Host_Reconnect_f
380
381 This command causes the client to wait for the signon messages again.
382 This is sent just before a server changes levels
383 ==================
384 */
385 void Host_Reconnect_f (void)
386 {
387         if (cls.protocol == PROTOCOL_QUAKEWORLD)
388         {
389                 if (cls.qw_downloadmemory)  // don't change when downloading
390                         return;
391
392                 S_StopAllSounds();
393
394                 if (cls.netcon)
395                 {
396                         if (cls.state == ca_connected && cls.signon < SIGNONS)
397                         {
398                                 Con_Printf("reconnecting...\n");
399                                 MSG_WriteChar(&cls.netcon->message, qw_clc_stringcmd);
400                                 MSG_WriteString(&cls.netcon->message, "new");
401                         }
402                         else
403                                 Con_Printf("Please use connect instead (reconnect not implemented)\n");
404                 }
405         }
406         else
407         {
408                 if (Cmd_Argc() != 1)
409                 {
410                         Con_Print("reconnect : wait for signon messages again\n");
411                         return;
412                 }
413                 if (!cls.signon)
414                 {
415                         Con_Print("reconnect: no signon, ignoring reconnect\n");
416                         return;
417                 }
418                 cls.signon = 0;         // need new connection messages
419         }
420 }
421
422 /*
423 =====================
424 Host_Connect_f
425
426 User command to connect to server
427 =====================
428 */
429 void Host_Connect_f (void)
430 {
431         if (Cmd_Argc() != 2)
432         {
433                 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
434                 return;
435         }
436         CL_EstablishConnection(Cmd_Argv(1));
437 }
438
439
440 /*
441 ===============================================================================
442
443 LOAD / SAVE GAME
444
445 ===============================================================================
446 */
447
448 #define SAVEGAME_VERSION        5
449
450 /*
451 ===============
452 Host_SavegameComment
453
454 Writes a SAVEGAME_COMMENT_LENGTH character comment describing the current
455 ===============
456 */
457 void Host_SavegameComment (char *text)
458 {
459         int             i;
460         char    kills[20];
461
462         for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
463                 text[i] = ' ';
464         // LordHavoc: added min() to prevent overflow
465         memcpy (text, cl.levelname, min(strlen(cl.levelname), SAVEGAME_COMMENT_LENGTH));
466         sprintf (kills,"kills:%3i/%3i", cl.stats[STAT_MONSTERS], cl.stats[STAT_TOTALMONSTERS]);
467         memcpy (text+22, kills, strlen(kills));
468         // convert space to _ to make stdio happy
469         // LordHavoc: convert control characters to _ as well
470         for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
471                 if (text[i] <= ' ')
472                         text[i] = '_';
473         text[SAVEGAME_COMMENT_LENGTH] = '\0';
474 }
475
476
477 /*
478 ===============
479 Host_Savegame_f
480 ===============
481 */
482 void Host_Savegame_f (void)
483 {
484         char    name[MAX_QPATH];
485         qfile_t *f;
486         int             i;
487         char    comment[SAVEGAME_COMMENT_LENGTH+1];
488
489         if (cmd_source != src_command)
490                 return;
491
492         if (cls.state != ca_connected || !sv.active)
493         {
494                 Con_Print("Not playing a local game.\n");
495                 return;
496         }
497
498         if (cl.intermission)
499         {
500                 Con_Print("Can't save in intermission.\n");
501                 return;
502         }
503
504         for (i = 0;i < svs.maxclients;i++)
505         {
506                 if (svs.clients[i].active)
507                 {
508                         if (i > 0)
509                         {
510                                 Con_Print("Can't save multiplayer games.\n");
511                                 return;
512                         }
513                         if (svs.clients[i].edict->fields.server->deadflag)
514                         {
515                                 Con_Print("Can't savegame with a dead player\n");
516                                 return;
517                         }
518                 }
519         }
520
521         if (Cmd_Argc() != 2)
522         {
523                 Con_Print("save <savename> : save a game\n");
524                 return;
525         }
526
527         if (strstr(Cmd_Argv(1), ".."))
528         {
529                 Con_Print("Relative pathnames are not allowed.\n");
530                 return;
531         }
532
533         strlcpy (name, Cmd_Argv(1), sizeof (name));
534         FS_DefaultExtension (name, ".sav", sizeof (name));
535
536         Con_Printf("Saving game to %s...\n", name);
537         f = FS_Open (name, "wb", false, false);
538         if (!f)
539         {
540                 Con_Print("ERROR: couldn't open.\n");
541                 return;
542         }
543
544         FS_Printf(f, "%i\n", SAVEGAME_VERSION);
545         Host_SavegameComment (comment);
546         FS_Printf(f, "%s\n", comment);
547         for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
548                 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
549         FS_Printf(f, "%d\n", current_skill);
550         FS_Printf(f, "%s\n", sv.name);
551         FS_Printf(f, "%f\n",sv.time);
552
553         // write the light styles
554         for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
555         {
556                 if (sv.lightstyles[i][0])
557                         FS_Printf(f, "%s\n", sv.lightstyles[i]);
558                 else
559                         FS_Print(f,"m\n");
560         }
561
562         SV_VM_Begin();
563
564         PRVM_ED_WriteGlobals (f);
565         for (i=0 ; i<prog->num_edicts ; i++)
566                 PRVM_ED_Write (f, PRVM_EDICT_NUM(i));
567
568         SV_VM_End();
569
570         FS_Close (f);
571         Con_Print("done.\n");
572 }
573
574
575 /*
576 ===============
577 Host_Loadgame_f
578 ===============
579 */
580 void Host_Loadgame_f (void)
581 {
582         char filename[MAX_QPATH];
583         char mapname[MAX_QPATH];
584         float time;
585         const char *start;
586         const char *t;
587         const char *oldt;
588         char *text;
589         prvm_edict_t *ent;
590         int i;
591         int entnum;
592         int version;
593         float spawn_parms[NUM_SPAWN_PARMS];
594
595         if (cmd_source != src_command)
596                 return;
597
598         if (Cmd_Argc() != 2)
599         {
600                 Con_Print("load <savename> : load a game\n");
601                 return;
602         }
603
604         strcpy (filename, Cmd_Argv(1));
605         FS_DefaultExtension (filename, ".sav", sizeof (filename));
606
607         Con_Printf("Loading game from %s...\n", filename);
608
609         cls.demonum = -1;               // stop demo loop in case this fails
610
611         t = text = (char *)FS_LoadFile (filename, tempmempool, false, NULL);
612         if (!text)
613         {
614                 Con_Print("ERROR: couldn't open.\n");
615                 return;
616         }
617
618         // version
619         COM_ParseToken(&t, false);
620         version = atoi(com_token);
621         if (version != SAVEGAME_VERSION)
622         {
623                 Mem_Free(text);
624                 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
625                 return;
626         }
627
628         // description
629         // this is a little hard to parse, as : is a separator in COM_ParseToken,
630         // so use the console parser instead
631         COM_ParseTokenConsole(&t);
632
633         for (i = 0;i < NUM_SPAWN_PARMS;i++)
634         {
635                 COM_ParseToken(&t, false);
636                 spawn_parms[i] = atof(com_token);
637         }
638         // skill
639         COM_ParseToken(&t, false);
640 // this silliness is so we can load 1.06 save files, which have float skill values
641         current_skill = (int)(atof(com_token) + 0.5);
642         Cvar_SetValue ("skill", (float)current_skill);
643
644         // mapname
645         COM_ParseToken(&t, false);
646         strcpy (mapname, com_token);
647
648         // time
649         COM_ParseToken(&t, false);
650         time = atof(com_token);
651
652         allowcheats = sv_cheats.integer != 0;
653
654         SV_SpawnServer (mapname);
655         if (!sv.active)
656         {
657                 Mem_Free(text);
658                 Con_Print("Couldn't load map\n");
659                 return;
660         }
661         sv.paused = true;               // pause until all clients connect
662         sv.loadgame = true;
663
664 // load the light styles
665
666         for (i = 0;i < MAX_LIGHTSTYLES;i++)
667         {
668                 // light style
669                 oldt = t;
670                 COM_ParseToken(&t, false);
671                 // if this is a 64 lightstyle savegame produced by Quake, stop now
672                 // we have to check this because darkplaces saves 256 lightstyle savegames
673                 if (com_token[0] == '{')
674                 {
675                         t = oldt;
676                         break;
677                 }
678                 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
679         }
680
681         // now skip everything before the first opening brace
682         // (this is for forward compatibility, so that older versions (at
683         // least ones with this fix) can load savegames with extra data before the
684         // first brace, as might be produced by a later engine version)
685         for(;;)
686         {
687                 oldt = t;
688                 COM_ParseToken(&t, false);
689                 if (com_token[0] == '{')
690                 {
691                         t = oldt;
692                         break;
693                 }
694         }
695
696 // load the edicts out of the savegame file
697         SV_VM_Begin();
698         // -1 is the globals
699         entnum = -1;
700         for (;;)
701         {
702                 start = t;
703                 while (COM_ParseToken(&t, false))
704                         if (!strcmp(com_token, "}"))
705                                 break;
706                 if (!COM_ParseToken(&start, false))
707                 {
708                         // end of file
709                         break;
710                 }
711                 if (strcmp(com_token,"{"))
712                 {
713                         Mem_Free(text);
714                         Host_Error ("First token isn't a brace");
715                 }
716
717                 if (entnum == -1)
718                 {
719                         // parse the global vars
720                         PRVM_ED_ParseGlobals (start);
721                 }
722                 else
723                 {
724                         // parse an edict
725                         if (entnum >= MAX_EDICTS)
726                         {
727                                 Mem_Free(text);
728                                 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)", MAX_EDICTS);
729                         }
730                         while (entnum >= prog->max_edicts)
731                                 //SV_IncreaseEdicts();
732                                 PRVM_MEM_IncreaseEdicts();
733                         ent = PRVM_EDICT_NUM(entnum);
734                         memset (ent->fields.server, 0, prog->progs->entityfields * 4);
735                         ent->priv.server->free = false;
736                         PRVM_ED_ParseEdict (start, ent);
737
738                         // link it into the bsp tree
739                         if (!ent->priv.server->free)
740                                 SV_LinkEdict (ent, false);
741                 }
742
743                 entnum++;
744         }
745         Mem_Free(text);
746
747         prog->num_edicts = entnum;
748         sv.time = time;
749
750         for (i = 0;i < NUM_SPAWN_PARMS;i++)
751                 svs.clients[0].spawn_parms[i] = spawn_parms[i];
752
753         SV_VM_End();
754
755         // make sure we're connected to loopback
756         if (cls.state == ca_disconnected || !(cls.state == ca_connected && cls.netcon != NULL && LHNETADDRESS_GetAddressType(&cls.netcon->peeraddress) == LHNETADDRESSTYPE_LOOP))
757                 CL_EstablishConnection("local:1");
758 }
759
760 //============================================================================
761
762 /*
763 ======================
764 Host_Name_f
765 ======================
766 */
767 cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player", "internal storage cvar for current player name (changed by name command)"};
768 void Host_Name_f (void)
769 {
770         int i, j;
771         char newName[sizeof(host_client->name)];
772
773         if (Cmd_Argc () == 1)
774         {
775                 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
776                 return;
777         }
778
779         if (Cmd_Argc () == 2)
780                 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
781         else
782                 strlcpy (newName, Cmd_Args(), sizeof (newName));
783
784         for (i = 0, j = 0;newName[i];i++)
785                 if (newName[i] != '\r' && newName[i] != '\n')
786                         newName[j++] = newName[i];
787         newName[j] = 0;
788
789         if (cmd_source == src_command)
790         {
791                 Cvar_Set ("_cl_name", newName);
792                 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "name", newName);
793                 if (cls.state == ca_connected)
794                         Cmd_ForwardToServer ();
795                 return;
796         }
797
798         if (sv.time < host_client->nametime)
799         {
800                 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
801                 return;
802         }
803
804         host_client->nametime = sv.time + 5;
805
806         // point the string back at updateclient->name to keep it safe
807         strlcpy (host_client->name, newName, sizeof (host_client->name));
808         host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
809         if (strcmp(host_client->old_name, host_client->name))
810         {
811                 if (host_client->spawned)
812                         SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
813                 strcpy(host_client->old_name, host_client->name);
814                 // send notification to all clients
815                 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
816                 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
817                 MSG_WriteString (&sv.reliable_datagram, host_client->name);
818         }
819 }
820
821 /*
822 ======================
823 Host_Playermodel_f
824 ======================
825 */
826 cvar_t cl_playermodel = {CVAR_SAVE, "_cl_playermodel", "", "internal storage cvar for current player model in Nexuiz (changed by playermodel command)"};
827 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
828 void Host_Playermodel_f (void)
829 {
830         int i, j;
831         char newPath[sizeof(host_client->playermodel)];
832
833         if (Cmd_Argc () == 1)
834         {
835                 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
836                 return;
837         }
838
839         if (Cmd_Argc () == 2)
840                 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
841         else
842                 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
843
844         for (i = 0, j = 0;newPath[i];i++)
845                 if (newPath[i] != '\r' && newPath[i] != '\n')
846                         newPath[j++] = newPath[i];
847         newPath[j] = 0;
848
849         if (cmd_source == src_command)
850         {
851                 Cvar_Set ("_cl_playermodel", newPath);
852                 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "playermodel", newPath);
853                 if (cls.state == ca_connected)
854                         Cmd_ForwardToServer ();
855                 return;
856         }
857
858         /*
859         if (sv.time < host_client->nametime)
860         {
861                 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
862                 return;
863         }
864
865         host_client->nametime = sv.time + 5;
866         */
867
868         // point the string back at updateclient->name to keep it safe
869         strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
870         if( eval_playermodel )
871                 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
872         if (strcmp(host_client->old_model, host_client->playermodel))
873         {
874                 strcpy(host_client->old_model, host_client->playermodel);
875                 /*// send notification to all clients
876                 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
877                 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
878                 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
879         }
880 }
881
882 /*
883 ======================
884 Host_Playerskin_f
885 ======================
886 */
887 cvar_t cl_playerskin = {CVAR_SAVE, "_cl_playerskin", "", "internal storage cvar for current player skin in Nexuiz (changed by playerskin command)"};
888 void Host_Playerskin_f (void)
889 {
890         int i, j;
891         char newPath[sizeof(host_client->playerskin)];
892
893         if (Cmd_Argc () == 1)
894         {
895                 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
896                 return;
897         }
898
899         if (Cmd_Argc () == 2)
900                 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
901         else
902                 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
903
904         for (i = 0, j = 0;newPath[i];i++)
905                 if (newPath[i] != '\r' && newPath[i] != '\n')
906                         newPath[j++] = newPath[i];
907         newPath[j] = 0;
908
909         if (cmd_source == src_command)
910         {
911                 Cvar_Set ("_cl_playerskin", newPath);
912                 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "playerskin", newPath);
913                 if (cls.state == ca_connected)
914                         Cmd_ForwardToServer ();
915                 return;
916         }
917
918         /*
919         if (sv.time < host_client->nametime)
920         {
921                 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
922                 return;
923         }
924
925         host_client->nametime = sv.time + 5;
926         */
927
928         // point the string back at updateclient->name to keep it safe
929         strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
930         if( eval_playerskin )
931                 PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
932         if (strcmp(host_client->old_skin, host_client->playerskin))
933         {
934                 if (host_client->spawned)
935                         SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
936                 strcpy(host_client->old_skin, host_client->playerskin);
937                 /*// send notification to all clients
938                 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
939                 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
940                 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
941         }
942 }
943
944 void Host_Version_f (void)
945 {
946         Con_Printf("Version: %s build %s\n", gamename, buildstring);
947 }
948
949 void Host_Say(qboolean teamonly)
950 {
951         client_t *save;
952         int j, quoted;
953         const char *p1;
954         char *p2;
955         // LordHavoc: long say messages
956         char text[1024];
957         qboolean fromServer = false;
958
959         if (cmd_source == src_command)
960         {
961                 if (cls.state == ca_dedicated)
962                 {
963                         fromServer = true;
964                         teamonly = false;
965                 }
966                 else
967                 {
968                         Cmd_ForwardToServer ();
969                         return;
970                 }
971         }
972
973         if (Cmd_Argc () < 2)
974                 return;
975
976         if (!teamplay.integer)
977                 teamonly = false;
978
979 // turn on color set 1
980         p1 = Cmd_Args();
981         quoted = false;
982         if (*p1 == '\"')
983         {
984                 quoted = true;
985                 p1++;
986         }
987         if (!fromServer)
988                 dpsnprintf (text, sizeof(text), "%c%s" STRING_COLOR_DEFAULT_STR ": %s", 1, host_client->name, p1);
989         else
990                 dpsnprintf (text, sizeof(text), "%c<%s" STRING_COLOR_DEFAULT_STR "> %s", 1, hostname.string, p1);
991         p2 = text + strlen(text);
992         while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
993         {
994                 if (p2[-1] == '\"' && quoted)
995                         quoted = false;
996                 p2[-1] = 0;
997                 p2--;
998         }
999         strlcat(text, "\n", sizeof(text));
1000
1001         // note: save is not a valid edict if fromServer is true
1002         save = host_client;
1003         for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1004                 if (host_client->spawned && (!teamonly || host_client->edict->fields.server->team == save->edict->fields.server->team))
1005                         SV_ClientPrint(text);
1006         host_client = save;
1007
1008         if (cls.state == ca_dedicated)
1009                 Con_Print(&text[1]);
1010 }
1011
1012
1013 void Host_Say_f(void)
1014 {
1015         Host_Say(false);
1016 }
1017
1018
1019 void Host_Say_Team_f(void)
1020 {
1021         Host_Say(true);
1022 }
1023
1024
1025 void Host_Tell_f(void)
1026 {
1027         client_t *save;
1028         int j;
1029         const char *p1, *p2;
1030         char text[MAX_INPUTLINE]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
1031         qboolean fromServer = false;
1032
1033         if (cmd_source == src_command)
1034         {
1035                 if (cls.state == ca_dedicated)
1036                         fromServer = true;
1037                 else
1038                 {
1039                         Cmd_ForwardToServer ();
1040                         return;
1041                 }
1042         }
1043
1044         if (Cmd_Argc () < 3)
1045                 return;
1046
1047         if (!fromServer)
1048                 sprintf (text, "%s: ", host_client->name);
1049         else
1050                 sprintf (text, "<%s> ", hostname.string);
1051
1052         p1 = Cmd_Args();
1053         p2 = p1 + strlen(p1);
1054         // remove the target name
1055         while (p1 < p2 && *p1 != ' ')
1056                 p1++;
1057         while (p1 < p2 && *p1 == ' ')
1058                 p1++;
1059         // remove trailing newlines
1060         while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1061                 p2--;
1062         // remove quotes if present
1063         if (*p1 == '"')
1064         {
1065                 p1++;
1066                 if (p2[-1] == '"')
1067                         p2--;
1068                 else if (fromServer)
1069                         Con_Print("Host_Tell: missing end quote\n");
1070                 else
1071                         SV_ClientPrint("Host_Tell: missing end quote\n");
1072         }
1073         while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1074                 p2--;
1075         for (j = (int)strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1076                 text[j++] = *p1++;
1077         text[j++] = '\n';
1078         text[j++] = 0;
1079
1080         save = host_client;
1081         for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1082                 if (host_client->spawned && !strcasecmp(host_client->name, Cmd_Argv(1)))
1083                         SV_ClientPrint(text);
1084         host_client = save;
1085 }
1086
1087
1088 /*
1089 ==================
1090 Host_Color_f
1091 ==================
1092 */
1093 cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0", "internal storage cvar for current player colors (changed by color command)"};
1094 void Host_Color_f(void)
1095 {
1096         int             top, bottom;
1097         int             playercolor;
1098         mfunction_t *f;
1099         func_t  SV_ChangeTeam;
1100
1101         if (Cmd_Argc() == 1)
1102         {
1103                 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1104                 Con_Print("color <0-15> [0-15]\n");
1105                 return;
1106         }
1107
1108         if (Cmd_Argc() == 2)
1109                 top = bottom = atoi(Cmd_Argv(1));
1110         else
1111         {
1112                 top = atoi(Cmd_Argv(1));
1113                 bottom = atoi(Cmd_Argv(2));
1114         }
1115
1116         top &= 15;
1117         // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1118         if (top > 15)
1119                 top = 15;
1120         bottom &= 15;
1121         // LordHavoc: allow skin colormaps 14 and 15 (was 13)
1122         if (bottom > 15)
1123                 bottom = 15;
1124
1125         playercolor = top*16 + bottom;
1126
1127         if (cmd_source == src_command)
1128         {
1129                 Cvar_SetValue ("_cl_color", playercolor);
1130                 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "topcolor", va("%i", top));
1131                 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "bottomcolor", va("%i", bottom));
1132                 if (cls.state == ca_connected && cls.protocol != PROTOCOL_QUAKEWORLD)
1133                         Cmd_ForwardToServer ();
1134                 return;
1135         }
1136
1137         if (cls.protocol == PROTOCOL_QUAKEWORLD)
1138                 return;
1139
1140         if (host_client->edict && (f = PRVM_ED_FindFunction ("SV_ChangeTeam")) && (SV_ChangeTeam = (func_t)(f - prog->functions)))
1141         {
1142                 Con_DPrint("Calling SV_ChangeTeam\n");
1143                 prog->globals.server->time = sv.time;
1144                 prog->globals.generic[OFS_PARM0] = playercolor;
1145                 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1146                 PRVM_ExecuteProgram (SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1147         }
1148         else
1149         {
1150                 prvm_eval_t *val;
1151                 if (host_client->edict)
1152                 {
1153                         if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_clientcolors)))
1154                                 val->_float = playercolor;
1155                         host_client->edict->fields.server->team = bottom + 1;
1156                 }
1157                 host_client->colors = playercolor;
1158                 if (host_client->old_colors != host_client->colors)
1159                 {
1160                         host_client->old_colors = host_client->colors;
1161                         // send notification to all clients
1162                         MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1163                         MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1164                         MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1165                 }
1166         }
1167 }
1168
1169 cvar_t cl_rate = {CVAR_SAVE, "_cl_rate", "10000", "internal storage cvar for current rate (changed by rate command)"};
1170 void Host_Rate_f(void)
1171 {
1172         int rate;
1173
1174         if (Cmd_Argc() != 2)
1175         {
1176                 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1177                 Con_Print("rate <500-25000>\n");
1178                 return;
1179         }
1180
1181         rate = atoi(Cmd_Argv(1));
1182
1183         if (cmd_source == src_command)
1184         {
1185                 Cvar_SetValue ("_cl_rate", bound(NET_MINRATE, rate, NET_MAXRATE));
1186                 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), "rate", va("%i", rate));
1187                 if (cls.state == ca_connected)
1188                         Cmd_ForwardToServer ();
1189                 return;
1190         }
1191
1192         host_client->rate = rate;
1193 }
1194
1195 /*
1196 ==================
1197 Host_Kill_f
1198 ==================
1199 */
1200 void Host_Kill_f (void)
1201 {
1202         if (cmd_source == src_command)
1203         {
1204                 Cmd_ForwardToServer ();
1205                 return;
1206         }
1207
1208         if (host_client->edict->fields.server->health <= 0)
1209         {
1210                 SV_ClientPrint("Can't suicide -- already dead!\n");
1211                 return;
1212         }
1213
1214         prog->globals.server->time = sv.time;
1215         prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1216         PRVM_ExecuteProgram (prog->globals.server->ClientKill, "QC function ClientKill is missing");
1217 }
1218
1219
1220 /*
1221 ==================
1222 Host_Pause_f
1223 ==================
1224 */
1225 void Host_Pause_f (void)
1226 {
1227
1228         if (cmd_source == src_command)
1229         {
1230                 Cmd_ForwardToServer ();
1231                 return;
1232         }
1233         if (!pausable.integer)
1234                 SV_ClientPrint("Pause not allowed.\n");
1235         else
1236         {
1237                 sv.paused ^= 1;
1238                 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1239                 // send notification to all clients
1240                 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1241                 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1242         }
1243 }
1244
1245 /*
1246 ======================
1247 Host_PModel_f
1248 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1249 LordHavoc: correction, Mindcrime will be removing pmodel in the future, but it's still stuck here for compatibility.
1250 ======================
1251 */
1252 cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0", "internal storage cvar for current player model number in nehahra (changed by pmodel command)"};
1253 static void Host_PModel_f (void)
1254 {
1255         int i;
1256         prvm_eval_t *val;
1257
1258         if (Cmd_Argc () == 1)
1259         {
1260                 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1261                 return;
1262         }
1263         i = atoi(Cmd_Argv(1));
1264
1265         if (cmd_source == src_command)
1266         {
1267                 if (cl_pmodel.integer == i)
1268                         return;
1269                 Cvar_SetValue ("_cl_pmodel", i);
1270                 if (cls.state == ca_connected)
1271                         Cmd_ForwardToServer ();
1272                 return;
1273         }
1274
1275         if (host_client->edict && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_pmodel)))
1276                 val->_float = i;
1277 }
1278
1279 //===========================================================================
1280
1281
1282 /*
1283 ==================
1284 Host_PreSpawn_f
1285 ==================
1286 */
1287 void Host_PreSpawn_f (void)
1288 {
1289         if (cmd_source == src_command)
1290         {
1291                 Con_Print("prespawn is not valid from the console\n");
1292                 return;
1293         }
1294
1295         if (host_client->spawned)
1296         {
1297                 Con_Print("prespawn not valid -- already spawned\n");
1298                 return;
1299         }
1300
1301         if (host_client->netconnection)
1302         {
1303                 SZ_Write (&host_client->netconnection->message, sv.signon.data, sv.signon.cursize);
1304                 MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1305                 MSG_WriteByte (&host_client->netconnection->message, 2);
1306         }
1307
1308         // reset the name change timer because the client will send name soon
1309         host_client->nametime = 0;
1310 }
1311
1312 /*
1313 ==================
1314 Host_Spawn_f
1315 ==================
1316 */
1317 void Host_Spawn_f (void)
1318 {
1319         int i;
1320         client_t *client;
1321         func_t RestoreGame;
1322         mfunction_t *f;
1323         int stats[MAX_CL_STATS];
1324
1325         if (cmd_source == src_command)
1326         {
1327                 Con_Print("spawn is not valid from the console\n");
1328                 return;
1329         }
1330
1331         if (host_client->spawned)
1332         {
1333                 Con_Print("Spawn not valid -- already spawned\n");
1334                 return;
1335         }
1336
1337         // reset name change timer again because they might want to change name
1338         // again in the first 5 seconds after connecting
1339         host_client->nametime = 0;
1340
1341         // LordHavoc: moved this above the QC calls at FrikaC's request
1342         // LordHavoc: commented this out
1343         //if (host_client->netconnection)
1344         //      SZ_Clear (&host_client->netconnection->message);
1345
1346         // run the entrance script
1347         if (sv.loadgame)
1348         {
1349                 // loaded games are fully initialized already
1350                 // if this is the last client to be connected, unpause
1351                 sv.paused = false;
1352
1353                 if ((f = PRVM_ED_FindFunction ("RestoreGame")))
1354                 if ((RestoreGame = (func_t)(f - prog->functions)))
1355                 {
1356                         Con_DPrint("Calling RestoreGame\n");
1357                         prog->globals.server->time = sv.time;
1358                         prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1359                         PRVM_ExecuteProgram (RestoreGame, "QC function RestoreGame is missing");
1360                 }
1361         }
1362         else
1363         {
1364                 //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);
1365
1366                 // copy spawn parms out of the client_t
1367                 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1368                         (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
1369
1370                 // call the spawn function
1371                 host_client->clientconnectcalled = true;
1372                 prog->globals.server->time = sv.time;
1373                 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1374                 PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
1375
1376                 if ((Sys_DoubleTime() - host_client->connecttime) <= sv.time)
1377                         Con_Printf("%s entered the game\n", host_client->name);
1378
1379                 PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
1380         }
1381
1382         if (!host_client->netconnection)
1383                 return;
1384
1385         // send time of update
1386         MSG_WriteByte (&host_client->netconnection->message, svc_time);
1387         MSG_WriteFloat (&host_client->netconnection->message, sv.time);
1388
1389         // send all current names, colors, and frag counts
1390         for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1391         {
1392                 if (!client->active)
1393                         continue;
1394                 MSG_WriteByte (&host_client->netconnection->message, svc_updatename);
1395                 MSG_WriteByte (&host_client->netconnection->message, i);
1396                 MSG_WriteString (&host_client->netconnection->message, client->name);
1397                 MSG_WriteByte (&host_client->netconnection->message, svc_updatefrags);
1398                 MSG_WriteByte (&host_client->netconnection->message, i);
1399                 MSG_WriteShort (&host_client->netconnection->message, client->frags);
1400                 MSG_WriteByte (&host_client->netconnection->message, svc_updatecolors);
1401                 MSG_WriteByte (&host_client->netconnection->message, i);
1402                 MSG_WriteByte (&host_client->netconnection->message, client->colors);
1403         }
1404
1405         // send all current light styles
1406         for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1407         {
1408                 if (sv.lightstyles[i][0])
1409                 {
1410                         MSG_WriteByte (&host_client->netconnection->message, svc_lightstyle);
1411                         MSG_WriteByte (&host_client->netconnection->message, (char)i);
1412                         MSG_WriteString (&host_client->netconnection->message, sv.lightstyles[i]);
1413                 }
1414         }
1415
1416         // send some stats
1417         MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1418         MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALSECRETS);
1419         MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->total_secrets);
1420
1421         MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1422         MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALMONSTERS);
1423         MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->total_monsters);
1424
1425         MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1426         MSG_WriteByte (&host_client->netconnection->message, STAT_SECRETS);
1427         MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->found_secrets);
1428
1429         MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1430         MSG_WriteByte (&host_client->netconnection->message, STAT_MONSTERS);
1431         MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->killed_monsters);
1432
1433         // send a fixangle
1434         // Never send a roll angle, because savegames can catch the server
1435         // in a state where it is expecting the client to correct the angle
1436         // and it won't happen if the game was just loaded, so you wind up
1437         // with a permanent head tilt
1438         if (sv.loadgame)
1439         {
1440                 MSG_WriteByte (&host_client->netconnection->message, svc_setangle);
1441                 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->v_angle[0], sv.protocol);
1442                 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->v_angle[1], sv.protocol);
1443                 MSG_WriteAngle (&host_client->netconnection->message, 0, sv.protocol);
1444                 sv.loadgame = false; // we're basically done with loading now
1445         }
1446         else
1447         {
1448                 MSG_WriteByte (&host_client->netconnection->message, svc_setangle);
1449                 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[0], sv.protocol);
1450                 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[1], sv.protocol);
1451                 MSG_WriteAngle (&host_client->netconnection->message, 0, sv.protocol);
1452         }
1453
1454         SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->netconnection->message, stats);
1455
1456         MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1457         MSG_WriteByte (&host_client->netconnection->message, 3);
1458 }
1459
1460 /*
1461 ==================
1462 Host_Begin_f
1463 ==================
1464 */
1465 void Host_Begin_f (void)
1466 {
1467         if (cmd_source == src_command)
1468         {
1469                 Con_Print("begin is not valid from the console\n");
1470                 return;
1471         }
1472
1473         host_client->spawned = true;
1474 }
1475
1476 //===========================================================================
1477
1478
1479 /*
1480 ==================
1481 Host_Kick_f
1482
1483 Kicks a user off of the server
1484 ==================
1485 */
1486 void Host_Kick_f (void)
1487 {
1488         char *who;
1489         const char *message = NULL;
1490         client_t *save;
1491         int i;
1492         qboolean byNumber = false;
1493
1494         if (cmd_source != src_command || !sv.active)
1495                 return;
1496
1497         SV_VM_Begin();
1498         save = host_client;
1499
1500         if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1501         {
1502                 i = (int)(atof(Cmd_Argv(2)) - 1);
1503                 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1504                         return;
1505                 byNumber = true;
1506         }
1507         else
1508         {
1509                 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1510                 {
1511                         if (!host_client->active)
1512                                 continue;
1513                         if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1514                                 break;
1515                 }
1516         }
1517
1518         if (i < svs.maxclients)
1519         {
1520                 if (cmd_source == src_command)
1521                 {
1522                         if (cls.state == ca_dedicated)
1523                                 who = "Console";
1524                         else
1525                                 who = cl_name.string;
1526                 }
1527                 else
1528                         who = save->name;
1529
1530                 // can't kick yourself!
1531                 if (host_client == save)
1532                         return;
1533
1534                 if (Cmd_Argc() > 2)
1535                 {
1536                         message = Cmd_Args();
1537                         COM_ParseToken(&message, false);
1538                         if (byNumber)
1539                         {
1540                                 message++;                                                      // skip the #
1541                                 while (*message == ' ')                         // skip white space
1542                                         message++;
1543                                 message += strlen(Cmd_Argv(2)); // skip the number
1544                         }
1545                         while (*message && *message == ' ')
1546                                 message++;
1547                 }
1548                 if (message)
1549                         SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1550                 else
1551                         SV_ClientPrintf("Kicked by %s\n", who);
1552                 SV_DropClient (false); // kicked
1553         }
1554
1555         host_client = save;
1556         SV_VM_End();
1557 }
1558
1559 /*
1560 ===============================================================================
1561
1562 DEBUGGING TOOLS
1563
1564 ===============================================================================
1565 */
1566
1567 /*
1568 ==================
1569 Host_Give_f
1570 ==================
1571 */
1572 void Host_Give_f (void)
1573 {
1574         const char *t;
1575         int v;
1576         prvm_eval_t *val;
1577
1578         if (cmd_source == src_command)
1579         {
1580                 Cmd_ForwardToServer ();
1581                 return;
1582         }
1583
1584         if (!allowcheats)
1585         {
1586                 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1587                 return;
1588         }
1589
1590         t = Cmd_Argv(1);
1591         v = atoi (Cmd_Argv(2));
1592
1593         switch (t[0])
1594         {
1595         case '0':
1596         case '1':
1597         case '2':
1598         case '3':
1599         case '4':
1600         case '5':
1601         case '6':
1602         case '7':
1603         case '8':
1604         case '9':
1605                 // MED 01/04/97 added hipnotic give stuff
1606                 if (gamemode == GAME_HIPNOTIC)
1607                 {
1608                         if (t[0] == '6')
1609                         {
1610                                 if (t[1] == 'a')
1611                                         host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_PROXIMITY_GUN;
1612                                 else
1613                                         host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | IT_GRENADE_LAUNCHER;
1614                         }
1615                         else if (t[0] == '9')
1616                                 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_LASER_CANNON;
1617                         else if (t[0] == '0')
1618                                 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_MJOLNIR;
1619                         else if (t[0] >= '2')
1620                                 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1621                 }
1622                 else
1623                 {
1624                         if (t[0] >= '2')
1625                                 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1626                 }
1627                 break;
1628
1629         case 's':
1630                 if (gamemode == GAME_ROGUE && (val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_shells1)))
1631                         val->_float = v;
1632
1633                 host_client->edict->fields.server->ammo_shells = v;
1634                 break;
1635         case 'n':
1636                 if (gamemode == GAME_ROGUE)
1637                 {
1638                         if ((val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_nails1)))
1639                         {
1640                                 val->_float = v;
1641                                 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1642                                         host_client->edict->fields.server->ammo_nails = v;
1643                         }
1644                 }
1645                 else
1646                 {
1647                         host_client->edict->fields.server->ammo_nails = v;
1648                 }
1649                 break;
1650         case 'l':
1651                 if (gamemode == GAME_ROGUE)
1652                 {
1653                         val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_lava_nails);
1654                         if (val)
1655                         {
1656                                 val->_float = v;
1657                                 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1658                                         host_client->edict->fields.server->ammo_nails = v;
1659                         }
1660                 }
1661                 break;
1662         case 'r':
1663                 if (gamemode == GAME_ROGUE)
1664                 {
1665                         val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_rockets1);
1666                         if (val)
1667                         {
1668                                 val->_float = v;
1669                                 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1670                                         host_client->edict->fields.server->ammo_rockets = v;
1671                         }
1672                 }
1673                 else
1674                 {
1675                         host_client->edict->fields.server->ammo_rockets = v;
1676                 }
1677                 break;
1678         case 'm':
1679                 if (gamemode == GAME_ROGUE)
1680                 {
1681                         val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_multi_rockets);
1682                         if (val)
1683                         {
1684                                 val->_float = v;
1685                                 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1686                                         host_client->edict->fields.server->ammo_rockets = v;
1687                         }
1688                 }
1689                 break;
1690         case 'h':
1691                 host_client->edict->fields.server->health = v;
1692                 break;
1693         case 'c':
1694                 if (gamemode == GAME_ROGUE)
1695                 {
1696                         val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_cells1);
1697                         if (val)
1698                         {
1699                                 val->_float = v;
1700                                 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1701                                         host_client->edict->fields.server->ammo_cells = v;
1702                         }
1703                 }
1704                 else
1705                 {
1706                         host_client->edict->fields.server->ammo_cells = v;
1707                 }
1708                 break;
1709         case 'p':
1710                 if (gamemode == GAME_ROGUE)
1711                 {
1712                         val = PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_ammo_plasma);
1713                         if (val)
1714                         {
1715                                 val->_float = v;
1716                                 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1717                                         host_client->edict->fields.server->ammo_cells = v;
1718                         }
1719                 }
1720                 break;
1721         }
1722 }
1723
1724 prvm_edict_t    *FindViewthing (void)
1725 {
1726         int             i;
1727         prvm_edict_t    *e;
1728
1729         for (i=0 ; i<prog->num_edicts ; i++)
1730         {
1731                 e = PRVM_EDICT_NUM(i);
1732                 if (!strcmp (PRVM_GetString(e->fields.server->classname), "viewthing"))
1733                         return e;
1734         }
1735         Con_Print("No viewthing on map\n");
1736         return NULL;
1737 }
1738
1739 /*
1740 ==================
1741 Host_Viewmodel_f
1742 ==================
1743 */
1744 void Host_Viewmodel_f (void)
1745 {
1746         prvm_edict_t    *e;
1747         model_t *m;
1748
1749         if (!sv.active)
1750                 return;
1751
1752         SV_VM_Begin();
1753         e = FindViewthing ();
1754         SV_VM_End();
1755         if (!e)
1756                 return;
1757
1758         m = Mod_ForName (Cmd_Argv(1), false, true, false);
1759         if (!m || !m->loaded || !m->Draw)
1760         {
1761                 Con_Printf("viewmodel: can't load %s\n", Cmd_Argv(1));
1762                 return;
1763         }
1764
1765         e->fields.server->frame = 0;
1766         cl.model_precache[(int)e->fields.server->modelindex] = m;
1767 }
1768
1769 /*
1770 ==================
1771 Host_Viewframe_f
1772 ==================
1773 */
1774 void Host_Viewframe_f (void)
1775 {
1776         prvm_edict_t    *e;
1777         int             f;
1778         model_t *m;
1779
1780         if (!sv.active)
1781                 return;
1782
1783         SV_VM_Begin();
1784         e = FindViewthing ();
1785         SV_VM_End();
1786         if (!e)
1787                 return;
1788         m = cl.model_precache[(int)e->fields.server->modelindex];
1789
1790         f = atoi(Cmd_Argv(1));
1791         if (f >= m->numframes)
1792                 f = m->numframes-1;
1793
1794         e->fields.server->frame = f;
1795 }
1796
1797
1798 void PrintFrameName (model_t *m, int frame)
1799 {
1800         if (m->animscenes)
1801                 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1802         else
1803                 Con_Printf("frame %i\n", frame);
1804 }
1805
1806 /*
1807 ==================
1808 Host_Viewnext_f
1809 ==================
1810 */
1811 void Host_Viewnext_f (void)
1812 {
1813         prvm_edict_t    *e;
1814         model_t *m;
1815
1816         if (!sv.active)
1817                 return;
1818
1819         SV_VM_Begin();
1820         e = FindViewthing ();
1821         SV_VM_End();
1822         if (!e)
1823                 return;
1824         m = cl.model_precache[(int)e->fields.server->modelindex];
1825
1826         e->fields.server->frame = e->fields.server->frame + 1;
1827         if (e->fields.server->frame >= m->numframes)
1828                 e->fields.server->frame = m->numframes - 1;
1829
1830         PrintFrameName (m, (int)e->fields.server->frame);
1831 }
1832
1833 /*
1834 ==================
1835 Host_Viewprev_f
1836 ==================
1837 */
1838 void Host_Viewprev_f (void)
1839 {
1840         prvm_edict_t    *e;
1841         model_t *m;
1842
1843         if (!sv.active)
1844                 return;
1845
1846         SV_VM_Begin();
1847         e = FindViewthing ();
1848         SV_VM_End();
1849         if (!e)
1850                 return;
1851
1852         m = cl.model_precache[(int)e->fields.server->modelindex];
1853
1854         e->fields.server->frame = e->fields.server->frame - 1;
1855         if (e->fields.server->frame < 0)
1856                 e->fields.server->frame = 0;
1857
1858         PrintFrameName (m, (int)e->fields.server->frame);
1859 }
1860
1861 /*
1862 ===============================================================================
1863
1864 DEMO LOOP CONTROL
1865
1866 ===============================================================================
1867 */
1868
1869
1870 /*
1871 ==================
1872 Host_Startdemos_f
1873 ==================
1874 */
1875 void Host_Startdemos_f (void)
1876 {
1877         int             i, c;
1878
1879         if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo") || COM_CheckParm("-demolooponly"))
1880                 return;
1881
1882         c = Cmd_Argc() - 1;
1883         if (c > MAX_DEMOS)
1884         {
1885                 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
1886                 c = MAX_DEMOS;
1887         }
1888         Con_Printf("%i demo(s) in loop\n", c);
1889
1890         for (i=1 ; i<c+1 ; i++)
1891                 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
1892
1893         // LordHavoc: clear the remaining slots
1894         for (;i <= MAX_DEMOS;i++)
1895                 cls.demos[i-1][0] = 0;
1896
1897         if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
1898         {
1899                 cls.demonum = 0;
1900                 CL_NextDemo ();
1901         }
1902         else
1903                 cls.demonum = -1;
1904 }
1905
1906
1907 /*
1908 ==================
1909 Host_Demos_f
1910
1911 Return to looping demos
1912 ==================
1913 */
1914 void Host_Demos_f (void)
1915 {
1916         if (cls.state == ca_dedicated)
1917                 return;
1918         if (cls.demonum == -1)
1919                 cls.demonum = 1;
1920         CL_Disconnect_f ();
1921         CL_NextDemo ();
1922 }
1923
1924 /*
1925 ==================
1926 Host_Stopdemo_f
1927
1928 Return to looping demos
1929 ==================
1930 */
1931 void Host_Stopdemo_f (void)
1932 {
1933         if (!cls.demoplayback)
1934                 return;
1935         CL_Disconnect ();
1936         Host_ShutdownServer ();
1937 }
1938
1939 void Host_SendCvar_f (void)
1940 {
1941         int             i;
1942         cvar_t  *c;
1943         client_t *old;
1944
1945         if(Cmd_Argc() != 2)
1946                 return;
1947         if(!(c = Cvar_FindVar(Cmd_Argv(1))))
1948                 return;
1949         if (cls.state != ca_dedicated)
1950                 Cmd_ForwardStringToServer(va("sentcvar %s %s\n", c->name, c->string));
1951         if(!sv.active)// || !SV_ParseClientCommandQC)
1952                 return;
1953
1954         old = host_client;
1955         if (cls.state != ca_dedicated)
1956                 i = 1;
1957         else
1958                 i = 0;
1959         for(;i<svs.maxclients;i++)
1960                 if(svs.clients[i].active && svs.clients[i].netconnection)
1961                 {
1962                         host_client = &svs.clients[i];
1963                         Host_ClientCommands(va("sendcvar %s\n", c->name));
1964                 }
1965         host_client = old;
1966 }
1967
1968 static void MaxPlayers_f(void)
1969 {
1970         int n;
1971
1972         if (Cmd_Argc() != 2)
1973         {
1974                 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
1975                 return;
1976         }
1977
1978         if (sv.active)
1979         {
1980                 Con_Print("maxplayers can not be changed while a server is running.\n");
1981                 return;
1982         }
1983
1984         n = atoi(Cmd_Argv(1));
1985         n = bound(1, n, MAX_SCOREBOARD);
1986         Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
1987
1988         if (svs.clients)
1989                 Mem_Free(svs.clients);
1990         svs.maxclients = n;
1991         svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
1992         if (n == 1)
1993                 Cvar_Set ("deathmatch", "0");
1994         else
1995                 Cvar_Set ("deathmatch", "1");
1996 }
1997
1998 //=============================================================================
1999
2000 // QuakeWorld commands
2001
2002 /*
2003 =====================
2004 Host_Rcon_f
2005
2006   Send the rest of the command line over as
2007   an unconnected command.
2008 =====================
2009 */
2010 void Host_Rcon_f (void) // credit: taken from QuakeWorld
2011 {
2012         int i;
2013         lhnetaddress_t to;
2014         lhnetsocket_t *mysocket;
2015
2016         if (!rcon_password.string || !rcon_password.string[0])
2017         {
2018                 Con_Printf ("You must set rcon_password before issuing an rcon command.\n");
2019                 return;
2020         }
2021
2022         for (i = 0;rcon_password.string[i];i++)
2023         {
2024                 if (rcon_password.string[i] <= ' ')
2025                 {
2026                         Con_Printf("rcon_password is not allowed to have any whitespace.\n");
2027                         return;
2028                 }
2029         }
2030
2031         if (cls.netcon)
2032                 to = cls.netcon->peeraddress;
2033         else
2034         {
2035                 if (!rcon_address.integer || !rcon_address.string[0])
2036                 {
2037                         Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
2038                         return;
2039                 }
2040                 LHNETADDRESS_FromString(&to, rcon_address.string, sv_netport.integer);
2041         }
2042         mysocket = NetConn_ChooseClientSocketForAddress(&to);
2043         if (mysocket)
2044         {
2045                 // simply put together the rcon packet and send it
2046                 NetConn_WriteString(mysocket, va("\377\377\377\377rcon %s %s", rcon_password.string, Cmd_Args()), &to);
2047         }
2048 }
2049
2050 /*
2051 ====================
2052 Host_User_f
2053
2054 user <name or userid>
2055
2056 Dump userdata / masterdata for a user
2057 ====================
2058 */
2059 void Host_User_f (void) // credit: taken from QuakeWorld
2060 {
2061         int             uid;
2062         int             i;
2063
2064         if (Cmd_Argc() != 2)
2065         {
2066                 Con_Printf ("Usage: user <username / userid>\n");
2067                 return;
2068         }
2069
2070         uid = atoi(Cmd_Argv(1));
2071
2072         for (i = 0;i < cl.maxclients;i++)
2073         {
2074                 if (!cl.scores[i].name[0])
2075                         continue;
2076                 if (cl.scores[i].qw_userid == uid || !strcasecmp(cl.scores[i].name, Cmd_Argv(1)))
2077                 {
2078                         InfoString_Print(cl.scores[i].qw_userinfo);
2079                         return;
2080                 }
2081         }
2082         Con_Printf ("User not in server.\n");
2083 }
2084
2085 /*
2086 ====================
2087 Host_Users_f
2088
2089 Dump userids for all current players
2090 ====================
2091 */
2092 void Host_Users_f (void) // credit: taken from QuakeWorld
2093 {
2094         int             i;
2095         int             c;
2096
2097         c = 0;
2098         Con_Printf ("userid frags name\n");
2099         Con_Printf ("------ ----- ----\n");
2100         for (i = 0;i < cl.maxclients;i++)
2101         {
2102                 if (cl.scores[i].name[0])
2103                 {
2104                         Con_Printf ("%6i %4i %s\n", cl.scores[i].qw_userid, cl.scores[i].frags, cl.scores[i].name);
2105                         c++;
2106                 }
2107         }
2108
2109         Con_Printf ("%i total users\n", c);
2110 }
2111
2112 /*
2113 ==================
2114 Host_FullServerinfo_f
2115
2116 Sent by server when serverinfo changes
2117 ==================
2118 */
2119 // TODO: shouldn't this be a cvar instead?
2120 void Host_FullServerinfo_f (void) // credit: taken from QuakeWorld
2121 {
2122         char temp[512];
2123         if (Cmd_Argc() != 2)
2124         {
2125                 Con_Printf ("usage: fullserverinfo <complete info string>\n");
2126                 return;
2127         }
2128
2129         strlcpy (cl.qw_serverinfo, Cmd_Argv(1), sizeof(cl.qw_serverinfo));
2130         InfoString_GetValue(cl.qw_serverinfo, "teamplay", temp, sizeof(temp));
2131         cl.qw_teamplay = atoi(temp);
2132 }
2133
2134 /*
2135 ==================
2136 Host_FullInfo_f
2137
2138 Allow clients to change userinfo
2139 ==================
2140 Casey was here :)
2141 */
2142 void Host_FullInfo_f (void) // credit: taken from QuakeWorld
2143 {
2144         char key[512];
2145         char value[512];
2146         char *o;
2147         const char *s;
2148
2149         if (Cmd_Argc() != 2)
2150         {
2151                 Con_Printf ("fullinfo <complete info string>\n");
2152                 return;
2153         }
2154
2155         s = Cmd_Argv(1);
2156         if (*s == '\\')
2157                 s++;
2158         while (*s)
2159         {
2160                 o = key;
2161                 while (*s && *s != '\\')
2162                         *o++ = *s++;
2163                 *o = 0;
2164
2165                 if (!*s)
2166                 {
2167                         Con_Printf ("MISSING VALUE\n");
2168                         return;
2169                 }
2170
2171                 o = value;
2172                 s++;
2173                 while (*s && *s != '\\')
2174                         *o++ = *s++;
2175                 *o = 0;
2176
2177                 if (*s)
2178                         s++;
2179
2180                 if (!strcasecmp(key, "pmodel") || !strcasecmp(key, "emodel"))
2181                         continue;
2182
2183                 if (key[0] == '*')
2184                 {
2185                         Con_Printf("Can't set star-key \"%s\" to \"%s\"\n", key, value);
2186                         continue;
2187                 }
2188
2189                 InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), key, value);
2190         }
2191 }
2192
2193 /*
2194 ==================
2195 CL_SetInfo_f
2196
2197 Allow clients to change userinfo
2198 ==================
2199 */
2200 void Host_SetInfo_f (void) // credit: taken from QuakeWorld
2201 {
2202         if (Cmd_Argc() == 1)
2203         {
2204                 InfoString_Print(cls.userinfo);
2205                 return;
2206         }
2207         if (Cmd_Argc() != 3)
2208         {
2209                 Con_Printf ("usage: setinfo [ <key> <value> ]\n");
2210                 return;
2211         }
2212         if (!strcasecmp(Cmd_Argv(1), "pmodel") || !strcasecmp(Cmd_Argv(1), "emodel"))
2213                 return;
2214         if (Cmd_Argv(1)[0] == '*')
2215         {
2216                 Con_Printf("Can't set star-key \"%s\" to \"%s\"\n", Cmd_Argv(1), Cmd_Argv(2));
2217                 return;
2218         }
2219         InfoString_SetValue(cls.userinfo, sizeof(cls.userinfo), Cmd_Argv(1), Cmd_Argv(2));
2220         if (cls.state == ca_connected)
2221                 Cmd_ForwardToServer ();
2222 }
2223
2224 /*
2225 ====================
2226 Host_Packet_f
2227
2228 packet <destination> <contents>
2229
2230 Contents allows \n escape character
2231 ====================
2232 */
2233 void Host_Packet_f (void) // credit: taken from QuakeWorld
2234 {
2235         char send[2048];
2236         int i, l;
2237         const char *in;
2238         char *out;
2239         lhnetaddress_t address;
2240         lhnetsocket_t *mysocket;
2241
2242         if (Cmd_Argc() != 3)
2243         {
2244                 Con_Printf ("packet <destination> <contents>\n");
2245                 return;
2246         }
2247
2248         if (!LHNETADDRESS_FromString (&address, Cmd_Argv(1), sv_netport.integer))
2249         {
2250                 Con_Printf ("Bad address\n");
2251                 return;
2252         }
2253
2254         in = Cmd_Argv(2);
2255         out = send+4;
2256         send[0] = send[1] = send[2] = send[3] = 0xff;
2257
2258         l = (int)strlen (in);
2259         for (i=0 ; i<l ; i++)
2260         {
2261                 if (out >= send + sizeof(send) - 1)
2262                         break;
2263                 if (in[i] == '\\' && in[i+1] == 'n')
2264                 {
2265                         *out++ = '\n';
2266                         i++;
2267                 }
2268                 else if (in[i] == '\\' && in[i+1] == '0')
2269                 {
2270                         *out++ = '\0';
2271                         i++;
2272                 }
2273                 else if (in[i] == '\\' && in[i+1] == 't')
2274                 {
2275                         *out++ = '\t';
2276                         i++;
2277                 }
2278                 else if (in[i] == '\\' && in[i+1] == 'r')
2279                 {
2280                         *out++ = '\r';
2281                         i++;
2282                 }
2283                 else if (in[i] == '\\' && in[i+1] == '"')
2284                 {
2285                         *out++ = '\"';
2286                         i++;
2287                 }
2288                 else
2289                         *out++ = in[i];
2290         }
2291
2292         mysocket = NetConn_ChooseClientSocketForAddress(&address);
2293         if (mysocket)
2294                 NetConn_Write(mysocket, send, out - send, &address);
2295 }
2296
2297 //=============================================================================
2298
2299 /*
2300 ==================
2301 Host_InitCommands
2302 ==================
2303 */
2304 void Host_InitCommands (void)
2305 {
2306         strcpy(cls.userinfo, "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\*ver\\dp");
2307
2308         Cmd_AddCommand ("status", Host_Status_f, "print server status information");
2309         Cmd_AddCommand ("quit", Host_Quit_f, "quit the game");
2310         if (gamemode == GAME_NEHAHRA)
2311         {
2312                 Cmd_AddCommand ("max", Host_God_f, "god mode (invulnerability)");
2313                 Cmd_AddCommand ("monster", Host_Notarget_f, "notarget mode (monsters do not see you)");
2314                 Cmd_AddCommand ("scrag", Host_Fly_f, "fly mode (flight)");
2315                 Cmd_AddCommand ("wraith", Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
2316                 Cmd_AddCommand ("gimme", Host_Give_f, "alter inventory");
2317         }
2318         else
2319         {
2320                 Cmd_AddCommand ("god", Host_God_f, "god mode (invulnerability)");
2321                 Cmd_AddCommand ("notarget", Host_Notarget_f, "notarget mode (monsters do not see you)");
2322                 Cmd_AddCommand ("fly", Host_Fly_f, "fly mode (flight)");
2323                 Cmd_AddCommand ("noclip", Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
2324                 Cmd_AddCommand ("give", Host_Give_f, "alter inventory");
2325         }
2326         Cmd_AddCommand ("map", Host_Map_f, "kick everyone off the server and start a new level");
2327         Cmd_AddCommand ("restart", Host_Restart_f, "restart current level");
2328         Cmd_AddCommand ("changelevel", Host_Changelevel_f, "change to another level, bringing along all connected clients");
2329         Cmd_AddCommand ("connect", Host_Connect_f, "connect to a server by IP address or hostname");
2330         Cmd_AddCommand ("reconnect", Host_Reconnect_f, "reset signon level in preparation for a new level (do not use)");
2331         Cmd_AddCommand ("version", Host_Version_f, "print engine version");
2332         Cmd_AddCommand ("say", Host_Say_f, "send a chat message to everyone on the server");
2333         Cmd_AddCommand ("say_team", Host_Say_Team_f, "send a chat message to your team on the server");
2334         Cmd_AddCommand ("tell", Host_Tell_f, "send a chat message to only one person on the server");
2335         Cmd_AddCommand ("kill", Host_Kill_f, "die instantly");
2336         Cmd_AddCommand ("pause", Host_Pause_f, "pause the game (if the server allows pausing)");
2337         Cmd_AddCommand ("kick", Host_Kick_f, "kick a player off the server by number or name");
2338         Cmd_AddCommand ("ping", Host_Ping_f, "print ping times of all players on the server");
2339         Cmd_AddCommand ("load", Host_Loadgame_f, "load a saved game file");
2340         Cmd_AddCommand ("save", Host_Savegame_f, "save the game to a file");
2341
2342         Cmd_AddCommand ("startdemos", Host_Startdemos_f, "start playing back the selected demos sequentially (used at end of startup script)");
2343         Cmd_AddCommand ("demos", Host_Demos_f, "restart looping demos defined by the last startdemos command");
2344         Cmd_AddCommand ("stopdemo", Host_Stopdemo_f, "stop playing or recording demo (like stop command) and return to looping demos");
2345
2346         Cmd_AddCommand ("viewmodel", Host_Viewmodel_f, "change model of viewthing entity in current level");
2347         Cmd_AddCommand ("viewframe", Host_Viewframe_f, "change animation frame of viewthing entity in current level");
2348         Cmd_AddCommand ("viewnext", Host_Viewnext_f, "change to next animation frame of viewthing entity in current level");
2349         Cmd_AddCommand ("viewprev", Host_Viewprev_f, "change to previous animation frame of viewthing entity in current level");
2350
2351         Cvar_RegisterVariable (&cl_name);
2352         Cmd_AddCommand ("name", Host_Name_f, "change your player name");
2353         Cvar_RegisterVariable (&cl_color);
2354         Cmd_AddCommand ("color", Host_Color_f, "change your player shirt and pants colors");
2355         Cvar_RegisterVariable (&cl_rate);
2356         Cmd_AddCommand ("rate", Host_Rate_f, "change your network connection speed");
2357         if (gamemode == GAME_NEHAHRA)
2358         {
2359                 Cvar_RegisterVariable (&cl_pmodel);
2360                 Cmd_AddCommand ("pmodel", Host_PModel_f, "change your player model choice (Nehahra specific)");
2361         }
2362
2363         // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
2364         Cvar_RegisterVariable (&cl_playermodel);
2365         Cmd_AddCommand ("playermodel", Host_Playermodel_f, "change your player model");
2366         Cvar_RegisterVariable (&cl_playerskin);
2367         Cmd_AddCommand ("playerskin", Host_Playerskin_f, "change your player skin number");
2368
2369         Cmd_AddCommand ("prespawn", Host_PreSpawn_f, "signon 1 (client acknowledges that server information has been received)");
2370         Cmd_AddCommand ("spawn", Host_Spawn_f, "signon 2 (client has sent player information, and is asking server to send scoreboard rankings)");
2371         Cmd_AddCommand ("begin", Host_Begin_f, "signon 3 (client asks server to start sending entities, and will go to signon 4 (playing) when the first entity update is received)");
2372         Cmd_AddCommand ("maxplayers", MaxPlayers_f, "sets limit on how many players (or bots) may be connected to the server at once");
2373
2374         Cmd_AddCommand ("sendcvar", Host_SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC");       // By [515]
2375
2376         Cvar_RegisterVariable (&rcon_password);
2377         Cvar_RegisterVariable (&rcon_address);
2378         Cmd_AddCommand ("rcon", Host_Rcon_f, "sends a command to the server console (if your rcon_password matches the server's rcon_password), or to the address specified by rcon_address when not connected (again rcon_password must match the server's)");
2379         Cmd_AddCommand ("user", Host_User_f, "prints additional information about a player number or name on the scoreboard");
2380         Cmd_AddCommand ("users", Host_Users_f, "prints additional information about all players on the scoreboard");
2381         Cmd_AddCommand ("fullserverinfo", Host_FullServerinfo_f, "internal use only, sent by server to client to update client's local copy of serverinfo string");
2382         Cmd_AddCommand ("fullinfo", Host_FullInfo_f, "allows client to modify their userinfo");
2383         Cmd_AddCommand ("setinfo", Host_SetInfo_f, "modifies your userinfo");
2384         Cmd_AddCommand ("packet", Host_Packet_f, "send a packet to the specified address:port containing a text string");
2385
2386         Cvar_RegisterVariable(&sv_cheats);
2387 }
2388