Renamed Datagram members, RCONSession::handle_packet now takes the datagram as the parameter.

Wed, 20 Jul 2016 18:20:20 +0300

author
Teemu Piippo <teemu@compsta2.com>
date
Wed, 20 Jul 2016 18:20:20 +0300
changeset 152
6be21be4bea1
parent 149
7643c21d546b
child 153
82aac80a2f1d
child 154
9cdd6b71f0d1

Renamed Datagram members, RCONSession::handle_packet now takes the datagram as the parameter.

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
sources/network/udpsocket.h file | annotate | diff | comparison | revisions
--- a/sources/network/rconsession.cpp	Wed Jul 20 17:53:13 2016 +0300
+++ b/sources/network/rconsession.cpp	Wed Jul 20 18:20:20 2016 +0300
@@ -116,21 +116,21 @@
 	}
 
 	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.address != m_address)
 		return;
 
 	try
 	{
-		while (packet.bytes_left() > 0)
+		while (datagram.message.bytes_left() > 0)
 		{
-			int header = packet.read_byte();
+			int header = datagram.message.read_byte();
 
 			switch (ServerResponse (header))
 			{
@@ -145,7 +145,7 @@
 				break;
 
 			case SVRC_SALT:
-				m_salt = packet.read_string();
+				m_salt = datagram.message.read_string();
 				m_state = RCON_AUTHENTICATING;
 				send_password();
 				break;
@@ -157,7 +157,7 @@
 
 			case SVRC_MESSAGE:
 				{
-					String message = packet.read_string();
+					String message = datagram.message.read_string();
 					message.normalize();
 					m_interface->printText ("%s\n", message.chars());
 				}
@@ -165,19 +165,19 @@
 
 			case SVRC_LOGGEDIN:
 				m_interface->print ("Login successful!\n");
-				m_serverProtocol = packet.read_byte();
-				m_hostname = packet.read_string();
+				m_serverProtocol = datagram.message.read_byte();
+				m_hostname = datagram.message.read_string();
 				m_interface->setTitle (m_hostname);
 				m_state = RCON_CONNECTED;
 
-				for (int i = packet.read_byte(); i > 0; --i)
-					process_server_updates (packet);
+				for (int i = datagram.message.read_byte(); i > 0; --i)
+					process_server_updates (datagram.message);
 
 				m_interface->print ("Previous messages:\n");
 
-				for (int i = packet.read_byte(); i > 0; --i)
+				for (int i = datagram.message.read_byte(); i > 0; --i)
 				{
-					String message = packet.read_string();
+					String message = datagram.message.read_string();
 					message.normalize();
 					m_interface->printText ("--- %s\n", message.chars());
 				}
@@ -186,12 +186,12 @@
 				break;
 
 			case SVRC_UPDATE:
-				process_server_updates (packet);
+				process_server_updates (datagram.message);
 				break;
 
 			case SVRC_TOOMANYTABCOMPLETES:
 				{
-					unsigned int numCompletions = packet.read_short();
+					unsigned int numCompletions = datagram.message.read_short();
 					m_interface->print ("%d completions for '%s'.\n",
 						int (numCompletions), m_lastTabComplete.chars());
 				}
@@ -200,10 +200,10 @@
 			case SVRC_TABCOMPLETE:
 				{
 					StringList completes;
-					completes.resize(packet.read_byte());
+					completes.resize(datagram.message.read_byte());
 
 					for (String& completion : completes)
-						completion = packet.read_string();
+						completion = datagram.message.read_string();
 
 					if (completes.size() == 1)
 					{
--- a/sources/network/rconsession.h	Wed Jul 20 17:53:13 2016 +0300
+++ b/sources/network/rconsession.h	Wed Jul 20 18:20:20 2016 +0300
@@ -98,7 +98,7 @@
 	const IPAddress& address() const;
 	void connect (IPAddress address);
 	void disconnect();
-	void handle_packet (Bytestream& packet, const IPAddress& from);
+	void handle_packet (Datagram &packet);
 	void process_server_updates (Bytestream& packet);
 	int num_admins() const;
 	void send (const Bytestream& packet);
--- a/sources/network/udpsocket.cpp	Wed Jul 20 17:53:13 2016 +0300
+++ b/sources/network/udpsocket.cpp	Wed Jul 20 18:20:20 2016 +0300
@@ -133,9 +133,9 @@
 	int decodedLength = sizeof decodedPacket;
 	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);
+	datagram.address.host = ntohl (claddr.sin_addr.s_addr);
+	datagram.address.port = ntohs (claddr.sin_port);
+	datagram.message = Bytestream (decodedPacket, decodedLength);
 	return true;
 }
 
--- a/sources/network/udpsocket.h	Wed Jul 20 17:53:13 2016 +0300
+++ b/sources/network/udpsocket.h	Wed Jul 20 18:20:20 2016 +0300
@@ -38,8 +38,8 @@
 
 struct Datagram
 {
-	Bytestream data;
-	IPAddress from;
+	Bytestream message;
+	IPAddress address;
 };
 
 // -------------------------------------------------------------------------------------------------

mercurial