summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-26 17:40:12 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2006-08-26 17:40:12 +0000
commit30d192259e6913a210156da2abce16e05b5a5825 (patch)
tree5c618bf3ffde465ae836d23156bdd761dc2b2a14
parentc2717aecc26d52d8be6d1b9350e9b0ff9dec1fc8 (diff)
downloadmanaserv-30d192259e6913a210156da2abce16e05b5a5825.tar.gz
manaserv-30d192259e6913a210156da2abce16e05b5a5825.tar.bz2
manaserv-30d192259e6913a210156da2abce16e05b5a5825.tar.xz
manaserv-30d192259e6913a210156da2abce16e05b5a5825.zip
Applied patch by Rogier, adding a stream operator to NetComputer for logging purposes.
-rw-r--r--ChangeLog8
-rw-r--r--src/connectionhandler.cpp10
-rw-r--r--src/netcomputer.cpp16
-rw-r--r--src/netcomputer.h10
4 files changed, 33 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 20de303c..ac82ca27 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-08-26 Rogier Polak <rogier_polak@users.sourceforge.net>
+
+ * src/netcomputer.h, src/netcomputer.cpp, src/connectionhandler.cpp:
+ Added private overloaded << operator to NetComputer, for logging of the
+ peers ip-address (patch applied by Bjørn Lindeijer).
+
2006-08-26 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/accounthandler.cpp: Set an arbitrary start position outside any
@@ -262,7 +268,7 @@
* src/configuration.cpp, src/accounthandler.cpp, src/dalstorage.cpp,
src/main.cpp, src/chathandler.cpp, src/messagehandler.cpp,
src/utils/stringfilter.cpp, src/utils/logger.h, src/skill.cpp: Changed
- LOG macros to have statement syntax.
+ LOG macros to have statement syntax.
2006-05-19 Guillaume Melquiond <guillaume.melquiond@gmail.com>
diff --git a/src/connectionhandler.cpp b/src/connectionhandler.cpp
index 1c73d758..96affdc6 100644
--- a/src/connectionhandler.cpp
+++ b/src/connectionhandler.cpp
@@ -116,11 +116,7 @@ void ConnectionHandler::process()
case ENET_EVENT_TYPE_RECEIVE:
{
- // Convert the client IP address to string
- // representation
- std::string ipaddr = ip4ToString(event.peer->address.host);
-
- NetComputer *comp = (NetComputer *)event.peer->data;
+ NetComputer *comp = (NetComputer*) event.peer->data;
#ifdef SCRIPT_SUPPORT
// This could be good if you wanted to extend the
@@ -140,11 +136,11 @@ void ConnectionHandler::process()
event.packet->dataLength);
LOG_INFO("Received message " << msg.getId() << " ("
<< event.packet->dataLength << " B) from "
- << ipaddr, 2);
+ << *comp, 2);
processMessage(comp, msg);
} else {
- LOG_ERROR("Message too short from " << ipaddr, 0);
+ LOG_ERROR("Message too short from " << *comp, 0);
}
/* Clean up the packet now that we're done using it. */
diff --git a/src/netcomputer.cpp b/src/netcomputer.cpp
index fd9bec5e..c27dd327 100644
--- a/src/netcomputer.cpp
+++ b/src/netcomputer.cpp
@@ -25,13 +25,11 @@
#include <iosfwd>
#include <queue>
-#include <iostream>
#include <enet/enet.h>
#include "defines.h"
#include "messageout.h"
-#include "connectionhandler.h"
#include "utils/logger.h"
@@ -69,7 +67,7 @@ NetComputer::send(const MessageOut &msg, bool reliable,
unsigned int channel)
{
LOG_INFO("Sending packet of length " << msg.getLength() << " to "
- << ip4ToString(mPeer->address.host), 2);
+ << *this, 2);
ENetPacket *packet;
packet = enet_packet_create(msg.getData(),
@@ -85,3 +83,15 @@ NetComputer::send(const MessageOut &msg, bool reliable,
LOG_WARN("Failure to create packet!", 0);
}
}
+
+std::ostream&
+operator <<(std::ostream &os, const NetComputer &comp)
+{
+ // address.host contains the ip-address in network-byte-order
+
+ os << ((comp.mPeer->address.host & 0xff000000) >> 24) << "."
+ << ((comp.mPeer->address.host & 0x00ff0000) >> 16) << "."
+ << ((comp.mPeer->address.host & 0x0000ff00) >> 8) << "."
+ << ((comp.mPeer->address.host & 0x000000ff) >> 0);
+ return os;
+}
diff --git a/src/netcomputer.h b/src/netcomputer.h
index 842d362b..5622e03c 100644
--- a/src/netcomputer.h
+++ b/src/netcomputer.h
@@ -26,6 +26,8 @@
#include <enet/enet.h>
+#include <iostream>
+
class MessageOut;
/**
@@ -83,6 +85,14 @@ class NetComputer
private:
ENetPeer *mPeer; /**< Client peer */
+
+ /**
+ * Converts the ip-address of the peer to a stringstream.
+ * Example:
+ * <code> std::cout << comp </code>
+ */
+ friend std::ostream& operator <<(std::ostream &os,
+ const NetComputer &comp);
};
#endif // _TMWSERV_NETCOMPUTER_H_