From 65a5155d584c7c41bbcd767b4b7b6722b6ea4f23 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 16 Sep 2014 13:52:36 +0300 Subject: add support for reading int64 from server. --- src/net/eathena/messagein.cpp | 19 +++++++++++++++++++ src/net/eathena/messagein.h | 2 ++ src/net/messagein.h | 4 +++- src/net/tmwa/messagein.cpp | 19 +++++++++++++++++++ src/net/tmwa/messagein.h | 2 ++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/src/net/eathena/messagein.cpp b/src/net/eathena/messagein.cpp index 60d89980d..db3eb1889 100644 --- a/src/net/eathena/messagein.cpp +++ b/src/net/eathena/messagein.cpp @@ -85,4 +85,23 @@ int32_t MessageIn::readInt32(const char *const str) return value; } +int64_t MessageIn::readInt64(const char *const str) +{ + int32_t value = -1; + if (mPos + 8 <= mLength) + { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + int64_t swap; + memcpy(&swap, mData + static_cast(mPos), sizeof(int64_t)); + value = SDL_Swap64(swap); +#else + memcpy(&value, mData + static_cast(mPos), sizeof(int64_t)); +#endif + } + DEBUGLOG2("readInt64: " + toStringPrint(value), mPos, str); + mPos += 8; + PacketCounters::incInBytes(8); + return value; +} + } // namespace EAthena diff --git a/src/net/eathena/messagein.h b/src/net/eathena/messagein.h index 3c267a888..1b9001c64 100644 --- a/src/net/eathena/messagein.h +++ b/src/net/eathena/messagein.h @@ -51,6 +51,8 @@ class MessageIn final : public Net::MessageIn int16_t readInt16(const char *const str = nullptr); /**< Reads a long. */ int32_t readInt32(const char *const str = nullptr); + + int64_t readInt64(const char *const str = nullptr); }; } // namespace EAthena diff --git a/src/net/messagein.h b/src/net/messagein.h index ba857ce64..d05f58b57 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -70,7 +70,9 @@ class MessageIn notfinal virtual int16_t readInt16(const char *const str = nullptr) = 0; /**< Reads a long. */ - virtual int readInt32(const char *const str = nullptr) = 0; + virtual int32_t readInt32(const char *const str = nullptr) = 0; + + virtual int64_t readInt64(const char *const str = nullptr) = 0; /** * Reads a special 3 byte block used by eAthena, containing x and y diff --git a/src/net/tmwa/messagein.cpp b/src/net/tmwa/messagein.cpp index d467048d7..8fe50249a 100644 --- a/src/net/tmwa/messagein.cpp +++ b/src/net/tmwa/messagein.cpp @@ -85,4 +85,23 @@ int32_t MessageIn::readInt32(const char *const str) return value; } +int64_t MessageIn::readInt64(const char *const str) +{ + int32_t value = -1; + if (mPos + 8 <= mLength) + { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + int64_t swap; + memcpy(&swap, mData + static_cast(mPos), sizeof(int64_t)); + value = SDL_Swap64(swap); +#else + memcpy(&value, mData + static_cast(mPos), sizeof(int64_t)); +#endif + } + DEBUGLOG2("readInt64: " + toStringPrint(value), mPos, str); + mPos += 8; + PacketCounters::incInBytes(8); + return value; +} + } // namespace TmwAthena diff --git a/src/net/tmwa/messagein.h b/src/net/tmwa/messagein.h index 26ce4612c..f0645ddda 100644 --- a/src/net/tmwa/messagein.h +++ b/src/net/tmwa/messagein.h @@ -51,6 +51,8 @@ class MessageIn final : public Net::MessageIn int16_t readInt16(const char *const str = nullptr); /**< Reads a long. */ int32_t readInt32(const char *const str = nullptr); + + int64_t readInt64(const char *const str = nullptr); }; } // namespace TmwAthena -- cgit v1.2.3-70-g09d2