]> git.xonotic.org Git - xonotic/darkplaces.git/blob - host_cmd.c
(Round 5) Break up host_cmd.c
[xonotic/darkplaces.git] / host_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 #include "sv_demo.h"
23 #include "image.h"
24
25 #include "prvm_cmds.h"
26 #include "utf8lib.h"
27
28 // for secure rcon authentication
29 #include "hmac.h"
30 #include "mdfour.h"
31 #include <time.h>
32
33 extern cvar_t sv_adminnick;
34 extern cvar_t sv_status_privacy;
35 extern cvar_t sv_status_show_qcstatus;
36 extern cvar_t sv_namechangetimer;
37 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"};
38 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"};
39 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"};
40 cvar_t rcon_address = {CVAR_CLIENT, "rcon_address", "", "server address to send rcon commands to (when not connected to a server)"};
41 cvar_t name = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "name", "player", "change your player name"};
42 cvar_t topcolor = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "topcolor", "0", "change the color of your shirt"};
43 cvar_t bottomcolor = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "bottomcolor", "0", "change the color of your pants"};
44 cvar_t team = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "team", "none", "QW team (4 character limit, example: blue)"};
45 cvar_t skin = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "skin", "", "QW player skin name (example: base)"};
46 cvar_t playermodel = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "playermodel", "", "current player model in Nexuiz/Xonotic"};
47 cvar_t playerskin = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "playerskin", "", "current player skin in Nexuiz/Xonotic"};
48 cvar_t noaim = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "noaim", "1", "QW option to disable vertical autoaim"};
49 cvar_t pmodel = {CVAR_CLIENT | CVAR_USERINFO | CVAR_SAVE, "pmodel", "0", "current player model number in nehahra"};
50 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)"};
51
52 //============================================================================
53
54 /*
55 ======================
56 CL_Playermodel_f
57 ======================
58 */
59 // the old cl_playermodel in cl_main has been renamed to __cl_playermodel
60 static void CL_Playermodel_f(cmd_state_t *cmd)
61 {
62         prvm_prog_t *prog = SVVM_prog;
63         int i, j;
64         char newPath[sizeof(host_client->playermodel)];
65
66         if (Cmd_Argc (cmd) == 1)
67         {
68                 if (cmd->source == src_command)
69                 {
70                         Con_Printf("\"playermodel\" is \"%s\"\n", playermodel.string);
71                 }
72                 return;
73         }
74
75         if (Cmd_Argc (cmd) == 2)
76                 strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
77         else
78                 strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
79
80         for (i = 0, j = 0;newPath[i];i++)
81                 if (newPath[i] != '\r' && newPath[i] != '\n')
82                         newPath[j++] = newPath[i];
83         newPath[j] = 0;
84
85         if (cmd->source == src_command)
86         {
87                 Cvar_Set (&cvars_all, "_cl_playermodel", newPath);
88                 return;
89         }
90
91         /*
92         if (host.realtime < host_client->nametime)
93         {
94                 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
95                 return;
96         }
97
98         host_client->nametime = host.realtime + 5;
99         */
100
101         // point the string back at updateclient->name to keep it safe
102         strlcpy (host_client->playermodel, newPath, sizeof (host_client->playermodel));
103         PRVM_serveredictstring(host_client->edict, playermodel) = PRVM_SetEngineString(prog, host_client->playermodel);
104         if (strcmp(host_client->old_model, host_client->playermodel))
105         {
106                 strlcpy(host_client->old_model, host_client->playermodel, sizeof(host_client->old_model));
107                 /*// send notification to all clients
108                 MSG_WriteByte (&sv.reliable_datagram, svc_updatepmodel);
109                 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
110                 MSG_WriteString (&sv.reliable_datagram, host_client->playermodel);*/
111         }
112 }
113
114 /*
115 ======================
116 CL_Playerskin_f
117 ======================
118 */
119 static void CL_Playerskin_f(cmd_state_t *cmd)
120 {
121         prvm_prog_t *prog = SVVM_prog;
122         int i, j;
123         char newPath[sizeof(host_client->playerskin)];
124
125         if (Cmd_Argc (cmd) == 1)
126         {
127                 if (cmd->source == src_command)
128                 {
129                         Con_Printf("\"playerskin\" is \"%s\"\n", playerskin.string);
130                 }
131                 return;
132         }
133
134         if (Cmd_Argc (cmd) == 2)
135                 strlcpy (newPath, Cmd_Argv(cmd, 1), sizeof (newPath));
136         else
137                 strlcpy (newPath, Cmd_Args(cmd), sizeof (newPath));
138
139         for (i = 0, j = 0;newPath[i];i++)
140                 if (newPath[i] != '\r' && newPath[i] != '\n')
141                         newPath[j++] = newPath[i];
142         newPath[j] = 0;
143
144         if (cmd->source == src_command)
145         {
146                 Cvar_Set (&cvars_all, "_cl_playerskin", newPath);
147                 return;
148         }
149
150         /*
151         if (host.realtime < host_client->nametime)
152         {
153                 SV_ClientPrintf("You can't change playermodel more than once every 5 seconds!\n");
154                 return;
155         }
156
157         host_client->nametime = host.realtime + 5;
158         */
159
160         // point the string back at updateclient->name to keep it safe
161         strlcpy (host_client->playerskin, newPath, sizeof (host_client->playerskin));
162         PRVM_serveredictstring(host_client->edict, playerskin) = PRVM_SetEngineString(prog, host_client->playerskin);
163         if (strcmp(host_client->old_skin, host_client->playerskin))
164         {
165                 //if (host_client->begun)
166                 //      SV_BroadcastPrintf("%s changed skin to %s\n", host_client->name, host_client->playerskin);
167                 strlcpy(host_client->old_skin, host_client->playerskin, sizeof(host_client->old_skin));
168                 /*// send notification to all clients
169                 MSG_WriteByte (&sv.reliable_datagram, svc_updatepskin);
170                 MSG_WriteByte (&sv.reliable_datagram, host_client - svs.clients);
171                 MSG_WriteString (&sv.reliable_datagram, host_client->playerskin);*/
172         }
173 }
174
175 /*
176 ==================
177 CL_Color_f
178 ==================
179 */
180 cvar_t cl_color = {CVAR_READONLY | CVAR_CLIENT | CVAR_SAVE, "_cl_color", "0", "internal storage cvar for current player colors (changed by color command)"};
181
182 // Ignore the callbacks so this two-to-three way synchronization doesn't cause an infinite loop.
183 static void CL_Color_c(char *string)
184 {
185         char vabuf[1024];
186         
187         Cvar_Set_NoCallback(&topcolor, va(vabuf, sizeof(vabuf), "%i", ((atoi(string) >> 4) & 15)));
188         Cvar_Set_NoCallback(&bottomcolor, va(vabuf, sizeof(vabuf), "%i", (atoi(string) & 15)));
189 }
190
191 static void CL_Topcolor_c(char *string)
192 {
193         char vabuf[1024];
194         
195         Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", atoi(string)*16 + bottomcolor.integer));
196 }
197
198 static void CL_Bottomcolor_c(char *string)
199 {
200         char vabuf[1024];
201
202         Cvar_Set_NoCallback(&cl_color, va(vabuf, sizeof(vabuf), "%i", topcolor.integer*16 + atoi(string)));
203 }
204
205 static void CL_Color_f(cmd_state_t *cmd)
206 {
207         int top, bottom;
208
209         if (Cmd_Argc(cmd) == 1)
210         {
211                 if (cmd->source == src_command)
212                 {
213                         Con_Printf("\"color\" is \"%i %i\"\n", topcolor.integer, bottomcolor.integer);
214                         Con_Print("color <0-15> [0-15]\n");
215                 }
216                 return;
217         }
218
219         if (Cmd_Argc(cmd) == 2)
220                 top = bottom = atoi(Cmd_Argv(cmd, 1));
221         else
222         {
223                 top = atoi(Cmd_Argv(cmd, 1));
224                 bottom = atoi(Cmd_Argv(cmd, 2));
225         }
226         /*
227          * This is just a convenient way to change topcolor and bottomcolor
228          * We can't change cl_color from here directly because topcolor and
229          * bottomcolor may be changed separately and do not call this function.
230          * So it has to be changed when the userinfo strings are updated, which
231          * happens twice here. Perhaps find a cleaner way?
232          */
233
234         top &= 15;
235         bottom &= 15;
236
237         // LadyHavoc: allowing skin colormaps 14 and 15 by commenting this out
238         //if (top > 13)
239         //      top = 13;
240         //if (bottom > 13)
241         //      bottom = 13;
242
243         if (cmd->source == src_command)
244         {
245                 Cvar_SetValueQuick(&topcolor, top);
246                 Cvar_SetValueQuick(&bottomcolor, bottom);
247                 return;
248         }
249 }
250
251 cvar_t rate = {CVAR_CLIENT | CVAR_SAVE | CVAR_USERINFO, "rate", "20000", "change your connection speed"};
252 cvar_t 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)"};
253
254 /*
255 ======================
256 CL_PModel_f
257 LadyHavoc: only supported for Nehahra, I personally think this is dumb, but Mindcrime won't listen.
258 LadyHavoc: correction, Mindcrime will be removing pmodel in the future, but it's still stuck here for compatibility.
259 ======================
260 */
261 static void CL_PModel_f(cmd_state_t *cmd)
262 {
263         prvm_prog_t *prog = SVVM_prog;
264         int i;
265
266         if (Cmd_Argc (cmd) == 1)
267         {
268                 if (cmd->source == src_command)
269                 {
270                         Con_Printf("\"pmodel\" is \"%s\"\n", pmodel.string);
271                 }
272                 return;
273         }
274         i = atoi(Cmd_Argv(cmd, 1));
275
276         if (cmd->source == src_command)
277         {
278                 if (pmodel.integer == i)
279                         return;
280                 Cvar_SetValue (&cvars_all, "_cl_pmodel", i);
281                 if (cls.state == ca_connected)
282                         Cmd_ForwardToServer_f(cmd);
283                 return;
284         }
285
286         PRVM_serveredictfloat(host_client->edict, pmodel) = i;
287 }
288
289 //===========================================================================
290
291 //===========================================================================
292
293 static void CL_SendCvar_f(cmd_state_t *cmd)
294 {
295         int             i;
296         cvar_t  *c;
297         const char *cvarname;
298         client_t *old;
299         char vabuf[1024];
300
301         if(Cmd_Argc(cmd) != 2)
302                 return;
303         cvarname = Cmd_Argv(cmd, 1);
304         if (cls.state == ca_connected)
305         {
306                 c = Cvar_FindVar(&cvars_all, cvarname, CVAR_CLIENT | CVAR_SERVER);
307                 // LadyHavoc: if there is no such cvar or if it is private, send a
308                 // reply indicating that it has no value
309                 if(!c || (c->flags & CVAR_PRIVATE))
310                         Cmd_ForwardStringToServer(va(vabuf, sizeof(vabuf), "sentcvar %s", cvarname));
311                 else
312                         Cmd_ForwardStringToServer(va(vabuf, sizeof(vabuf), "sentcvar %s \"%s\"", c->name, c->string));
313                 return;
314         }
315         if(!sv.active)// || !PRVM_serverfunction(SV_ParseClientCommand))
316                 return;
317
318         old = host_client;
319         if (cls.state != ca_dedicated)
320                 i = 1;
321         else
322                 i = 0;
323         for(;i<svs.maxclients;i++)
324                 if(svs.clients[i].active && svs.clients[i].netconnection)
325                 {
326                         host_client = &svs.clients[i];
327                         SV_ClientCommands("sendcvar %s\n", cvarname);
328                 }
329         host_client = old;
330 }
331
332 /*
333 =====================
334 CL_PQRcon_f
335
336 ProQuake rcon support
337 =====================
338 */
339 static void CL_PQRcon_f(cmd_state_t *cmd)
340 {
341         int n;
342         const char *e;
343         lhnetsocket_t *mysocket;
344
345         if (Cmd_Argc(cmd) == 1)
346         {
347                 Con_Printf("%s: Usage: %s command\n", Cmd_Argv(cmd, 0), Cmd_Argv(cmd, 0));
348                 return;
349         }
350
351         if (!rcon_password.string || !rcon_password.string[0] || rcon_secure.integer > 0)
352         {
353                 Con_Printf ("You must set rcon_password before issuing an pqrcon command, and rcon_secure must be 0.\n");
354                 return;
355         }
356
357         e = strchr(rcon_password.string, ' ');
358         n = e ? e-rcon_password.string : (int)strlen(rcon_password.string);
359
360         if (cls.netcon)
361                 cls.rcon_address = cls.netcon->peeraddress;
362         else
363         {
364                 if (!rcon_address.string[0])
365                 {
366                         Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
367                         return;
368                 }
369                 LHNETADDRESS_FromString(&cls.rcon_address, rcon_address.string, sv_netport.integer);
370         }
371         mysocket = NetConn_ChooseClientSocketForAddress(&cls.rcon_address);
372         if (mysocket)
373         {
374                 sizebuf_t buf;
375                 unsigned char bufdata[64];
376                 buf.data = bufdata;
377                 SZ_Clear(&buf);
378                 MSG_WriteLong(&buf, 0);
379                 MSG_WriteByte(&buf, CCREQ_RCON);
380                 SZ_Write(&buf, (const unsigned char*)rcon_password.string, n);
381                 MSG_WriteByte(&buf, 0); // terminate the (possibly partial) string
382                 MSG_WriteString(&buf, Cmd_Args(cmd));
383                 StoreBigLong(buf.data, NETFLAG_CTL | (buf.cursize & NETFLAG_LENGTH_MASK));
384                 NetConn_Write(mysocket, buf.data, buf.cursize, &cls.rcon_address);
385                 SZ_Clear(&buf);
386         }
387 }
388
389 //=============================================================================
390
391 // QuakeWorld commands
392
393 /*
394 =====================
395 CL_Rcon_f
396
397   Send the rest of the command line over as
398   an unconnected command.
399 =====================
400 */
401 static void CL_Rcon_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
402 {
403         int i, n;
404         const char *e;
405         lhnetsocket_t *mysocket;
406
407         if (Cmd_Argc(cmd) == 1)
408         {
409                 Con_Printf("%s: Usage: %s command\n", Cmd_Argv(cmd, 0), Cmd_Argv(cmd, 0));
410                 return;
411         }
412
413         if (!rcon_password.string || !rcon_password.string[0])
414         {
415                 Con_Printf ("You must set rcon_password before issuing an rcon command.\n");
416                 return;
417         }
418
419         e = strchr(rcon_password.string, ' ');
420         n = e ? e-rcon_password.string : (int)strlen(rcon_password.string);
421
422         if (cls.netcon)
423                 cls.rcon_address = cls.netcon->peeraddress;
424         else
425         {
426                 if (!rcon_address.string[0])
427                 {
428                         Con_Printf ("You must either be connected, or set the rcon_address cvar to issue rcon commands\n");
429                         return;
430                 }
431                 LHNETADDRESS_FromString(&cls.rcon_address, rcon_address.string, sv_netport.integer);
432         }
433         mysocket = NetConn_ChooseClientSocketForAddress(&cls.rcon_address);
434         if (mysocket && Cmd_Args(cmd)[0])
435         {
436                 // simply put together the rcon packet and send it
437                 if(Cmd_Argv(cmd, 0)[0] == 's' || rcon_secure.integer > 1)
438                 {
439                         if(cls.rcon_commands[cls.rcon_ringpos][0])
440                         {
441                                 char s[128];
442                                 LHNETADDRESS_ToString(&cls.rcon_addresses[cls.rcon_ringpos], s, sizeof(s), true);
443                                 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]);
444                                 cls.rcon_commands[cls.rcon_ringpos][0] = 0;
445                                 --cls.rcon_trying;
446                         }
447                         for (i = 0;i < MAX_RCONS;i++)
448                                 if(cls.rcon_commands[i][0])
449                                         if (!LHNETADDRESS_Compare(&cls.rcon_address, &cls.rcon_addresses[i]))
450                                                 break;
451                         ++cls.rcon_trying;
452                         if(i >= MAX_RCONS)
453                                 NetConn_WriteString(mysocket, "\377\377\377\377getchallenge", &cls.rcon_address); // otherwise we'll request the challenge later
454                         strlcpy(cls.rcon_commands[cls.rcon_ringpos], Cmd_Args(cmd), sizeof(cls.rcon_commands[cls.rcon_ringpos]));
455                         cls.rcon_addresses[cls.rcon_ringpos] = cls.rcon_address;
456                         cls.rcon_timeout[cls.rcon_ringpos] = host.realtime + rcon_secure_challengetimeout.value;
457                         cls.rcon_ringpos = (cls.rcon_ringpos + 1) % MAX_RCONS;
458                 }
459                 else if(rcon_secure.integer > 0)
460                 {
461                         char buf[1500];
462                         char argbuf[1500];
463                         dpsnprintf(argbuf, sizeof(argbuf), "%ld.%06d %s", (long) time(NULL), (int) (rand() % 1000000), Cmd_Args(cmd));
464                         memcpy(buf, "\377\377\377\377srcon HMAC-MD4 TIME ", 24);
465                         if(HMAC_MDFOUR_16BYTES((unsigned char *) (buf + 24), (unsigned char *) argbuf, (int)strlen(argbuf), (unsigned char *) rcon_password.string, n))
466                         {
467                                 buf[40] = ' ';
468                                 strlcpy(buf + 41, argbuf, sizeof(buf) - 41);
469                                 NetConn_Write(mysocket, buf, 41 + (int)strlen(buf + 41), &cls.rcon_address);
470                         }
471                 }
472                 else
473                 {
474                         char buf[1500];
475                         memcpy(buf, "\377\377\377\377", 4);
476                         dpsnprintf(buf+4, sizeof(buf)-4, "rcon %.*s %s",  n, rcon_password.string, Cmd_Args(cmd));
477                         NetConn_WriteString(mysocket, buf, &cls.rcon_address);
478                 }
479         }
480 }
481
482 static void CL_RCon_ClearPassword_c(char *string)
483 {
484         // whenever rcon_secure is changed to 0, clear rcon_password for
485         // security reasons (prevents a send-rcon-password-as-plaintext
486         // attack based on NQ protocol session takeover and svc_stufftext)
487         if(atoi(string) <= 0)
488                 Cvar_SetQuick(&rcon_password, "");
489 }
490
491 /*
492 ==================
493 CL_FullServerinfo_f
494
495 Sent by server when serverinfo changes
496 ==================
497 */
498 // TODO: shouldn't this be a cvar instead?
499 static void CL_FullServerinfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
500 {
501         char temp[512];
502         if (Cmd_Argc(cmd) != 2)
503         {
504                 Con_Printf ("usage: fullserverinfo <complete info string>\n");
505                 return;
506         }
507
508         strlcpy (cl.qw_serverinfo, Cmd_Argv(cmd, 1), sizeof(cl.qw_serverinfo));
509         InfoString_GetValue(cl.qw_serverinfo, "teamplay", temp, sizeof(temp));
510         cl.qw_teamplay = atoi(temp);
511 }
512
513 /*
514 ==================
515 CL_FullInfo_f
516
517 Allow clients to change userinfo
518 ==================
519 Casey was here :)
520 */
521 static void CL_FullInfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
522 {
523         char key[512];
524         char value[512];
525         const char *s;
526
527         if (Cmd_Argc(cmd) != 2)
528         {
529                 Con_Printf ("fullinfo <complete info string>\n");
530                 return;
531         }
532
533         s = Cmd_Argv(cmd, 1);
534         if (*s == '\\')
535                 s++;
536         while (*s)
537         {
538                 size_t len = strcspn(s, "\\");
539                 if (len >= sizeof(key)) {
540                         len = sizeof(key) - 1;
541                 }
542                 strlcpy(key, s, len + 1);
543                 s += len;
544                 if (!*s)
545                 {
546                         Con_Printf ("MISSING VALUE\n");
547                         return;
548                 }
549                 ++s; // Skip over backslash.
550
551                 len = strcspn(s, "\\");
552                 if (len >= sizeof(value)) {
553                         len = sizeof(value) - 1;
554                 }
555                 strlcpy(value, s, len + 1);
556
557                 CL_SetInfo(key, value, false, false, false, false);
558
559                 s += len;
560                 if (!*s)
561                 {
562                         break;
563                 }
564                 ++s; // Skip over backslash.
565         }
566 }
567
568 /*
569 ==================
570 CL_SetInfo_f
571
572 Allow clients to change userinfo
573 ==================
574 */
575 static void CL_SetInfo_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
576 {
577         if (Cmd_Argc(cmd) == 1)
578         {
579                 InfoString_Print(cls.userinfo);
580                 return;
581         }
582         if (Cmd_Argc(cmd) != 3)
583         {
584                 Con_Printf ("usage: setinfo [ <key> <value> ]\n");
585                 return;
586         }
587         CL_SetInfo(Cmd_Argv(cmd, 1), Cmd_Argv(cmd, 2), true, false, false, false);
588 }
589
590 /*
591 ====================
592 CL_Packet_f
593
594 packet <destination> <contents>
595
596 Contents allows \n escape character
597 ====================
598 */
599 static void CL_Packet_f(cmd_state_t *cmd) // credit: taken from QuakeWorld
600 {
601         char send[2048];
602         int i, l;
603         const char *in;
604         char *out;
605         lhnetaddress_t address;
606         lhnetsocket_t *mysocket;
607
608         if (Cmd_Argc(cmd) != 3)
609         {
610                 Con_Printf ("packet <destination> <contents>\n");
611                 return;
612         }
613
614         if (!LHNETADDRESS_FromString (&address, Cmd_Argv(cmd, 1), sv_netport.integer))
615         {
616                 Con_Printf ("Bad address\n");
617                 return;
618         }
619
620         in = Cmd_Argv(cmd, 2);
621         out = send+4;
622         send[0] = send[1] = send[2] = send[3] = -1;
623
624         l = (int)strlen (in);
625         for (i=0 ; i<l ; i++)
626         {
627                 if (out >= send + sizeof(send) - 1)
628                         break;
629                 if (in[i] == '\\' && in[i+1] == 'n')
630                 {
631                         *out++ = '\n';
632                         i++;
633                 }
634                 else if (in[i] == '\\' && in[i+1] == '0')
635                 {
636                         *out++ = '\0';
637                         i++;
638                 }
639                 else if (in[i] == '\\' && in[i+1] == 't')
640                 {
641                         *out++ = '\t';
642                         i++;
643                 }
644                 else if (in[i] == '\\' && in[i+1] == 'r')
645                 {
646                         *out++ = '\r';
647                         i++;
648                 }
649                 else if (in[i] == '\\' && in[i+1] == '"')
650                 {
651                         *out++ = '\"';
652                         i++;
653                 }
654                 else
655                         *out++ = in[i];
656         }
657
658         mysocket = NetConn_ChooseClientSocketForAddress(&address);
659         if (!mysocket)
660                 mysocket = NetConn_ChooseServerSocketForAddress(&address);
661         if (mysocket)
662                 NetConn_Write(mysocket, send, out - send, &address);
663 }
664
665 static void CL_PingPLReport_f(cmd_state_t *cmd)
666 {
667         char *errbyte;
668         int i;
669         int l = Cmd_Argc(cmd);
670         if (l > cl.maxclients)
671                 l = cl.maxclients;
672         for (i = 0;i < l;i++)
673         {
674                 cl.scores[i].qw_ping = atoi(Cmd_Argv(cmd, 1+i*2));
675                 cl.scores[i].qw_packetloss = strtol(Cmd_Argv(cmd, 1+i*2+1), &errbyte, 0);
676                 if(errbyte && *errbyte == ',')
677                         cl.scores[i].qw_movementloss = atoi(errbyte + 1);
678                 else
679                         cl.scores[i].qw_movementloss = 0;
680         }
681 }
682
683 //=============================================================================
684
685 /*
686 ==================
687 Host_InitCommands
688 ==================
689 */
690 void Host_InitCommands (void)
691 {
692         dpsnprintf(cls.userinfo, sizeof(cls.userinfo), "\\name\\player\\team\\none\\topcolor\\0\\bottomcolor\\0\\rate\\10000\\msg\\1\\noaim\\1\\*ver\\dp");
693
694         Cvar_RegisterVariable(&name);
695         Cvar_RegisterAlias(&name, "_cl_name");
696         Cvar_RegisterVariable(&cl_color);
697         Cvar_RegisterCallback(&cl_color, CL_Color_c);
698         Cvar_RegisterVariable(&topcolor);
699         Cvar_RegisterCallback(&topcolor, CL_Topcolor_c);
700         Cvar_RegisterVariable(&bottomcolor);
701         Cvar_RegisterCallback(&bottomcolor, CL_Bottomcolor_c);
702         Cvar_RegisterVariable(&rate);
703         Cvar_RegisterAlias(&rate, "_cl_rate");
704         Cvar_RegisterVariable(&rate_burstsize);
705         Cvar_RegisterAlias(&rate_burstsize, "_cl_rate_burstsize");
706         Cvar_RegisterVariable(&pmodel);
707         Cvar_RegisterAlias(&pmodel, "_cl_pmodel");
708         Cvar_RegisterVariable(&playermodel);
709         Cvar_RegisterAlias(&playermodel, "_cl_playermodel");
710         Cvar_RegisterVariable(&playerskin);
711         Cvar_RegisterAlias(&playerskin, "_cl_playerskin");
712         Cvar_RegisterVariable(&rcon_password);
713         Cvar_RegisterVariable(&rcon_address);
714         Cvar_RegisterVariable(&rcon_secure);
715         Cvar_RegisterCallback(&rcon_secure, CL_RCon_ClearPassword_c);
716         Cvar_RegisterVariable(&rcon_secure_challengetimeout);
717         Cvar_RegisterVariable(&r_fixtrans_auto);
718         Cvar_RegisterVariable(&team);
719         Cvar_RegisterVariable(&skin);
720         Cvar_RegisterVariable(&noaim);
721
722         Cmd_AddCommand(CMD_CLIENT, "color", CL_Color_f, "change your player shirt and pants colors");
723         Cmd_AddCommand(CMD_USERINFO, "pmodel", CL_PModel_f, "(Nehahra-only) change your player model choice");
724         Cmd_AddCommand(CMD_USERINFO, "playermodel", CL_Playermodel_f, "change your player model");
725         Cmd_AddCommand(CMD_USERINFO, "playerskin", CL_Playerskin_f, "change your player skin number");
726
727         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");
728         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");
729         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");
730         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)");
731         Cmd_AddCommand(CMD_CLIENT, "fullinfo", CL_FullInfo_f, "allows client to modify their userinfo");
732         Cmd_AddCommand(CMD_CLIENT, "setinfo", CL_SetInfo_f, "modifies your userinfo");
733         Cmd_AddCommand(CMD_CLIENT, "packet", CL_Packet_f, "send a packet to the specified address:port containing a text string");
734         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)");
735
736         // commands that are only sent by server to client for execution
737         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)");
738         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");
739 }
740
741 void Host_NoOperation_f(cmd_state_t *cmd)
742 {
743 }