net: Add error codes to DMLSession::invalid_message

I'm going to rethink this though because I'd like to have more detailed error codes.
This commit is contained in:
Joshua Scott 2018-04-20 17:22:51 +01:00
parent e26a20d650
commit 7932ee2831
2 changed files with 10 additions and 3 deletions

View File

@ -8,6 +8,12 @@ namespace protocol
{ {
namespace net namespace net
{ {
enum class InvalidDMLMessageErrorCode
{
INVALID_MESSAGE_DATA,
INSUFFICIENT_ACCESS
};
/** /**
* Implements an application protocol that uses the DML * Implements an application protocol that uses the DML
* message system (as seen in Wizard101 and Pirate101). * message system (as seen in Wizard101 and Pirate101).
@ -24,7 +30,7 @@ namespace net
protected: protected:
void on_application_message(const PacketHeader& header) override; void on_application_message(const PacketHeader& header) override;
virtual void on_message(const dml::Message &message) {} virtual void on_message(const dml::Message &message) {}
virtual void on_invalid_message() {} virtual void on_invalid_message(InvalidDMLMessageErrorCode error) {}
private: private:
const dml::MessageManager &m_manager; const dml::MessageManager &m_manager;
}; };

View File

@ -21,10 +21,11 @@ namespace net
void DMLSession::on_application_message(const PacketHeader& header) void DMLSession::on_application_message(const PacketHeader& header)
{ {
// Attempt to create a Message instance from the data in the stream
const auto *message = m_manager.message_from_binary(m_data_stream); const auto *message = m_manager.message_from_binary(m_data_stream);
if (!message) if (!message)
{ {
on_invalid_message(); on_invalid_message(InvalidDMLMessageErrorCode::INVALID_MESSAGE_DATA);
return; return;
} }
@ -32,7 +33,7 @@ namespace net
if (get_access_level() >= message->get_access_level()) if (get_access_level() >= message->get_access_level())
on_message(*message); on_message(*message);
else else
on_invalid_message(); on_invalid_message(InvalidDMLMessageErrorCode::INSUFFICIENT_ACCESS);
delete message; delete message;
} }
} }