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