summaryrefslogtreecommitdiff
path: root/src/net/tmwa/messagein.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tmwa/messagein.h')
-rw-r--r--src/net/tmwa/messagein.h73
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