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