diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-04-08 17:37:02 +0200 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-05-05 22:30:00 +0200 |
commit | 96abc4a9658b3318d0052dc5cd31a3c15d76a494 (patch) | |
tree | ff1d8e02b5020a08c01ab1605b0474a48eb77c42 /src/net/manaserv/messageout.cpp | |
parent | e9eda63dcad0b842d637c13e415ef4f751ea2adf (diff) | |
download | mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.tar.gz mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.tar.bz2 mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.tar.xz mana-96abc4a9658b3318d0052dc5cd31a3c15d76a494.zip |
Removed the shared base classes of MessageIn and MessageOut
There wasn't a whole lot gained by sharing a common base class, and it makes
extending the manaserv Message{In,Out} classes with a debugging mode
unnecessarily complicated.
Reviewed-by: Yohann Ferreira
Diffstat (limited to 'src/net/manaserv/messageout.cpp')
-rw-r--r-- | src/net/manaserv/messageout.cpp | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/net/manaserv/messageout.cpp b/src/net/manaserv/messageout.cpp index 6a8482e8..7cecc03d 100644 --- a/src/net/manaserv/messageout.cpp +++ b/src/net/manaserv/messageout.cpp @@ -28,7 +28,9 @@ namespace ManaServ { MessageOut::MessageOut(uint16_t id): - Net::MessageOut(id) + mData(0), + mDataSize(0), + mPos(0) { writeInt16(id); } @@ -44,6 +46,13 @@ void MessageOut::expand(size_t bytes) mDataSize = mPos + bytes; } +void MessageOut::writeInt8(uint8_t value) +{ + expand(1); + mData[mPos] = value; + mPos += 1; +} + void MessageOut::writeInt16(uint16_t value) { expand(2); @@ -60,4 +69,31 @@ void MessageOut::writeInt32(uint32_t value) mPos += 4; } +void MessageOut::writeString(const std::string &string, int length) +{ + int stringLength = string.length(); + if (length < 0) + { + // Write the length at the start if not fixed + writeInt16(stringLength); + length = stringLength; + } + else if (length < stringLength) + { + // Make sure the length of the string is no longer than specified + stringLength = length; + } + expand(length); + + // Write the actual string + memcpy(mData + mPos, string.data(), stringLength); + + // Pad remaining space with zeros + if (length > stringLength) + { + memset(mData + mPos + stringLength, '\0', length - stringLength); + } + mPos += length; +} + } // namespace ManaServ |