summaryrefslogtreecommitdiff
path: root/src/actions/commands.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-08-25 11:47:22 +0300
committerAndrei Karas <akaras@inbox.ru>2014-08-25 11:47:22 +0300
commitd1a7fe4f55b967d7d844c0587f976d7d393b99e0 (patch)
tree8ccb940101cca150fd099c443bbeff5e6d2c380a /src/actions/commands.cpp
parentc4ce93f62d1d4e857c5f763cbee063a4dae10d59 (diff)
downloadplus-d1a7fe4f55b967d7d844c0587f976d7d393b99e0.tar.gz
plus-d1a7fe4f55b967d7d844c0587f976d7d393b99e0.tar.bz2
plus-d1a7fe4f55b967d7d844c0587f976d7d393b99e0.tar.xz
plus-d1a7fe4f55b967d7d844c0587f976d7d393b99e0.zip
Simplify relation chat commands.
Diffstat (limited to 'src/actions/commands.cpp')
-rw-r--r--src/actions/commands.cpp113
1 files changed, 49 insertions, 64 deletions
diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp
index 034dafdfb..1ec9f03c7 100644
--- a/src/actions/commands.cpp
+++ b/src/actions/commands.cpp
@@ -78,64 +78,6 @@
namespace Actions
{
-static void changeRelation(std::string args,
- const PlayerRelation::Relation relation,
- const std::string &relationText,
- ChatTab *const tab)
-{
- if (!tab)
- return;
-
- if (args.empty())
- {
- WhisperTab *const whisper = dynamic_cast<WhisperTab* const>(tab);
- if (!whisper || whisper->getNick().empty())
- {
- // TRANSLATORS: change relation
- tab->chatLog(_("Please specify a name."), ChatMsgType::BY_SERVER);
- return;
- }
- args = whisper->getNick();
- }
-
- if (player_relations.getRelation(args) == relation)
- {
- // TRANSLATORS: change relation
- tab->chatLog(strprintf(_("Player already %s!"),
- relationText.c_str()), ChatMsgType::BY_SERVER);
- return;
- }
- else
- {
- player_relations.setRelation(args, relation);
- }
-
- if (player_relations.getRelation(args) == relation)
- {
- // TRANSLATORS: change relation
- tab->chatLog(strprintf(_("Player successfully %s!"),
- relationText.c_str()), ChatMsgType::BY_SERVER);
- }
- else
- {
- // TRANSLATORS: change relation
- tab->chatLog(strprintf(_("Player could not be %s!"),
- relationText.c_str()), ChatMsgType::BY_SERVER);
- }
-}
-
-impHandler(chatAnnounce)
-{
- Net::getAdminHandler()->announce(event.args);
- return true;
-}
-
-impHandler(chatIgnore)
-{
- changeRelation(event.args, PlayerRelation::IGNORED, "ignored", event.tab);
- return true;
-}
-
static std::string getNick(const InputEvent &event)
{
std::string args = event.args;
@@ -160,7 +102,7 @@ static void reportRelation(const InputEvent &event,
{
if (event.tab)
{
- if (player_relations.getRelation(args) == rel)
+ if (player_relations.getRelation(event.args) == rel)
{
// TRANSLATORS: unignore command
event.tab->chatLog(str1, ChatMsgType::BY_SERVER);
@@ -173,6 +115,49 @@ static void reportRelation(const InputEvent &event,
}
}
+static void changeRelation(const InputEvent &event,
+ const PlayerRelation::Relation relation,
+ const std::string &relationText)
+{
+ if (!event.tab)
+ return;
+
+ std::string args = getNick(event);
+ if (args.empty())
+ return;
+
+ if (player_relations.getRelation(args) == relation)
+ {
+ // TRANSLATORS: change relation
+ event.tab->chatLog(strprintf(_("Player already %s!"),
+ relationText.c_str()), ChatMsgType::BY_SERVER);
+ return;
+ }
+ else
+ {
+ player_relations.setRelation(args, relation);
+ }
+
+ reportRelation(event,
+ relation,
+ // TRANSLATORS: change relation
+ strprintf(_("Player successfully %s!"), relationText.c_str()),
+ // TRANSLATORS: change relation
+ strprintf(_("Player could not be %s!"), relationText.c_str()));
+}
+
+impHandler(chatAnnounce)
+{
+ Net::getAdminHandler()->announce(event.args);
+ return true;
+}
+
+impHandler(chatIgnore)
+{
+ changeRelation(event, PlayerRelation::IGNORED, "ignored");
+ return true;
+}
+
impHandler(chatUnignore)
{
std::string args = getNick(event);
@@ -235,35 +220,35 @@ impHandler(chatErase)
impHandler(chatFriend)
{
// TRANSLATORS: adding friend command
- changeRelation(event.args, PlayerRelation::FRIEND, _("friend"), event.tab);
+ changeRelation(event, PlayerRelation::FRIEND, _("friend"));
return true;
}
impHandler(chatDisregard)
{
// TRANSLATORS: disregard command
- changeRelation(event.args, PlayerRelation::DISREGARDED, _("disregarded"), event.tab);
+ changeRelation(event, PlayerRelation::DISREGARDED, _("disregarded"));
return true;
}
impHandler(chatNeutral)
{
// TRANSLATORS: neutral command
- changeRelation(event.args, PlayerRelation::NEUTRAL, _("neutral"), event.tab);
+ changeRelation(event, PlayerRelation::NEUTRAL, _("neutral"));
return true;
}
impHandler(chatBlackList)
{
// TRANSLATORS: blacklist command
- changeRelation(event.args, PlayerRelation::BLACKLISTED, _("blacklisted"), event.tab);
+ changeRelation(event, PlayerRelation::BLACKLISTED, _("blacklisted"));
return true;
}
impHandler(chatEnemy)
{
// TRANSLATORS: enemy command
- changeRelation(event.args, PlayerRelation::ENEMY2, _("enemy"), event.tab);
+ changeRelation(event, PlayerRelation::ENEMY2, _("enemy"));
return true;
}