diff options
Diffstat (limited to 'modules/fantasy.cpp')
-rw-r--r-- | modules/fantasy.cpp | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/modules/fantasy.cpp b/modules/fantasy.cpp index 023ef286f..20585f527 100644 --- a/modules/fantasy.cpp +++ b/modules/fantasy.cpp @@ -1,15 +1,25 @@ -/* Fantasy functionality +/* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2013-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see <http://www.gnu.org/licenses/>. */ #include "module.h" +#include "modules/fantasy.h" +#include "modules/botserv/info.h" class CommandBSSetFantasy : public Command { @@ -20,20 +30,20 @@ class CommandBSSetFantasy : public Command this->SetSyntax(_("\037channel\037 {\037ON|OFF\037}")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { - ChannelInfo *ci = ChannelInfo::Find(params[0]); + ChanServ::Channel *ci = ChanServ::Find(params[0]); const Anope::string &value = params[1]; if (ci == NULL) { - source.Reply(CHAN_X_NOT_REGISTERED, params[0].c_str()); + source.Reply(_("Channel \002{0}\002 isn't registered."), params[0]); return; } if (!source.HasPriv("botserv/administration") && !source.AccessFor(ci).HasPriv("SET")) { - source.Reply(ACCESS_DENIED); + source.Reply(_("Access denied. You do not have the \002{0}\002 privilege on \002{1}\002."), "SET", ci->GetName()); return; } @@ -46,24 +56,24 @@ class CommandBSSetFantasy : public Command if (value.equals_ci("ON")) { bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable fantasy"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to enable fantasy"; - ci->Extend<bool>("BS_FANTASY"); - source.Reply(_("Fantasy mode is now \002on\002 on channel %s."), ci->name.c_str()); + ci->SetS<bool>("BS_FANTASY", true); + source.Reply(_("Fantasy mode is now \002on\002 on channel \002{0}\002."), ci->GetName()); } else if (value.equals_ci("OFF")) { bool override = !source.AccessFor(ci).HasPriv("SET"); - Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable fantasy"; + Log(override ? LOG_OVERRIDE : LOG_COMMAND, source, this, ci) << "to disable fantasy"; - ci->Shrink<bool>("BS_FANTASY"); - source.Reply(_("Fantasy mode is now \002off\002 on channel %s."), ci->name.c_str()); + ci->UnsetS<bool>("BS_FANTASY"); + source.Reply(_("Fantasy mode is now \002off\002 on channel \002{0}\002."), ci->GetName()); } else this->OnSyntaxError(source, source.command); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(_(" \n" @@ -75,26 +85,31 @@ class CommandBSSetFantasy : public Command "Note that users wanting to use fantaisist\n" "commands MUST have enough access for both\n" "the FANTASIA and the command they are executing."), - Config->GetModule(this->owner)->Get<const Anope::string>("fantasycharacter", "!").c_str()); + Config->GetModule(this->GetOwner())->Get<Anope::string>("fantasycharacter", "!").c_str()); return true; } }; class Fantasy : public Module + , public EventHook<Event::Privmsg> + , public EventHook<Event::ServiceBotEvent> { - SerializableExtensibleItem<bool> fantasy; + Serialize::Field<ChanServ::Channel, bool> fantasy; CommandBSSetFantasy commandbssetfantasy; public: - Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR), - fantasy(this, "BS_FANTASY"), commandbssetfantasy(this) + Fantasy(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook<Event::Privmsg>(this) + , EventHook<Event::ServiceBotEvent>(this) + , fantasy(this, "BS_FANTASY") + , commandbssetfantasy(this) { } - void OnPrivmsg(User *u, Channel *c, Anope::string &msg) anope_override + void OnPrivmsg(User *u, Channel *c, Anope::string &msg) override { - if (!u || !c || !c->ci || !c->ci->bi || msg.empty() || msg[0] == '\1') + if (!u || !c || !c->ci || !c->ci->GetBot() || msg.empty() || msg[0] == '\1') return; if (Config->GetClient("BotServ") && !fantasy.HasExt(c->ci)) @@ -109,7 +124,7 @@ class Fantasy : public Module Anope::string normalized_param0 = Anope::NormalizeBuffer(params[0]); Anope::string fantasy_chars = Config->GetModule(this)->Get<Anope::string>("fantasycharacter", "!"); - if (!normalized_param0.find(c->ci->bi->nick)) + if (!normalized_param0.find(c->ci->GetBot()->nick)) { params.erase(params.begin()); } @@ -146,7 +161,7 @@ class Fantasy : public Module return; const CommandInfo &info = it->second; - ServiceReference<Command> cmd("Command", info.name); + ServiceReference<Command> cmd(info.name); if (!cmd) { Log(LOG_DEBUG) << "Fantasy command " << it->first << " exists for non-existent service " << info.name << "!"; @@ -173,22 +188,22 @@ class Fantasy : public Module if (params.size() < cmd->min_params) return; - CommandSource source(u->nick, u, u->Account(), u, c->ci->bi); + CommandSource source(u->nick, u, u->Account(), u, c->ci->GetBot()); source.c = c; source.command = it->first; source.permission = info.permission; - AccessGroup ag = c->ci->AccessFor(u); + ChanServ::AccessGroup ag = c->ci->AccessFor(u); bool has_fantasia = ag.HasPriv("FANTASIA") || source.HasPriv("botserv/fantasy"); EventReturn MOD_RESULT; if (has_fantasia) { - FOREACH_RESULT(OnBotFantasy, MOD_RESULT, (source, cmd, c->ci, params)); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotFantasy::OnBotFantasy, source, cmd, c->ci, params); } else { - FOREACH_RESULT(OnBotNoFantasyAccess, MOD_RESULT, (source, cmd, c->ci, params)); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotNoFantasyAccess::OnBotNoFantasyAccess, source, cmd, c->ci, params); } if (MOD_RESULT == EVENT_STOP || !has_fantasia) @@ -197,18 +212,18 @@ class Fantasy : public Module if (MOD_RESULT != EVENT_ALLOW && !info.permission.empty() && !source.HasCommand(info.permission)) return; - FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, cmd, params)); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreCommand::OnPreCommand, source, cmd, params); if (MOD_RESULT == EVENT_STOP) return; - Reference<NickCore> nc_reference(u->Account()); + Reference<NickServ::Account> nc_reference(u->Account()); cmd->Execute(source, params); if (!nc_reference) source.nc = NULL; - FOREACH_MOD(OnPostCommand, (source, cmd, params)); + EventManager::Get()->Dispatch(&Event::PostCommand::OnPostCommand, source, cmd, params); } - void OnBotInfo(CommandSource &source, BotInfo *bi, ChannelInfo *ci, InfoFormatter &info) + void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) override { if (fantasy.HasExt(ci)) info.AddOption(_("Fantasy")); |