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/tmwa/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/tmwa/messagein.h')
-rw-r--r-- | src/net/tmwa/messagein.h | 73 |
1 files changed, 68 insertions, 5 deletions
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 <cstdint> #include <string> 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 |