diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-09 00:21:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-09 00:33:31 +0300 |
commit | d9c62405db9a3f8bffaa5789bd63f59a65e29e3a (patch) | |
tree | 78c5417e3d2818f1844cd0a0730b6570eefbb9ef /src/net/messagein.cpp | |
parent | 02215574dc2b24eeef9c4ab55776334856bfbaf5 (diff) | |
download | plus-d9c62405db9a3f8bffaa5789bd63f59a65e29e3a.tar.gz plus-d9c62405db9a3f8bffaa5789bd63f59a65e29e3a.tar.bz2 plus-d9c62405db9a3f8bffaa5789bd63f59a65e29e3a.tar.xz plus-d9c62405db9a3f8bffaa5789bd63f59a65e29e3a.zip |
improve messagein class.
Diffstat (limited to 'src/net/messagein.cpp')
-rw-r--r-- | src/net/messagein.cpp | 42 |
1 files changed, 20 insertions, 22 deletions
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 2858368e2..a833c6cde 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -54,7 +54,7 @@ unsigned char MessageIn::readInt8() mPos += 1; PacketCounters::incInBytes(1); - DEBUGLOG("readInt8: " + toString(static_cast<int>(value))); + DEBUGLOG("readInt8: " + toStringPrint(static_cast<int>(value))); return value; } @@ -62,7 +62,7 @@ void MessageIn::readCoordinates(uint16_t &x, uint16_t &y) { if (mPos + 3 <= mLength) { - unsigned char const *const p + const unsigned char *const p = reinterpret_cast<unsigned char const *const>(mData + mPos); x = static_cast<short unsigned>(p[0] | ((p[1] & 0x07) << 8)); y = static_cast<short unsigned>((p[1] >> 3) | ((p[2] & 0x3F) << 5)); @@ -74,7 +74,7 @@ void MessageIn::readCoordinates(uint16_t &x, uint16_t &y) static_cast<int>(y)))); } -uint8_t MessageIn::fromServerDirection(uint8_t serverDir) +uint8_t MessageIn::fromServerDirection(const uint8_t serverDir) { // Translate from eAthena format switch (serverDir) @@ -113,9 +113,7 @@ void MessageIn::readCoordinates(uint16_t &x, uint16_t &y, uint8_t &direction) if (mPos + 3 <= mLength) { const char *const data = mData + mPos; - int16_t temp; - - temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff); + int16_t temp = MAKEWORD(data[1] & 0x00c0, data[0] & 0x00ff); x = static_cast<unsigned short>(temp >> 6); temp = MAKEWORD(data[2] & 0x00f0, data[1] & 0x003f); y = static_cast<unsigned short>(temp >> 4); @@ -137,9 +135,7 @@ void MessageIn::readCoordinatePair(uint16_t &srcX, uint16_t &srcY, if (mPos + 5 <= mLength) { const char *const data = mData + mPos; - int16_t temp; - - temp = MAKEWORD(data[3], data[2] & 0x000f); + int16_t temp = MAKEWORD(data[3], data[2] & 0x000f); dstX = static_cast<unsigned short>(temp >> 2); dstY = MAKEWORD(data[4], data[3] & 0x0003); @@ -159,7 +155,7 @@ void MessageIn::readCoordinatePair(uint16_t &srcX, uint16_t &srcY, PacketCounters::incInBytes(5); } -void MessageIn::skip(unsigned int length) +void MessageIn::skip(const unsigned int length) { mPos += length; PacketCounters::incInBytes(length); @@ -181,11 +177,12 @@ std::string MessageIn::readString(int length) } // Read the string - char const *const stringBeg = mData + mPos; - char const *const stringEnd - = static_cast<char const *>(memchr(stringBeg, '\0', length)); + const char *const stringBeg = mData + mPos; + const char *const stringEnd + = static_cast<const char *const>(memchr(stringBeg, '\0', length)); - std::string str(stringBeg, stringEnd ? stringEnd - stringBeg : length); + const std::string str(stringBeg, stringEnd + ? stringEnd - stringBeg : length); mPos += length; PacketCounters::incInBytes(length); DEBUGLOG("readString: " + str); @@ -206,10 +203,11 @@ std::string MessageIn::readRawString(int length) } // Read the string - char const *const stringBeg = mData + mPos; - char const *const stringEnd - = static_cast<char const *const>(memchr(stringBeg, '\0', length)); - std::string str(stringBeg, stringEnd ? stringEnd - stringBeg : length); + const char *const stringBeg = mData + mPos; + const char *const stringEnd + = static_cast<const char *const>(memchr(stringBeg, '\0', length)); + std::string str(stringBeg, stringEnd + ? stringEnd - stringBeg : length); mPos += length; PacketCounters::incInBytes(length); @@ -218,10 +216,10 @@ std::string MessageIn::readRawString(int length) if (stringEnd) { const long len2 = length - (stringEnd - stringBeg) - 1; - char const *const stringBeg2 = stringEnd + 1; - char const *const stringEnd2 - = static_cast<char const *const>(memchr(stringBeg2, '\0', len2)); - std::string hiddenPart = std::string(stringBeg2, + const char *const stringBeg2 = stringEnd + 1; + const char *const stringEnd2 + = static_cast<const char *const>(memchr(stringBeg2, '\0', len2)); + const std::string hiddenPart = std::string(stringBeg2, stringEnd2 ? stringEnd2 - stringBeg2 : len2); if (hiddenPart.length() > 0) { |