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