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