diff options
author | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-29 08:43:50 +0000 |
---|---|---|
committer | Guillaume Melquiond <guillaume.melquiond@gmail.com> | 2007-08-29 08:43:50 +0000 |
commit | d9ae86e09977082791d5b24e304eabc5456ab4cf (patch) | |
tree | 655700119e723d637144b57de6f177d331dc4bb6 | |
parent | a8dc1f23ab7eff1f6c4e59d11446e80ad6780d33 (diff) | |
download | manaserv-d9ae86e09977082791d5b24e304eabc5456ab4cf.tar.gz manaserv-d9ae86e09977082791d5b24e304eabc5456ab4cf.tar.bz2 manaserv-d9ae86e09977082791d5b24e304eabc5456ab4cf.tar.xz manaserv-d9ae86e09977082791d5b24e304eabc5456ab4cf.zip |
Completed handler for admin commands, so that they can also touch local players.
-rw-r--r-- | ChangeLog | 3 | ||||
-rw-r--r-- | src/game-server/command.cpp | 16 | ||||
-rw-r--r-- | src/game-server/gamehandler.cpp | 15 | ||||
-rw-r--r-- | src/game-server/gamehandler.hpp | 6 |
4 files changed, 38 insertions, 2 deletions
@@ -2,6 +2,9 @@ * data/scripts/libtmw.lua: Fixed race condition between quest_reply and npc_next. + * src/game-server/command.cpp, src/game-server/gamehandler.cpp, + src/game-server/gamehandler.hpp: Completed handler for admin commands, + so that they can also touch local players. 2007-08-28 Guillaume Melquiond <guillaume.melquiond@gmail.com> diff --git a/src/game-server/command.cpp b/src/game-server/command.cpp index d4327c39..94207439 100644 --- a/src/game-server/command.cpp +++ b/src/game-server/command.cpp @@ -25,6 +25,7 @@ #include "defines.h" #include "game-server/character.hpp" +#include "game-server/gamehandler.hpp" #include "game-server/inventory.hpp" #include "game-server/item.hpp" #include "game-server/itemmanager.hpp" @@ -269,8 +270,19 @@ void runCommand(Character *ch, std::string const &text) } else { - // TODO: explicitly named character. - return; + GameClient *c = gameHandler->getClientByNameSlow(arg); + if (!c) + { + /* TODO: forward command to other game servers through + account server, in case the player is elsewhere. */ + return; + } + if (c->status != CLIENT_CONNECTED) + { + // No suitable character. + return; + } + args[i] = (intptr_t)c->character; } break; diff --git a/src/game-server/gamehandler.cpp b/src/game-server/gamehandler.cpp index df72c6b7..40507d9a 100644 --- a/src/game-server/gamehandler.cpp +++ b/src/game-server/gamehandler.cpp @@ -537,3 +537,18 @@ GameHandler::deletePendingConnect(Character* character) { delete character; } + +GameClient *GameHandler::getClientByNameSlow(std::string const &name) +{ + for (NetComputers::const_iterator i = clients.begin(), + i_end = clients.end(); i != i_end; ++i) + { + GameClient *c = static_cast< GameClient * >(*i); + Character *ch = c->character; + if (ch && ch->getName() == name) + { + return c; + } + } + return NULL; +} diff --git a/src/game-server/gamehandler.hpp b/src/game-server/gamehandler.hpp index b82d4e7f..f564c60d 100644 --- a/src/game-server/gamehandler.hpp +++ b/src/game-server/gamehandler.hpp @@ -109,6 +109,12 @@ class GameHandler: public ConnectionHandler void deletePendingConnect(Character* character); + /** + * Gets the client associated to a character name. This method is slow, + * so it should never be called for regular operations. + */ + GameClient *getClientByNameSlow(std::string const &); + protected: NetComputer *computerConnected(ENetPeer *); void computerDisconnected(NetComputer *); |