From: Mario Date: Sat, 7 Sep 2024 21:06:16 +0000 (+1000) Subject: Restore ability to use the packet command on the server side X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=b7d1946d3130c0bf77138e24d68888fae9426e1a;p=xonotic%2Fdarkplaces.git Restore ability to use the packet command on the server side --- diff --git a/cl_cmd.c b/cl_cmd.c index 4556d2cf..2a86b1c0 100644 --- a/cl_cmd.c +++ b/cl_cmd.c @@ -401,81 +401,6 @@ static void CL_Users_f(cmd_state_t *cmd) // credit: taken from QuakeWorld Con_Printf ("%i total users\n", c); } -/* -==================== -CL_Packet_f - -packet - -Contents allows \n escape character -==================== -*/ -static void CL_Packet_f(cmd_state_t *cmd) // credit: taken from QuakeWorld -{ - char send[2048]; - int i, l; - const char *in; - char *out; - lhnetaddress_t address; - lhnetsocket_t *mysocket; - - if (Cmd_Argc(cmd) != 3) - { - Con_Printf ("packet \n"); - return; - } - - if (!LHNETADDRESS_FromString (&address, Cmd_Argv(cmd, 1), sv_netport.integer)) - { - Con_Printf ("Bad address\n"); - return; - } - - in = Cmd_Argv(cmd, 2); - out = send+4; - send[0] = send[1] = send[2] = send[3] = -1; - - l = (int)strlen (in); - for (i=0 ; i= send + sizeof(send) - 1) - break; - if (in[i] == '\\' && in[i+1] == 'n') - { - *out++ = '\n'; - i++; - } - else if (in[i] == '\\' && in[i+1] == '0') - { - *out++ = '\0'; - i++; - } - else if (in[i] == '\\' && in[i+1] == 't') - { - *out++ = '\t'; - i++; - } - else if (in[i] == '\\' && in[i+1] == 'r') - { - *out++ = '\r'; - i++; - } - else if (in[i] == '\\' && in[i+1] == '"') - { - *out++ = '\"'; - i++; - } - else - *out++ = in[i]; - } - - mysocket = NetConn_ChooseClientSocketForAddress(&address); - if (!mysocket) - mysocket = NetConn_ChooseServerSocketForAddress(&address); - if (mysocket) - NetConn_Write(mysocket, send, out - send, &address); -} - /* ===================== CL_PQRcon_f @@ -777,7 +702,6 @@ void CL_InitCommands(void) 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)"); Cmd_AddCommand(CF_SHARED, "user", CL_User_f, "prints additional information about a player number or name on the scoreboard"); Cmd_AddCommand(CF_SHARED, "users", CL_Users_f, "prints additional information about all players on the scoreboard"); - Cmd_AddCommand(CF_CLIENT, "packet", CL_Packet_f, "send a packet to the specified address:port containing a text string"); Cmd_AddCommand(CF_CLIENT, "fullinfo", CL_FullInfo_f, "allows client to modify their userinfo"); Cmd_AddCommand(CF_CLIENT, "setinfo", CL_SetInfo_f, "modifies your userinfo"); 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)"); diff --git a/host.c b/host.c index b92f11b3..50ad7af4 100644 --- a/host.c +++ b/host.c @@ -269,6 +269,81 @@ static void Host_LoadConfig_f(cmd_state_t *cmd) Host_AddConfigText(cmd); } +/* +==================== +Host_Packet_f + +packet + +Contents allows \n escape character +==================== +*/ +static void Host_Packet_f(cmd_state_t *cmd) // credit: taken from QuakeWorld +{ + char send[2048]; + int i, l; + const char *in; + char *out; + lhnetaddress_t address; + lhnetsocket_t *mysocket; + + if (Cmd_Argc(cmd) != 3) + { + Con_Printf ("packet \n"); + return; + } + + if (!LHNETADDRESS_FromString (&address, Cmd_Argv(cmd, 1), sv_netport.integer)) + { + Con_Printf ("Bad address\n"); + return; + } + + in = Cmd_Argv(cmd, 2); + out = send+4; + send[0] = send[1] = send[2] = send[3] = -1; + + l = (int)strlen (in); + for (i=0 ; i= send + sizeof(send) - 1) + break; + if (in[i] == '\\' && in[i+1] == 'n') + { + *out++ = '\n'; + i++; + } + else if (in[i] == '\\' && in[i+1] == '0') + { + *out++ = '\0'; + i++; + } + else if (in[i] == '\\' && in[i+1] == 't') + { + *out++ = '\t'; + i++; + } + else if (in[i] == '\\' && in[i+1] == 'r') + { + *out++ = '\r'; + i++; + } + else if (in[i] == '\\' && in[i+1] == '"') + { + *out++ = '\"'; + i++; + } + else + *out++ = in[i]; + } + + mysocket = NetConn_ChooseClientSocketForAddress(&address); + if (!mysocket) + mysocket = NetConn_ChooseServerSocketForAddress(&address); + if (mysocket) + NetConn_Write(mysocket, send, out - send, &address); +} + /* ======================= Host_InitLocal @@ -282,6 +357,7 @@ static void Host_InitLocal (void) Cmd_AddCommand(CF_SHARED, "saveconfig", Host_SaveConfig_f, "save settings to config.cfg (or a specified filename) immediately (also automatic when quitting)"); Cmd_AddCommand(CF_SHARED, "loadconfig", Host_LoadConfig_f, "reset everything and reload configs"); Cmd_AddCommand(CF_SHARED, "sendcvar", SendCvar_f, "sends the value of a cvar to the server as a sentcvar command, for use by QuakeC"); + Cmd_AddCommand(CF_SHARED, "packet", Host_Packet_f, "send a packet to the specified address:port containing a text string"); Cvar_RegisterVariable (&host_framerate); Cvar_RegisterCallback (&host_framerate, Host_Framerate_c); Cvar_RegisterVariable (&host_speeds);