summaryrefslogtreecommitdiff
path: root/src/net/manaserv/messageout.cpp
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-05-01 22:38:07 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2012-05-05 22:30:00 +0200
commitdf9ed1ab4364fe29bf260cae51827cc2722eff78 (patch)
tree45324f700d2b2c87983fa4b8c5ed01ee2e68ba70 /src/net/manaserv/messageout.cpp
parent96abc4a9658b3318d0052dc5cd31a3c15d76a494 (diff)
downloadmana-df9ed1ab4364fe29bf260cae51827cc2722eff78.tar.gz
mana-df9ed1ab4364fe29bf260cae51827cc2722eff78.tar.bz2
mana-df9ed1ab4364fe29bf260cae51827cc2722eff78.tar.xz
mana-df9ed1ab4364fe29bf260cae51827cc2722eff78.zip
Added debugging mode to the protocol
This makes the client able to send and receive messages sent in debugging mode, where the contents of the messages are annotated. For messages sent from the client the debugging mode is currently always enabled. Later on this could be an internal option or controlled from the server side. Reviewed-by: Erik Schilling
Diffstat (limited to 'src/net/manaserv/messageout.cpp')
-rw-r--r--src/net/manaserv/messageout.cpp32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/net/manaserv/messageout.cpp b/src/net/manaserv/messageout.cpp
index 7cecc03d..1197176f 100644
--- a/src/net/manaserv/messageout.cpp
+++ b/src/net/manaserv/messageout.cpp
@@ -29,10 +29,16 @@ namespace ManaServ {
MessageOut::MessageOut(uint16_t id):
mData(0),
+ mPos(0),
mDataSize(0),
- mPos(0)
+ mDebugMode(false)
{
+ bool debug = true;
+ if (debug)
+ id |= ManaServ::XXMSG_DEBUG_FLAG;
+
writeInt16(id);
+ mDebugMode = debug;
}
MessageOut::~MessageOut()
@@ -48,6 +54,9 @@ void MessageOut::expand(size_t bytes)
void MessageOut::writeInt8(uint8_t value)
{
+ if (mDebugMode)
+ writeValueType(ManaServ::Int8);
+
expand(1);
mData[mPos] = value;
mPos += 1;
@@ -55,6 +64,9 @@ void MessageOut::writeInt8(uint8_t value)
void MessageOut::writeInt16(uint16_t value)
{
+ if (mDebugMode)
+ writeValueType(ManaServ::Int16);
+
expand(2);
uint16_t t = ENET_HOST_TO_NET_16(value);
memcpy(mData + mPos, &t, 2);
@@ -63,6 +75,9 @@ void MessageOut::writeInt16(uint16_t value)
void MessageOut::writeInt32(uint32_t value)
{
+ if (mDebugMode)
+ writeValueType(ManaServ::Int32);
+
expand(4);
uint32_t t = ENET_HOST_TO_NET_32(value);
memcpy(mData + mPos, &t, 4);
@@ -71,6 +86,12 @@ void MessageOut::writeInt32(uint32_t value)
void MessageOut::writeString(const std::string &string, int length)
{
+ if (mDebugMode)
+ {
+ writeValueType(ManaServ::String);
+ writeInt16(length);
+ }
+
int stringLength = string.length();
if (length < 0)
{
@@ -88,12 +109,19 @@ void MessageOut::writeString(const std::string &string, int length)
// Write the actual string
memcpy(mData + mPos, string.data(), stringLength);
- // Pad remaining space with zeros
if (length > stringLength)
{
+ // Pad remaining space with zeros
memset(mData + mPos + stringLength, '\0', length - stringLength);
}
mPos += length;
}
+void MessageOut::writeValueType(ManaServ::ValueType type)
+{
+ expand(1);
+ mData[mPos] = type;
+ mPos += 1;
+}
+
} // namespace ManaServ