diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-04-08 17:37:02 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-05-05 22:30:00 +0200 |
commit | 96abc4a9658b3318d0052dc5cd31a3c15d76a494 (patch) | |
tree | ff1d8e02b5020a08c01ab1605b0474a48eb77c42 /src/net/manaserv/messagein.h | |
parent | e9eda63dcad0b842d637c13e415ef4f751ea2adf (diff) | |
download | mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.tar.gz mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.tar.bz2 mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.tar.xz mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.zip |
Removed the shared base classes of MessageIn and MessageOut
There wasn't a whole lot gained by sharing a common base class, and it makes
extending the manaserv Message{In,Out} classes with a debugging mode
unnecessarily complicated.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/net/manaserv/messagein.h')
-rw-r--r-- | src/net/manaserv/messagein.h | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/src/net/manaserv/messagein.h b/src/net/manaserv/messagein.h index 97e68812..ef0c29bf 100644 --- a/src/net/manaserv/messagein.h +++ b/src/net/manaserv/messagein.h @@ -22,24 +22,71 @@ #ifndef NET_MANASERV_MESSAGEIN_H #define NET_MANASERV_MESSAGEIN_H -#include "net/messagein.h" +#include <cstdint> +#include <string> namespace ManaServ { /** - * Used for parsing an incoming message. + * Used for parsing an incoming message from manaserv. * * \ingroup Network */ -class MessageIn : public Net::MessageIn +class MessageIn { public: MessageIn(const char *data, unsigned int length); + /** + * Returns the message ID. + */ + uint16_t getId() const { return mId; } + + /** + * Returns the message length. + */ + unsigned int getLength() const { return mLength; } + + /** + * Returns the length of unread data. + */ + unsigned int getUnreadLength() const { return mLength - mPos; } + + /** + * Reads an unsigned 8-bit integer from the message. + */ + uint8_t readInt8(); + + /** + * Reads an unsigned 16-bit integer from the message. + */ uint16_t readInt16(); + + /** + * Reads an unsigned 32-bit integer from the message. + */ uint32_t readInt32(); + + /** + * Reads a string. If a length is not given (-1), it is assumed + * that the length of the string is stored in a short at the + * start of the string. + */ + std::string readString(int length = -1); + + private: + const char *mData; /**< The message data. */ + unsigned int mLength; /**< The length of the data. */ + unsigned short mId; /**< The message ID. */ + + /** + * Actual position in the packet. From 0 to packet->length. + * A value bigger than packet->length means EOP was reached when + * reading it. + */ + unsigned int mPos; }; -} +} // namespace ManaServ #endif // NET_MANASERV_MESSAGEIN_H |