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