]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - netconn.c
allow multiple rcon commands in the same packet, separated by NUL
[xonotic/darkplaces.git] / netconn.c
index c83b3bde1a8888320f4aa33d198f1031b5054143..b231c11ad98b5a8d2b772f6655abd4a87f2879c6 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -505,7 +505,7 @@ qboolean NetConn_CanSend(netconn_t *conn)
        }
 }
 
-int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate)
+int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolversion_t protocol, int rate, qboolean quakesignon_suppressreliables)
 {
        int totallen = 0;
 
@@ -622,7 +622,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                }
 
                // if we have a new reliable message to send, do so
-               if (!conn->sendMessageLength && conn->message.cursize)
+               if (!conn->sendMessageLength && conn->message.cursize && !quakesignon_suppressreliables)
                {
                        if (conn->message.cursize > (int)sizeof(conn->sendMessage))
                        {
@@ -673,7 +673,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                }
 
                // if we have an unreliable message to send, do so
-               //if (data->cursize)
+               if (data->cursize)
                {
                        packetLen = NET_HEADERSIZE + data->cursize;
 
@@ -697,8 +697,7 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
                        packetsSent++;
                        unreliableMessagesSent++;
 
-                       if (data->cursize)
-                               totallen += packetLen + 28;
+                       totallen += packetLen + 28;
                }
        }
 
@@ -712,6 +711,16 @@ int NetConn_SendUnreliableMessage(netconn_t *conn, sizebuf_t *data, protocolvers
        return 0;
 }
 
+qboolean NetConn_HaveClientPorts(void)
+{
+       return !!cl_numsockets;
+}
+
+qboolean NetConn_HaveServerPorts(void)
+{
+       return !!sv_numsockets;
+}
+
 void NetConn_CloseClientPorts(void)
 {
        for (;cl_numsockets > 0;cl_numsockets--)
@@ -919,8 +928,6 @@ static int NetConn_ReceivedMessage(netconn_t *conn, unsigned char *data, int len
        if (length < 8)
                return 0;
 
-       // TODO: add netgraph stuff rather than just packetloss counting...
-
        if (protocol == PROTOCOL_QUAKEWORLD)
        {
                int sequence, sequence_ack;
@@ -1168,7 +1175,7 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer
        cls.signon = 0;                         // need all the signon messages before playing
        cls.protocol = initialprotocol;
        // reset move sequence numbering on this new connection
-       cls.movesequence = 0;
+       cls.movesequence = 1;
        cls.servermovesequence = 0;
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
                Cmd_ForwardStringToServer("new");
@@ -1182,7 +1189,7 @@ void NetConn_ConnectionEstablished(lhnetsocket_t *mysocket, lhnetaddress_t *peer
                msg.data = buf;
                msg.maxsize = sizeof(buf);
                MSG_WriteChar(&msg, clc_nop);
-               NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol, 10000);
+               NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol, 10000, false);
        }
 }
 
@@ -1726,7 +1733,7 @@ void NetConn_ClientFrame(void)
                while (cl_sockets[i] && (length = NetConn_Read(cl_sockets[i], readbuffer, sizeof(readbuffer), &peeraddress)) > 0)
                        NetConn_ClientParsePacket(cl_sockets[i], readbuffer, length, &peeraddress);
        NetConn_QueryQueueFrame();
-       if (cls.netcon && realtime > cls.netcon->timeout)
+       if (cls.netcon && realtime > cls.netcon->timeout && !sv.active)
        {
                Con_Print("Connection timed out\n");
                CL_Disconnect();
@@ -2084,6 +2091,7 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                {
                        int i;
                        char *s = string + 5;
+                       char *endpos = string + length + 1; // one behind the NUL, so adding strlen+1 will eventually reach it
                        char password[64];
                        for (i = 0;*s > ' ';s++)
                                if (i < (int)sizeof(password) - 1)
@@ -2092,10 +2100,23 @@ static int NetConn_ServerParsePacket(lhnetsocket_t *mysocket, unsigned char *dat
                        if (password[0] > ' ' && !strcmp(rcon_password.string, password))
                        {
                                // looks like a legitimate rcon command with the correct password
-                               Con_Printf("server received rcon command from %s:\n%s\n", host_client ? host_client->name : addressstring2, s);
+                               char *s_ptr = s;
+                               while(s_ptr != endpos)
+                               {
+                                       size_t l = strlen(s_ptr);
+                                       if(l)
+                                               Con_Printf("server received rcon command from %s:\n%s\n", host_client ? host_client->name : addressstring2, s_ptr);
+                                       s_ptr += l + 1;
+                               }
                                rcon_redirect = true;
                                rcon_redirect_bufferpos = 0;
-                               Cmd_ExecuteString(s, src_command);
+                               while(s != endpos)
+                               {
+                                       size_t l = strlen(s);
+                                       if(l)
+                                               Cmd_ExecuteString(s, src_command);
+                                       s += l + 1;
+                               }
                                rcon_redirect_buffer[rcon_redirect_bufferpos] = 0;
                                rcon_redirect = false;
                                // print resulting text to client