summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commandhandler.cpp80
-rw-r--r--src/commandhandler.h2
-rw-r--r--src/gui/chatwindow.cpp5
-rw-r--r--src/gui/widgets/chattab.cpp3
4 files changed, 90 insertions, 0 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index d04fda150..862ac56b4 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -32,6 +32,7 @@
#include "localplayer.h"
#include "logger.h"
#include "main.h"
+#include "party.h"
#include "gui/chatwindow.h"
#include "gui/helpwindow.h"
@@ -1194,3 +1195,82 @@ void CommandHandler::handleDump(const std::string &args A_UNUSED,
{
}
#endif
+
+void CommandHandler::replaceVars(std::string &str)
+{
+ if (!player_node || !actorSpriteManager)
+ return;
+
+ if (str.find("<PLAYER>") != std::string::npos)
+ {
+ Being *target = player_node->getTarget();
+ if (!target || target->getType() != ActorSprite::PLAYER)
+ {
+ target = actorSpriteManager->findNearestLivingBeing(
+ player_node, 20, ActorSprite::PLAYER);
+ }
+ if (target)
+ replaceAll(str, "<PLAYER>", target->getName());
+ else
+ replaceAll(str, "<PLAYER>", "");
+ }
+ if (str.find("<MONSTER>") != std::string::npos)
+ {
+ Being *target = player_node->getTarget();
+ if (!target || target->getType() != ActorSprite::MONSTER)
+ {
+ target = actorSpriteManager->findNearestLivingBeing(
+ player_node, 20, ActorSprite::MONSTER);
+ }
+ if (target)
+ replaceAll(str, "<MONSTER>", target->getName());
+ else
+ replaceAll(str, "<MONSTER>", "");
+ }
+ if (str.find("<PEOPLE>") != std::string::npos)
+ {
+ std::vector<std::string> names;
+ std::string newStr = "";
+ actorSpriteManager->getPlayerNames(names, false);
+ std::vector<std::string>::const_iterator it = names.begin();
+ std::vector<std::string>::const_iterator it_end = names.end();
+ for (; it != it_end; ++ it)
+ {
+ if (*it != player_node->getName())
+ newStr += *it + ",";
+ }
+ if (newStr[newStr.size() - 1] == ',')
+ newStr = newStr.substr(0, newStr.size() - 1);
+ if (!newStr.empty())
+ replaceAll(str, "<PEOPLE>", newStr);
+ else
+ replaceAll(str, "<PEOPLE>", "");
+ }
+ if (str.find("<PARTY>") != std::string::npos)
+ {
+ std::vector<std::string> names;
+ std::string newStr = "";
+ Party *party = nullptr;
+ if (player_node->isInParty() && (party = player_node->getParty()))
+ {
+ party->getNames(names);
+ std::vector<std::string>::const_iterator it = names.begin();
+ std::vector<std::string>::const_iterator it_end = names.end();
+ for (; it != it_end; ++ it)
+ {
+ if (*it != player_node->getName())
+ newStr += *it + ",";
+ }
+ if (newStr[newStr.size() - 1] == ',')
+ newStr = newStr.substr(0, newStr.size() - 1);
+ if (!newStr.empty())
+ replaceAll(str, "<PARTY>", newStr);
+ else
+ replaceAll(str, "<PARTY>", "");
+ }
+ else
+ {
+ replaceAll(str, "<PARTY>", "");
+ }
+ }
+}
diff --git a/src/commandhandler.h b/src/commandhandler.h
index f8b44e04f..b97b191ff 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -59,6 +59,8 @@ class CommandHandler
void handleCommands(const std::string &command,
ChatTab *tab = localChatTab);
+ void replaceVars(std::string &str);
+
static char parseBoolean(const std::string &value);
protected:
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 33c24e9c7..84d61cf65 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -24,6 +24,7 @@
#include "actorspritemanager.h"
#include "client.h"
+#include "commandhandler.h"
#include "configuration.h"
#include "guild.h"
#include "keyboardconfig.h"
@@ -305,6 +306,10 @@ void ChatWindow::fillCommands()
mCommands.push_back("/serverunignoreall");
mCommands.push_back("/dumpg");
mCommands.push_back("/pseudoaway ");
+ mCommands.push_back("<PLAYER>");
+ mCommands.push_back("<MONSTER>");
+ mCommands.push_back("<PEOPLE>");
+ mCommands.push_back("<PARTY>");
}
void ChatWindow::loadGMCommands()
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 72af1b0b8..c2db20574 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -349,6 +349,9 @@ void ChatTab::chatInput(const std::string &message)
start = msg.find('[', start + 1);
}
+ if (commandHandler)
+ commandHandler->replaceVars(msg);
+
// Prepare ordinary message
if (msg[0] != '/')
handleInput(msg);