From 96abc4a9658b3318d0052dc5cd31a3c15d76a494 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 8 Apr 2012 17:37:02 +0200 Subject: 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 --- src/net/tmwa/messagein.h | 73 ++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 5 deletions(-) (limited to 'src/net/tmwa/messagein.h') diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h index 714f71bb..48121187 100644 --- a/src/net/tmwa/messagein.h +++ b/src/net/tmwa/messagein.h @@ -22,26 +22,89 @@ #ifndef NET_TA_MESSAGEIN_H #define NET_TA_MESSAGEIN_H -#include "net/messagein.h" - +#include #include namespace TmwAthena { /** - * Used for parsing an incoming message. + * Used for parsing an incoming message from eAthena. * * \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 special 3 byte block used by eAthena, containing x and y + * coordinates and direction. + */ + void readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction); + + /** + * Reads a special 5 byte block used by eAthena, containing a source + * and destination coordinate pair. + */ + void readCoordinatePair(uint16_t &srcX, uint16_t &srcY, + uint16_t &dstX, uint16_t &dstY); + + /** + * Skips a given number of bytes. + */ + void skip(unsigned int length); + + /** + * 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; }; -} +} // TmwAthena #endif // NET_TA_MESSAGEIN_H -- cgit v1.2.3-60-g2f50