summaryrefslogtreecommitdiff
path: root/src/net/tmwa
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/tmwa')
-rw-r--r--src/net/tmwa/messagein.cpp22
-rw-r--r--src/net/tmwa/messagein.h2
2 files changed, 23 insertions, 1 deletions
diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp
index 214540483..75dcb917c 100644
--- a/src/net/tmwa/messagein.cpp
+++ b/src/net/tmwa/messagein.cpp
@@ -22,6 +22,7 @@
#include "net/tmwa/messagein.h"
+#include "net/net.h"
#include "net/packetcounters.h"
#include "logger.h"
@@ -43,7 +44,26 @@ MessageIn::MessageIn(const char *const data, const unsigned int length) :
void MessageIn::postInit()
{
// Read the message ID
- mId = readInt16("packet id");
+ mId = readId();
+ IGNOREDEBUGLOG;
+ DEBUGLOG2("Receive packet", 0, "MessageIn");
+ readInt16("packet id");
+}
+
+uint16_t MessageIn::readId()
+{
+ int16_t value = -1;
+ if (mPos + 2 <= mLength)
+ {
+#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ int16_t swap;
+ memcpy(&swap, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+ value = SDL_Swap16(swap);
+#else
+ memcpy(&value, mData + static_cast<size_t>(mPos), sizeof(int16_t));
+#endif
+ }
+ return value;
}
int16_t MessageIn::readInt16(const char *const str)
diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h
index f0645ddda..12e2b58cf 100644
--- a/src/net/tmwa/messagein.h
+++ b/src/net/tmwa/messagein.h
@@ -53,6 +53,8 @@ class MessageIn final : public Net::MessageIn
int32_t readInt32(const char *const str = nullptr);
int64_t readInt64(const char *const str = nullptr);
+
+ uint16_t readId();
};
} // namespace TmwAthena