]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Restore ability to use the packet command on the server side Mario/shared_packet_command
authorMario <mario.mario@y7mail.com>
Sat, 7 Sep 2024 21:06:16 +0000 (07:06 +1000)
committerMario <mario.mario@y7mail.com>
Sat, 7 Sep 2024 21:06:16 +0000 (07:06 +1000)
cl_cmd.c
host.c

index 4556d2cf7ec8292c6b8bd0395945c69c8e102850..2a86b1c05aa1ae49c36537d188dfda73618e48ad 100644 (file)
--- 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 <destination> <contents>
-
-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 <destination> <contents>\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<l ; i++)
-       {
-               if (out >= 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 b92f11b3ee0dcb219e3fee80b87a599de83dca9f..50ad7af4e2da3a36c3c84c981c0ed4b8fecb2892 100644 (file)
--- 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 <destination> <contents>
+
+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 <destination> <contents>\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<l ; i++)
+       {
+               if (out >= 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);