summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-31 09:45:43 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2007-03-31 09:45:43 +0000
commitbd9b9a04c0ec07c957014d0679d386c7b42e5312 (patch)
treef18a9c3de8a88f99472d0e87dd19e89512dca880
parenta85d2b47912ea32e3ecf77632242fa6f759a0ade (diff)
downloadmanaserv-bd9b9a04c0ec07c957014d0679d386c7b42e5312.tar.gz
manaserv-bd9b9a04c0ec07c957014d0679d386c7b42e5312.tar.bz2
manaserv-bd9b9a04c0ec07c957014d0679d386c7b42e5312.tar.xz
manaserv-bd9b9a04c0ec07c957014d0679d386c7b42e5312.zip
Moved writing of incoming messages into MessageIn and tweaked the printing of
the message ID.
-rw-r--r--ChangeLog3
-rw-r--r--src/defines.h14
-rw-r--r--src/net/connectionhandler.cpp12
-rw-r--r--src/net/messagein.cpp11
-rw-r--r--src/net/messagein.hpp30
5 files changed, 53 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 87da126b..72598d47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,9 @@
src/game-server/spawnarea.hpp, src/game-server/monster.cpp,
src/game-server/monster.hpp, src/game-server/trigger.hpp: Made a start
with having monsters spawn using a SpawnArea.
+ * src/net/messagein.hpp, src/net/messagein.cpp,
+ src/net/connectionhandler.cpp: Moved writing of incoming messages into
+ MessageIn and tweaked the printing of the message ID.
2007-03-30 Bjørn Lindeijer <bjorn@lindeijer.nl>
diff --git a/src/defines.h b/src/defines.h
index ad1b47e0..ccd4a191 100644
--- a/src/defines.h
+++ b/src/defines.h
@@ -188,13 +188,13 @@ enum {
CPMSG_LIST_CHANNELS_RESPONSE = 0x0424, // W number of channels, S channels
// Inter-server
- GAMSG_REGISTER = 0x500, // S address, W port, { W map id }*
- AGMSG_ACTIVE_MAP = 0x501, // W map id
- AGMSG_PLAYER_ENTER = 0x510, // B*32 token, serialised character data
- GAMSG_PLAYER_DATA = 0x520, // serialised character data
- GAMSG_REDIRECT = 0x530, // L id
- AGMSG_REDIRECT_RESPONSE = 0x531, // L id, B*32 token, S game address, W game port
- GAMSG_PLAYER_RECONNECT = 0x532, // L id, B*32 token
+ GAMSG_REGISTER = 0x0500, // S address, W port, { W map id }*
+ AGMSG_ACTIVE_MAP = 0x0501, // W map id
+ AGMSG_PLAYER_ENTER = 0x0510, // B*32 token, serialised character data
+ GAMSG_PLAYER_DATA = 0x0520, // serialised character data
+ GAMSG_REDIRECT = 0x0530, // L id
+ AGMSG_REDIRECT_RESPONSE = 0x0531, // L id, B*32 token, S game address, W game port
+ GAMSG_PLAYER_RECONNECT = 0x0532, // L id, B*32 token
XXMSG_INVALID = 0x7FFF
};
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp
index 04bf0169..6de1835e 100644
--- a/src/net/connectionhandler.cpp
+++ b/src/net/connectionhandler.cpp
@@ -38,10 +38,11 @@ bool ConnectionHandler::startListen(enet_uint16 port)
address.port = port;
LOG_INFO("Listening on port " << port << "...");
- host = enet_host_create(&address /* the address to bind the server host to */,
- MAX_CLIENTS /* allow up to MAX_CLIENTS clients and/or outgoing connections */,
- 0 /* assume any amount of incoming bandwidth */,
- 0 /* assume any amount of outgoing bandwidth */);
+ host = enet_host_create(
+ &address /* the address to bind the server host to */,
+ MAX_CLIENTS /* allow up to MAX_CLIENTS connections */,
+ 0 /* assume any amount of incoming bandwidth */,
+ 0 /* assume any amount of outgoing bandwidth */);
return host;
}
@@ -111,8 +112,7 @@ void ConnectionHandler::process(enet_uint32 timeout)
if (event.packet->dataLength >= 2) {
MessageIn msg((char *)event.packet->data,
event.packet->dataLength);
- LOG_DEBUG("Received message " << msg.getId() << " ("
- << event.packet->dataLength << " B) from "
+ LOG_DEBUG("Received message " << msg << " from "
<< *comp);
processMessage(comp, msg);
diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp
index 783cbf11..2b5eaf27 100644
--- a/src/net/messagein.cpp
+++ b/src/net/messagein.cpp
@@ -22,6 +22,8 @@
*/
#include <string>
+#include <iostream>
+#include <iomanip>
#include <enet/enet.h>
#include "net/messagein.hpp"
@@ -96,3 +98,12 @@ std::string MessageIn::readString(int length)
return readString;
}
+
+std::ostream&
+operator <<(std::ostream &os, const MessageIn &msg)
+{
+ os << std::setw(6) << std::hex << std::showbase << std::internal
+ << std::setfill('0') << msg.getId()
+ << std::dec << " (" << msg.getLength() << " B)";
+ return os;
+}
diff --git a/src/net/messagein.hpp b/src/net/messagein.hpp
index 79063f97..674974f8 100644
--- a/src/net/messagein.hpp
+++ b/src/net/messagein.hpp
@@ -39,7 +39,17 @@ class MessageIn
*/
MessageIn(const char *data, int length);
- int getId() { return mId; } /**< Returns the message ID. */
+ /**
+ * Returns the message ID.
+ */
+ int
+ getId() const { return mId; }
+
+ /**
+ * Returns the total length of this message.
+ */
+ int
+ getLength() const { return mLength; }
int readByte(); /**< Reads a byte. */
int readShort(); /**< Reads a short. */
@@ -50,16 +60,22 @@ class MessageIn
* that the length of the string is stored in a short at the
* start of the string.
*/
- std::string readString(int length = -1);
+ std::string
+ readString(int length = -1);
/**
* Returns the length of unread data.
*/
- int getUnreadLength() { return mLength - mPos; }
+ int
+ getUnreadLength() const { return mLength - mPos; }
+
+ /**
+ * Returns
+ */
private:
const char *mData; /**< Packet data */
- unsigned short mLength; /**< Length of data in bytes */
+ unsigned short mLength; /**< Length of data in bytes */
unsigned short mId; /**< The message ID. */
/**
@@ -67,6 +83,12 @@ class MessageIn
* bigger than packet->length means EOP was reached when reading it.
*/
unsigned short mPos;
+
+ /**
+ * Streams message ID and length to the given output stream.
+ */
+ friend std::ostream& operator <<(std::ostream &os,
+ const MessageIn &msg);
};
#endif