X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_alias.cpp;h=4d942854cbdeff85c5aa5dd2093a205a1ea37643;hb=e950f568d0f571e9475aa38177486468714de4d3;hp=ec426fe9b998b319927d38648037993661c40770;hpb=46a39046196f55b52336e19662bb7bac85b731ac;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_alias.cpp b/src/modules/m_alias.cpp index ec426fe9b..4d942854c 100644 --- a/src/modules/m_alias.cpp +++ b/src/modules/m_alias.cpp @@ -22,8 +22,6 @@ #include "inspircd.h" -/* $ModDesc: Provides aliases of commands. */ - /** An alias definition */ class Alias @@ -59,26 +57,23 @@ class Alias class ModuleAlias : public Module { - private: - char fprefix; /* We cant use a map, there may be multiple aliases with the same name. * We can, however, use a fancy invention: the multimap. Maps a key to one or more values. * -- w00t - */ + */ std::multimap Aliases; /* whether or not +B users are allowed to use fantasy commands */ bool AllowBots; + UserModeReference botmode; - virtual void ReadAliases() + void ReadAliases() { - ConfigReader MyConf; - - AllowBots = MyConf.ReadFlag("fantasy", "allowbots", "no", 0); - - std::string fpre = MyConf.ReadValue("fantasy","prefix",0); + ConfigTag* fantasy = ServerInstance->Config->ConfValue("fantasy"); + AllowBots = fantasy->getBool("allowbots", false); + std::string fpre = fantasy->getString("prefix", "!"); fprefix = fpre.empty() ? '!' : fpre[0]; Aliases.clear(); @@ -87,7 +82,8 @@ class ModuleAlias : public Module { ConfigTag* tag = i->second; Alias a; - a.AliasedCommand = tag->getString("text").c_str(); + std::string aliastext = tag->getString("text"); + a.AliasedCommand = aliastext.c_str(); tag->readString("replace", a.ReplaceFormat, true); a.RequiredNick = tag->getString("requires"); a.ULineOnly = tag->getBool("uline"); @@ -101,20 +97,17 @@ class ModuleAlias : public Module } public: - ModuleAlias() + : botmode(this, "bot") { - ReadAliases(); - ServerInstance->Modules->Attach(I_OnPreCommand, this); - ServerInstance->Modules->Attach(I_OnRehash, this); - ServerInstance->Modules->Attach(I_OnUserMessage, this); } - virtual ~ModuleAlias() + void init() CXX11_OVERRIDE { + ReadAliases(); } - virtual Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { return Version("Provides aliases of commands.", VF_VENDOR); } @@ -144,7 +137,7 @@ class ModuleAlias : public Module return word; } - virtual ModResult OnPreCommand(std::string &command, std::vector ¶meters, LocalUser *user, bool validated, const std::string &original_line) + ModResult OnPreCommand(std::string &command, std::vector ¶meters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE { std::multimap::iterator i, upperbound; @@ -184,9 +177,9 @@ class ModuleAlias : public Module return MOD_RES_PASSTHRU; } - virtual void OnUserMessage(User *user, void *dest, int target_type, const std::string &text, char status, const CUList &exempt_list) + void OnUserMessage(User *user, void *dest, int target_type, const std::string &text, char status, const CUList &exempt_list, MessageType msgtype) CXX11_OVERRIDE { - if (target_type != TYPE_CHANNEL) + if ((target_type != TYPE_CHANNEL) || (msgtype != MSG_PRIVMSG)) { return; } @@ -198,7 +191,7 @@ class ModuleAlias : public Module } /* Stop here if the user is +B and allowbot is set to no. */ - if (!AllowBots && user->IsModeSet('B')) + if (!AllowBots && user->IsModeSet(botmode)) { return; } @@ -253,7 +246,7 @@ class ModuleAlias : public Module } - int DoAlias(User *user, Channel *c, Alias *a, const std::string compare, const std::string safe) + int DoAlias(User *user, Channel *c, Alias *a, const std::string& compare, const std::string& safe) { User *u = NULL; @@ -272,7 +265,7 @@ class ModuleAlias : public Module } } - if ((a->OperOnly) && (!IS_OPER(user))) + if ((a->OperOnly) && (!user->IsOper())) return 0; if (!a->RequiredNick.empty()) @@ -280,7 +273,7 @@ class ModuleAlias : public Module u = ServerInstance->FindNick(a->RequiredNick); if (!u) { - user->WriteNumeric(401, ""+std::string(user->nick)+" "+a->RequiredNick+" :is currently unavailable. Please try again later."); + user->WriteNumeric(401, ""+user->nick+" "+a->RequiredNick+" :is currently unavailable. Please try again later."); return 1; } } @@ -289,7 +282,7 @@ class ModuleAlias : public Module if (!ServerInstance->ULine(u->server)) { ServerInstance->SNO->WriteToSnoMask('a', "NOTICE -- Service "+a->RequiredNick+" required by alias "+std::string(a->AliasedCommand.c_str())+" is not on a u-lined server, possibly underhanded antics detected!"); - user->WriteNumeric(401, ""+std::string(user->nick)+" "+a->RequiredNick+" :is an imposter! Please inform an IRC operator as soon as possible."); + user->WriteNumeric(401, ""+user->nick+" "+a->RequiredNick+" :is an imposter! Please inform an IRC operator as soon as possible."); return 1; } } @@ -318,7 +311,7 @@ class ModuleAlias : public Module void DoCommand(const std::string& newline, User* user, Channel *chan, const std::string &original_line) { std::string result; - result.reserve(MAXBUF); + result.reserve(newline.length()); for (unsigned int i = 0; i < newline.length(); i++) { char c = newline[i]; @@ -369,19 +362,19 @@ class ModuleAlias : public Module std::string command, token; ss.GetToken(command); - while (ss.GetToken(token) && (pars.size() <= MAXPARAMETERS)) + while (ss.GetToken(token)) { pars.push_back(token); } ServerInstance->Parser->CallHandler(command, pars, user); } - virtual void OnRehash(User* user) + void OnRehash(User* user) CXX11_OVERRIDE { ReadAliases(); } - virtual void Prioritize() + void Prioritize() { // Prioritise after spanningtree so that channel aliases show the alias before the effects. Module* linkmod = ServerInstance->Modules->Find("m_spanningtree.so");