mirror of https://github.com/SeanOMik/libki.git
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:
parent
e26a20d650
commit
7932ee2831
|
@ -8,6 +8,12 @@ namespace protocol
|
|||
{
|
||||
namespace net
|
||||
{
|
||||
enum class InvalidDMLMessageErrorCode
|
||||
{
|
||||
INVALID_MESSAGE_DATA,
|
||||
INSUFFICIENT_ACCESS
|
||||
};
|
||||
|
||||
/**
|
||||
* Implements an application protocol that uses the DML
|
||||
* message system (as seen in Wizard101 and Pirate101).
|
||||
|
@ -24,7 +30,7 @@ namespace net
|
|||
protected:
|
||||
void on_application_message(const PacketHeader& header) override;
|
||||
virtual void on_message(const dml::Message &message) {}
|
||||
virtual void on_invalid_message() {}
|
||||
virtual void on_invalid_message(InvalidDMLMessageErrorCode error) {}
|
||||
private:
|
||||
const dml::MessageManager &m_manager;
|
||||
};
|
||||
|
|
|
@ -21,10 +21,11 @@ namespace net
|
|||
|
||||
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);
|
||||
if (!message)
|
||||
{
|
||||
on_invalid_message();
|
||||
on_invalid_message(InvalidDMLMessageErrorCode::INVALID_MESSAGE_DATA);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -32,7 +33,7 @@ namespace net
|
|||
if (get_access_level() >= message->get_access_level())
|
||||
on_message(*message);
|
||||
else
|
||||
on_invalid_message();
|
||||
on_invalid_message(InvalidDMLMessageErrorCode::INSUFFICIENT_ACCESS);
|
||||
delete message;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue