summaryrefslogtreecommitdiff
path: root/src/net/messagein.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2018-03-05 22:44:38 +0300
committerAndrei Karas <akaras@inbox.ru>2018-03-05 22:45:27 +0300
commitb6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75 (patch)
treefaca6ca89481e93ee25caba81d23c6068f68dda2 /src/net/messagein.cpp
parent135fa01ee301fd878c93444999a625f64ccf76c1 (diff)
downloadplus-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.tar.gz
plus-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.tar.bz2
plus-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.tar.xz
plus-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.zip
Add method for read unsigned int 32 from packet.
Diffstat (limited to 'src/net/messagein.cpp')
-rw-r--r--src/net/messagein.cpp23
1 files changed, 22 insertions, 1 deletions
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
@@ -180,6 +180,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);
mPos += 4;
@@ -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)