summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-29 08:43:50 +0000
committerGuillaume Melquiond <guillaume.melquiond@gmail.com>2007-08-29 08:43:50 +0000
commitd9ae86e09977082791d5b24e304eabc5456ab4cf (patch)
tree655700119e723d637144b57de6f177d331dc4bb6 /src
parenta8dc1f23ab7eff1f6c4e59d11446e80ad6780d33 (diff)
downloadmanaserv-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.
Diffstat (limited to 'src')
-rw-r--r--src/game-server/command.cpp16
-rw-r--r--src/game-server/gamehandler.cpp15
-rw-r--r--src/game-server/gamehandler.hpp6
3 files changed, 35 insertions, 2 deletions
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 *);