From b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 Mar 2018 22:44:38 +0300 Subject: Add method for read unsigned int 32 from packet. --- src/net/messagein.cpp | 23 ++++++++++++++++++++++- src/net/messagein.h | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'src/net') diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 1e0ac22db..1226102d7 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -179,6 +179,27 @@ int32_t MessageIn::readInt32(const char *const str) memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int32_t)); #endif // SDL_BYTEORDER == SDL_BIG_ENDIAN + } + DEBUGLOG2("readInt32: " + toStringPrint(CAST_S32(value)), + mPos, str); + mPos += 4; + PacketCounters::incInBytes(4); + return value; +} + +uint32_t MessageIn::readUInt32(const char *const str) +{ + uint32_t value = -1; + if (mPos + 4 <= mLength) + { +#if SDL_BYTEORDER == SDL_BIG_ENDIAN + uint32_t swap; + memcpy(&swap, mData + CAST_SIZE(mPos), sizeof(int32_t)); + value = SDL_Swap32(swap); +#else // SDL_BYTEORDER == SDL_BIG_ENDIAN + + memcpy(&value, mData + CAST_SIZE(mPos), sizeof(int32_t)); +#endif // SDL_BYTEORDER == SDL_BIG_ENDIAN } DEBUGLOG2("readInt32: " + toStringPrint(CAST_U32(value)), mPos, str); @@ -189,7 +210,7 @@ int32_t MessageIn::readInt32(const char *const str) BeingId MessageIn::readBeingId(const char *const str) { - return fromInt(readInt32(str), BeingId); + return fromInt(readUInt32(str), BeingId); } int64_t MessageIn::readInt64(const char *const str) diff --git a/src/net/messagein.h b/src/net/messagein.h index e67dcbe8a..ea2caa499 100644 --- a/src/net/messagein.h +++ b/src/net/messagein.h @@ -78,6 +78,8 @@ class MessageIn notfinal /**< Reads a long. */ int32_t readInt32(const char *const str); + uint32_t readUInt32(const char *const str); + int64_t readInt64(const char *const str); BeingId readBeingId(const char *const str); -- cgit v1.2.3-70-g09d2