# HG changeset patch # User Teemu Piippo # Date 1469028020 -10800 # Node ID 6be21be4bea1c56a00638e3f6a9093813843c717 # Parent 7643c21d546b8a729344d62fee36a79c9077a012 Renamed Datagram members, RCONSession::handle_packet now takes the datagram as the parameter. diff -r 7643c21d546b -r 6be21be4bea1 sources/network/rconsession.cpp --- 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) { diff -r 7643c21d546b -r 6be21be4bea1 sources/network/rconsession.h --- 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); diff -r 7643c21d546b -r 6be21be4bea1 sources/network/udpsocket.cpp --- 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 (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; } diff -r 7643c21d546b -r 6be21be4bea1 sources/network/udpsocket.h --- 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; }; // -------------------------------------------------------------------------------------------------