# HG changeset patch # User Teemu Piippo # Date 1453688131 -7200 # Node ID 9f54db6f9922ae5471c7d169fd05e7cc868b69d6 # Parent 5900be70c619644adb212de263a318ce1230bdd7 Commit ZFC's end of reliable RCON streams diff -r 5900be70c619 -r 9f54db6f9922 sources/network/rconsession.cpp --- a/sources/network/rconsession.cpp Sat Jan 09 17:48:45 2016 +0200 +++ b/sources/network/rconsession.cpp Mon Jan 25 04:15:31 2016 +0200 @@ -117,18 +117,23 @@ } for (Datagram datagram; m_socket.read (datagram);) - handle_packet (datagram.data, datagram.from); + handle_packet (datagram); } // ------------------------------------------------------------------------------------------------- // -void RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) +void RCONSession::handle_packet (Datagram& datagram) { - if (from != m_address) + if (datagram.from != m_address) return; try { + Bytestream& packet = datagram.data; + int32_t header = packet.read_long(); + int32_t sequenceNumber = (header != 0) ? packet.read_long() : 0; + m_interface->print("Recieved packet with header 0x%x and sequence number #%d\n", header, sequenceNumber); + while (packet.bytes_left() > 0) { int header = packet.read_byte(); @@ -187,6 +192,7 @@ // Watch sv_hostname so that we can update the titlebar when it changes. request_watch("sv_hostname"); + m_interface->print ("Watch requested.\n"); break; case SVRC_UPDATE: @@ -256,7 +262,7 @@ break; case SVRC_YOUREDISCONNECTED: - m_interface->print ("You have been disconnected: %s", packet.read_string().chars()); + m_interface->print ("You have been disconnected: %s\n", packet.read_string().chars()); m_interface->disconnected(); break; } diff -r 5900be70c619 -r 9f54db6f9922 sources/network/rconsession.h --- a/sources/network/rconsession.h Sat Jan 09 17:48:45 2016 +0200 +++ b/sources/network/rconsession.h Mon Jan 25 04:15:31 2016 +0200 @@ -104,7 +104,7 @@ const IPAddress& address() const; void connect (IPAddress address); void disconnect(); - void handle_packet (Bytestream& packet, const IPAddress& from); + void handle_packet (Datagram& datagram); void process_server_updates (Bytestream& packet); int num_admins() const; void send (const Bytestream& packet); diff -r 5900be70c619 -r 9f54db6f9922 sources/network/udpsocket.cpp --- a/sources/network/udpsocket.cpp Sat Jan 09 17:48:45 2016 +0200 +++ b/sources/network/udpsocket.cpp Mon Jan 25 04:15:31 2016 +0200 @@ -129,10 +129,15 @@ return false; } + if (length < 4) + { + m_error = "The server sent a too short packet"; + return false; + } + unsigned char decodedPacket[MAX_DATAGRAM_LENGTH]; int decodedLength = sizeof decodedPacket; - HUFFMAN_Decode (reinterpret_cast (HuffmanBuffer), - decodedPacket, length, &decodedLength); + HUFFMAN_Decode (reinterpret_cast(HuffmanBuffer), decodedPacket, length, &decodedLength); datagram.from.host = ntohl (claddr.sin_addr.s_addr); datagram.from.port = ntohs (claddr.sin_port); datagram.data = Bytestream (decodedPacket, decodedLength);