2 Copyright (C) 1996-1997 Id Software, Inc.
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.
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.
13 See the GNU General Public License for more details.
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.
26 cvar_t sv_cheats = {0, "sv_cheats", "0", "enables cheat commands in any game, and cheat impulses in dpmod"};
27 cvar_t sv_adminnick = {CVAR_SAVE, "sv_adminnick", "", "nick name to use for admin messages instead of host name"};
28 cvar_t sv_status_privacy = {CVAR_SAVE, "sv_status_privacy", "0", "do not show IP addresses in 'status' replies to clients"};
29 cvar_t rcon_password = {CVAR_PRIVATE, "rcon_password", "", "password to authenticate rcon commands"};
30 cvar_t rcon_address = {0, "rcon_address", "", "server address to send rcon commands to (when not connected to a server)"};
31 cvar_t team = {CVAR_USERINFO | CVAR_SAVE, "team", "none", "QW team (4 character limit, example: blue)"};
32 cvar_t skin = {CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (example: base)"};
33 cvar_t noaim = {CVAR_USERINFO | CVAR_SAVE, "noaim", "1", "QW option to disable vertical autoaim"};
34 cvar_t r_fixtrans_auto = {0, "r_fixtrans_auto", "0", "automatically fixtrans textures (when set to 2, it also saves the fixed versions to a fixtrans directory)"};
35 qboolean allowcheats = false;
37 extern qboolean host_shuttingdown;
45 void Host_Quit_f (void)
48 Con_Printf("shutting down already!\n");
58 void Host_Status_f (void)
61 int seconds, minutes, hours = 0, j, players;
62 void (*print) (const char *fmt, ...);
64 if (cmd_source == src_command)
66 // if running a client, try to send over network so the client's status report parser will see the report
67 if (cls.state == ca_connected)
69 Cmd_ForwardToServer ();
75 print = SV_ClientPrintf;
80 for (players = 0, j = 0;j < svs.maxclients;j++)
81 if (svs.clients[j].active)
83 print ("host: %s\n", Cvar_VariableString ("hostname"));
84 print ("version: %s build %s\n", gamename, buildstring);
85 print ("protocol: %i (%s)\n", Protocol_NumberForEnum(sv.protocol), Protocol_NameForEnum(sv.protocol));
86 print ("map: %s\n", sv.name);
87 print ("timing: %s\n", Host_TimingReport());
88 print ("players: %i active (%i max)\n\n", players, svs.maxclients);
89 for (j = 0, client = svs.clients;j < svs.maxclients;j++, client++)
93 seconds = (int)(realtime - client->connecttime);
94 minutes = seconds / 60;
97 seconds -= (minutes * 60);
100 minutes -= (hours * 60);
104 print ("#%-3u %-16.16s %3i %2i:%02i:%02i\n", j+1, client->name, client->frags, hours, minutes, seconds);
105 if(sv_status_privacy.integer && cmd_source != src_command)
106 print (" %s\n", client->netconnection ? "hidden" : "botclient");
108 print (" %s\n", client->netconnection ? client->netconnection->address : "botclient");
117 Sets client to godmode
120 void Host_God_f (void)
124 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
128 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_GODMODE;
129 if (!((int)host_client->edict->fields.server->flags & FL_GODMODE) )
130 SV_ClientPrint("godmode OFF\n");
132 SV_ClientPrint("godmode ON\n");
135 void Host_Notarget_f (void)
139 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
143 host_client->edict->fields.server->flags = (int)host_client->edict->fields.server->flags ^ FL_NOTARGET;
144 if (!((int)host_client->edict->fields.server->flags & FL_NOTARGET) )
145 SV_ClientPrint("notarget OFF\n");
147 SV_ClientPrint("notarget ON\n");
150 qboolean noclip_anglehack;
152 void Host_Noclip_f (void)
156 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
160 if (host_client->edict->fields.server->movetype != MOVETYPE_NOCLIP)
162 noclip_anglehack = true;
163 host_client->edict->fields.server->movetype = MOVETYPE_NOCLIP;
164 SV_ClientPrint("noclip ON\n");
168 noclip_anglehack = false;
169 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
170 SV_ClientPrint("noclip OFF\n");
178 Sets client to flymode
181 void Host_Fly_f (void)
185 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
189 if (host_client->edict->fields.server->movetype != MOVETYPE_FLY)
191 host_client->edict->fields.server->movetype = MOVETYPE_FLY;
192 SV_ClientPrint("flymode ON\n");
196 host_client->edict->fields.server->movetype = MOVETYPE_WALK;
197 SV_ClientPrint("flymode OFF\n");
208 void Host_Pings_f (void); // called by Host_Ping_f
209 void Host_Ping_f (void)
213 void (*print) (const char *fmt, ...);
215 if (cmd_source == src_command)
217 // if running a client, try to send over network so the client's ping report parser will see the report
218 if (cls.state == ca_connected)
220 Cmd_ForwardToServer ();
226 print = SV_ClientPrintf;
231 print("Client ping times:\n");
232 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
236 print("%4i %s\n", bound(0, (int)floor(client->ping*1000+0.5), 9999), client->name);
239 // now call the Pings command also, which will send a report that contains packet loss for the scoreboard (as well as a simpler ping report)
240 // actually, don't, it confuses old clients (resulting in "unknown command pingplreport" flooding the console)
245 ===============================================================================
249 ===============================================================================
253 ======================
258 command from the console. Active clients are kicked off.
259 ======================
261 void Host_Map_f (void)
263 char level[MAX_QPATH];
267 Con_Print("map <levelname> : start a new game (kicks off all players)\n");
271 // GAME_DELUXEQUAKE - clear warpmark (used by QC)
272 if (gamemode == GAME_DELUXEQUAKE)
273 Cvar_Set("warpmark", "");
275 cls.demonum = -1; // stop demo loop in case this fails
278 Host_ShutdownServer();
283 svs.serverflags = 0; // haven't completed an episode yet
284 allowcheats = sv_cheats.integer != 0;
285 strlcpy(level, Cmd_Argv(1), sizeof(level));
286 SV_SpawnServer(level);
287 if (sv.active && cls.state == ca_disconnected)
288 CL_EstablishConnection("local:1");
295 Goes to a new map, taking all clients along
298 void Host_Changelevel_f (void)
300 char level[MAX_QPATH];
304 Con_Print("changelevel <levelname> : continue game on a new level\n");
317 SV_SaveSpawnparms ();
319 allowcheats = sv_cheats.integer != 0;
320 strlcpy(level, Cmd_Argv(1), sizeof(level));
321 SV_SpawnServer(level);
322 if (sv.active && cls.state == ca_disconnected)
323 CL_EstablishConnection("local:1");
330 Restarts the current server for a dead player
333 void Host_Restart_f (void)
335 char mapname[MAX_QPATH];
339 Con_Print("restart : restart current level\n");
344 Con_Print("Only the server may restart\n");
351 allowcheats = sv_cheats.integer != 0;
352 strlcpy(mapname, sv.name, sizeof(mapname));
353 SV_SpawnServer(mapname);
354 if (sv.active && cls.state == ca_disconnected)
355 CL_EstablishConnection("local:1");
362 This command causes the client to wait for the signon messages again.
363 This is sent just before a server changes levels
366 void Host_Reconnect_f (void)
369 // if not connected, reconnect to the most recent server
372 // if we have connected to a server recently, the userinfo
373 // will still contain its IP address, so get the address...
374 InfoString_GetValue(cls.userinfo, "*ip", temp, sizeof(temp));
376 CL_EstablishConnection(temp);
378 Con_Printf("Reconnect to what server? (you have not connected to a server yet)\n");
381 // if connected, do something based on protocol
382 if (cls.protocol == PROTOCOL_QUAKEWORLD)
384 // quakeworld can just re-login
385 if (cls.qw_downloadmemory) // don't change when downloading
390 if (cls.state == ca_connected && cls.signon < SIGNONS)
392 Con_Printf("reconnecting...\n");
393 MSG_WriteChar(&cls.netcon->message, qw_clc_stringcmd);
394 MSG_WriteString(&cls.netcon->message, "new");
399 // netquake uses reconnect on level changes (silly)
402 Con_Print("reconnect : wait for signon messages again\n");
407 Con_Print("reconnect: no signon, ignoring reconnect\n");
410 cls.signon = 0; // need new connection messages
415 =====================
418 User command to connect to server
419 =====================
421 void Host_Connect_f (void)
425 Con_Print("connect <serveraddress> : connect to a multiplayer game\n");
428 CL_EstablishConnection(Cmd_Argv(1));
433 ===============================================================================
437 ===============================================================================
440 #define SAVEGAME_VERSION 5
442 void Host_Savegame_to (const char *name)
445 int i, lightstyles = 64;
446 char comment[SAVEGAME_COMMENT_LENGTH+1];
449 // first we have to figure out if this can be saved in 64 lightstyles
450 // (for Quake compatibility)
451 for (i=64 ; i<MAX_LIGHTSTYLES ; i++)
452 if (sv.lightstyles[i][0])
455 isserver = !strcmp(PRVM_NAME, "server");
457 Con_Printf("Saving game to %s...\n", name);
458 f = FS_OpenRealFile(name, "wb", false);
461 Con_Print("ERROR: couldn't open.\n");
465 FS_Printf(f, "%i\n", SAVEGAME_VERSION);
467 memset(comment, 0, sizeof(comment));
469 dpsnprintf(comment, sizeof(comment), "%-21.21s kills:%3i/%3i", PRVM_GetString(prog->edicts->fields.server->message), (int)prog->globals.server->killed_monsters, (int)prog->globals.server->total_monsters);
471 dpsnprintf(comment, sizeof(comment), "(crash dump of %s progs)", PRVM_NAME);
472 // convert space to _ to make stdio happy
473 // LordHavoc: convert control characters to _ as well
474 for (i=0 ; i<SAVEGAME_COMMENT_LENGTH ; i++)
475 if (comment[i] <= ' ')
477 comment[SAVEGAME_COMMENT_LENGTH] = '\0';
479 FS_Printf(f, "%s\n", comment);
482 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
483 FS_Printf(f, "%f\n", svs.clients[0].spawn_parms[i]);
484 FS_Printf(f, "%d\n", current_skill);
485 FS_Printf(f, "%s\n", sv.name);
486 FS_Printf(f, "%f\n",sv.time);
490 for (i=0 ; i<NUM_SPAWN_PARMS ; i++)
491 FS_Printf(f, "(dummy)\n");
492 FS_Printf(f, "%d\n", 0);
493 FS_Printf(f, "%s\n", "(dummy)");
494 FS_Printf(f, "%f\n", realtime);
497 // write the light styles
498 for (i=0 ; i<lightstyles ; i++)
500 if (isserver && sv.lightstyles[i][0])
501 FS_Printf(f, "%s\n", sv.lightstyles[i]);
506 PRVM_ED_WriteGlobals (f);
507 for (i=0 ; i<prog->num_edicts ; i++)
509 FS_Printf(f,"// edict %d\n", i);
510 //Con_Printf("edict %d...\n", i);
511 PRVM_ED_Write (f, PRVM_EDICT_NUM(i));
516 FS_Printf(f,"// DarkPlaces extended savegame\n");
517 // darkplaces extension - extra lightstyles, support for color lightstyles
518 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
519 if (isserver && sv.lightstyles[i][0])
520 FS_Printf(f, "sv.lightstyles %i %s\n", i, sv.lightstyles[i]);
522 // darkplaces extension - model precaches
523 for (i=1 ; i<MAX_MODELS ; i++)
524 if (sv.model_precache[i][0])
525 FS_Printf(f,"sv.model_precache %i %s\n", i, sv.model_precache[i]);
527 // darkplaces extension - sound precaches
528 for (i=1 ; i<MAX_SOUNDS ; i++)
529 if (sv.sound_precache[i][0])
530 FS_Printf(f,"sv.sound_precache %i %s\n", i, sv.sound_precache[i]);
535 Con_Print("done.\n");
543 void Host_Savegame_f (void)
545 char name[MAX_QPATH];
549 Con_Print("Can't save - no server running.\n");
555 // singleplayer checks
558 Con_Print("Can't save in intermission.\n");
562 if (svs.clients[0].active && svs.clients[0].edict->fields.server->deadflag)
564 Con_Print("Can't savegame with a dead player\n");
569 Con_Print("Warning: saving a multiplayer game may have strange results when restored (to properly resume, all players must join in the same player slots and then the game can be reloaded).\n");
573 Con_Print("save <savename> : save a game\n");
577 if (strstr(Cmd_Argv(1), ".."))
579 Con_Print("Relative pathnames are not allowed.\n");
583 strlcpy (name, Cmd_Argv(1), sizeof (name));
584 FS_DefaultExtension (name, ".sav", sizeof (name));
587 Host_Savegame_to(name);
597 void Host_Loadgame_f (void)
599 char filename[MAX_QPATH];
600 char mapname[MAX_QPATH];
610 float spawn_parms[NUM_SPAWN_PARMS];
614 Con_Print("load <savename> : load a game\n");
618 strlcpy (filename, Cmd_Argv(1), sizeof(filename));
619 FS_DefaultExtension (filename, ".sav", sizeof (filename));
621 Con_Printf("Loading game from %s...\n", filename);
623 // stop playing demos
624 if (cls.demoplayback)
630 cls.demonum = -1; // stop demo loop in case this fails
632 t = text = (char *)FS_LoadFile (filename, tempmempool, false, NULL);
635 Con_Print("ERROR: couldn't open.\n");
640 COM_ParseToken_Simple(&t, false, false);
641 version = atoi(com_token);
642 if (version != SAVEGAME_VERSION)
645 Con_Printf("Savegame is version %i, not %i\n", version, SAVEGAME_VERSION);
650 COM_ParseToken_Simple(&t, false, false);
652 for (i = 0;i < NUM_SPAWN_PARMS;i++)
654 COM_ParseToken_Simple(&t, false, false);
655 spawn_parms[i] = atof(com_token);
658 COM_ParseToken_Simple(&t, false, false);
659 // this silliness is so we can load 1.06 save files, which have float skill values
660 current_skill = (int)(atof(com_token) + 0.5);
661 Cvar_SetValue ("skill", (float)current_skill);
664 COM_ParseToken_Simple(&t, false, false);
665 strlcpy (mapname, com_token, sizeof(mapname));
668 COM_ParseToken_Simple(&t, false, false);
669 time = atof(com_token);
671 allowcheats = sv_cheats.integer != 0;
673 SV_SpawnServer (mapname);
677 Con_Print("Couldn't load map\n");
680 sv.paused = true; // pause until all clients connect
683 // load the light styles
689 for (i = 0;i < MAX_LIGHTSTYLES;i++)
693 COM_ParseToken_Simple(&t, false, false);
694 // if this is a 64 lightstyle savegame produced by Quake, stop now
695 // we have to check this because darkplaces may save more than 64
696 if (com_token[0] == '{')
701 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
704 // now skip everything before the first opening brace
705 // (this is for forward compatibility, so that older versions (at
706 // least ones with this fix) can load savegames with extra data before the
707 // first brace, as might be produced by a later engine version)
711 if (!COM_ParseToken_Simple(&t, false, false))
713 if (com_token[0] == '{')
720 // load the edicts out of the savegame file
725 while (COM_ParseToken_Simple(&t, false, false))
726 if (!strcmp(com_token, "}"))
728 if (!COM_ParseToken_Simple(&start, false, false))
733 if (strcmp(com_token,"{"))
736 Host_Error ("First token isn't a brace");
741 // parse the global vars
742 PRVM_ED_ParseGlobals (start);
747 if (entnum >= MAX_EDICTS)
750 Host_Error("Host_PerformLoadGame: too many edicts in save file (reached MAX_EDICTS %i)", MAX_EDICTS);
752 while (entnum >= prog->max_edicts)
753 PRVM_MEM_IncreaseEdicts();
754 ent = PRVM_EDICT_NUM(entnum);
755 memset (ent->fields.server, 0, prog->progs->entityfields * 4);
756 ent->priv.server->free = false;
757 PRVM_ED_ParseEdict (start, ent);
759 // link it into the bsp tree
760 if (!ent->priv.server->free)
761 SV_LinkEdict (ent, false);
769 prog->num_edicts = entnum;
772 for (i = 0;i < NUM_SPAWN_PARMS;i++)
773 svs.clients[0].spawn_parms[i] = spawn_parms[i];
775 // read extended data if present
776 // the extended data is stored inside a /* */ comment block, which the
777 // parser intentionally skips, so we have to check for it manually here
778 while (*end == '\r' || *end == '\n')
780 if (end[0] == '/' && end[1] == '*' && (end[2] == '\r' || end[2] == '\n'))
782 Con_Printf("Loading extended DarkPlaces savegame\n");
784 memset(sv.lightstyles[0], 0, sizeof(sv.lightstyles));
785 memset(sv.model_precache[0], 0, sizeof(sv.model_precache));
786 memset(sv.sound_precache[0], 0, sizeof(sv.sound_precache));
787 while (COM_ParseToken_Simple(&t, false, false))
789 if (!strcmp(com_token, "sv.lightstyles"))
791 COM_ParseToken_Simple(&t, false, false);
793 COM_ParseToken_Simple(&t, false, false);
794 if (i >= 0 && i < MAX_LIGHTSTYLES)
795 strlcpy(sv.lightstyles[i], com_token, sizeof(sv.lightstyles[i]));
797 Con_Printf("unsupported lightstyle %i \"%s\"\n", i, com_token);
799 else if (!strcmp(com_token, "sv.model_precache"))
801 COM_ParseToken_Simple(&t, false, false);
803 COM_ParseToken_Simple(&t, false, false);
804 if (i >= 0 && i < MAX_MODELS)
806 strlcpy(sv.model_precache[i], com_token, sizeof(sv.model_precache[i]));
807 sv.models[i] = Mod_ForName (sv.model_precache[i], true, false, false);
810 Con_Printf("unsupported model %i \"%s\"\n", i, com_token);
812 else if (!strcmp(com_token, "sv.sound_precache"))
814 COM_ParseToken_Simple(&t, false, false);
816 COM_ParseToken_Simple(&t, false, false);
817 if (i >= 0 && i < MAX_SOUNDS)
818 strlcpy(sv.sound_precache[i], com_token, sizeof(sv.sound_precache[i]));
820 Con_Printf("unsupported sound %i \"%s\"\n", i, com_token);
822 // skip any trailing text or unrecognized commands
823 while (COM_ParseToken_Simple(&t, true, false) && strcmp(com_token, "\n"))
830 // make sure we're connected to loopback
831 if (sv.active && cls.state == ca_disconnected)
832 CL_EstablishConnection("local:1");
835 //============================================================================
838 ======================
840 ======================
842 cvar_t cl_name = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "_cl_name", "player", "internal storage cvar for current player name (changed by name command)"};
843 void Host_Name_f (void)
846 qboolean valid_colors;
847 char newName[sizeof(host_client->name)];
849 if (Cmd_Argc () == 1)
851 Con_Printf("\"name\" is \"%s\"\n", cl_name.string);
855 if (Cmd_Argc () == 2)
856 strlcpy (newName, Cmd_Argv(1), sizeof (newName));
858 strlcpy (newName, Cmd_Args(), sizeof (newName));
860 if (cmd_source == src_command)
862 Cvar_Set ("_cl_name", newName);
866 if (realtime < host_client->nametime)
868 SV_ClientPrintf("You can't change name more than once every 5 seconds!\n");
872 host_client->nametime = realtime + 5;
874 // point the string back at updateclient->name to keep it safe
875 strlcpy (host_client->name, newName, sizeof (host_client->name));
877 for (i = 0, j = 0;host_client->name[i];i++)
878 if (host_client->name[i] != '\r' && host_client->name[i] != '\n')
879 host_client->name[j++] = host_client->name[i];
880 host_client->name[j] = 0;
882 if(host_client->name[0] == 1 || host_client->name[0] == 2)
883 // may interfere with chat area, and will needlessly beep; so let's add a ^7
885 memmove(host_client->name + 2, host_client->name, sizeof(host_client->name) - 2);
886 host_client->name[sizeof(host_client->name) - 1] = 0;
887 host_client->name[0] = STRING_COLOR_TAG;
888 host_client->name[1] = '0' + STRING_COLOR_DEFAULT;
891 COM_StringLengthNoColors(host_client->name, 0, &valid_colors);
892 if(!valid_colors) // NOTE: this also proves the string is not empty, as "" is a valid colored string
895 l = strlen(host_client->name);
896 if(l < sizeof(host_client->name) - 1)
898 // duplicate the color tag to escape it
899 host_client->name[i] = STRING_COLOR_TAG;
900 host_client->name[i+1] = 0;
901 //Con_DPrintf("abuse detected, adding another trailing color tag\n");
905 // remove the last character to fix the color code
906 host_client->name[l-1] = 0;
907 //Con_DPrintf("abuse detected, removing a trailing color tag\n");
911 // find the last color tag offset and decide if we need to add a reset tag
912 for (i = 0, j = -1;host_client->name[i];i++)
914 if (host_client->name[i] == STRING_COLOR_TAG)
916 if (host_client->name[i+1] >= '0' && host_client->name[i+1] <= '9')
919 // if this happens to be a reset tag then we don't need one
920 if (host_client->name[i+1] == '0' + STRING_COLOR_DEFAULT)
925 if (host_client->name[i+1] == STRING_COLOR_TAG)
932 // does not end in the default color string, so add it
933 if (j >= 0 && strlen(host_client->name) < sizeof(host_client->name) - 2)
934 memcpy(host_client->name + strlen(host_client->name), STRING_COLOR_DEFAULT_STR, strlen(STRING_COLOR_DEFAULT_STR) + 1);
936 host_client->edict->fields.server->netname = PRVM_SetEngineString(host_client->name);
937 if (strcmp(host_client->old_name, host_client->name))
939 if (host_client->spawned)
940 SV_BroadcastPrintf("%s changed name to %s\n", host_client->old_name, host_client->name);
941 strlcpy(host_client->old_name, host_client->name, sizeof(host_client->old_name));
942 // send notification to all clients
943 MSG_WriteByte (&sv.reliable_datagram, svc_updatename);
944 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
945 MSG_WriteString (&sv.reliable_datagram, host_client->name);
946 SV_WriteNetnameIntoDemo(host_client);
951 ======================
953 ======================
955 cvar_t cl_playermodel = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "_cl_playermodel", "", "internal storage cvar for current player model in Nexuiz (changed by playermodel command)"};
956 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
957 void Host_Playermodel_f (void)
960 char newPath[sizeof(host_client->playermodel)];
962 if (Cmd_Argc () == 1)
964 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
968 if (Cmd_Argc () == 2)
969 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
971 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
973 for (i = 0, j = 0;newPath[i];i++)
974 if (newPath[i] != '\r' && newPath[i] != '\n')
975 newPath[j++] = newPath[i];
978 if (cmd_source == src_command)
980 Cvar_Set ("_cl_playermodel", newPath);
985 if (realtime < host_client->nametime)
987 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
991 host_client->nametime = realtime + 5;
994 // point the string back at updateclient->name to keep it safe
995 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
996 if( prog->fieldoffsets.playermodel >= 0 )
997 PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.playermodel)->string = PRVM_SetEngineString(host_client->playermodel);
998 if (strcmp(host_client->old_model, host_client->playermodel))
1000 strlcpy(host_client->old_model, host_client->playermodel, sizeof(host_client->old_model));
1001 /*// send notification to all clients
1002 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
1003 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1004 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
1009 ======================
1011 ======================
1013 cvar_t cl_playerskin = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "_cl_playerskin", "", "internal storage cvar for current player skin in Nexuiz (changed by playerskin command)"};
1014 void Host_Playerskin_f (void)
1017 char newPath[sizeof(host_client->playerskin)];
1019 if (Cmd_Argc () == 1)
1021 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
1025 if (Cmd_Argc () == 2)
1026 strlcpy (newPath, Cmd_Argv(1), sizeof (newPath));
1028 strlcpy (newPath, Cmd_Args(), sizeof (newPath));
1030 for (i = 0, j = 0;newPath[i];i++)
1031 if (newPath[i] != '\r' && newPath[i] != '\n')
1032 newPath[j++] = newPath[i];
1035 if (cmd_source == src_command)
1037 Cvar_Set ("_cl_playerskin", newPath);
1042 if (realtime < host_client->nametime)
1044 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
1048 host_client->nametime = realtime + 5;
1051 // point the string back at updateclient->name to keep it safe
1052 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
1053 if( prog->fieldoffsets.playerskin >= 0 )
1054 PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.playerskin)->string = PRVM_SetEngineString(host_client->playerskin);
1055 if (strcmp(host_client->old_skin, host_client->playerskin))
1057 //if (host_client->spawned)
1058 // SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
1059 strlcpy(host_client->old_skin, host_client->playerskin, sizeof(host_client->old_skin));
1060 /*// send notification to all clients
1061 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
1062 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1063 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
1067 void Host_Version_f (void)
1069 Con_Printf("Version: %s build %s\n", gamename, buildstring);
1072 void Host_Say(qboolean teamonly)
1078 // LordHavoc: long say messages
1080 qboolean fromServer = false;
1082 if (cmd_source == src_command)
1084 if (cls.state == ca_dedicated)
1091 Cmd_ForwardToServer ();
1096 if (Cmd_Argc () < 2)
1099 if (!teamplay.integer)
1109 // note this uses the chat prefix \001
1110 if (!fromServer && !teamonly)
1111 dpsnprintf (text, sizeof(text), "\001%s: %s", host_client->name, p1);
1112 else if (!fromServer && teamonly)
1113 dpsnprintf (text, sizeof(text), "\001(%s): %s", host_client->name, p1);
1114 else if(*(sv_adminnick.string))
1115 dpsnprintf (text, sizeof(text), "\001<%s> %s", sv_adminnick.string, p1);
1117 dpsnprintf (text, sizeof(text), "\001<%s> %s", hostname.string, p1);
1118 p2 = text + strlen(text);
1119 while ((const char *)p2 > (const char *)text && (p2[-1] == '\r' || p2[-1] == '\n' || (p2[-1] == '\"' && quoted)))
1121 if (p2[-1] == '\"' && quoted)
1126 strlcat(text, "\n", sizeof(text));
1128 // note: save is not a valid edict if fromServer is true
1130 for (j = 0, host_client = svs.clients;j < svs.maxclients;j++, host_client++)
1131 if (host_client->active && (!teamonly || host_client->edict->fields.server->team == save->edict->fields.server->team))
1132 SV_ClientPrint(text);
1135 if (cls.state == ca_dedicated)
1136 Con_Print(&text[1]);
1140 void Host_Say_f(void)
1146 void Host_Say_Team_f(void)
1152 void Host_Tell_f(void)
1154 const char *playername_start = NULL;
1155 size_t playername_length = 0;
1156 int playernumber = 0;
1159 const char *p1, *p2;
1160 char text[MAX_INPUTLINE]; // LordHavoc: FIXME: temporary buffer overflow fix (was 64)
1161 qboolean fromServer = false;
1163 if (cmd_source == src_command)
1165 if (cls.state == ca_dedicated)
1169 Cmd_ForwardToServer ();
1174 if (Cmd_Argc () < 2)
1177 // note this uses the chat prefix \001
1179 dpsnprintf (text, sizeof(text), "\001%s tells you: ", host_client->name);
1180 else if(*(sv_adminnick.string))
1181 dpsnprintf (text, sizeof(text), "\001<%s tells you> ", sv_adminnick.string);
1183 dpsnprintf (text, sizeof(text), "\001<%s tells you> ", hostname.string);
1186 p2 = p1 + strlen(p1);
1187 // remove the target name
1188 while (p1 < p2 && *p1 == ' ')
1193 while (p1 < p2 && *p1 == ' ')
1195 while (p1 < p2 && isdigit(*p1))
1197 playernumber = playernumber * 10 + (*p1 - '0');
1205 playername_start = p1;
1206 while (p1 < p2 && *p1 != '"')
1208 playername_length = p1 - playername_start;
1214 playername_start = p1;
1215 while (p1 < p2 && *p1 != ' ')
1217 playername_length = p1 - playername_start;
1219 while (p1 < p2 && *p1 == ' ')
1221 if(playername_start)
1223 // set playernumber to the right client
1225 if(playername_length >= sizeof(namebuf))
1228 Con_Print("Host_Tell: too long player name/ID\n");
1230 SV_ClientPrint("Host_Tell: too long player name/ID\n");
1233 memcpy(namebuf, playername_start, playername_length);
1234 namebuf[playername_length] = 0;
1235 for (playernumber = 0; playernumber < svs.maxclients; playernumber++)
1237 if (!svs.clients[playernumber].active)
1239 if (strcasecmp(svs.clients[playernumber].name, namebuf) == 0)
1243 if(playernumber < 0 || playernumber >= svs.maxclients || !(svs.clients[playernumber].active))
1246 Con_Print("Host_Tell: invalid player name/ID\n");
1248 SV_ClientPrint("Host_Tell: invalid player name/ID\n");
1251 // remove trailing newlines
1252 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1254 // remove quotes if present
1260 else if (fromServer)
1261 Con_Print("Host_Tell: missing end quote\n");
1263 SV_ClientPrint("Host_Tell: missing end quote\n");
1265 while (p2 > p1 && (p2[-1] == '\n' || p2[-1] == '\r'))
1268 return; // empty say
1269 for (j = (int)strlen(text);j < (int)(sizeof(text) - 2) && p1 < p2;)
1275 host_client = svs.clients + playernumber;
1276 SV_ClientPrint(text);
1286 cvar_t cl_color = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "_cl_color", "0", "internal storage cvar for current player colors (changed by color command)"};
1287 void Host_Color(int changetop, int changebottom)
1289 int top, bottom, playercolor;
1291 // get top and bottom either from the provided values or the current values
1292 // (allows changing only top or bottom, or both at once)
1293 top = changetop >= 0 ? changetop : (cl_color.integer >> 4);
1294 bottom = changebottom >= 0 ? changebottom : cl_color.integer;
1298 // LordHavoc: allowing skin colormaps 14 and 15 by commenting this out
1304 playercolor = top*16 + bottom;
1306 if (cmd_source == src_command)
1308 Cvar_SetValueQuick(&cl_color, playercolor);
1312 if (cls.protocol == PROTOCOL_QUAKEWORLD)
1315 if (host_client->edict && prog->funcoffsets.SV_ChangeTeam)
1317 Con_DPrint("Calling SV_ChangeTeam\n");
1318 prog->globals.server->time = sv.time;
1319 prog->globals.generic[OFS_PARM0] = playercolor;
1320 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1321 PRVM_ExecuteProgram(prog->funcoffsets.SV_ChangeTeam, "QC function SV_ChangeTeam is missing");
1326 if (host_client->edict)
1328 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.clientcolors)))
1329 val->_float = playercolor;
1330 host_client->edict->fields.server->team = bottom + 1;
1332 host_client->colors = playercolor;
1333 if (host_client->old_colors != host_client->colors)
1335 host_client->old_colors = host_client->colors;
1336 // send notification to all clients
1337 MSG_WriteByte (&sv.reliable_datagram, svc_updatecolors);
1338 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
1339 MSG_WriteByte (&sv.reliable_datagram, host_client->colors);
1344 void Host_Color_f(void)
1348 if (Cmd_Argc() == 1)
1350 Con_Printf("\"color\" is \"%i %i\"\n", cl_color.integer >> 4, cl_color.integer & 15);
1351 Con_Print("color <0-15> [0-15]\n");
1355 if (Cmd_Argc() == 2)
1356 top = bottom = atoi(Cmd_Argv(1));
1359 top = atoi(Cmd_Argv(1));
1360 bottom = atoi(Cmd_Argv(2));
1362 Host_Color(top, bottom);
1365 void Host_TopColor_f(void)
1367 if (Cmd_Argc() == 1)
1369 Con_Printf("\"topcolor\" is \"%i\"\n", (cl_color.integer >> 4) & 15);
1370 Con_Print("topcolor <0-15>\n");
1374 Host_Color(atoi(Cmd_Argv(1)), -1);
1377 void Host_BottomColor_f(void)
1379 if (Cmd_Argc() == 1)
1381 Con_Printf("\"bottomcolor\" is \"%i\"\n", cl_color.integer & 15);
1382 Con_Print("bottomcolor <0-15>\n");
1386 Host_Color(-1, atoi(Cmd_Argv(1)));
1389 cvar_t cl_rate = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "_cl_rate", "20000", "internal storage cvar for current rate (changed by rate command)"};
1390 void Host_Rate_f(void)
1394 if (Cmd_Argc() != 2)
1396 Con_Printf("\"rate\" is \"%i\"\n", cl_rate.integer);
1397 Con_Print("rate <bytespersecond>\n");
1401 rate = atoi(Cmd_Argv(1));
1403 if (cmd_source == src_command)
1405 Cvar_SetValue ("_cl_rate", max(NET_MINRATE, rate));
1409 host_client->rate = rate;
1417 void Host_Kill_f (void)
1419 if (host_client->edict->fields.server->health <= 0)
1421 SV_ClientPrint("Can't suicide -- already dead!\n");
1425 prog->globals.server->time = sv.time;
1426 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1427 PRVM_ExecuteProgram (prog->globals.server->ClientKill, "QC function ClientKill is missing");
1436 void Host_Pause_f (void)
1438 if (!pausable.integer)
1439 SV_ClientPrint("Pause not allowed.\n");
1443 SV_BroadcastPrintf("%s %spaused the game\n", host_client->name, sv.paused ? "" : "un");
1444 // send notification to all clients
1445 MSG_WriteByte(&sv.reliable_datagram, svc_setpause);
1446 MSG_WriteByte(&sv.reliable_datagram, sv.paused);
1451 ======================
1453 LordHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
1454 LordHavoc: correction, Mindcrime will be removing pmodel in the future, but it's still stuck here for compatibility.
1455 ======================
1457 cvar_t cl_pmodel = {CVAR_SAVE | CVAR_NQUSERINFOHACK, "_cl_pmodel", "0", "internal storage cvar for current player model number in nehahra (changed by pmodel command)"};
1458 static void Host_PModel_f (void)
1463 if (Cmd_Argc () == 1)
1465 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
1468 i = atoi(Cmd_Argv(1));
1470 if (cmd_source == src_command)
1472 if (cl_pmodel.integer == i)
1474 Cvar_SetValue ("_cl_pmodel", i);
1475 if (cls.state == ca_connected)
1476 Cmd_ForwardToServer ();
1480 if (host_client->edict && (val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.pmodel)))
1484 //===========================================================================
1492 void Host_PreSpawn_f (void)
1494 if (host_client->spawned)
1496 Con_Print("prespawn not valid -- already spawned\n");
1500 if (host_client->netconnection)
1502 SZ_Write (&host_client->netconnection->message, sv.signon.data, sv.signon.cursize);
1503 MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1504 MSG_WriteByte (&host_client->netconnection->message, 2);
1505 host_client->sendsignon = 0; // enable unlimited sends again
1508 // reset the name change timer because the client will send name soon
1509 host_client->nametime = 0;
1517 void Host_Spawn_f (void)
1521 int stats[MAX_CL_STATS];
1523 if (host_client->spawned)
1525 Con_Print("Spawn not valid -- already spawned\n");
1529 // reset name change timer again because they might want to change name
1530 // again in the first 5 seconds after connecting
1531 host_client->nametime = 0;
1533 // LordHavoc: moved this above the QC calls at FrikaC's request
1534 // LordHavoc: commented this out
1535 //if (host_client->netconnection)
1536 // SZ_Clear (&host_client->netconnection->message);
1538 // run the entrance script
1541 // loaded games are fully initialized already
1542 if (prog->funcoffsets.RestoreGame)
1544 Con_DPrint("Calling RestoreGame\n");
1545 prog->globals.server->time = sv.time;
1546 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1547 PRVM_ExecuteProgram(prog->funcoffsets.RestoreGame, "QC function RestoreGame is missing");
1552 //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);
1554 // copy spawn parms out of the client_t
1555 for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
1556 (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
1558 // call the spawn function
1559 host_client->clientconnectcalled = true;
1560 prog->globals.server->time = sv.time;
1561 prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
1562 PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
1564 if (cls.state == ca_dedicated)
1565 Con_Printf("%s connected\n", host_client->name);
1567 PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
1570 if (!host_client->netconnection)
1573 // send time of update
1574 MSG_WriteByte (&host_client->netconnection->message, svc_time);
1575 MSG_WriteFloat (&host_client->netconnection->message, sv.time);
1577 // send all current names, colors, and frag counts
1578 for (i = 0, client = svs.clients;i < svs.maxclients;i++, client++)
1580 if (!client->active)
1582 MSG_WriteByte (&host_client->netconnection->message, svc_updatename);
1583 MSG_WriteByte (&host_client->netconnection->message, i);
1584 MSG_WriteString (&host_client->netconnection->message, client->name);
1585 MSG_WriteByte (&host_client->netconnection->message, svc_updatefrags);
1586 MSG_WriteByte (&host_client->netconnection->message, i);
1587 MSG_WriteShort (&host_client->netconnection->message, client->frags);
1588 MSG_WriteByte (&host_client->netconnection->message, svc_updatecolors);
1589 MSG_WriteByte (&host_client->netconnection->message, i);
1590 MSG_WriteByte (&host_client->netconnection->message, client->colors);
1593 // send all current light styles
1594 for (i=0 ; i<MAX_LIGHTSTYLES ; i++)
1596 if (sv.lightstyles[i][0])
1598 MSG_WriteByte (&host_client->netconnection->message, svc_lightstyle);
1599 MSG_WriteByte (&host_client->netconnection->message, (char)i);
1600 MSG_WriteString (&host_client->netconnection->message, sv.lightstyles[i]);
1605 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1606 MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALSECRETS);
1607 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->total_secrets);
1609 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1610 MSG_WriteByte (&host_client->netconnection->message, STAT_TOTALMONSTERS);
1611 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->total_monsters);
1613 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1614 MSG_WriteByte (&host_client->netconnection->message, STAT_SECRETS);
1615 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->found_secrets);
1617 MSG_WriteByte (&host_client->netconnection->message, svc_updatestat);
1618 MSG_WriteByte (&host_client->netconnection->message, STAT_MONSTERS);
1619 MSG_WriteLong (&host_client->netconnection->message, (int)prog->globals.server->killed_monsters);
1622 // Never send a roll angle, because savegames can catch the server
1623 // in a state where it is expecting the client to correct the angle
1624 // and it won't happen if the game was just loaded, so you wind up
1625 // with a permanent head tilt
1628 MSG_WriteByte (&host_client->netconnection->message, svc_setangle);
1629 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->v_angle[0], sv.protocol);
1630 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->v_angle[1], sv.protocol);
1631 MSG_WriteAngle (&host_client->netconnection->message, 0, sv.protocol);
1635 MSG_WriteByte (&host_client->netconnection->message, svc_setangle);
1636 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[0], sv.protocol);
1637 MSG_WriteAngle (&host_client->netconnection->message, host_client->edict->fields.server->angles[1], sv.protocol);
1638 MSG_WriteAngle (&host_client->netconnection->message, 0, sv.protocol);
1641 SV_WriteClientdataToMessage (host_client, host_client->edict, &host_client->netconnection->message, stats);
1643 MSG_WriteByte (&host_client->netconnection->message, svc_signonnum);
1644 MSG_WriteByte (&host_client->netconnection->message, 3);
1652 void Host_Begin_f (void)
1654 host_client->spawned = true;
1656 // LordHavoc: note: this code also exists in SV_DropClient
1660 for (i = 0;i < svs.maxclients;i++)
1661 if (svs.clients[i].active && !svs.clients[i].spawned)
1663 if (i == svs.maxclients)
1665 Con_Printf("Loaded game, everyone rejoined - unpausing\n");
1666 sv.paused = sv.loadgame = false; // we're basically done with loading now
1671 //===========================================================================
1678 Kicks a user off of the server
1681 void Host_Kick_f (void)
1684 const char *message = NULL;
1687 qboolean byNumber = false;
1695 if (Cmd_Argc() > 2 && strcmp(Cmd_Argv(1), "#") == 0)
1697 i = (int)(atof(Cmd_Argv(2)) - 1);
1698 if (i < 0 || i >= svs.maxclients || !(host_client = svs.clients + i)->active)
1704 for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
1706 if (!host_client->active)
1708 if (strcasecmp(host_client->name, Cmd_Argv(1)) == 0)
1713 if (i < svs.maxclients)
1715 if (cmd_source == src_command)
1717 if (cls.state == ca_dedicated)
1720 who = cl_name.string;
1725 // can't kick yourself!
1726 if (host_client == save)
1731 message = Cmd_Args();
1732 COM_ParseToken_Simple(&message, false, false);
1735 message++; // skip the #
1736 while (*message == ' ') // skip white space
1738 message += strlen(Cmd_Argv(2)); // skip the number
1740 while (*message && *message == ' ')
1744 SV_ClientPrintf("Kicked by %s: %s\n", who, message);
1746 SV_ClientPrintf("Kicked by %s\n", who);
1747 SV_DropClient (false); // kicked
1755 ===============================================================================
1759 ===============================================================================
1767 void Host_Give_f (void)
1775 SV_ClientPrint("No cheats allowed, use sv_cheats 1 and restart level to enable.\n");
1780 v = atoi (Cmd_Argv(2));
1794 // MED 01/04/97 added hipnotic give stuff
1795 if (gamemode == GAME_HIPNOTIC)
1800 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_PROXIMITY_GUN;
1802 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | IT_GRENADE_LAUNCHER;
1804 else if (t[0] == '9')
1805 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_LASER_CANNON;
1806 else if (t[0] == '0')
1807 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | HIT_MJOLNIR;
1808 else if (t[0] >= '2')
1809 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1814 host_client->edict->fields.server->items = (int)host_client->edict->fields.server->items | (IT_SHOTGUN << (t[0] - '2'));
1819 if (gamemode == GAME_ROGUE && (val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ammo_shells1)))
1822 host_client->edict->fields.server->ammo_shells = v;
1825 if (gamemode == GAME_ROGUE)
1827 if ((val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ammo_nails1)))
1830 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1831 host_client->edict->fields.server->ammo_nails = v;
1836 host_client->edict->fields.server->ammo_nails = v;
1840 if (gamemode == GAME_ROGUE)
1842 val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ammo_lava_nails);
1846 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1847 host_client->edict->fields.server->ammo_nails = v;
1852 if (gamemode == GAME_ROGUE)
1854 val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ammo_rockets1);
1858 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1859 host_client->edict->fields.server->ammo_rockets = v;
1864 host_client->edict->fields.server->ammo_rockets = v;
1868 if (gamemode == GAME_ROGUE)
1870 val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ammo_multi_rockets);
1874 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1875 host_client->edict->fields.server->ammo_rockets = v;
1880 host_client->edict->fields.server->health = v;
1883 if (gamemode == GAME_ROGUE)
1885 val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ammo_cells1);
1889 if (host_client->edict->fields.server->weapon <= IT_LIGHTNING)
1890 host_client->edict->fields.server->ammo_cells = v;
1895 host_client->edict->fields.server->ammo_cells = v;
1899 if (gamemode == GAME_ROGUE)
1901 val = PRVM_EDICTFIELDVALUE(host_client->edict, prog->fieldoffsets.ammo_plasma);
1905 if (host_client->edict->fields.server->weapon > IT_LIGHTNING)
1906 host_client->edict->fields.server->ammo_cells = v;
1913 prvm_edict_t *FindViewthing (void)
1918 for (i=0 ; i<prog->num_edicts ; i++)
1920 e = PRVM_EDICT_NUM(i);
1921 if (!strcmp (PRVM_GetString(e->fields.server->classname), "viewthing"))
1924 Con_Print("No viewthing on map\n");
1933 void Host_Viewmodel_f (void)
1942 e = FindViewthing ();
1947 m = Mod_ForName (Cmd_Argv(1), false, true, false);
1948 if (!m || !m->loaded || !m->Draw)
1950 Con_Printf("viewmodel: can't load %s\n", Cmd_Argv(1));
1954 e->fields.server->frame = 0;
1955 cl.model_precache[(int)e->fields.server->modelindex] = m;
1963 void Host_Viewframe_f (void)
1973 e = FindViewthing ();
1977 m = cl.model_precache[(int)e->fields.server->modelindex];
1979 f = atoi(Cmd_Argv(1));
1980 if (f >= m->numframes)
1983 e->fields.server->frame = f;
1987 void PrintFrameName (dp_model_t *m, int frame)
1990 Con_Printf("frame %i: %s\n", frame, m->animscenes[frame].name);
1992 Con_Printf("frame %i\n", frame);
2000 void Host_Viewnext_f (void)
2009 e = FindViewthing ();
2013 m = cl.model_precache[(int)e->fields.server->modelindex];
2015 e->fields.server->frame = e->fields.server->frame + 1;
2016 if (e->fields.server->frame >= m->numframes)
2017 e->fields.server->frame = m->numframes - 1;
2019 PrintFrameName (m, (int)e->fields.server->frame);
2027 void Host_Viewprev_f (void)
2036 e = FindViewthing ();
2041 m = cl.model_precache[(int)e->fields.server->modelindex];
2043 e->fields.server->frame = e->fields.server->frame - 1;
2044 if (e->fields.server->frame < 0)
2045 e->fields.server->frame = 0;
2047 PrintFrameName (m, (int)e->fields.server->frame);
2051 ===============================================================================
2055 ===============================================================================
2064 void Host_Startdemos_f (void)
2068 if (cls.state == ca_dedicated || COM_CheckParm("-listen") || COM_CheckParm("-benchmark") || COM_CheckParm("-demo") || COM_CheckParm("-capturedemo"))
2074 Con_Printf("Max %i demos in demoloop\n", MAX_DEMOS);
2077 Con_DPrintf("%i demo(s) in loop\n", c);
2079 for (i=1 ; i<c+1 ; i++)
2080 strlcpy (cls.demos[i-1], Cmd_Argv(i), sizeof (cls.demos[i-1]));
2082 // LordHavoc: clear the remaining slots
2083 for (;i <= MAX_DEMOS;i++)
2084 cls.demos[i-1][0] = 0;
2086 if (!sv.active && cls.demonum != -1 && !cls.demoplayback)
2100 Return to looping demos
2103 void Host_Demos_f (void)
2105 if (cls.state == ca_dedicated)
2107 if (cls.demonum == -1)
2117 Return to looping demos
2120 void Host_Stopdemo_f (void)
2122 if (!cls.demoplayback)
2125 Host_ShutdownServer ();
2128 void Host_SendCvar_f (void)
2132 const char *cvarname;
2137 cvarname = Cmd_Argv(1);
2138 if (cls.state == ca_connected)
2140 c = Cvar_FindVar(cvarname);
2141 // LordHavoc: if there is no such cvar or if it is private, send a
2142 // reply indicating that it has no value
2143 if(!c || (c->flags & CVAR_PRIVATE))
2144 Cmd_ForwardStringToServer(va("sentcvar %s", cvarname));
2146 Cmd_ForwardStringToServer(va("sentcvar %s \"%s\"", c->name, c->string));
2149 if(!sv.active)// || !prog->funcoffsets.SV_ParseClientCommand)
2153 if (cls.state != ca_dedicated)
2157 for(;i<svs.maxclients;i++)
2158 if(svs.clients[i].active && svs.clients[i].netconnection)
2160 host_client = &svs.clients[i];
2161 Host_ClientCommands(va("sendcvar %s\n", cvarname));
2166 static void MaxPlayers_f(void)
2170 if (Cmd_Argc() != 2)
2172 Con_Printf("\"maxplayers\" is \"%u\"\n", svs.maxclients);
2178 Con_Print("maxplayers can not be changed while a server is running.\n");
2182 n = atoi(Cmd_Argv(1));
2183 n = bound(1, n, MAX_SCOREBOARD);
2184 Con_Printf("\"maxplayers\" set to \"%u\"\n", n);
2187 Mem_Free(svs.clients);
2189 svs.clients = (client_t *)Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
2191 Cvar_Set ("deathmatch", "0");
2193 Cvar_Set ("deathmatch", "1");
2196 //=============================================================================
2198 // QuakeWorld commands
2201 =====================
2204 Send the rest of the command line over as
2205 an unconnected command.
2206 =====================
2208 void Host_Rcon_f (void) // credit: taken from QuakeWorld
2212 lhnetsocket_t *mysocket;
2214 if (!rcon_password.string || !rcon_password.string[0])
2216 Con_Printf ("You must set rcon_password before issuing an rcon command.\n");
2220 for (i = 0;rcon_password.string[i];i++)
2222 if (rcon_password.string[i] <= ' ')
2224 Con_Printf("rcon_password is not allowed to have any whitespace.\n");
2230 to = cls.netcon->peeraddress;
2233 if (!rcon_address.string[0])
2235 Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
2238 LHNETADDRESS_FromString(&to, rcon_address.string, sv_netport.integer);
2240 mysocket = NetConn_ChooseClientSocketForAddress(&to);
2243 // simply put together the rcon packet and send it
2244 NetConn_WriteString(mysocket, va("\377\377\377\377rcon %s %s", rcon_password.string, Cmd_Args()), &to);
2249 ====================
2252 user <name or userid>
2254 Dump userdata / masterdata for a user
2255 ====================
2257 void Host_User_f (void) // credit: taken from QuakeWorld
2262 if (Cmd_Argc() != 2)
2264 Con_Printf ("Usage: user <username / userid>\n");
2268 uid = atoi(Cmd_Argv(1));
2270 for (i = 0;i < cl.maxclients;i++)
2272 if (!cl.scores[i].name[0])
2274 if (cl.scores[i].qw_userid == uid || !strcasecmp(cl.scores[i].name, Cmd_Argv(1)))
2276 InfoString_Print(cl.scores[i].qw_userinfo);
2280 Con_Printf ("User not in server.\n");
2284 ====================
2287 Dump userids for all current players
2288 ====================
2290 void Host_Users_f (void) // credit: taken from QuakeWorld
2296 Con_Printf ("userid frags name\n");
2297 Con_Printf ("------ ----- ----\n");
2298 for (i = 0;i < cl.maxclients;i++)
2300 if (cl.scores[i].name[0])
2302 Con_Printf ("%6i %4i %s\n", cl.scores[i].qw_userid, cl.scores[i].frags, cl.scores[i].name);
2307 Con_Printf ("%i total users\n", c);
2312 Host_FullServerinfo_f
2314 Sent by server when serverinfo changes
2317 // TODO: shouldn't this be a cvar instead?
2318 void Host_FullServerinfo_f (void) // credit: taken from QuakeWorld
2321 if (Cmd_Argc() != 2)
2323 Con_Printf ("usage: fullserverinfo <complete info string>\n");
2327 strlcpy (cl.qw_serverinfo, Cmd_Argv(1), sizeof(cl.qw_serverinfo));
2328 InfoString_GetValue(cl.qw_serverinfo, "teamplay", temp, sizeof(temp));
2329 cl.qw_teamplay = atoi(temp);
2336 Allow clients to change userinfo
2340 void Host_FullInfo_f (void) // credit: taken from QuakeWorld
2347 if (Cmd_Argc() != 2)
2349 Con_Printf ("fullinfo <complete info string>\n");
2359 while (*s && *s != '\\')
2365 Con_Printf ("MISSING VALUE\n");
2371 while (*s && *s != '\\')
2378 CL_SetInfo(key, value, false, false, false, false);
2386 Allow clients to change userinfo
2389 void Host_SetInfo_f (void) // credit: taken from QuakeWorld
2391 if (Cmd_Argc() == 1)
2393 InfoString_Print(cls.userinfo);
2396 if (Cmd_Argc() != 3)
2398 Con_Printf ("usage: setinfo [ <key> <value> ]\n");
2401 CL_SetInfo(Cmd_Argv(1), Cmd_Argv(2), true, false, false, false);
2405 ====================
2408 packet <destination> <contents>
2410 Contents allows \n escape character
2411 ====================
2413 void Host_Packet_f (void) // credit: taken from QuakeWorld
2419 lhnetaddress_t address;
2420 lhnetsocket_t *mysocket;
2422 if (Cmd_Argc() != 3)
2424 Con_Printf ("packet <destination> <contents>\n");
2428 if (!LHNETADDRESS_FromString (&address, Cmd_Argv(1), sv_netport.integer))
2430 Con_Printf ("Bad address\n");
2436 send[0] = send[1] = send[2] = send[3] = 0xff;
2438 l = (int)strlen (in);
2439 for (i=0 ; i<l ; i++)
2441 if (out >= send + sizeof(send) - 1)
2443 if (in[i] == '\\' && in[i+1] == 'n')
2448 else if (in[i] == '\\' && in[i+1] == '0')
2453 else if (in[i] == '\\' && in[i+1] == 't')
2458 else if (in[i] == '\\' && in[i+1] == 'r')
2463 else if (in[i] == '\\' && in[i+1] == '"')
2472 mysocket = NetConn_ChooseClientSocketForAddress(&address);
2474 mysocket = NetConn_ChooseServerSocketForAddress(&address);
2476 NetConn_Write(mysocket, send, out - send, &address);
2480 ====================
2483 Send back ping and packet loss update for all current players to this player
2484 ====================
2486 void Host_Pings_f (void)
2488 int i, j, ping, packetloss;
2491 if (!host_client->netconnection)
2494 if (sv.protocol != PROTOCOL_QUAKEWORLD)
2496 MSG_WriteByte(&host_client->netconnection->message, svc_stufftext);
2497 MSG_WriteUnterminatedString(&host_client->netconnection->message, "pingplreport");
2499 for (i = 0;i < svs.maxclients;i++)
2502 if (svs.clients[i].netconnection)
2503 for (j = 0;j < NETGRAPH_PACKETS;j++)
2504 if (svs.clients[i].netconnection->incoming_unreliablesize[j] == NETGRAPH_LOSTPACKET)
2506 packetloss = packetloss * 100 / NETGRAPH_PACKETS;
2507 ping = (int)floor(svs.clients[i].ping*1000+0.5);
2508 ping = bound(0, ping, 9999);
2509 if (sv.protocol == PROTOCOL_QUAKEWORLD)
2511 // send qw_svc_updateping and qw_svc_updatepl messages
2512 MSG_WriteByte(&host_client->netconnection->message, qw_svc_updateping);
2513 MSG_WriteShort(&host_client->netconnection->message, ping);
2514 MSG_WriteByte(&host_client->netconnection->message, qw_svc_updatepl);
2515 MSG_WriteByte(&host_client->netconnection->message, packetloss);
2519 // write the string into the packet as multiple unterminated strings to avoid needing a local buffer
2520 dpsnprintf(temp, sizeof(temp), " %d %d", ping, packetloss);
2521 MSG_WriteUnterminatedString(&host_client->netconnection->message, temp);
2524 if (sv.protocol != PROTOCOL_QUAKEWORLD)
2525 MSG_WriteString(&host_client->netconnection->message, "\n");
2528 void Host_PingPLReport_f(void)
2532 if (l > cl.maxclients)
2534 for (i = 0;i < l;i++)
2536 cl.scores[i].qw_ping = atoi(Cmd_Argv(1+i*2));
2537 cl.scores[i].qw_packetloss = atoi(Cmd_Argv(1+i*2+1));
2541 //=============================================================================
2548 void Host_InitCommands (void)
2550 dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp");
2552 Cmd_AddCommand_WithClientCommand ("status", Host_Status_f, Host_Status_f, "print server status information");
2553 Cmd_AddCommand ("quit", Host_Quit_f, "quit the game");
2554 if (gamemode == GAME_NEHAHRA)
2556 Cmd_AddCommand_WithClientCommand ("max", NULL, Host_God_f, "god mode (invulnerability)");
2557 Cmd_AddCommand_WithClientCommand ("monster", NULL, Host_Notarget_f, "notarget mode (monsters do not see you)");
2558 Cmd_AddCommand_WithClientCommand ("scrag", NULL, Host_Fly_f, "fly mode (flight)");
2559 Cmd_AddCommand_WithClientCommand ("wraith", NULL, Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
2560 Cmd_AddCommand_WithClientCommand ("gimme", NULL, Host_Give_f, "alter inventory");
2564 Cmd_AddCommand_WithClientCommand ("god", NULL, Host_God_f, "god mode (invulnerability)");
2565 Cmd_AddCommand_WithClientCommand ("notarget", NULL, Host_Notarget_f, "notarget mode (monsters do not see you)");
2566 Cmd_AddCommand_WithClientCommand ("fly", NULL, Host_Fly_f, "fly mode (flight)");
2567 Cmd_AddCommand_WithClientCommand ("noclip", NULL, Host_Noclip_f, "noclip mode (flight without collisions, move through walls)");
2568 Cmd_AddCommand_WithClientCommand ("give", NULL, Host_Give_f, "alter inventory");
2570 Cmd_AddCommand ("map", Host_Map_f, "kick everyone off the server and start a new level");
2571 Cmd_AddCommand ("restart", Host_Restart_f, "restart current level");
2572 Cmd_AddCommand ("changelevel", Host_Changelevel_f, "change to another level, bringing along all connected clients");
2573 Cmd_AddCommand ("connect", Host_Connect_f, "connect to a server by IP address or hostname");
2574 Cmd_AddCommand ("reconnect", Host_Reconnect_f, "reconnect to the last server you were on, or resets a quakeworld connection (do not use if currently playing on a netquake server)");
2575 Cmd_AddCommand ("version", Host_Version_f, "print engine version");
2576 Cmd_AddCommand_WithClientCommand ("say", Host_Say_f, Host_Say_f, "send a chat message to everyone on the server");
2577 Cmd_AddCommand_WithClientCommand ("say_team", Host_Say_Team_f, Host_Say_Team_f, "send a chat message to your team on the server");
2578 Cmd_AddCommand_WithClientCommand ("tell", Host_Tell_f, Host_Tell_f, "send a chat message to only one person on the server");
2579 Cmd_AddCommand_WithClientCommand ("kill", NULL, Host_Kill_f, "die instantly");
2580 Cmd_AddCommand_WithClientCommand ("pause", NULL, Host_Pause_f, "pause the game (if the server allows pausing)");
2581 Cmd_AddCommand ("kick", Host_Kick_f, "kick a player off the server by number or name");
2582 Cmd_AddCommand_WithClientCommand ("ping", Host_Ping_f, Host_Ping_f, "print ping times of all players on the server");
2583 Cmd_AddCommand ("load", Host_Loadgame_f, "load a saved game file");
2584 Cmd_AddCommand ("save", Host_Savegame_f, "save the game to a file");
2586 Cmd_AddCommand ("startdemos", Host_Startdemos_f, "start playing back the selected demos sequentially (used at end of startup script)");
2587 Cmd_AddCommand ("demos", Host_Demos_f, "restart looping demos defined by the last startdemos command");
2588 Cmd_AddCommand ("stopdemo", Host_Stopdemo_f, "stop playing or recording demo (like stop command) and return to looping demos");
2590 Cmd_AddCommand ("viewmodel", Host_Viewmodel_f, "change model of viewthing entity in current level");
2591 Cmd_AddCommand ("viewframe", Host_Viewframe_f, "change animation frame of viewthing entity in current level");
2592 Cmd_AddCommand ("viewnext", Host_Viewnext_f, "change to next animation frame of viewthing entity in current level");
2593 Cmd_AddCommand ("viewprev", Host_Viewprev_f, "change to previous animation frame of viewthing entity in current level");
2595 Cvar_RegisterVariable (&cl_name);
2596 Cmd_AddCommand_WithClientCommand ("name", Host_Name_f, Host_Name_f, "change your player name");
2597 Cvar_RegisterVariable (&cl_color);
2598 Cmd_AddCommand_WithClientCommand ("color", Host_Color_f, Host_Color_f, "change your player shirt and pants colors");
2599 Cvar_RegisterVariable (&cl_rate);
2600 Cmd_AddCommand_WithClientCommand ("rate", Host_Rate_f, Host_Rate_f, "change your network connection speed");
2601 if (gamemode == GAME_NEHAHRA)
2603 Cvar_RegisterVariable (&cl_pmodel);
2604 Cmd_AddCommand_WithClientCommand ("pmodel", Host_PModel_f, Host_PModel_f, "change your player model choice (Nehahra specific)");
2607 // BLACK: This isnt game specific anymore (it was GAME_NEXUIZ at first)
2608 Cvar_RegisterVariable (&cl_playermodel);
2609 Cmd_AddCommand_WithClientCommand ("playermodel", Host_Playermodel_f, Host_Playermodel_f, "change your player model");
2610 Cvar_RegisterVariable (&cl_playerskin);
2611 Cmd_AddCommand_WithClientCommand ("playerskin", Host_Playerskin_f, Host_Playerskin_f, "change your player skin number");
2613 Cmd_AddCommand_WithClientCommand ("prespawn", NULL, Host_PreSpawn_f, "signon 1 (client acknowledges that server information has been received)");
2614 Cmd_AddCommand_WithClientCommand ("spawn", NULL, Host_Spawn_f, "signon 2 (client has sent player information, and is asking server to send scoreboard rankings)");
2615 Cmd_AddCommand_WithClientCommand ("begin", NULL, 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)");
2616 Cmd_AddCommand ("maxplayers", MaxPlayers_f, "sets limit on how many players (or bots) may be connected to the server at once");
2618 Cmd_AddCommand ("sendcvar", Host_SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC");
2620 Cvar_RegisterVariable (&rcon_password);
2621 Cvar_RegisterVariable (&rcon_address);
2622 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)");
2623 Cmd_AddCommand ("user", Host_User_f, "prints additional information about a player number or name on the scoreboard");
2624 Cmd_AddCommand ("users", Host_Users_f, "prints additional information about all players on the scoreboard");
2625 Cmd_AddCommand ("fullserverinfo", Host_FullServerinfo_f, "internal use only, sent by server to client to update client's local copy of serverinfo string");
2626 Cmd_AddCommand ("fullinfo", Host_FullInfo_f, "allows client to modify their userinfo");
2627 Cmd_AddCommand ("setinfo", Host_SetInfo_f, "modifies your userinfo");
2628 Cmd_AddCommand ("packet", Host_Packet_f, "send a packet to the specified address:port containing a text string");
2629 Cmd_AddCommand ("topcolor", Host_TopColor_f, "QW command to set top color without changing bottom color");
2630 Cmd_AddCommand ("bottomcolor", Host_BottomColor_f, "QW command to set bottom color without changing top color");
2632 Cmd_AddCommand_WithClientCommand ("pings", NULL, Host_Pings_f, "command sent by clients to request updated ping and packetloss of players on scoreboard (originally from QW, but also used on NQ servers)");
2633 Cmd_AddCommand ("pingplreport", Host_PingPLReport_f, "command sent by server containing client ping and packet loss values for scoreboard, triggered by pings command from client (not used by QW servers)");
2635 Cmd_AddCommand ("fixtrans", Image_FixTransparentPixels_f, "change alpha-zero pixels in an image file to sensible values, and write out a new TGA (warning: SLOW)");
2636 Cvar_RegisterVariable (&r_fixtrans_auto);
2638 Cvar_RegisterVariable (&team);
2639 Cvar_RegisterVariable (&skin);
2640 Cvar_RegisterVariable (&noaim);
2642 Cvar_RegisterVariable(&sv_cheats);
2643 Cvar_RegisterVariable(&sv_adminnick);
2644 Cvar_RegisterVariable(&sv_status_privacy);
2647 void Host_NoOperation_f(void)