diff options
author | Adam <Adam@anope.org> | 2013-05-27 19:36:37 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-05-27 19:36:37 -0400 |
commit | 37b3535543b81c3d75c8f62b83d422f0d2fbced0 (patch) | |
tree | 8a062415c91d352e4b6bd180cbf238d1f159802d /src | |
parent | c21e8d9204f9b671177a63d4daa21957bffc1d9f (diff) |
Initially attach all modules to all events, and detach them as the events are run if they are not implemented per module
Diffstat (limited to 'src')
-rw-r--r-- | src/access.cpp | 4 | ||||
-rw-r--r-- | src/bots.cpp | 14 | ||||
-rw-r--r-- | src/channels.cpp | 34 | ||||
-rw-r--r-- | src/command.cpp | 4 | ||||
-rw-r--r-- | src/config.cpp | 2 | ||||
-rw-r--r-- | src/init.cpp | 2 | ||||
-rw-r--r-- | src/logger.cpp | 2 | ||||
-rw-r--r-- | src/main.cpp | 8 | ||||
-rw-r--r-- | src/messages.cpp | 18 | ||||
-rw-r--r-- | src/misc.cpp | 4 | ||||
-rw-r--r-- | src/modes.cpp | 6 | ||||
-rw-r--r-- | src/modulemanager.cpp | 98 | ||||
-rw-r--r-- | src/nickalias.cpp | 2 | ||||
-rw-r--r-- | src/nickcore.cpp | 18 | ||||
-rw-r--r-- | src/process.cpp | 2 | ||||
-rw-r--r-- | src/regchannel.cpp | 18 | ||||
-rw-r--r-- | src/serialize.cpp | 14 | ||||
-rw-r--r-- | src/servers.cpp | 10 | ||||
-rw-r--r-- | src/uplink.cpp | 6 | ||||
-rw-r--r-- | src/users.cpp | 20 |
20 files changed, 146 insertions, 140 deletions
diff --git a/src/access.cpp b/src/access.cpp index a8da63c50..b0c98b9db 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -308,13 +308,13 @@ bool AccessGroup::HasPriv(const Anope::string &name) const else if (this->founder) return true; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnGroupCheckPriv, OnGroupCheckPriv(this, name)); + FOREACH_RESULT(OnGroupCheckPriv, MOD_RESULT, (this, name)); if (MOD_RESULT != EVENT_CONTINUE) return MOD_RESULT == EVENT_ALLOW; for (unsigned i = this->size(); i > 0; --i) { ChanAccess *access = this->at(i - 1); - FOREACH_RESULT(I_OnCheckPriv, OnCheckPriv(access, name)); + FOREACH_RESULT(OnCheckPriv, MOD_RESULT, (access, name)); if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name)) return true; } diff --git a/src/bots.cpp b/src/bots.cpp index 3ea2ef485..74cf0d9e4 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -31,7 +31,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A if (!this->uid.empty()) (*BotListByUID)[this->uid] = this; - FOREACH_MOD(I_OnCreateBot, OnCreateBot(this)); + FOREACH_MOD(OnCreateBot, (this)); // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) @@ -49,7 +49,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A BotInfo::~BotInfo() { - FOREACH_MOD(I_OnDelBot, OnDelBot(this)); + FOREACH_MOD(OnDelBot, (this)); // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) @@ -133,8 +133,8 @@ const std::set<ChannelInfo *> &BotInfo::GetChannels() const void BotInfo::Assign(User *u, ChannelInfo *ci) { - EventReturn MOD_RESULT = EVENT_CONTINUE; - FOREACH_RESULT(I_OnPreBotAssign, OnPreBotAssign(u, ci, this)); + EventReturn MOD_RESULT; + FOREACH_RESULT(OnPreBotAssign, MOD_RESULT, (u, ci, this)); if (MOD_RESULT == EVENT_STOP) return; @@ -144,13 +144,13 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) ci->bi = this; this->channels->insert(ci); - FOREACH_MOD(I_OnBotAssign, OnBotAssign(u, ci, this)); + FOREACH_MOD(OnBotAssign, (u, ci, this)); } void BotInfo::UnAssign(User *u, ChannelInfo *ci) { - EventReturn MOD_RESULT = EVENT_CONTINUE; - FOREACH_RESULT(I_OnBotUnAssign, OnBotUnAssign(u, ci)); + EventReturn MOD_RESULT; + FOREACH_RESULT(OnBotUnAssign, MOD_RESULT, (u, ci)); if (MOD_RESULT == EVENT_STOP) return; diff --git a/src/channels.cpp b/src/channels.cpp index d774b8c8d..8e391699e 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -45,12 +45,12 @@ Channel::Channel(const Anope::string &nname, time_t ts) if (Me && Me->IsSynced()) Log(NULL, this, "create"); - FOREACH_MOD(I_OnChannelCreate, OnChannelCreate(this)); + FOREACH_MOD(OnChannelCreate, (this)); } Channel::~Channel() { - FOREACH_MOD(I_OnChannelDelete, OnChannelDelete(this)); + FOREACH_MOD(OnChannelDelete, (this)); ModeManager::StackerDel(this); @@ -87,7 +87,7 @@ void Channel::Reset() void Channel::Sync() { - FOREACH_MOD(I_OnChannelSync, OnChannelSync(this)); + FOREACH_MOD(OnChannelSync, (this)); } void Channel::CheckModes() @@ -104,7 +104,7 @@ void Channel::CheckModes() } EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnCheckModes, OnCheckModes(this)); + FOREACH_RESULT(OnCheckModes, MOD_RESULT, (this)); if (MOD_RESULT == EVENT_STOP) return; @@ -164,7 +164,7 @@ bool Channel::CheckDelete() return false; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnCheckDelete, OnCheckDelete(this)); + FOREACH_RESULT(OnCheckDelete, MOD_RESULT, (this)); return MOD_RESULT != EVENT_STOP && this->users.empty(); } @@ -174,7 +174,7 @@ ChanUserContainer* Channel::JoinUser(User *user) if (user->server && user->server->IsSynced()) Log(user, this, "join"); - FOREACH_MOD(I_OnJoinChannel, OnJoinChannel(user, this)); + FOREACH_MOD(OnJoinChannel, (user, this)); ChanUserContainer *cuc = new ChanUserContainer(user, this); user->chans[this] = cuc; @@ -188,7 +188,7 @@ void Channel::DeleteUser(User *user) if (user->server && user->server->IsSynced() && !user->Quitting()) Log(user, this, "leave"); - FOREACH_MOD(I_OnLeaveChannel, OnLeaveChannel(user, this)); + FOREACH_MOD(OnLeaveChannel, (user, this)); ChanUserContainer *cu = user->FindChannel(this); if (!this->users.erase(user)) @@ -311,7 +311,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop if (cc) cc->status.AddMode(cm->mchar); - FOREACH_RESULT(I_OnChannelModeSet, OnChannelModeSet(this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm->name, param)); /* Enforce secureops, etc */ if (enforce_mlock && MOD_RESULT != EVENT_STOP) @@ -335,7 +335,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop cml->OnAdd(this, param); } - FOREACH_RESULT(I_OnChannelModeSet, OnChannelModeSet(this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm->name, param)); /* Check if we should enforce mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) @@ -376,7 +376,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A if (cc) cc->status.DelMode(cm->mchar); - FOREACH_RESULT(I_OnChannelModeUnset, OnChannelModeUnset(this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm->name, param)); if (enforce_mlock && MOD_RESULT != EVENT_STOP) this->SetCorrectModes(u, false); @@ -403,7 +403,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A cml->OnDel(this, param); } - FOREACH_RESULT(I_OnChannelModeUnset, OnChannelModeUnset(this, setter, cm->name, param)); + FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm->name, param)); /* Check for mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) @@ -752,9 +752,9 @@ void Channel::KickInternal(MessageSource &source, const Anope::string &nick, con Anope::string this_name = this->name; ChannelStatus status = cu->status; - FOREACH_MOD(I_OnPreUserKicked, OnPreUserKicked(source, cu, reason)); + FOREACH_MOD(OnPreUserKicked, (source, cu, reason)); this->DeleteUser(target); /* This can delete this; */ - FOREACH_MOD(I_OnUserKicked, OnUserKicked(source, target, this_name, status, reason)); + FOREACH_MOD(OnUserKicked, (source, target, this_name, status, reason)); } bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) @@ -777,7 +777,7 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) bi = this->ci->WhoSends(); EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnBotKick, OnBotKick(bi, this, u, buf)); + FOREACH_RESULT(OnBotKick, MOD_RESULT, (bi, this, u, buf)); if (MOD_RESULT == EVENT_STOP) return false; IRCD->SendKick(bi, this, u, "%s", buf); @@ -797,7 +797,7 @@ void Channel::ChangeTopicInternal(const Anope::string &user, const Anope::string Log(LOG_DEBUG) << "Topic of " << this->name << " changed by " << (u ? u->nick : user) << " to " << newtopic; - FOREACH_MOD(I_OnTopicUpdated, OnTopicUpdated(this, user, this->topic)); + FOREACH_MOD(OnTopicUpdated, (this, user, this->topic)); } void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts) @@ -813,7 +813,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop /* Now that the topic is set update the time set. This is *after* we set it so the protocol modules are able to tell the old last set time */ this->topic_time = Anope::CurTime; - FOREACH_MOD(I_OnTopicUpdated, OnTopicUpdated(this, user, this->topic)); + FOREACH_MOD(OnTopicUpdated, (this, user, this->topic)); } void Channel::SetCorrectModes(User *user, bool give_modes) @@ -836,7 +836,7 @@ void Channel::SetCorrectModes(User *user, bool give_modes) */ bool take_modes = (registered && !this->HasMode("REGISTERED")) || (!registered && this->syncing && user->server->IsSynced()); - FOREACH_MOD(I_OnSetCorrectModes, OnSetCorrectModes(user, this, u_access, give_modes, take_modes)); + FOREACH_MOD(OnSetCorrectModes, (user, this, u_access, give_modes, take_modes)); /* Never take modes from ulines */ take_modes &= !user->server->IsULined(); diff --git a/src/command.cpp b/src/command.cpp index 421c90b93..c3131bda2 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -259,7 +259,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) source.permission = info.permission; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, c, params)); + FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, c, params)); if (MOD_RESULT == EVENT_STOP) return; @@ -279,7 +279,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) } c->Execute(source, params); - FOREACH_MOD(I_OnPostCommand, OnPostCommand(source, c, params)); + FOREACH_MOD(OnPostCommand, (source, c, params)); } bool Command::FindCommandFromService(const Anope::string &command_service, BotInfo* &bot, Anope::string &name) diff --git a/src/config.cpp b/src/config.cpp index d90c9728c..e560a6896 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -130,7 +130,7 @@ Conf::Conf() : Block("") this->LoadConf(f); } - FOREACH_MOD(I_OnReload, OnReload(this)); + FOREACH_MOD(OnReload, (this)); /* Check for modified values that aren't allowed to be modified */ if (Config) diff --git a/src/init.cpp b/src/init.cpp index 0a93c07f5..3cd27cddd 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -463,7 +463,7 @@ void Anope::Init(int ac, char **av) /* Load up databases */ Log() << "Loading databases..."; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnLoadDatabase, OnLoadDatabase()); + FOREACH_RESULT(OnLoadDatabase, MOD_RESULT, ()); static_cast<void>(MOD_RESULT); Log() << "Databases loaded"; diff --git a/src/logger.cpp b/src/logger.cpp index 3873c1dee..f5b7ff55c 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -129,7 +129,7 @@ Log::~Log() else if (this->type == LOG_TERMINAL) std::cout << this->BuildPrefix() << this->buf.str() << std::endl; - FOREACH_MOD(I_OnLog, OnLog(this)); + FOREACH_MOD(OnLog, (this)); if (Config) for (unsigned i = 0; i < Config->LogInfos.size(); ++i) diff --git a/src/main.cpp b/src/main.cpp index 576df28a6..d799d9a21 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -60,7 +60,7 @@ class ExpireTimer : public Timer void Tick(time_t) anope_override { - FOREACH_MOD(I_OnExpireTick, OnExpireTick()); + FOREACH_MOD(OnExpireTick, ()); } }; @@ -70,7 +70,7 @@ void Anope::SaveDatabases() return; Log(LOG_DEBUG) << "Saving databases"; - FOREACH_MOD(I_OnSaveDatabase, OnSaveDatabase()); + FOREACH_MOD(OnSaveDatabase, ()); } /** The following comes from InspIRCd to get the full path of the Anope executable @@ -181,11 +181,11 @@ int main(int ac, char **av, char **envp) if (Anope::Restarting) { - FOREACH_MOD(I_OnRestart, OnRestart()); + FOREACH_MOD(OnRestart, ()); } else { - FOREACH_MOD(I_OnShutdown, OnShutdown()); + FOREACH_MOD(OnShutdown, ()); } if (Anope::QuitReason.empty()) diff --git a/src/messages.cpp b/src/messages.cpp index d9a89ef46..f651b7352 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -25,7 +25,7 @@ using namespace Message; void Away::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - FOREACH_MOD(I_OnUserAway, OnUserAway(source.GetUser(), params.empty() ? "" : params[0])); + FOREACH_MOD(OnUserAway, (source.GetUser(), params.empty() ? "" : params[0])); } void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) @@ -57,7 +57,7 @@ void Invite::Run(MessageSource &source, const std::vector<Anope::string> ¶ms if (!targ || targ->server != Me || !c || c->FindUser(targ)) return; - FOREACH_MOD(I_OnInvite, OnInvite(source.GetUser(), c, targ)); + FOREACH_MOD(OnInvite, (source.GetUser(), c, targ)); } void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) @@ -79,9 +79,9 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) ++it; Anope::string channame = cc->chan->name; - FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(user, cc->chan)); + FOREACH_MOD(OnPrePartChannel, (user, cc->chan)); cc->chan->DeleteUser(user); - FOREACH_MOD(I_OnPartChannel, OnPartChannel(user, Channel::Find(channame), channame, "")); + FOREACH_MOD(OnPartChannel, (user, Channel::Find(channame), channame, "")); } continue; } @@ -261,10 +261,10 @@ void Part::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) continue; Log(u, c, "part") << "Reason: " << (!reason.empty() ? reason : "No reason"); - FOREACH_MOD(I_OnPrePartChannel, OnPrePartChannel(u, c)); + FOREACH_MOD(OnPrePartChannel, (u, c)); Anope::string ChannelName = c->name; c->DeleteUser(u); - FOREACH_MOD(I_OnPartChannel, OnPartChannel(u, c, ChannelName, !reason.empty() ? reason : "")); + FOREACH_MOD(OnPartChannel, (u, c, ChannelName, !reason.empty() ? reason : "")); } } @@ -285,7 +285,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m Channel *c = Channel::Find(receiver); if (c) { - FOREACH_MOD(I_OnPrivmsg, OnPrivmsg(u, c, message)); + FOREACH_MOD(OnPrivmsg, (u, c, message)); } } else @@ -316,7 +316,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m if (bi) { EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnBotPrivmsg, OnBotPrivmsg(u, bi, message)); + FOREACH_RESULT(OnBotPrivmsg, MOD_RESULT, (u, bi, message)); if (MOD_RESULT == EVENT_STOP) return; @@ -364,7 +364,7 @@ void SQuit::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) return; } - FOREACH_MOD(I_OnServerQuit, OnServerQuit(s)); + FOREACH_MOD(OnServerQuit, (s)); s->Delete(s->GetName() + " " + s->GetUplink()->GetName()); } diff --git a/src/misc.cpp b/src/misc.cpp index 6fb9e8c91..fd08ffb2a 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -477,7 +477,7 @@ bool Anope::Match(const Anope::string &str, const Anope::string &mask, bool case void Anope::Encrypt(const Anope::string &src, Anope::string &dest) { EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnEncrypt, OnEncrypt(src, dest)); + FOREACH_RESULT(OnEncrypt, MOD_RESULT, (src, dest)); static_cast<void>(MOD_RESULT); } @@ -492,7 +492,7 @@ bool Anope::Decrypt(const Anope::string &src, Anope::string &dest) Anope::string hashm(src.begin(), src.begin() + pos); EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnDecrypt, OnDecrypt(hashm, src, dest)); + FOREACH_RESULT(OnDecrypt, MOD_RESULT, (hashm, src, dest)); if (MOD_RESULT == EVENT_ALLOW) return true; diff --git a/src/modes.cpp b/src/modes.cpp index 2e9a49f09..8eab97480 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -140,7 +140,7 @@ ChannelMode::~ChannelMode() bool ChannelMode::CanSet(User *u) const { EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnCanSet, OnCanSet(u, this)); + FOREACH_RESULT(OnCanSet, MOD_RESULT, (u, this)); return MOD_RESULT != EVENT_STOP; } @@ -350,7 +350,7 @@ bool ModeManager::AddUserMode(UserMode *um) UserModesByName[um->name] = um; - FOREACH_MOD(I_OnUserModeAdd, OnUserModeAdd(um)); + FOREACH_MOD(OnUserModeAdd, (um)); return true; } @@ -384,7 +384,7 @@ bool ModeManager::AddChannelMode(ChannelMode *cm) ChannelModesByName[cm->name] = cm; - FOREACH_MOD(I_OnChannelModeAdd, OnChannelModeAdd(cm)); + FOREACH_MOD(OnChannelModeAdd, (cm)); return true; } diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 211304cae..a3719b412 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -22,7 +22,7 @@ #endif std::list<Module *> ModuleManager::Modules; -std::vector<Module *> ModuleManager::EventHandlers[I_END]; +std::map<Anope::string, std::vector<Module *> > ModuleManager::EventHandlers; #ifdef _WIN32 void ModuleManager::CleanupRuntimeDirectory() @@ -112,6 +112,19 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out } #endif +std::vector<Module *> &ModuleManager::GetEventHandlers(const Anope::string &name) +{ + std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.find(name); + if (it != EventHandlers.end()) + return it->second; + + std::vector<Module *> &modules = EventHandlers[name]; + /* Populate initial vector */ + std::copy(Modules.begin(), Modules.end(), std::back_inserter(modules)); + + return modules; +} + /* This code was found online at http://www.linuxjournal.com/article/3687#comment-26593 * * This function will take a pointer from either dlsym or GetProcAddress and cast it in @@ -226,24 +239,38 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) else Log(LOG_DEBUG_2) << "Module " << modname << " is compiled against current version of Anope " << Anope::VersionShort(); - /* If the module is hooked to the reload event it wants to initialize its config here */ - if (std::find(EventHandlers[I_OnReload].begin(), EventHandlers[I_OnReload].end(), m) != EventHandlers[I_OnReload].end()) + /* Initialize config */ + try + { + m->OnReload(Config); + } + catch (const ModuleException &ex) + { + Log() << "Module " << modname << " couldn't load:" << ex.GetReason(); + DeleteModule(m); + return MOD_ERR_EXCEPTION; + } + catch (const ConfigException &ex) + { + Log() << "Module " << modname << " couldn't load due to configuration problems: " << ex.GetReason(); + DeleteModule(m); + return MOD_ERR_EXCEPTION; + } + catch (const NotImplementedException &ex) { - try - { - m->OnReload(Config); - } - catch (const ConfigException &ex) - { - Log() << "Module " << modname << " couldn't load due to configuration problems: " << ex.GetReason(); - DeleteModule(m); - return MOD_ERR_EXCEPTION; - } } Log(LOG_DEBUG) << "Module " << modname << " loaded."; - FOREACH_MOD(I_OnModuleLoad, OnModuleLoad(u, m)); + /* Attach module to all events */ + for (std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) + /* Modules can already be attached here if loading them causes a new event to trigged, which initializes this vector + * to all known modules, which includes this one. + */ + if (std::find(it->second.begin(), it->second.end(), m) != it->second.end()) + it->second.push_back(m); + + FOREACH_MOD(OnModuleLoad, (u, m)); return MOD_ERR_OK; } @@ -253,7 +280,7 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u) if (!m) return MOD_ERR_PARAMS; - FOREACH_MOD(I_OnModuleUnload, OnModuleUnload(u, m)); + FOREACH_MOD(OnModuleUnload, (u, m)); return DeleteModule(m); } @@ -340,47 +367,26 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) return MOD_ERR_OK; } -bool ModuleManager::Attach(Implementation i, Module *mod) -{ - if (std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod) != EventHandlers[i].end()) - return false; - - EventHandlers[i].push_back(mod); - return true; -} - -bool ModuleManager::Detach(Implementation i, Module *mod) -{ - std::vector<Module *>::iterator x = std::find(EventHandlers[i].begin(), EventHandlers[i].end(), mod); - - if (x == EventHandlers[i].end()) - return false; - - EventHandlers[i].erase(x); - return true; -} - -void ModuleManager::Attach(Implementation *i, Module *mod, size_t sz) -{ - for (size_t n = 0; n < sz; ++n) - Attach(i[n], mod); -} - void ModuleManager::DetachAll(Module *mod) { - for (size_t n = I_BEGIN + 1; n != I_END; ++n) - Detach(static_cast<Implementation>(n), mod); + for (std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) + { + std::vector<Module *> &mods = it->second; + std::vector<Module *>::iterator it2 = std::find(mods.begin(), mods.end(), mod); + if (it2 != mods.end()) + mods.erase(it2); + } } bool ModuleManager::SetPriority(Module *mod, Priority s) { - for (size_t n = I_BEGIN + 1; n != I_END; ++n) - SetPriority(mod, static_cast<Implementation>(n), s); + for (std::map<Anope::string, std::vector<Module *> >::iterator it = EventHandlers.begin(); it != EventHandlers.end(); ++it) + SetPriority(mod, it->first, s); return true; } -bool ModuleManager::SetPriority(Module *mod, Implementation i, Priority s, Module **modules, size_t sz) +bool ModuleManager::SetPriority(Module *mod, const Anope::string &i, Priority s, Module **modules, size_t sz) { /** To change the priority of a module, we first find its position in the vector, * then we find the position of the other modules in the vector that this module diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 327340a1d..1595987e4 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -51,7 +51,7 @@ NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Serial NickAlias::~NickAlias() { - FOREACH_MOD(I_OnDelNick, OnDelNick(this)); + FOREACH_MOD(OnDelNick, (this)); /* Accept nicks that have no core, because of database load functions */ if (this->nc) diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 9e2ff8dbb..5779767dd 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -33,12 +33,12 @@ NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), if (old == NickCoreList->size()) Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?"; - FOREACH_MOD(I_OnNickCoreCreate, OnNickCoreCreate(this)); + FOREACH_MOD(OnNickCoreCreate, (this)); } NickCore::~NickCore() { - FOREACH_MOD(I_OnDelCore, OnDelCore(this)); + FOREACH_MOD(OnDelCore, (this)); if (!this->chanaccess->empty()) Log(LOG_DEBUG) << "Non-empty chanaccess list in destructor!"; @@ -140,7 +140,7 @@ void NickCore::SetDisplay(const NickAlias *na) if (na->nc != this || na->nick == this->display) return; - FOREACH_MOD(I_OnChangeCoreDisplay, OnChangeCoreDisplay(this, na->nick)); + FOREACH_MOD(OnChangeCoreDisplay, (this, na->nick)); /* Remove the core from the list */ NickCoreList->erase(this->display); @@ -158,7 +158,7 @@ bool NickCore::IsServicesOper() const void NickCore::AddAccess(const Anope::string &entry) { this->access.push_back(entry); - FOREACH_MOD(I_OnNickAddAccess, OnNickAddAccess(this, entry)); + FOREACH_MOD(OnNickAddAccess, (this, entry)); } Anope::string NickCore::GetAccess(unsigned entry) const @@ -187,7 +187,7 @@ void NickCore::EraseAccess(const Anope::string &entry) for (unsigned i = 0, end = this->access.size(); i < end; ++i) if (this->access[i] == entry) { - FOREACH_MOD(I_OnNickEraseAccess, OnNickEraseAccess(this, entry)); + FOREACH_MOD(OnNickEraseAccess, (this, entry)); this->access.erase(this->access.begin() + i); break; } @@ -195,7 +195,7 @@ void NickCore::EraseAccess(const Anope::string &entry) void NickCore::ClearAccess() { - FOREACH_MOD(I_OnNickClearAccess, OnNickClearAccess(this)); + FOREACH_MOD(OnNickClearAccess, (this)); this->access.clear(); } @@ -219,7 +219,7 @@ bool NickCore::IsOnAccess(const User *u) const void NickCore::AddCert(const Anope::string &entry) { this->cert.push_back(entry); - FOREACH_MOD(I_OnNickAddCert, OnNickAddCert(this, entry)); + FOREACH_MOD(OnNickAddCert, (this, entry)); } Anope::string NickCore::GetCert(unsigned entry) const @@ -243,7 +243,7 @@ void NickCore::EraseCert(const Anope::string &entry) for (unsigned i = 0, end = this->cert.size(); i < end; ++i) if (this->cert[i] == entry) { - FOREACH_MOD(I_OnNickEraseCert, OnNickEraseCert(this, entry)); + FOREACH_MOD(OnNickEraseCert, (this, entry)); this->cert.erase(this->cert.begin() + i); break; } @@ -251,7 +251,7 @@ void NickCore::EraseCert(const Anope::string &entry) void NickCore::ClearCert() { - FOREACH_MOD(I_OnNickClearCert, OnNickClearCert(this)); + FOREACH_MOD(OnNickClearCert, (this)); this->cert.clear(); } diff --git a/src/process.cpp b/src/process.cpp index a767b87c2..649228f03 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -70,7 +70,7 @@ void Anope::Process(const Anope::string &buffer) MessageSource src(source); EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnMessage, OnMessage(src, command, params)); + FOREACH_RESULT(OnMessage, MOD_RESULT, (src, command, params)); if (MOD_RESULT == EVENT_STOP) return; diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 2fcb3ca14..bd8c3dca0 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -292,7 +292,7 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInf if (old == RegisteredChannelList->size()) Log(LOG_DEBUG) << "Duplicate channel " << this->name << " in registered channel table?"; - FOREACH_MOD(I_OnCreateChan, OnCreateChan(this)); + FOREACH_MOD(OnCreateChan, (this)); } ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), @@ -348,12 +348,12 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), this->log_settings->push_back(l); } - FOREACH_MOD(I_OnCreateChan, OnCreateChan(this)); + FOREACH_MOD(OnCreateChan, (this)); } ChannelInfo::~ChannelInfo() { - FOREACH_MOD(I_OnDelChan, OnDelChan(this)); + FOREACH_MOD(OnDelChan, (this)); Log(LOG_DEBUG) << "Deleting channel " << this->name; @@ -766,7 +766,7 @@ BadWord* ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type) this->badwords->push_back(bw); - FOREACH_MOD(I_OnBadWordAdd, OnBadWordAdd(this, bw)); + FOREACH_MOD(OnBadWordAdd, (this, bw)); return bw; } @@ -791,7 +791,7 @@ void ChannelInfo::EraseBadWord(unsigned index) if (this->badwords->empty() || index >= this->badwords->size()) return; - FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, (*this->badwords)[index])); + FOREACH_MOD(OnBadWordDel, (this, (*this->badwords)[index])); delete this->badwords->at(index); } @@ -838,7 +838,7 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string & std::pair<Anope::string, ModeLock *> ml = std::make_pair(mode->name, new ModeLock(this, status, mode->name, param, setter, created)); EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnMLock, OnMLock(this, ml.second)); + FOREACH_RESULT(OnMLock, MOD_RESULT, (this, ml.second)); if (MOD_RESULT == EVENT_STOP) return false; @@ -891,7 +891,7 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin continue; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second)); + FOREACH_RESULT(OnUnMLock, MOD_RESULT, (this, it->second)); if (MOD_RESULT != EVENT_STOP) { delete it->second; @@ -913,7 +913,7 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin if (ml->set == status && ml->param == param) { EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second)); + FOREACH_RESULT(OnUnMLock, MOD_RESULT, (this, it->second)); if (MOD_RESULT == EVENT_STOP) return false; delete it->second; @@ -1026,7 +1026,7 @@ bool ChannelInfo::CheckKick(User *user) Anope::string mask, reason; EventReturn MOD_RESULT; - FOREACH_RESULT(I_OnCheckKick, OnCheckKick(user, this, mask, reason)); + FOREACH_RESULT(OnCheckKick, MOD_RESULT, (user, this, mask, reason)); if (MOD_RESULT != EVENT_STOP) return false; diff --git a/src/serialize.cpp b/src/serialize.cpp index bb95cdc41..ef79bc396 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -55,7 +55,7 @@ Serializable::Serializable(const Anope::string &serialize_type) : last_commit(0) this->s_iter = SerializableItems->end(); --this->s_iter; - FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this)); + FOREACH_MOD(OnSerializableConstruct, (this)); } Serializable::Serializable(const Serializable &other) : last_commit(0), last_commit_time(0), id(0), redis_ignore(0) @@ -66,12 +66,12 @@ Serializable::Serializable(const Serializable &other) : last_commit(0), last_com this->s_type = other.s_type; - FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this)); + FOREACH_MOD(OnSerializableConstruct, (this)); } Serializable::~Serializable() { - FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this)); + FOREACH_MOD(OnSerializableDestruct, (this)); SerializableItems->erase(this->s_iter); } @@ -84,10 +84,10 @@ Serializable &Serializable::operator=(const Serializable &) void Serializable::QueueUpdate() { /* Schedule updater */ - FOREACH_MOD(I_OnSerializableUpdate, OnSerializableUpdate(this)); + FOREACH_MOD(OnSerializableUpdate, (this)); /* Check for modifications now - this can delete this object! */ - FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this->GetSerializableType())); + FOREACH_MOD(OnSerializeCheck, (this->GetSerializableType())); } bool Serializable::IsCached(Serialize::Data &data) @@ -120,7 +120,7 @@ Type::Type(const Anope::string &n, unserialize_func f, Module *o) : name(n), un TypeOrder.push_back(this->name); Types[this->name] = this; - FOREACH_MOD(I_OnSerializeTypeCreate, OnSerializeTypeCreate(this)); + FOREACH_MOD(OnSerializeTypeCreate, (this)); } Type::~Type() @@ -138,7 +138,7 @@ Serializable *Type::Unserialize(Serializable *obj, Serialize::Data &data) void Type::Check() { - FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this)); + FOREACH_MOD(OnSerializeCheck, (this)); } time_t Type::GetTimestamp() const diff --git a/src/servers.cpp b/src/servers.cpp index d8fc84a81..ee4891138 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -118,7 +118,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano } } - FOREACH_MOD(I_OnNewServer, OnNewServer(this)); + FOREACH_MOD(OnNewServer, (this)); } Server::~Server() @@ -152,7 +152,7 @@ Server::~Server() void Server::Delete(const Anope::string &reason) { this->quit_reason = reason; - FOREACH_MOD(I_OnServerQuit, OnServerQuit(this)); + FOREACH_MOD(OnServerQuit, (this)); delete this; } @@ -237,7 +237,7 @@ void Server::Sync(bool sync_links) Log(this, "sync") << "is done syncing"; - FOREACH_MOD(I_OnServerSync, OnServerSync(this)); + FOREACH_MOD(OnServerSync, (this)); if (sync_links && !this->links.empty()) { @@ -247,7 +247,7 @@ void Server::Sync(bool sync_links) if (this->GetUplink() && this->GetUplink() == Me) { - FOREACH_MOD(I_OnPreUplinkSync, OnPreUplinkSync(this)); + FOREACH_MOD(OnPreUplinkSync, (this)); for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it) { @@ -258,7 +258,7 @@ void Server::Sync(bool sync_links) IRCD->SendEOB(); Me->Sync(false); - FOREACH_MOD(I_OnUplinkSync, OnUplinkSync(this)); + FOREACH_MOD(OnUplinkSync, (this)); if (!Anope::NoFork && Anope::AtTerm()) { diff --git a/src/uplink.cpp b/src/uplink.cpp index dccdbf8fb..9f2caa02d 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -46,7 +46,7 @@ void Uplink::Connect() new UplinkSocket(); if (!Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost").empty()) UplinkSock->Bind(Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost")); - FOREACH_MOD(I_OnPreServerConnect, OnPreServerConnect()); + FOREACH_MOD(OnPreServerConnect, ()); Anope::string ip = Anope::Resolve(u.host, u.ipv6 ? AF_INET6 : AF_INET); Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << "), port " << u.port; UplinkSock->Connect(ip, u.port); @@ -62,7 +62,7 @@ UplinkSocket::~UplinkSocket() { if (IRCD && Servers::GetUplink() && Servers::GetUplink()->IsSynced()) { - FOREACH_MOD(I_OnServerDisconnect, OnServerDisconnect()); + FOREACH_MOD(OnServerDisconnect, ()); for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { @@ -129,7 +129,7 @@ void UplinkSocket::OnConnect() { Log(LOG_TERMINAL) << "Successfully connected to uplink #" << (Anope::CurrentUplink + 1) << " " << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port; IRCD->SendConnect(); - FOREACH_MOD(I_OnServerConnect, OnServerConnect()); + FOREACH_MOD(OnServerConnect, ()); } void UplinkSocket::OnError(const Anope::string &error) diff --git a/src/users.cpp b/src/users.cpp index cba624104..cc99cd63e 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -83,7 +83,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: bool exempt = false; if (server && server->IsULined()) exempt = true; - FOREACH_MOD(I_OnUserConnect, OnUserConnect(this, exempt)); + FOREACH_MOD(OnUserConnect, (this, exempt)); } void User::ChangeNick(const Anope::string &newnick, time_t ts) @@ -122,7 +122,7 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) } } - FOREACH_MOD(I_OnUserNickChange, OnUserNickChange(this, old)); + FOREACH_MOD(OnUserNickChange, (this, old)); } void User::SetDisplayedHost(const Anope::string &shost) @@ -236,7 +236,7 @@ User::~User() --this->server->users; } - FOREACH_MOD(I_OnPreUserLogoff, OnPreUserLogoff(this)); + FOREACH_MOD(OnPreUserLogoff, (this)); ModeManager::StackerDel(this); this->Logout(); @@ -251,7 +251,7 @@ User::~User() if (!this->uid.empty()) UserListByUID.erase(this->uid); - FOREACH_MOD(I_OnPostUserLogoff, OnPostUserLogoff(this)); + FOREACH_MOD(OnPostUserLogoff, (this)); } void User::SendMessage(const BotInfo *source, const char *fmt, ...) @@ -302,7 +302,7 @@ void User::Identify(NickAlias *na) this->Login(na->nc); IRCD->SendLogin(this); - FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(this)); + FOREACH_MOD(OnNickIdentify, (this)); if (this->IsServicesOper()) { @@ -338,7 +338,7 @@ void User::Login(NickCore *core) if (this->server->IsSynced()) Log(this, "account") << "is now identified as " << this->nc->display; - FOREACH_MOD(I_OnUserLogin, OnUserLogin(this)); + FOREACH_MOD(OnUserLogin, (this)); } void User::Logout() @@ -406,7 +406,7 @@ bool User::IsServicesOper() } EventReturn MOD_RESULT; - FOREACH_RESULT(I_IsServicesOper, IsServicesOper(this)); + FOREACH_RESULT(IsServicesOper, MOD_RESULT, (this)); if (MOD_RESULT == EVENT_STOP) return false; @@ -458,7 +458,7 @@ void User::SetModeInternal(UserMode *um, const Anope::string ¶m) this->modes[um->name] = param; - FOREACH_MOD(I_OnUserModeSet, OnUserModeSet(this, um->name)); + FOREACH_MOD(OnUserModeSet, (this, um->name)); } void User::RemoveModeInternal(UserMode *um) @@ -468,7 +468,7 @@ void User::RemoveModeInternal(UserMode *um) this->modes.erase(um->name); - FOREACH_MOD(I_OnUserModeUnset, OnUserModeUnset(this, um->name)); + FOREACH_MOD(OnUserModeUnset, (this, um->name)); } void User::SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param) @@ -668,7 +668,7 @@ void User::Quit(const Anope::string &reason) return; } - FOREACH_MOD(I_OnUserQuit, OnUserQuit(this, reason)); + FOREACH_MOD(OnUserQuit, (this, reason)); this->quit = true; quitting_users.push_back(this); |