diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-03-31 10:23:00 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2007-03-31 10:23:00 +0000 |
commit | eba3a8635b308475aa4bcfc5f5cd058c48ed679d (patch) | |
tree | c6c44e6d8d53f97d6fed0177fe5a07ce432a4b0e /src | |
parent | bd9b9a04c0ec07c957014d0679d386c7b42e5312 (diff) | |
download | manaserv-eba3a8635b308475aa4bcfc5f5cd058c48ed679d.tar.gz manaserv-eba3a8635b308475aa4bcfc5f5cd058c48ed679d.tar.bz2 manaserv-eba3a8635b308475aa4bcfc5f5cd058c48ed679d.tar.xz manaserv-eba3a8635b308475aa4bcfc5f5cd058c48ed679d.zip |
Moved writing of outgoing messages into MessageOut and added printing of the
message ID.
Diffstat (limited to 'src')
-rw-r--r-- | src/net/messagein.cpp | 4 | ||||
-rw-r--r-- | src/net/messageout.cpp | 20 | ||||
-rw-r--r-- | src/net/messageout.hpp | 6 | ||||
-rw-r--r-- | src/net/netcomputer.cpp | 2 |
4 files changed, 29 insertions, 3 deletions
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 2b5eaf27..bf43478b 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -42,7 +42,7 @@ int MessageIn::readByte() int value = -1; if (mPos < mLength) { - value = (unsigned char)mData[mPos]; + value = (unsigned char) mData[mPos]; } mPos += 1; return value; @@ -55,7 +55,7 @@ int MessageIn::readShort() { uint16_t t; memcpy(&t, mData + mPos, 2); - value = (unsigned short)ENET_NET_TO_HOST_16(t); + value = (unsigned short) ENET_NET_TO_HOST_16(t); } mPos += 2; return value; diff --git a/src/net/messageout.cpp b/src/net/messageout.cpp index 34655e4c..929514a6 100644 --- a/src/net/messageout.cpp +++ b/src/net/messageout.cpp @@ -24,6 +24,8 @@ #include <cstdlib> #include <iosfwd> #include <string> +#include <iostream> +#include <iomanip> #include <enet/enet.h> #include "net/messageout.hpp" @@ -133,3 +135,21 @@ MessageOut::writeString(const std::string &string, int length) } mPos += length; } + +std::ostream& +operator <<(std::ostream &os, const MessageOut &msg) +{ + if (msg.getLength() >= 2) + { + unsigned short id = ENET_NET_TO_HOST_16(*(short*) msg.mData); + os << std::setw(6) << std::hex << std::showbase << std::internal + << std::setfill('0') << id + << std::dec << " (" << msg.getLength() << " B)"; + } + else + { + os << "Unknown" + << std::dec << " (" << msg.getLength() << " B)"; + } + return os; +} diff --git a/src/net/messageout.hpp b/src/net/messageout.hpp index 8ec6b171..bb252c24 100644 --- a/src/net/messageout.hpp +++ b/src/net/messageout.hpp @@ -91,6 +91,12 @@ class MessageOut char *mData; /**< Data building up. */ unsigned int mPos; /**< Position in the data. */ unsigned int mDataSize; /**< Allocated datasize. */ + + /** + * Streams message ID and length to the given output stream. + */ + friend std::ostream& operator <<(std::ostream &os, + const MessageOut &msg); }; #endif //_TMWSERV_MESSAGEOUT_H_ diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp index d35779da..47d7ea1a 100644 --- a/src/net/netcomputer.cpp +++ b/src/net/netcomputer.cpp @@ -64,7 +64,7 @@ void NetComputer::send(const MessageOut &msg, bool reliable, unsigned int channel) { - LOG_DEBUG("Sending packet of length " << msg.getLength() << " to " << *this); + LOG_DEBUG("Sending message " << msg << " to " << *this); ENetPacket *packet; packet = enet_packet_create(msg.getData(), |