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