summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game-server/gamehandler.cpp27
-rw-r--r--src/game-server/gamehandler.hpp13
-rw-r--r--src/game-server/main-game.cpp8
-rw-r--r--src/game-server/state.cpp6
-rw-r--r--src/game-server/state.hpp2
-rw-r--r--src/net/bandwidth.cpp44
-rw-r--r--src/net/bandwidth.hpp40
-rw-r--r--src/net/connection.cpp17
-rw-r--r--src/net/connection.hpp12
-rw-r--r--src/net/connectionhandler.cpp2
-rw-r--r--src/net/netcomputer.cpp40
-rw-r--r--src/net/netcomputer.hpp24
12 files changed, 225 insertions, 10 deletions
diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp
index 7886ac18..fe5b7df1 100644
--- a/src/game-server/gamehandler.cpp
+++ b/src/game-server/gamehandler.cpp
@@ -45,7 +45,9 @@
const unsigned int TILES_TO_BE_NEAR = 7;
GameHandler::GameHandler():
- mTokenCollector(this)
+ mTokenCollector(this),
+ mTotalBandwidthOut(0),
+ mTotalBandwidthIn(0)
{
}
@@ -608,3 +610,26 @@ void GameHandler::handleSendPost(GameClient *client, MessageIn &message)
postMan->addCharacter(client->character);
accountHandler->sendPost(client->character, message);
}
+
+int GameHandler::calculateTotalOut()
+{
+ for (NetComputers::const_iterator i = clients.begin(),
+ i_end = clients.end(); i != i_end; ++i)
+ {
+ mTotalBandwidthOut += (*i)->totalOut();
+ }
+
+ return mTotalBandwidthOut;
+}
+
+int GameHandler::calculateTotalIn()
+{
+ for (NetComputers::const_iterator i = clients.begin(),
+ i_end = clients.end(); i != i_end; ++i)
+ {
+ mTotalBandwidthIn += (*i)->totalIn();
+ (*i)->reset();
+ }
+
+ return mTotalBandwidthIn;
+}
diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp
index 0ae0d495..42ba8cbc 100644
--- a/src/game-server/gamehandler.hpp
+++ b/src/game-server/gamehandler.hpp
@@ -118,6 +118,16 @@ class GameHandler: public ConnectionHandler
*/
GameClient *getClientByNameSlow(std::string const &);
+ /**
+ * Calculate the total amount of bandwidth sent to all clients
+ */
+ int calculateTotalOut();
+
+ /**
+ * Calculate the total amount of bandwidth received from all clients
+ */
+ int calculateTotalIn();
+
protected:
NetComputer *computerConnected(ENetPeer *);
void computerDisconnected(NetComputer *);
@@ -154,6 +164,9 @@ class GameHandler: public ConnectionHandler
*/
TokenCollector<GameHandler, GameClient *, Character *> mTokenCollector;
+ int mTotalBandwidthOut;
+ int mTotalBandwidthIn;
+
};
extern GameHandler *gameHandler;
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index 0bf088bd..40b99358 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -311,9 +311,13 @@ int main(int argc, char *argv[])
// Handle all messages that are in the message queues
accountHandler->process();
- if (worldTime % 100 == 0)
+ if (worldTime % 300 == 0)
{
accountHandler->sendStatistics();
+ LOG_INFO("Total Account Output: " << accountHandler->totalOut() << " Bytes");
+ LOG_INFO("Total Account Input: " << accountHandler->totalIn() << " Bytes");
+ LOG_INFO("Total Client Output: " << gameHandler->calculateTotalOut() << " Bytes");
+ LOG_INFO("Total Client Input: " << gameHandler->calculateTotalIn() << " Bytes");
}
}
else
@@ -325,7 +329,7 @@ int main(int argc, char *argv[])
}
gameHandler->process();
// Update all active objects/beings
- GameState::update();
+ GameState::update(worldTime);
// Send potentially urgent outgoing messages
gameHandler->flush();
}
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index aeafa0cd..61829a57 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -429,7 +429,7 @@ static void informPlayer(MapComposite *map, Character *p)
static bool dbgLockObjects;
#endif
-void GameState::update()
+void GameState::update(int worldTime)
{
# ifndef NDEBUG
dbgLockObjects = true;
@@ -450,6 +450,10 @@ void GameState::update()
for (CharacterIterator p(map->getWholeMapIterator()); p; ++p)
{
informPlayer(map, *p);
+ if (worldTime % 2000 == 0)
+ {
+ accountHandler->sendCharacterData(*p);
+ }
}
for (ObjectIterator i(map->getWholeMapIterator()); i; ++i)
diff --git a/src/game-server/state.hpp b/src/game-server/state.hpp
index 7adaabe8..7cd69d76 100644
--- a/src/game-server/state.hpp
+++ b/src/game-server/state.hpp
@@ -34,7 +34,7 @@ namespace GameState
/**
* Updates game state (contains core server logic).
*/
- void update();
+ void update(int worldTime);
/**
* Inserts an object in the game world.
diff --git a/src/net/bandwidth.cpp b/src/net/bandwidth.cpp
new file mode 100644
index 00000000..5fa580ee
--- /dev/null
+++ b/src/net/bandwidth.cpp
@@ -0,0 +1,44 @@
+/*
+ * The Mana World Server
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "bandwidth.hpp"
+
+BandwidthMonitor::BandwidthMonitor():
+ mAmountOutput(0),
+ mAmountInput(0)
+{
+}
+
+void BandwidthMonitor::increaseOutput(int size)
+{
+ mAmountOutput += size;
+}
+
+void BandwidthMonitor::increaseInput(int size)
+{
+ mAmountInput += size;
+}
+
+void BandwidthMonitor::reset()
+{
+ mAmountOutput = 0;
+ mAmountInput = 0;
+}
diff --git a/src/net/bandwidth.hpp b/src/net/bandwidth.hpp
new file mode 100644
index 00000000..a524bfc0
--- /dev/null
+++ b/src/net/bandwidth.hpp
@@ -0,0 +1,40 @@
+/*
+ * The Mana World Server
+ * Copyright 2008 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _TMWSERV_BANDWIDTH_H_
+#define _TMWSERV_BANDWIDTH_H_
+
+class BandwidthMonitor
+{
+public:
+ BandwidthMonitor();
+ void increaseOutput(int size);
+ void increaseInput(int size);
+ void reset();
+ int totalOut() const { return mAmountOutput; }
+ int totalIn() const { return mAmountInput; }
+
+private:
+ int mAmountOutput;
+ int mAmountInput;
+};
+
+#endif
diff --git a/src/net/connection.cpp b/src/net/connection.cpp
index 4749c888..c99ee909 100644
--- a/src/net/connection.cpp
+++ b/src/net/connection.cpp
@@ -20,6 +20,7 @@
*/
#include "net/connection.hpp"
+#include "net/bandwidth.hpp"
#include "net/messagein.hpp"
#include "net/messageout.hpp"
#include "utils/logger.h"
@@ -28,6 +29,7 @@ Connection::Connection():
mRemote(0),
mLocal(0)
{
+ mBandwidth = new BandwidthMonitor;
}
bool Connection::start(std::string const &address, int port)
@@ -66,9 +68,11 @@ void Connection::stop()
enet_peer_reset(mRemote);
if (mLocal)
enet_host_destroy(mLocal);
+ delete mBandwidth;
mRemote = 0;
mLocal = 0;
+ mBandwidth = 0;
}
bool Connection::isConnected() const
@@ -83,6 +87,8 @@ void Connection::send(MessageOut const &msg, bool reliable, unsigned channel)
return;
}
+ mBandwidth->increaseOutput(msg.getLength());
+
ENetPacket *packet;
packet = enet_packet_create(msg.getData(),
msg.getLength(),
@@ -107,6 +113,7 @@ void Connection::process()
{
MessageIn msg((char *)event.packet->data,
event.packet->dataLength);
+ mBandwidth->increaseInput(event.packet->dataLength);
processMessage(msg);
}
else
@@ -122,3 +129,13 @@ void Connection::process()
}
}
}
+
+int Connection::totalOut()
+{
+ return mBandwidth->totalOut();
+}
+
+int Connection::totalIn()
+{
+ return mBandwidth->totalIn();
+}
diff --git a/src/net/connection.hpp b/src/net/connection.hpp
index 74eaaac7..0d417092 100644
--- a/src/net/connection.hpp
+++ b/src/net/connection.hpp
@@ -27,6 +27,7 @@
class MessageIn;
class MessageOut;
+class BandwidthMonitor;
/**
* A point-to-point connection to a remote host. The remote host can use a
@@ -65,6 +66,16 @@ class Connection
*/
void process();
+ /**
+ * Return total output
+ */
+ int totalOut();
+
+ /**
+ * Return total input
+ */
+ int totalIn();
+
protected:
/**
* Processes a single message from the remote host.
@@ -74,6 +85,7 @@ class Connection
private:
ENetPeer *mRemote;
ENetHost *mLocal;
+ BandwidthMonitor *mBandwidth;
};
#endif
diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp
index 88e6f636..dd1828ac 100644
--- a/src/net/connectionhandler.cpp
+++ b/src/net/connectionhandler.cpp
@@ -104,6 +104,8 @@ void ConnectionHandler::process(enet_uint32 timeout)
LOG_DEBUG("Received message " << msg << " from "
<< *comp);
+ comp->increaseIn(event.packet->dataLength);
+
processMessage(comp, msg);
} else {
LOG_ERROR("Message too short from " << *comp);
diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp
index d5b0ea77..657f615b 100644
--- a/src/net/netcomputer.cpp
+++ b/src/net/netcomputer.cpp
@@ -23,15 +23,19 @@
#include <queue>
#include <enet/enet.h>
-#include "defines.h"
-#include "net/messageout.hpp"
-#include "net/netcomputer.hpp"
-#include "utils/logger.h"
-#include "utils/processorutils.hpp"
+#include "bandwidth.hpp"
+#include "messageout.hpp"
+#include "netcomputer.hpp"
+
+#include "../defines.h"
+
+#include "../utils/logger.h"
+#include "../utils/processorutils.hpp"
NetComputer::NetComputer(ENetPeer *peer):
mPeer(peer)
{
+ mBandwidth = new BandwidthMonitor;
}
bool
@@ -64,6 +68,8 @@ NetComputer::send(const MessageOut &msg, bool reliable,
{
LOG_DEBUG("Sending message " << msg << " to " << *this);
+ mBandwidth->increaseOutput(msg.getLength());
+
ENetPacket *packet;
packet = enet_packet_create(msg.getData(),
msg.getLength(),
@@ -79,6 +85,30 @@ NetComputer::send(const MessageOut &msg, bool reliable,
}
}
+int
+NetComputer::totalOut()
+{
+ return mBandwidth->totalOut();
+}
+
+int
+NetComputer::totalIn()
+{
+ return mBandwidth->totalIn();
+}
+
+void
+NetComputer::increaseIn(int size)
+{
+ mBandwidth->increaseInput(size);
+}
+
+void
+NetComputer::reset()
+{
+ mBandwidth->reset();
+}
+
std::ostream&
operator <<(std::ostream &os, const NetComputer &comp)
{
diff --git a/src/net/netcomputer.hpp b/src/net/netcomputer.hpp
index 9a73c576..6acbb53b 100644
--- a/src/net/netcomputer.hpp
+++ b/src/net/netcomputer.hpp
@@ -26,6 +26,7 @@
#include <enet/enet.h>
class MessageOut;
+class BandwidthMonitor;
/**
* This class represents a known computer on the network. For example a
@@ -80,8 +81,31 @@ class NetComputer
send(const MessageOut &msg, bool reliable = true,
unsigned int channel = 0);
+ /**
+ * Gets the amount of bandwidth that has been sent out by the server
+ * to this client
+ */
+ int totalOut();
+
+ /**
+ * Gets the amount of bandwidth that has been received by the server
+ * from this client
+ */
+ int totalIn();
+
+ /**
+ * Increase the total received by the server from the client
+ */
+ void increaseIn(int size);
+
+ /**
+ * Reset the totals
+ */
+ void reset();
+
private:
ENetPeer *mPeer; /**< Client peer */
+ BandwidthMonitor *mBandwidth; /**< Bandwidth monitoring */
/**
* Converts the ip-address of the peer to a stringstream.