diff options
Diffstat (limited to 'src/net/messagein.h')
-rw-r--r-- | src/net/messagein.h | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/src/net/messagein.h b/src/net/messagein.h index d97cd8b6..68bbb933 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -1,5 +1,5 @@ /* - * The Mana World + * The Mana World Server * Copyright 2004 The Mana World Development Team * * This file is part of The Mana World. @@ -21,10 +21,11 @@ * $Id$ */ -#ifndef _TMW_MESSAGEIN_ -#define _TMW_MESSAGEIN_ +#ifndef _TMWSERV_MESSAGEIN_H_ +#define _TMWSERV_MESSAGEIN_H_ #include <string> + #include <SDL_types.h> /** @@ -32,10 +33,6 @@ */ class MessageIn { - friend Sint8& operator<<(Sint8 &lhs, MessageIn &msg); - friend Sint16& operator<<(Sint16 &lhs, MessageIn &msg); - friend Sint32& operator<<(Sint32 &lhs, MessageIn &msg); - public: /** * Constructor. @@ -43,55 +40,51 @@ class MessageIn MessageIn(const char *data, unsigned int length); /** - * Returns the message ID. + * Destructor. */ - short - getId() { return mId; } + ~MessageIn(); - /** - * Returns the message length. - */ - unsigned int - getLength() { return mLength; } + short getId() { return mId; } /**< Returns the message ID. */ - Sint8 readInt8(); /**< Reads a byte. */ - Sint16 readInt16(); /**< Reads a short. */ - Sint32 readInt32(); /**< Reads a long. */ + char readByte(); /**< Reads a byte. */ + short readShort(); /**< Reads a short. */ + long readLong(); /**< Reads a long. */ /** - * Reads a special 3 byte block used by eAthena, containing x and y - * coordinates and direction. + * Reads a 3-byte block containing tile-based coordinates. */ - void - readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction); + void readCoordinates(Uint16 &x, Uint16 &y); /** - * Reads a special 5 byte block used by eAthena, containing a source - * and destination coordinate pair. + * 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. */ - void - readCoordinatePair(Uint16 &srcX, Uint16 &srcY, - Uint16 &dstX, Uint16 &dstY); + std::string readString(int length = -1); /** - * Skips a given number of bytes. + * Returns the message length. */ - void - skip(unsigned int length); + unsigned int + getLength() { return mLength; } /** - * 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. + * Returns the length of unread data. */ - std::string - readString(int length = -1); + unsigned int + getUnreadLength() { return mLength - mPos; } private: const char* mData; /**< The message data. */ unsigned int mLength; /**< The length of the data. */ - unsigned int mPos; /**< The position in the data. */ 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; }; #endif |