diff options
author | Philipp Sehmisch <crush@themanaworld.org> | 2008-11-20 22:23:54 +0100 |
---|---|---|
committer | Philipp Sehmisch <crush@themanaworld.org> | 2008-11-20 22:23:54 +0100 |
commit | 7f4209d5b5c0f0f8d02d664365be9a8c605b95d9 (patch) | |
tree | f96a116f953b7c585bc457e86c8e025143e313fa /src | |
parent | d9189cba9db278b20c07bcb31ae481ad9804aaa5 (diff) | |
parent | 4c67ba28360338e376be3f7fd990f3895054a455 (diff) | |
download | manaserv-7f4209d5b5c0f0f8d02d664365be9a8c605b95d9.tar.gz manaserv-7f4209d5b5c0f0f8d02d664365be9a8c605b95d9.tar.bz2 manaserv-7f4209d5b5c0f0f8d02d664365be9a8c605b95d9.tar.xz manaserv-7f4209d5b5c0f0f8d02d664365be9a8c605b95d9.zip |
Merge branch 'master' of git@gitorious.org:tmwserv/mainline
Diffstat (limited to 'src')
-rw-r--r-- | src/defines.h | 15 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 156 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 27 | ||||
-rw-r--r-- | src/game-server/gamehandler.hpp | 13 | ||||
-rw-r--r-- | src/game-server/main-game.cpp | 14 | ||||
-rw-r--r-- | src/net/bandwidth.cpp | 53 | ||||
-rw-r--r-- | src/net/bandwidth.hpp | 28 | ||||
-rw-r--r-- | src/net/connection.cpp | 17 | ||||
-rw-r--r-- | src/net/connection.hpp | 11 | ||||
-rw-r--r-- | src/net/connectionhandler.cpp | 3 | ||||
-rw-r--r-- | src/net/netcomputer.cpp | 27 | ||||
-rw-r--r-- | src/net/netcomputer.hpp | 23 |
12 files changed, 196 insertions, 191 deletions
diff --git a/src/defines.h b/src/defines.h index e1c36796..4bad3e9b 100644 --- a/src/defines.h +++ b/src/defines.h @@ -23,13 +23,20 @@ /** * Enumeration type for account levels. + * A normal player would have permissions of 1 + * A tester would have permissions of 3 (AL_PLAYER | AL_TESTER) + * A dev would have permissions of 7 (AL_PLAYER | AL_TESTER | AL_DEV) + * A gm would have permissions of 11 (AL_PLAYER | AL_TESTER | AL_GM) + * A admin would have permissions of 255 (*) */ enum { - AL_BANNED = 0, /**< This user is currently banned. */ - AL_NORMAL = 10, /**< User has regular rights. */ - AL_GM = 50, /**< User can perform a subset of administrator tasks. */ - AL_ADMIN = 99 /**< User can perform administrator tasks. */ + AL_BANNED = 0, /**< This user is currently banned. */ + AL_PLAYER = 1, /**< User has regular rights. */ + AL_TESTER = 2, /**< User can perform testing tasks. */ + AL_DEV = 4, /**< User is a developer and can perform dev tasks */ + AL_GM = 8, /**< User is a moderator and can perform mod tasks */ + AL_ADMIN = 128 /**< User can perform administrator tasks. */ }; enum diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index e7a43231..3822e2ef 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -39,6 +39,18 @@ static void say(const std::string error, Character *player) GameState::sayTo(player, NULL, error); } +static bool handlePermissions(Character *player, unsigned int permissions) +{ + if (player->getAccountLevel() & permissions) + { + return true; + } + + say("Invalid permissions", player); + + return false; +} + static std::string getArgument(std::string &args) { std::string argument = ""; @@ -79,26 +91,39 @@ static void handleHelp(Character *player, std::string &args) { if (args == "") { - if (player->getAccountLevel() >= AL_GM) + if (player->getAccountLevel() & AL_PLAYER) { say("Game Master Commands:", player); say("@help [command]", player); + say("@report <bug>", player); + } + + if (player->getAccountLevel() & AL_TESTER) + { say("@warp <character> <map> <x> <y>", player); - say("@item", player); - say("@drop", player); - say("@money", player); + say("@goto <character>", player); + } + + if (player->getAccountLevel() & AL_GM) + { + say("@recall <character>", player); + say("@ban <character> <length of time>", player); + } + + if (player->getAccountLevel() & AL_DEV) + { + say("@item <character> <item id> <amount>", player); + say("@drop <item id> <amount>", player); + say("@money <character> <amount>", player); say("@spawn <monster id> <number>", player); - say("@goto", player); - say("@recall", player); - say("@ban", player); - say("@attribute", player); + say("@attribute <character> <attribute> <value>", player); } - if (player->getAccountLevel() == AL_ADMIN) + if (player->getAccountLevel() & AL_ADMIN) { say("Administrator Commands", player); say("@reload", player); - say("@level", player); + say("@setgroup <character> <AL level>", player); } } else @@ -474,17 +499,9 @@ static void handleRecall(Character *player, std::string &args) static void handleReload(Character *player) { - // check for valid permissions // reload the items and monsters - if (player->getAccountLevel() == AL_ADMIN) - { - ItemManager::reload(); - MonsterManager::reload(); - } - else - { - say("Invalid permissions.", player); - } + ItemManager::reload(); + MonsterManager::reload(); } static void handleBan(Character *player, std::string &args) @@ -531,17 +548,17 @@ static void handleBan(Character *player, std::string &args) accountHandler->banCharacter(other, length); } -static void handleLevel(Character *player, std::string &args) +static void handleSetGroup(Character *player, std::string &args) { Character *other; - int level; + int level = 0; // get the arguments std::string character = getArgument(args); - std::string valuestr = getArgument(args); + std::string levelstr = getArgument(args); // check all arguments are there - if (character == "" || valuestr == "") + if (character == "" || levelstr == "") { say("Invalid number of arguments given.", player); return; @@ -563,19 +580,32 @@ static void handleLevel(Character *player, std::string &args) } } - // check the amount is really an integer - if (!utils::isNumeric(valuestr)) + // check which level they should be + // refer to defines.h for level info + if (levelstr == "AL_PLAYER") { - say("Invalid argument", player); - return; + level = AL_PLAYER; + } + else if (levelstr == "AL_TESTER") + { + level = AL_PLAYER | AL_TESTER; + } + else if (levelstr == "AL_GM") + { + level = AL_PLAYER | AL_TESTER | AL_GM; + } + else if (levelstr == "AL_DEV") + { + level = AL_PLAYER | AL_TESTER | AL_DEV; + } + else if (levelstr == "AL_ADMIN") + { + level = 255; } - // put the amount into an integer - level = utils::stringToInt(valuestr); - - if (level < 0) + if (level == 0) { - say("Invalid level", player); + say("Invalid group", player); return; } @@ -645,17 +675,22 @@ static void handleAttribute(Character *player, std::string &args) other->setAttribute(attr, value); } -void CommandHandler::handleCommand(Character *player, - const std::string &command) +static void handleReport(Character *player, std::string &args) { - // check character permissions - // finer tuning for checking per command can be done - // in the handle function for that command - if (player->getAccountLevel() < AL_GM) + std::string bugReport = getArgument(args); + + if (bugReport == "") { + say("Invalid number of arguments given.", player); return; } + // TODO: Send the report to a developer or something +} + +void CommandHandler::handleCommand(Character *player, + const std::string &command) +{ // get command type, and arguments // remove first character (the @) std::string::size_type pos = command.find(' '); @@ -665,51 +700,68 @@ void CommandHandler::handleCommand(Character *player, // handle the command if (type == "help") { - handleHelp(player, args); + if (handlePermissions(player, AL_PLAYER)) + handleHelp(player, args); } else if (type == "warp") { - handleWarp(player, args); + if (handlePermissions(player, AL_TESTER)) + handleWarp(player, args); } else if (type == "item") { - handleItem(player, args); + if (handlePermissions(player, AL_DEV)) + handleItem(player, args); } else if (type == "drop") { - handleDrop(player, args); + if (handlePermissions(player, AL_DEV)) + handleDrop(player, args); } else if (type == "money") { - handleMoney(player, args); + if (handlePermissions(player, AL_DEV)) + handleMoney(player, args); } else if (type == "spawn") { - handleSpawn(player, args); + if (handlePermissions(player, AL_DEV)) + handleSpawn(player, args); } else if (type == "goto") { - handleGoto(player, args); + if (handlePermissions(player, AL_TESTER)) + handleGoto(player, args); } else if (type == "recall") { - handleRecall(player, args); + if (handlePermissions(player, AL_GM)) + handleRecall(player, args); } else if (type == "reload") { - handleReload(player); + if (handlePermissions(player, AL_ADMIN)) + handleReload(player); } else if (type == "ban") { - handleBan(player, args); + if (handlePermissions(player, AL_GM)) + handleBan(player, args); } - else if (type == "level") + else if (type == "setgroup") { - handleLevel(player, args); + if (handlePermissions(player, AL_ADMIN)) + handleSetGroup(player, args); } else if (type == "attribute") { - handleAttribute(player, args); + if (handlePermissions(player, AL_DEV)) + handleAttribute(player, args); + } + else if (type == "report") + { + if (handlePermissions(player, AL_PLAYER)) + handleReport(player, args); } else { diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index fe5b7df1..7886ac18 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -45,9 +45,7 @@ const unsigned int TILES_TO_BE_NEAR = 7; GameHandler::GameHandler(): - mTokenCollector(this), - mTotalBandwidthOut(0), - mTotalBandwidthIn(0) + mTokenCollector(this) { } @@ -610,26 +608,3 @@ 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 42ba8cbc..0ae0d495 100644 --- a/src/game-server/gamehandler.hpp +++ b/src/game-server/gamehandler.hpp @@ -118,16 +118,6 @@ 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 *); @@ -164,9 +154,6 @@ 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 40b99358..a0723e31 100644 --- a/src/game-server/main-game.cpp +++ b/src/game-server/main-game.cpp @@ -38,6 +38,7 @@ #include "game-server/postman.hpp" #include "game-server/resourcemanager.hpp" #include "game-server/state.hpp" +#include "net/bandwidth.hpp" #include "net/connectionhandler.hpp" #include "net/messageout.hpp" #include "utils/logger.h" @@ -68,6 +69,9 @@ AccountConnection *accountHandler; /** Post Man **/ PostMan *postMan; +/** Bandwidth Monitor */ +BandwidthMonitor *gBandwidth; + /** Callback used when SIGQUIT signal is received. */ void closeGracefully(int) { @@ -151,6 +155,7 @@ void initialize() gameHandler = new GameHandler; accountHandler = new AccountConnection; postMan = new PostMan; + gBandwidth = new BandwidthMonitor; // --- Initialize enet. if (enet_initialize() != 0) { @@ -187,6 +192,7 @@ void deinitialize() delete gameHandler; delete accountHandler; delete postMan; + delete gBandwidth; // Destroy Managers delete stringFilter; @@ -314,10 +320,10 @@ int main(int argc, char *argv[]) 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"); + LOG_INFO("Total Account Output: " << gBandwidth->totalInterServerOut() << " Bytes"); + LOG_INFO("Total Account Input: " << gBandwidth->totalInterServerIn() << " Bytes"); + LOG_INFO("Total Client Output: " << gBandwidth->totalClientOut() << " Bytes"); + LOG_INFO("Total Client Input: " << gBandwidth->totalClientIn() << " Bytes"); } } else diff --git a/src/net/bandwidth.cpp b/src/net/bandwidth.cpp index 5fa580ee..c7b6f8e3 100644 --- a/src/net/bandwidth.cpp +++ b/src/net/bandwidth.cpp @@ -21,24 +21,59 @@ #include "bandwidth.hpp" +#include "netcomputer.hpp" + BandwidthMonitor::BandwidthMonitor(): - mAmountOutput(0), - mAmountInput(0) + mAmountServerOutput(0), + mAmountServerInput(0), + mAmountClientOutput(0), + mAmountClientInput(0) { } -void BandwidthMonitor::increaseOutput(int size) +void BandwidthMonitor::increaseInterServerOutput(int size) { - mAmountOutput += size; + mAmountServerOutput += size; } -void BandwidthMonitor::increaseInput(int size) +void BandwidthMonitor::increaseInterServerInput(int size) { - mAmountInput += size; + mAmountServerInput += size; } -void BandwidthMonitor::reset() +void BandwidthMonitor::increaseClientOutput(NetComputer *nc, int size) { - mAmountOutput = 0; - mAmountInput = 0; + mAmountClientOutput += size; + // look for an existing client stored + ClientBandwidth::iterator itr = mClientBandwidth.find(nc); + + // if there isnt one, create one + if (itr == mClientBandwidth.end()) + { + std::pair<ClientBandwidth::iterator, bool> retItr; + retItr = mClientBandwidth.insert(std::pair<NetComputer*, std::pair<int, int> >(nc, std::pair<int, int>(0, 0))); + itr = retItr.first; + } + + itr->second.first += size; + } + +void BandwidthMonitor::increaseClientInput(NetComputer *nc, int size) +{ + mAmountClientInput += size; + + // look for an existing client stored + ClientBandwidth::iterator itr = mClientBandwidth.find(nc); + + // if there isnt one, create it + if (itr == mClientBandwidth.end()) + { + std::pair<ClientBandwidth::iterator, bool> retItr; + retItr = mClientBandwidth.insert(std::pair<NetComputer*, std::pair<int, int> >(nc, std::pair<int, int>(0, 0))); + itr = retItr.first; + } + + itr->second.second += size; +} + diff --git a/src/net/bandwidth.hpp b/src/net/bandwidth.hpp index a524bfc0..2129fc9a 100644 --- a/src/net/bandwidth.hpp +++ b/src/net/bandwidth.hpp @@ -22,19 +22,33 @@ #ifndef _TMWSERV_BANDWIDTH_H_ #define _TMWSERV_BANDWIDTH_H_ +#include <map> + +class NetComputer; + class BandwidthMonitor { public: BandwidthMonitor(); - void increaseOutput(int size); - void increaseInput(int size); - void reset(); - int totalOut() const { return mAmountOutput; } - int totalIn() const { return mAmountInput; } + void increaseInterServerOutput(int size); + void increaseInterServerInput(int size); + void increaseClientOutput(NetComputer *nc, int size); + void increaseClientInput(NetComputer *nc, int size); + int totalInterServerOut() const { return mAmountServerOutput; } + int totalInterServerIn() const { return mAmountServerInput; } + int totalClientOut() const { return mAmountClientOutput; } + int totalClientIn() const { return mAmountClientInput; } private: - int mAmountOutput; - int mAmountInput; + int mAmountServerOutput; + int mAmountServerInput; + int mAmountClientOutput; + int mAmountClientInput; + // map of client to output and input + typedef std::map<NetComputer*, std::pair<int, int> > ClientBandwidth; + ClientBandwidth mClientBandwidth; }; +extern BandwidthMonitor *gBandwidth; + #endif diff --git a/src/net/connection.cpp b/src/net/connection.cpp index c99ee909..0b1f6079 100644 --- a/src/net/connection.cpp +++ b/src/net/connection.cpp @@ -29,7 +29,6 @@ Connection::Connection(): mRemote(0), mLocal(0) { - mBandwidth = new BandwidthMonitor; } bool Connection::start(std::string const &address, int port) @@ -68,11 +67,9 @@ 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 @@ -87,7 +84,7 @@ void Connection::send(MessageOut const &msg, bool reliable, unsigned channel) return; } - mBandwidth->increaseOutput(msg.getLength()); + gBandwidth->increaseInterServerOutput(msg.getLength()); ENetPacket *packet; packet = enet_packet_create(msg.getData(), @@ -113,7 +110,7 @@ void Connection::process() { MessageIn msg((char *)event.packet->data, event.packet->dataLength); - mBandwidth->increaseInput(event.packet->dataLength); + gBandwidth->increaseInterServerInput(event.packet->dataLength); processMessage(msg); } else @@ -129,13 +126,3 @@ 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 0d417092..f815d46b 100644 --- a/src/net/connection.hpp +++ b/src/net/connection.hpp @@ -66,16 +66,6 @@ class Connection */ void process(); - /** - * Return total output - */ - int totalOut(); - - /** - * Return total input - */ - int totalIn(); - protected: /** * Processes a single message from the remote host. @@ -85,7 +75,6 @@ class Connection private: ENetPeer *mRemote; ENetHost *mLocal; - BandwidthMonitor *mBandwidth; }; #endif diff --git a/src/net/connectionhandler.cpp b/src/net/connectionhandler.cpp index dd1828ac..3f3bb72a 100644 --- a/src/net/connectionhandler.cpp +++ b/src/net/connectionhandler.cpp @@ -23,6 +23,7 @@ #include "net/connectionhandler.hpp" #include "defines.h" +#include "net/bandwidth.hpp" #include "net/messagein.hpp" #include "net/messageout.hpp" #include "net/netcomputer.hpp" @@ -104,7 +105,7 @@ void ConnectionHandler::process(enet_uint32 timeout) LOG_DEBUG("Received message " << msg << " from " << *comp); - comp->increaseIn(event.packet->dataLength); + gBandwidth->increaseClientInput(comp, event.packet->dataLength); processMessage(comp, msg); } else { diff --git a/src/net/netcomputer.cpp b/src/net/netcomputer.cpp index 657f615b..ff2bbb71 100644 --- a/src/net/netcomputer.cpp +++ b/src/net/netcomputer.cpp @@ -35,7 +35,6 @@ NetComputer::NetComputer(ENetPeer *peer): mPeer(peer) { - mBandwidth = new BandwidthMonitor; } bool @@ -68,7 +67,7 @@ NetComputer::send(const MessageOut &msg, bool reliable, { LOG_DEBUG("Sending message " << msg << " to " << *this); - mBandwidth->increaseOutput(msg.getLength()); + gBandwidth->increaseClientOutput(this, msg.getLength()); ENetPacket *packet; packet = enet_packet_create(msg.getData(), @@ -85,30 +84,6 @@ 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 6acbb53b..b85456a6 100644 --- a/src/net/netcomputer.hpp +++ b/src/net/netcomputer.hpp @@ -81,31 +81,8 @@ 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. |