Commit ZFC's end of reliable RCON streams protocol5

Mon, 25 Jan 2016 04:15:31 +0200

author
Teemu Piippo <crimsondusk64@gmail.com>
date
Mon, 25 Jan 2016 04:15:31 +0200
branch
protocol5
changeset 130
9f54db6f9922
parent 108
5900be70c619
child 131
4996c8684b93

Commit ZFC's end of reliable RCON streams

sources/network/rconsession.cpp file | annotate | diff | comparison | revisions
sources/network/rconsession.h file | annotate | diff | comparison | revisions
sources/network/udpsocket.cpp file | annotate | diff | comparison | revisions
--- 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;
 			}
--- 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);
--- 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<unsigned char*> (HuffmanBuffer),
-		decodedPacket, length, &decodedLength);
+	HUFFMAN_Decode (reinterpret_cast<unsigned char*>(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);

mercurial