summaryrefslogtreecommitdiff
path: root/src/net/tmwa/messageout.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-04-08 17:37:02 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-05-05 22:30:00 +0200
commit96abc4a9658b3318d0052dc5cd31a3c15d76a494 (patch)
treeff1d8e02b5020a08c01ab1605b0474a48eb77c42 /src/net/tmwa/messageout.cpp
parente9eda63dcad0b842d637c13e415ef4f751ea2adf (diff)
downloadmana-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/tmwa/messageout.cpp')
-rw-r--r--src/net/tmwa/messageout.cpp45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/net/tmwa/messageout.cpp b/src/net/tmwa/messageout.cpp
index 7f09ecce..ae5f6dba 100644
--- a/src/net/tmwa/messageout.cpp
+++ b/src/net/tmwa/messageout.cpp
@@ -27,15 +27,16 @@
#include <SDL_endian.h>
#include <cstring>
-#include <string>
namespace TmwAthena {
MessageOut::MessageOut(uint16_t id):
- Net::MessageOut(id)
+ mDataSize(0),
+ mPos(0)
{
mNetwork = TmwAthena::Network::instance();
mData = mNetwork->mOutBuffer + mNetwork->mOutSize;
+
writeInt16(id);
}
@@ -44,11 +45,18 @@ void MessageOut::expand(size_t bytes)
mNetwork->mOutSize += bytes;
}
+void MessageOut::writeInt8(uint8_t value)
+{
+ expand(1);
+ mData[mPos] = value;
+ mPos += 1;
+}
+
void MessageOut::writeInt16(uint16_t value)
{
expand(2);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- uint16_t swap=SDL_Swap16(value);
+ uint16_t swap = SDL_Swap16(value);
memcpy(mData + mPos, &swap, sizeof(uint16_t));
#else
memcpy(mData + mPos, &value, sizeof(uint16_t));
@@ -60,7 +68,7 @@ void MessageOut::writeInt32(uint32_t value)
{
expand(4);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
- uint32_t swap=SDL_Swap32(value);
+ uint32_t swap = SDL_Swap32(value);
memcpy(mData + mPos, &swap, sizeof(uint32_t));
#else
memcpy(mData + mPos, &value, sizeof(uint32_t));
@@ -68,10 +76,37 @@ 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;
+}
+
void MessageOut::writeCoordinates(uint16_t x, uint16_t y, uint8_t direction)
{
char *data = mData + mPos;
- mNetwork->mOutSize += 3;
+ expand(3);
mPos += 3;
uint16_t temp = x;