--- a/sources/network/rconsession.cpp Sat Dec 13 04:32:15 2014 +0200 +++ b/sources/network/rconsession.cpp Sat Dec 13 04:50:33 2014 +0200 @@ -88,73 +88,75 @@ RCONSession::handle_packet (Bytestream& packet, const IPAddress& from) -> void { print ("Processing packet of %1 bytes\n", packet.written_length()); - bool ok = true; - - while (packet.bytes_left() > 0) - { - int header = packet.read_byte (&ok); - print ("Recieved packet with header %1\n", header); - switch (ServerResponse (header)) + try + { + while (packet.bytes_left() > 0) { - case SVRC_OLDPROTOCOL: - print ("wrong version\n"); - m_state = RCON_DISCONNECTED; - break; + int header = packet.read_byte(); + print ("Recieved packet with header %1\n", header); + + switch (ServerResponse (header)) + { + case SVRC_OLDPROTOCOL: + print ("wrong version\n"); + m_state = RCON_DISCONNECTED; + break; - case SVRC_BANNED: - print ("you're banned\n"); - m_state = RCON_DISCONNECTED; - break; + case SVRC_BANNED: + print ("you're banned\n"); + m_state = RCON_DISCONNECTED; + break; - case SVRC_SALT: - { - String salt = packet.read_string(); - m_salt = salt; - m_state = RCON_AUTHENTICATING; - send_password(); - } - break; + case SVRC_SALT: + { + String salt = packet.read_string(); + m_salt = salt; + m_state = RCON_AUTHENTICATING; + send_password(); + } + break; - case SVRC_INVALIDPASSWORD: - print ("bad password\n"); - m_state = RCON_DISCONNECTED; - break; + case SVRC_INVALIDPASSWORD: + print ("bad password\n"); + m_state = RCON_DISCONNECTED; + break; - case SVRC_MESSAGE: - { - String message = packet.read_string(); - if (message.ends_with ("\n")) - message.remove_from_end (1); - print ("message: %1\n", message); - } - break; + case SVRC_MESSAGE: + { + String message = packet.read_string(); + if (message.ends_with ("\n")) + message.remove_from_end (1); + print ("message: %1\n", message); + } + break; - case SVRC_LOGGEDIN: - print ("login successful\n"); - m_serverProtocol = packet.read_byte(); - m_hostname = packet.read_string(); - m_state = RCON_CONNECTED; + case SVRC_LOGGEDIN: + print ("login successful\n"); + m_serverProtocol = packet.read_byte(); + m_hostname = packet.read_string(); + m_state = RCON_CONNECTED; + + for (int i = packet.read_byte(); i > 0; --i) + process_server_updates (packet); - for (int i = packet.read_byte(); i > 0; --i) + for (int i = packet.read_byte(); i > 0; --i) + { + String message = packet.read_string(); + message.normalize(); + print ("--- %1\n", message); + } + break; + + case SVRC_UPDATE: process_server_updates (packet); - - for (int i = packet.read_byte(); i > 0; --i) - { - String message = packet.read_string(); - message.normalize(); - print ("--- %1\n", message); + break; } - - break; - - case SVRC_UPDATE: - process_server_updates (packet); - break; } - - if (not ok) - print ("error while reading packet\n"); + } + catch (std::exception& e) + { + print ("error while reading packet: %1\n", e.what()); } }