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.
25 #include "prvm_cmds.h"
28 extern cvar_t sv_adminnick;
29 extern cvar_t sv_status_privacy;
30 extern cvar_t sv_status_show_qcstatus;
31 extern cvar_t sv_namechangetimer;
32 cvar_t cl_team = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "team", "none", "QW team (4 character limit, example: blue)"};
33 cvar_t cl_skin = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (example: base)"};
34 cvar_t cl_playermodel = {CVAR_CLIENT | CVAR_SERVER | CVAR_USERINFO | CVAR_SAVE, "playermodel", "", "current player model in Nexuiz/Xonotic"};
35 cvar_t cl_playerskin = {CVAR_CLIENT | CVAR_SERVER | CVAR_USERINFO | CVAR_SAVE, "playerskin", "", "current player skin in Nexuiz/Xonotic"};
36 cvar_t cl_noaim = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "noaim", "1", "QW option to disable vertical autoaim"};
37 cvar_t cl_pmodel = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "pmodel", "0", "current player model number in nehahra"};
38 cvar_t r_fixtrans_auto = {CVAR_CLIENT, "r_fixtrans_auto", "0", "automatically fixtrans textures (when set to 2, it also saves the fixed versions to a fixtrans directory)"};
40 //============================================================================
43 ======================
45 ======================
47 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
48 static void CL_Playermodel_f(cmd_state_t *cmd)
50 prvm_prog_t *prog = SVVM_prog;
52 char newPath[sizeof(host_client->playermodel)];
54 if (Cmd_Argc (cmd) == 1)
56 if (cmd->source == src_command)
58 Con_Printf("\"playermodel\" is \"%s\"\n", cl_playermodel.string);
63 if (Cmd_Argc (cmd) == 2)
64 strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
66 strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
68 for (i = 0, j = 0;newPath[i];i++)
69 if (newPath[i] != '\r' && newPath[i] != '\n')
70 newPath[j++] = newPath[i];
73 if (cmd->source == src_command)
75 Cvar_Set (&cvars_all, "_cl_playermodel", newPath);
80 if (host.realtime < host_client->nametime)
82 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
86 host_client->nametime = host.realtime + 5;
89 // point the string back at updateclient->name to keep it safe
90 strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
91 PRVM_serveredictstring(host_client->edict, playermodel) = PRVM_SetEngineString(prog, host_client->playermodel);
92 if (strcmp(host_client->old_model, host_client->playermodel))
94 strlcpy(host_client->old_model, host_client->playermodel, sizeof(host_client->old_model));
95 /*// send notification to all clients
96 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
97 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
98 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
103 ======================
105 ======================
107 static void CL_Playerskin_f(cmd_state_t *cmd)
109 prvm_prog_t *prog = SVVM_prog;
111 char newPath[sizeof(host_client->playerskin)];
113 if (Cmd_Argc (cmd) == 1)
115 if (cmd->source == src_command)
117 Con_Printf("\"playerskin\" is \"%s\"\n", cl_playerskin.string);
122 if (Cmd_Argc (cmd) == 2)
123 strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
125 strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
127 for (i = 0, j = 0;newPath[i];i++)
128 if (newPath[i] != '\r' && newPath[i] != '\n')
129 newPath[j++] = newPath[i];
132 if (cmd->source == src_command)
134 Cvar_Set (&cvars_all, "_cl_playerskin", newPath);
139 if (host.realtime < host_client->nametime)
141 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
145 host_client->nametime = host.realtime + 5;
148 // point the string back at updateclient->name to keep it safe
149 strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
150 PRVM_serveredictstring(host_client->edict, playerskin) = PRVM_SetEngineString(prog, host_client->playerskin);
151 if (strcmp(host_client->old_skin, host_client->playerskin))
153 //if (host_client->begun)
154 // SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
155 strlcpy(host_client->old_skin, host_client->playerskin, sizeof(host_client->old_skin));
156 /*// send notification to all clients
157 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
158 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
159 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
163 cvar_t cl_rate = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "rate", "20000", "change your connection speed"};
164 cvar_t cl_rate_burstsize = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "rate_burstsize", "1024", "internal storage cvar for current rate control burst size (changed by rate_burstsize command)"};
167 ======================
169 LadyHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
170 LadyHavoc: correction, Mindcrime will be removing pmodel in the future, but it's still stuck here for compatibility.
171 ======================
173 static void CL_PModel_f(cmd_state_t *cmd)
175 prvm_prog_t *prog = SVVM_prog;
178 if (Cmd_Argc (cmd) == 1)
180 if (cmd->source == src_command)
182 Con_Printf("\"pmodel\" is \"%s\"\n", cl_pmodel.string);
186 i = atoi(Cmd_Argv(cmd, 1));
188 if (cmd->source == src_command)
190 if (cl_pmodel.integer == i)
192 Cvar_SetValue (&cvars_all, "_cl_pmodel", i);
193 if (cls.state == ca_connected)
194 CL_ForwardToServer_f(cmd);
198 PRVM_serveredictfloat(host_client->edict, pmodel) = i;
201 //===========================================================================
203 //===========================================================================
205 static void CL_SendCvar_f(cmd_state_t *cmd)
209 const char *cvarname;
213 if(Cmd_Argc(cmd) != 2)
215 cvarname = Cmd_Argv(cmd, 1);
216 if (cls.state == ca_connected)
218 c = Cvar_FindVar(&cvars_all, cvarname, CVAR_CLIENT | CVAR_SERVER);
219 // LadyHavoc: if there is no such cvar or if it is private, send a
220 // reply indicating that it has no value
221 if(!c || (c->flags & CVAR_PRIVATE))
222 CL_ForwardToServer(va(vabuf, sizeof(vabuf), "sentcvar %s", cvarname));
224 CL_ForwardToServer(va(vabuf, sizeof(vabuf), "sentcvar %s \"%s\"", c->name, c->string));
227 if(!sv.active)// || !PRVM_serverfunction(SV_ParseClientCommand))
231 if (cls.state != ca_dedicated)
235 for(;i<svs.maxclients;i++)
236 if(svs.clients[i].active && svs.clients[i].netconnection)
238 host_client = &svs.clients[i];
239 SV_ClientCommands("sendcvar %s\n", cvarname);
244 //=============================================================================
246 // QuakeWorld commands
252 Sent by server when serverinfo changes
255 // TODO: shouldn't this be a cvar instead?
256 static void CL_FullServerinfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
259 if (Cmd_Argc(cmd) != 2)
261 Con_Printf ("usage: fullserverinfo <complete info string>\n");
265 strlcpy (cl.qw_serverinfo, Cmd_Argv(cmd, 1), sizeof(cl.qw_serverinfo));
266 InfoString_GetValue(cl.qw_serverinfo, "teamplay", temp, sizeof(temp));
267 cl.qw_teamplay = atoi(temp);
274 Allow clients to change userinfo
278 static void CL_FullInfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
284 if (Cmd_Argc(cmd) != 2)
286 Con_Printf ("fullinfo <complete info string>\n");
290 s = Cmd_Argv(cmd, 1);
295 size_t len = strcspn(s, "\\");
296 if (len >= sizeof(key)) {
297 len = sizeof(key) - 1;
299 strlcpy(key, s, len + 1);
303 Con_Printf ("MISSING VALUE\n");
306 ++s; // Skip over backslash.
308 len = strcspn(s, "\\");
309 if (len >= sizeof(value)) {
310 len = sizeof(value) - 1;
312 strlcpy(value, s, len + 1);
314 CL_SetInfo(key, value, false, false, false, false);
321 ++s; // Skip over backslash.
329 Allow clients to change userinfo
332 static void CL_SetInfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
334 if (Cmd_Argc(cmd) == 1)
336 InfoString_Print(cls.userinfo);
339 if (Cmd_Argc(cmd) != 3)
341 Con_Printf ("usage: setinfo [ <key> <value> ]\n");
344 CL_SetInfo(Cmd_Argv(cmd, 1), Cmd_Argv(cmd, 2), true, false, false, false);
347 static void CL_PingPLReport_f(cmd_state_t *cmd)
351 int l = Cmd_Argc(cmd);
352 if (l > cl.maxclients)
354 for (i = 0;i < l;i++)
356 cl.scores[i].qw_ping = atoi(Cmd_Argv(cmd, 1+i*2));
357 cl.scores[i].qw_packetloss = strtol(Cmd_Argv(cmd, 1+i*2+1), &errbyte, 0);
358 if(errbyte && *errbyte == ',')
359 cl.scores[i].qw_movementloss = atoi(errbyte + 1);
361 cl.scores[i].qw_movementloss = 0;
365 //=============================================================================
372 void Host_InitCommands (void)
374 dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp");
376 Cvar_RegisterVariable(&cl_name);
377 Cvar_RegisterAlias(&cl_name, "_cl_name");
378 Cvar_RegisterVariable(&cl_rate);
379 Cvar_RegisterAlias(&cl_rate, "_cl_rate");
380 Cvar_RegisterVariable(&cl_rate_burstsize);
381 Cvar_RegisterAlias(&cl_rate_burstsize, "_cl_rate_burstsize");
382 Cvar_RegisterVariable(&cl_pmodel);
383 Cvar_RegisterAlias(&cl_pmodel, "_cl_pmodel");
384 Cvar_RegisterVariable(&cl_playermodel);
385 Cvar_RegisterAlias(&cl_playermodel, "_cl_playermodel");
386 Cvar_RegisterVariable(&cl_playerskin);
387 Cvar_RegisterAlias(&cl_playerskin, "_cl_playerskin");
388 Cvar_RegisterVariable(&rcon_password);
389 Cvar_RegisterVariable(&r_fixtrans_auto);
390 Cvar_RegisterVariable(&cl_team);
391 Cvar_RegisterVariable(&cl_skin);
392 Cvar_RegisterVariable(&cl_noaim);
394 Cmd_AddCommand(CMD_USERINFO, "pmodel", CL_PModel_f, "(Nehahra-only) change your player model choice");
395 Cmd_AddCommand(CMD_USERINFO, "playermodel", CL_Playermodel_f, "change your player model");
396 Cmd_AddCommand(CMD_USERINFO, "playerskin", CL_Playerskin_f, "change your player skin number");
398 Cmd_AddCommand(CMD_CLIENT, "sendcvar", CL_SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC");
399 Cmd_AddCommand(CMD_CLIENT, "fullinfo", CL_FullInfo_f, "allows client to modify their userinfo");
400 Cmd_AddCommand(CMD_CLIENT, "setinfo", CL_SetInfo_f, "modifies your userinfo");
401 Cmd_AddCommand(CMD_CLIENT, "fixtrans", Image_FixTransparentPixels_f, "change alpha-zero pixels in an image file to sensible values, and write out a new TGA (warning: SLOW)");
403 // commands that are only sent by server to client for execution
404 Cmd_AddCommand(CMD_CLIENT_FROM_SERVER, "pingplreport", CL_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)");
405 Cmd_AddCommand(CMD_CLIENT_FROM_SERVER, "fullserverinfo", CL_FullServerinfo_f, "internal use only, sent by server to client to update client's local copy of serverinfo string");
408 void Host_NoOperation_f(cmd_state_t *cmd)