]> git.xonotic.org Git - xonotic/darkplaces.git/blob - cl_cmd.c
(Round 7) host_cmd.c is no more. Last remaining cmds/cvars moved.
[xonotic/darkplaces.git] / cl_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 // for secure rcon authentication
24 #include "hmac.h"
25 #include "mdfour.h"
26 #include "image.h"
27 #include <time.h>
28
29 cvar_t cl_name = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "name", "player", "change your player name"};
30 cvar_t cl_rate = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "rate", "20000", "change your connection speed"};
31 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)"};
32 cvar_t cl_topcolor = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "topcolor", "0", "change the color of your shirt"};
33 cvar_t cl_bottomcolor = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "bottomcolor", "0", "change the color of your pants"};
34 cvar_t cl_team = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "team", "none", "QW team (4 character limit, example: blue)"};
35 cvar_t cl_skin = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (example: base)"};
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)"};
39 cvar_t rcon_password = {CVAR_CLIENT | CVAR_SERVER | CVAR_PRIVATE, "rcon_password", "", "password to authenticate rcon commands; NOTE: changing rcon_secure clears rcon_password, so set rcon_secure always before rcon_password; may be set to a string of the form user1:pass1 user2:pass2 user3:pass3 to allow multiple user accounts - the client then has to specify ONE of these combinations"};
40 cvar_t rcon_secure = {CVAR_CLIENT | CVAR_SERVER, "rcon_secure", "0", "force secure rcon authentication (1 = time based, 2 = challenge based); NOTE: changing rcon_secure clears rcon_password, so set rcon_secure always before rcon_password"};
41 cvar_t rcon_secure_challengetimeout = {CVAR_CLIENT, "rcon_secure_challengetimeout", "5", "challenge-based secure rcon: time out requests if no challenge came within this time interval"};
42 cvar_t rcon_address = {CVAR_CLIENT, "rcon_address", "", "server address to send rcon commands to (when not connected to a server)"};
43
44 /*
45 ===================
46 CL_ForwardToServer
47
48 Sends an entire command string over to the server, unprocessed
49 ===================
50 */
51 void CL_ForwardToServer (const char *s)
52 {
53         char temp[128];
54         if (cls.state != ca_connected)
55         {
56                 Con_Printf("Can't \"%s\", not connected\n", s);
57                 return;
58         }
59
60         if (!cls.netcon)
61                 return;
62
63         // LadyHavoc: thanks to Fuh for bringing the pure evil of SZ_Print to my
64         // attention, it has been eradicated from here, its only (former) use in
65         // all of darkplaces.
66         if (cls.protocol == PROTOCOL_QUAKEWORLD)
67                 MSG_WriteByte(&cls.netcon->message, qw_clc_stringcmd);
68         else
69                 MSG_WriteByte(&cls.netcon->message, clc_stringcmd);
70         if ((!strncmp(s, "say ", 4) || !strncmp(s, "say_team ", 9)) && cl_locs_enable.integer)
71         {
72                 // say/say_team commands can replace % character codes with status info
73                 while (*s)
74                 {
75                         if (*s == '%' && s[1])
76                         {
77                                 // handle proquake message macros
78                                 temp[0] = 0;
79                                 switch (s[1])
80                                 {
81                                 case 'l': // current location
82                                         CL_Locs_FindLocationName(temp, sizeof(temp), cl.movement_origin);
83                                         break;
84                                 case 'h': // current health
85                                         dpsnprintf(temp, sizeof(temp), "%i", cl.stats[STAT_HEALTH]);
86                                         break;
87                                 case 'a': // current armor
88                                         dpsnprintf(temp, sizeof(temp), "%i", cl.stats[STAT_ARMOR]);
89                                         break;
90                                 case 'x': // current rockets
91                                         dpsnprintf(temp, sizeof(temp), "%i", cl.stats[STAT_ROCKETS]);
92                                         break;
93                                 case 'c': // current cells
94                                         dpsnprintf(temp, sizeof(temp), "%i", cl.stats[STAT_CELLS]);
95                                         break;
96                                 // silly proquake macros
97                                 case 'd': // loc at last death
98                                         CL_Locs_FindLocationName(temp, sizeof(temp), cl.lastdeathorigin);
99                                         break;
100                                 case 't': // current time
101                                         dpsnprintf(temp, sizeof(temp), "%.0f:%.0f", floor(cl.time / 60), cl.time - floor(cl.time / 60) * 60);
102                                         break;
103                                 case 'r': // rocket launcher status ("I have RL", "I need rockets", "I need RL")
104                                         if (!(cl.stats[STAT_ITEMS] & IT_ROCKET_LAUNCHER))
105                                                 dpsnprintf(temp, sizeof(temp), "I need RL");
106                                         else if (!cl.stats[STAT_ROCKETS])
107                                                 dpsnprintf(temp, sizeof(temp), "I need rockets");
108                                         else
109                                                 dpsnprintf(temp, sizeof(temp), "I have RL");
110                                         break;
111                                 case 'p': // powerup status (outputs "quad" "pent" and "eyes" according to status)
112                                         if (cl.stats[STAT_ITEMS] & IT_QUAD)
113                                         {
114                                                 if (temp[0])
115                                                         strlcat(temp, " ", sizeof(temp));
116                                                 strlcat(temp, "quad", sizeof(temp));
117                                         }
118                                         if (cl.stats[STAT_ITEMS] & IT_INVULNERABILITY)
119                                         {
120                                                 if (temp[0])
121                                                         strlcat(temp, " ", sizeof(temp));
122                                                 strlcat(temp, "pent", sizeof(temp));
123                                         }
124                                         if (cl.stats[STAT_ITEMS] & IT_INVISIBILITY)
125                                         {
126                                                 if (temp[0])
127                                                         strlcat(temp, " ", sizeof(temp));
128                                                 strlcat(temp, "eyes", sizeof(temp));
129                                         }
130                                         break;
131                                 case 'w': // weapon status (outputs "SSG:NG:SNG:GL:RL:LG" with the text between : characters omitted if you lack the weapon)
132                                         if (cl.stats[STAT_ITEMS] & IT_SUPER_SHOTGUN)
133                                                 strlcat(temp, "SSG", sizeof(temp));
134                                         strlcat(temp, ":", sizeof(temp));
135                                         if (cl.stats[STAT_ITEMS] & IT_NAILGUN)
136                                                 strlcat(temp, "NG", sizeof(temp));
137                                         strlcat(temp, ":", sizeof(temp));
138                                         if (cl.stats[STAT_ITEMS] & IT_SUPER_NAILGUN)
139                                                 strlcat(temp, "SNG", sizeof(temp));
140                                         strlcat(temp, ":", sizeof(temp));
141                                         if (cl.stats[STAT_ITEMS] & IT_GRENADE_LAUNCHER)
142                                                 strlcat(temp, "GL", sizeof(temp));
143                                         strlcat(temp, ":", sizeof(temp));
144                                         if (cl.stats[STAT_ITEMS] & IT_ROCKET_LAUNCHER)
145                                                 strlcat(temp, "RL", sizeof(temp));
146                                         strlcat(temp, ":", sizeof(temp));
147                                         if (cl.stats[STAT_ITEMS] & IT_LIGHTNING)
148                                                 strlcat(temp, "LG", sizeof(temp));
149                                         break;
150                                 default:
151                                         // not a recognized macro, print it as-is...
152                                         temp[0] = s[0];
153                                         temp[1] = s[1];
154                                         temp[2] = 0;
155                                         break;
156                                 }
157                                 // write the resulting text
158                                 SZ_Write(&cls.netcon->message, (unsigned char *)temp, (int)strlen(temp));
159                                 s += 2;
160                                 continue;
161                         }
162                         MSG_WriteByte(&cls.netcon->message, *s);
163                         s++;
164                 }
165                 MSG_WriteByte(&cls.netcon->message, 0);
166         }
167         else // any other command is passed on as-is
168                 SZ_Write(&cls.netcon->message, (const unsigned char *)s, (int)strlen(s) + 1);
169 }
170
171 void CL_ForwardToServer_f (cmd_state_t *cmd)
172 {
173         const char *s;
174         char vabuf[1024];
175         if (!strcasecmp(Cmd_Argv(cmd, 0), "cmd"))
176         {
177                 // we want to strip off "cmd", so just send the args
178                 s = Cmd_Argc(cmd) > 1 ? Cmd_Args(cmd) : "";
179         }
180         else
181         {
182                 // we need to keep the command name, so send Cmd_Argv(cmd, 0), a space and then Cmd_Args(cmd)
183                 s = va(vabuf, sizeof(vabuf), "%s %s", Cmd_Argv(cmd, 0), Cmd_Argc(cmd) > 1 ? Cmd_Args(cmd) : "");
184         }
185         // don't send an empty forward message if the user tries "cmd" by itself
186         if (!s || !*s)
187                 return;
188         CL_ForwardToServer(s);
189 }
190
191 static void CL_SendCvar_f(cmd_state_t *cmd)
192 {
193         cvar_t  *c;
194         const char *cvarname;
195         char vabuf[1024];
196
197         if(Cmd_Argc(cmd) != 2)
198                 return;
199         cvarname = Cmd_Argv(cmd, 1);
200         if (cls.state == ca_connected)
201         {
202                 c = Cvar_FindVar(&cvars_all, cvarname, CVAR_CLIENT | CVAR_SERVER);
203                 // LadyHavoc: if there is no such cvar or if it is private, send a
204                 // reply indicating that it has no value
205                 if(!c || (c->flags & CVAR_PRIVATE))
206                         CL_ForwardToServer(va(vabuf, sizeof(vabuf), "sentcvar %s", cvarname));
207                 else
208                         CL_ForwardToServer(va(vabuf, sizeof(vabuf), "sentcvar %s \"%s\"", c->name, c->string));
209                 return;
210         }
211 }
212
213 /*
214 ==================
215 CL_Color_f
216 ==================
217 */
218 cvar_t cl_color = {CVAR_READONLY | CVAR_CLIENT | CVAR_SAVE, "_cl_color", "0", "internal storage cvar for current player colors (changed by color command)"};
219
220 // Ignore the callbacks so this two-to-three way synchronization doesn't cause an infinite loop.
221 static void CL_Color_c(cvar_t *var)
222 {
223         char vabuf[1024];
224         
225         Cvar_Set_NoCallback(&cl_topcolor, va(vabuf, sizeof(vabuf), "%i", ((var->integer >> 4) & 15)));
226         Cvar_Set_NoCallback(&cl_bottomcolor, va(vabuf, sizeof(vabuf), "%i", (var->integer & 15)));
227 }
228
229 static void CL_Topcolor_c(cvar_t *var)
230 {
231         char vabuf[1024];
232         
233         Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", var->integer*16 + cl_bottomcolor.integer));
234 }
235
236 static void CL_Bottomcolor_c(cvar_t *var)
237 {
238         char vabuf[1024];
239
240         Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", cl_topcolor.integer*16 + var->integer));
241 }
242
243 static void CL_Color_f(cmd_state_t *cmd)
244 {
245         int top, bottom;
246
247         if (Cmd_Argc(cmd) == 1)
248         {
249                 if (cmd->source == src_command)
250                 {
251                         Con_Printf("\"color\" is \"%i %i\"\n", cl_topcolor.integer, cl_bottomcolor.integer);
252                         Con_Print("color <0-15> [0-15]\n");
253                 }
254                 return;
255         }
256
257         if (Cmd_Argc(cmd) == 2)
258                 top = bottom = atoi(Cmd_Argv(cmd, 1));
259         else
260         {
261                 top = atoi(Cmd_Argv(cmd, 1));
262                 bottom = atoi(Cmd_Argv(cmd, 2));
263         }
264         /*
265          * This is just a convenient way to change topcolor and bottomcolor
266          * We can't change cl_color from here directly because topcolor and
267          * bottomcolor may be changed separately and do not call this function.
268          * So it has to be changed when the userinfo strings are updated, which
269          * happens twice here. Perhaps find a cleaner way?
270          */
271
272         top = top >= 0 ? top : cl_topcolor.integer;
273         bottom = bottom >= 0 ? bottom : cl_bottomcolor.integer;
274
275         top &= 15;
276         bottom &= 15;
277
278         // LadyHavoc: allowing skin colormaps 14 and 15 by commenting this out
279         //if (top > 13)
280         //      top = 13;
281         //if (bottom > 13)
282         //      bottom = 13;
283
284         if (cmd->source == src_command)
285         {
286                 Cvar_SetValueQuick(&cl_topcolor, top);
287                 Cvar_SetValueQuick(&cl_bottomcolor, bottom);
288                 return;
289         }
290 }
291
292 /*
293 ====================
294 CL_Packet_f
295
296 packet <destination> <contents>
297
298 Contents allows \n escape character
299 ====================
300 */
301 static void CL_Packet_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
302 {
303         char send[2048];
304         int i, l;
305         const char *in;
306         char *out;
307         lhnetaddress_t address;
308         lhnetsocket_t *mysocket;
309
310         if (Cmd_Argc(cmd) != 3)
311         {
312                 Con_Printf ("packet <destination> <contents>\n");
313                 return;
314         }
315
316         if (!LHNETADDRESS_FromString (&address, Cmd_Argv(cmd, 1), sv_netport.integer))
317         {
318                 Con_Printf ("Bad address\n");
319                 return;
320         }
321
322         in = Cmd_Argv(cmd, 2);
323         out = send+4;
324         send[0] = send[1] = send[2] = send[3] = -1;
325
326         l = (int)strlen (in);
327         for (i=0 ; i<l ; i++)
328         {
329                 if (out >= send + sizeof(send) - 1)
330                         break;
331                 if (in[i] == '\\' && in[i+1] == 'n')
332                 {
333                         *out++ = '\n';
334                         i++;
335                 }
336                 else if (in[i] == '\\' && in[i+1] == '0')
337                 {
338                         *out++ = '\0';
339                         i++;
340                 }
341                 else if (in[i] == '\\' && in[i+1] == 't')
342                 {
343                         *out++ = '\t';
344                         i++;
345                 }
346                 else if (in[i] == '\\' && in[i+1] == 'r')
347                 {
348                         *out++ = '\r';
349                         i++;
350                 }
351                 else if (in[i] == '\\' && in[i+1] == '"')
352                 {
353                         *out++ = '\"';
354                         i++;
355                 }
356                 else
357                         *out++ = in[i];
358         }
359
360         mysocket = NetConn_ChooseClientSocketForAddress(&address);
361         if (!mysocket)
362                 mysocket = NetConn_ChooseServerSocketForAddress(&address);
363         if (mysocket)
364                 NetConn_Write(mysocket, send, out - send, &address);
365 }
366
367 /*
368 =====================
369 CL_PQRcon_f
370
371 ProQuake rcon support
372 =====================
373 */
374 static void CL_PQRcon_f(cmd_state_t *cmd)
375 {
376         int n;
377         const char *e;
378         lhnetsocket_t *mysocket;
379
380         if (Cmd_Argc(cmd) == 1)
381         {
382                 Con_Printf("%s: Usage: %s command\n", Cmd_Argv(cmd, 0), Cmd_Argv(cmd, 0));
383                 return;
384         }
385
386         if (!rcon_password.string || !rcon_password.string[0] || rcon_secure.integer > 0)
387         {
388                 Con_Printf ("You must set rcon_password before issuing an pqrcon command, and rcon_secure must be 0.\n");
389                 return;
390         }
391
392         e = strchr(rcon_password.string, ' ');
393         n = e ? e-rcon_password.string : (int)strlen(rcon_password.string);
394
395         if (cls.netcon)
396                 cls.rcon_address = cls.netcon->peeraddress;
397         else
398         {
399                 if (!rcon_address.string[0])
400                 {
401                         Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
402                         return;
403                 }
404                 LHNETADDRESS_FromString(&cls.rcon_address, rcon_address.string, sv_netport.integer);
405         }
406         mysocket = NetConn_ChooseClientSocketForAddress(&cls.rcon_address);
407         if (mysocket)
408         {
409                 sizebuf_t buf;
410                 unsigned char bufdata[64];
411                 buf.data = bufdata;
412                 SZ_Clear(&buf);
413                 MSG_WriteLong(&buf, 0);
414                 MSG_WriteByte(&buf, CCREQ_RCON);
415                 SZ_Write(&buf, (const unsigned char*)rcon_password.string, n);
416                 MSG_WriteByte(&buf, 0); // terminate the (possibly partial) string
417                 MSG_WriteString(&buf, Cmd_Args(cmd));
418                 StoreBigLong(buf.data, NETFLAG_CTL | (buf.cursize & NETFLAG_LENGTH_MASK));
419                 NetConn_Write(mysocket, buf.data, buf.cursize, &cls.rcon_address);
420                 SZ_Clear(&buf);
421         }
422 }
423
424 /*
425 =====================
426 CL_Rcon_f
427
428   Send the rest of the command line over as
429   an unconnected command.
430 =====================
431 */
432 static void CL_Rcon_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
433 {
434         int i, n;
435         const char *e;
436         lhnetsocket_t *mysocket;
437
438         if (Cmd_Argc(cmd) == 1)
439         {
440                 Con_Printf("%s: Usage: %s command\n", Cmd_Argv(cmd, 0), Cmd_Argv(cmd, 0));
441                 return;
442         }
443
444         if (!rcon_password.string || !rcon_password.string[0])
445         {
446                 Con_Printf ("You must set rcon_password before issuing an rcon command.\n");
447                 return;
448         }
449
450         e = strchr(rcon_password.string, ' ');
451         n = e ? e-rcon_password.string : (int)strlen(rcon_password.string);
452
453         if (cls.netcon)
454                 cls.rcon_address = cls.netcon->peeraddress;
455         else
456         {
457                 if (!rcon_address.string[0])
458                 {
459                         Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
460                         return;
461                 }
462                 LHNETADDRESS_FromString(&cls.rcon_address, rcon_address.string, sv_netport.integer);
463         }
464         mysocket = NetConn_ChooseClientSocketForAddress(&cls.rcon_address);
465         if (mysocket && Cmd_Args(cmd)[0])
466         {
467                 // simply put together the rcon packet and send it
468                 if(Cmd_Argv(cmd, 0)[0] == 's' || rcon_secure.integer > 1)
469                 {
470                         if(cls.rcon_commands[cls.rcon_ringpos][0])
471                         {
472                                 char s[128];
473                                 LHNETADDRESS_ToString(&cls.rcon_addresses[cls.rcon_ringpos], s, sizeof(s), true);
474                                 Con_Printf("rcon to %s (for command %s) failed: too many buffered commands (possibly increase MAX_RCONS)\n", s, cls.rcon_commands[cls.rcon_ringpos]);
475                                 cls.rcon_commands[cls.rcon_ringpos][0] = 0;
476                                 --cls.rcon_trying;
477                         }
478                         for (i = 0;i < MAX_RCONS;i++)
479                                 if(cls.rcon_commands[i][0])
480                                         if (!LHNETADDRESS_Compare(&cls.rcon_address, &cls.rcon_addresses[i]))
481                                                 break;
482                         ++cls.rcon_trying;
483                         if(i >= MAX_RCONS)
484                                 NetConn_WriteString(mysocket, "\377\377\377\377getchallenge", &cls.rcon_address); // otherwise we'll request the challenge later
485                         strlcpy(cls.rcon_commands[cls.rcon_ringpos], Cmd_Args(cmd), sizeof(cls.rcon_commands[cls.rcon_ringpos]));
486                         cls.rcon_addresses[cls.rcon_ringpos] = cls.rcon_address;
487                         cls.rcon_timeout[cls.rcon_ringpos] = host.realtime + rcon_secure_challengetimeout.value;
488                         cls.rcon_ringpos = (cls.rcon_ringpos + 1) % MAX_RCONS;
489                 }
490                 else if(rcon_secure.integer > 0)
491                 {
492                         char buf[1500];
493                         char argbuf[1500];
494                         dpsnprintf(argbuf, sizeof(argbuf), "%ld.%06d %s", (long) time(NULL), (int) (rand() % 1000000), Cmd_Args(cmd));
495                         memcpy(buf, "\377\377\377\377srcon HMAC-MD4 TIME ", 24);
496                         if(HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 24), (unsigned char *) argbuf, (int)strlen(argbuf), (unsigned char *) rcon_password.string, n))
497                         {
498                                 buf[40] = ' ';
499                                 strlcpy(buf + 41, argbuf, sizeof(buf) - 41);
500                                 NetConn_Write(mysocket, buf, 41 + (int)strlen(buf + 41), &cls.rcon_address);
501                         }
502                 }
503                 else
504                 {
505                         char buf[1500];
506                         memcpy(buf, "\377\377\377\377", 4);
507                         dpsnprintf(buf+4, sizeof(buf)-4, "rcon %.*s %s",  n, rcon_password.string, Cmd_Args(cmd));
508                         NetConn_WriteString(mysocket, buf, &cls.rcon_address);
509                 }
510         }
511 }
512
513 static void CL_RCon_ClearPassword_c(cvar_t *var)
514 {
515         // whenever rcon_secure is changed to 0, clear rcon_password for
516         // security reasons (prevents a send-rcon-password-as-plaintext
517         // attack based on NQ protocol session takeover and svc_stufftext)
518         if(var->integer <= 0)
519                 Cvar_SetQuick(&rcon_password, "");
520 }
521
522 /*
523 ==================
524 CL_FullServerinfo_f
525
526 Sent by server when serverinfo changes
527 ==================
528 */
529 // TODO: shouldn't this be a cvar instead?
530 static void CL_FullServerinfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
531 {
532         char temp[512];
533         if (Cmd_Argc(cmd) != 2)
534         {
535                 Con_Printf ("usage: fullserverinfo <complete info string>\n");
536                 return;
537         }
538
539         strlcpy (cl.qw_serverinfo, Cmd_Argv(cmd, 1), sizeof(cl.qw_serverinfo));
540         InfoString_GetValue(cl.qw_serverinfo, "teamplay", temp, sizeof(temp));
541         cl.qw_teamplay = atoi(temp);
542 }
543
544 /*
545 ==================
546 CL_FullInfo_f
547
548 Allow clients to change userinfo
549 ==================
550 Casey was here :)
551 */
552 static void CL_FullInfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
553 {
554         char key[512];
555         char value[512];
556         const char *s;
557
558         if (Cmd_Argc(cmd) != 2)
559         {
560                 Con_Printf ("fullinfo <complete info string>\n");
561                 return;
562         }
563
564         s = Cmd_Argv(cmd, 1);
565         if (*s == '\\')
566                 s++;
567         while (*s)
568         {
569                 size_t len = strcspn(s, "\\");
570                 if (len >= sizeof(key)) {
571                         len = sizeof(key) - 1;
572                 }
573                 strlcpy(key, s, len + 1);
574                 s += len;
575                 if (!*s)
576                 {
577                         Con_Printf ("MISSING VALUE\n");
578                         return;
579                 }
580                 ++s; // Skip over backslash.
581
582                 len = strcspn(s, "\\");
583                 if (len >= sizeof(value)) {
584                         len = sizeof(value) - 1;
585                 }
586                 strlcpy(value, s, len + 1);
587
588                 CL_SetInfo(key, value, false, false, false, false);
589
590                 s += len;
591                 if (!*s)
592                 {
593                         break;
594                 }
595                 ++s; // Skip over backslash.
596         }
597 }
598
599 /*
600 ==================
601 CL_SetInfo_f
602
603 Allow clients to change userinfo
604 ==================
605 */
606 static void CL_SetInfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
607 {
608         if (Cmd_Argc(cmd) == 1)
609         {
610                 InfoString_Print(cls.userinfo);
611                 return;
612         }
613         if (Cmd_Argc(cmd) != 3)
614         {
615                 Con_Printf ("usage: setinfo [ <key> <value> ]\n");
616                 return;
617         }
618         CL_SetInfo(Cmd_Argv(cmd, 1), Cmd_Argv(cmd, 2), true, false, false, false);
619 }
620
621 static void CL_PingPLReport_f(cmd_state_t *cmd)
622 {
623         char *errbyte;
624         int i;
625         int l = Cmd_Argc(cmd);
626         if (l > cl.maxclients)
627                 l = cl.maxclients;
628         for (i = 0;i < l;i++)
629         {
630                 cl.scores[i].qw_ping = atoi(Cmd_Argv(cmd, 1+i*2));
631                 cl.scores[i].qw_packetloss = strtol(Cmd_Argv(cmd, 1+i*2+1), &errbyte, 0);
632                 if(errbyte && *errbyte == ',')
633                         cl.scores[i].qw_movementloss = atoi(errbyte + 1);
634                 else
635                         cl.scores[i].qw_movementloss = 0;
636         }
637 }
638
639 void CL_InitCommands(void)
640 {
641         dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp");
642
643         Cvar_RegisterVariable(&cl_name);
644         Cvar_RegisterAlias(&cl_name, "_cl_name");
645         Cvar_RegisterVariable(&cl_rate);
646         Cvar_RegisterAlias(&cl_rate, "_cl_rate");
647         Cvar_RegisterVariable(&cl_rate_burstsize);
648         Cvar_RegisterAlias(&cl_rate_burstsize, "_cl_rate_burstsize");
649         Cvar_RegisterVariable(&cl_pmodel);
650         Cvar_RegisterAlias(&cl_pmodel, "_cl_pmodel");
651         Cvar_RegisterVariable(&cl_color);
652         Cvar_RegisterCallback(&cl_color, CL_Color_c);
653         Cvar_RegisterVariable(&cl_topcolor);
654         Cvar_RegisterCallback(&cl_topcolor, CL_Topcolor_c);
655         Cvar_RegisterVariable(&cl_bottomcolor);
656         Cvar_RegisterCallback(&cl_bottomcolor, CL_Bottomcolor_c);
657         Cvar_RegisterVariable(&rcon_address);
658         Cvar_RegisterVariable(&rcon_secure);
659         Cvar_RegisterCallback(&rcon_secure, CL_RCon_ClearPassword_c);
660         Cvar_RegisterVariable(&rcon_secure_challengetimeout);
661         Cvar_RegisterVariable(&rcon_password);
662         Cvar_RegisterVariable(&r_fixtrans_auto);
663         Cvar_RegisterVariable(&cl_team);
664         Cvar_RegisterVariable(&cl_skin);
665         Cvar_RegisterVariable(&cl_noaim);       
666
667         Cmd_AddCommand(CMD_CLIENT | CMD_CLIENT_FROM_SERVER, "cmd", CL_ForwardToServer_f, "send a console commandline to the server (used by some mods)");
668         Cmd_AddCommand(CMD_CLIENT, "color", CL_Color_f, "change your player shirt and pants colors");
669         Cmd_AddCommand(CMD_CLIENT, "rcon", CL_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); note: if rcon_secure is set, client and server clocks must be synced e.g. via NTP");
670         Cmd_AddCommand(CMD_CLIENT, "srcon", CL_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); this always works as if rcon_secure is set; note: client and server clocks must be synced e.g. via NTP");
671         Cmd_AddCommand(CMD_CLIENT, "pqrcon", CL_PQRcon_f, "sends a command to a proquake 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)");
672         Cmd_AddCommand(CMD_CLIENT, "packet", CL_Packet_f, "send a packet to the specified address:port containing a text string");
673         Cmd_AddCommand(CMD_CLIENT, "fullinfo", CL_FullInfo_f, "allows client to modify their userinfo");
674         Cmd_AddCommand(CMD_CLIENT, "setinfo", CL_SetInfo_f, "modifies your userinfo");
675         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");
676         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)");
677
678         // commands that are only sent by server to client for execution
679         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)");
680         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");
681 }