From c33d54dd45efd88f95014bd41813accb15e76f89 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 23 Aug 2014 23:16:19 +0300 Subject: Move chat command /ignore into actions. --- src/actions/commands.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'src/actions/commands.cpp') diff --git a/src/actions/commands.cpp b/src/actions/commands.cpp index c7607a2cd..7afc7efed 100644 --- a/src/actions/commands.cpp +++ b/src/actions/commands.cpp @@ -66,20 +66,74 @@ #include "gui/windows/shortcutwindow.h" #include "gui/windows/updaterwindow.h" -#include "gui/widgets/tabs/chattab.h" +#include "gui/widgets/tabs/whispertab.h" #include "net/adminhandler.h" #include "net/net.h" +#include "utils/gettext.h" + #include "debug.h" 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(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; +} + } // namespace Actions -- cgit v1.2.3-70-g09d2