summaryrefslogtreecommitdiff
path: root/src/net
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
parent135fa01ee301fd878c93444999a625f64ccf76c1 (diff)
downloadmanaverse-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.tar.gz
manaverse-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.tar.bz2
manaverse-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.tar.xz
manaverse-b6cd136e3edf9d5c0eaaef47118ff1a72d7b0c75.zip
Add method for read unsigned int 32 from packet.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/messagein.cpp23
-rw-r--r--src/net/messagein.h2
2 files changed, 24 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)
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);