diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/access.cpp | 6 | ||||
| -rw-r--r-- | src/base.cpp | 24 | ||||
| -rw-r--r-- | src/bots.cpp | 15 | ||||
| -rw-r--r-- | src/channels.cpp | 35 | ||||
| -rw-r--r-- | src/command.cpp | 5 | ||||
| -rw-r--r-- | src/config.cpp | 4 | ||||
| -rw-r--r-- | src/event.cpp | 103 | ||||
| -rw-r--r-- | src/init.cpp | 3 | ||||
| -rw-r--r-- | src/logger.cpp | 5 | ||||
| -rw-r--r-- | src/main.cpp | 9 | ||||
| -rw-r--r-- | src/messages.cpp | 21 | ||||
| -rw-r--r-- | src/misc.cpp | 5 | ||||
| -rw-r--r-- | src/modes.cpp | 7 | ||||
| -rw-r--r-- | src/module.cpp | 2 | ||||
| -rw-r--r-- | src/modulemanager.cpp | 126 | ||||
| -rw-r--r-- | src/nickalias.cpp | 3 | ||||
| -rw-r--r-- | src/nickcore.cpp | 13 | ||||
| -rw-r--r-- | src/process.cpp | 3 | ||||
| -rw-r--r-- | src/regchannel.cpp | 7 | ||||
| -rw-r--r-- | src/serialize.cpp | 15 | ||||
| -rw-r--r-- | src/servers.cpp | 11 | ||||
| -rw-r--r-- | src/service.cpp | 126 | ||||
| -rw-r--r-- | src/uplink.cpp | 7 | ||||
| -rw-r--r-- | src/users.cpp | 23 |
24 files changed, 362 insertions, 216 deletions
diff --git a/src/access.cpp b/src/access.cpp index 1b90bb59f..26c8dee27 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -16,6 +16,7 @@ #include "users.h" #include "account.h" #include "protocol.h" +#include "event.h" static struct { @@ -312,8 +313,7 @@ AccessGroup::AccessGroup() : std::vector<ChanAccess *>() static bool HasPriv(const AccessGroup &ag, const ChanAccess *access, const Anope::string &name) { - EventReturn MOD_RESULT; - FOREACH_RESULT(OnCheckPriv, MOD_RESULT, (access, name)); + EventReturn MOD_RESULT = Event::OnCheckPriv(&Event::CheckPriv::OnCheckPriv, access, name); if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name)) { typedef std::multimap<const ChanAccess *, const ChanAccess *> path; @@ -353,7 +353,7 @@ bool AccessGroup::HasPriv(const Anope::string &name) const return true; EventReturn MOD_RESULT; - FOREACH_RESULT(OnGroupCheckPriv, MOD_RESULT, (this, name)); + MOD_RESULT = Event::OnGroupCheckPriv(&Event::GroupCheckPriv::OnGroupCheckPriv, this, name); if (MOD_RESULT != EVENT_CONTINUE) return MOD_RESULT == EVENT_ALLOW; diff --git a/src/base.cpp b/src/base.cpp index 1b6a560d7..0fcd868bc 100644 --- a/src/base.cpp +++ b/src/base.cpp @@ -11,8 +11,28 @@ #include "anope.h" #include "service.h" -std::map<Anope::string, std::map<Anope::string, Service *> > Service::Services; -std::map<Anope::string, std::map<Anope::string, Anope::string> > Service::Aliases; +std::map<Anope::string, std::map<Anope::string, Service *> > *Service::Services = NULL; +std::map<Anope::string, std::map<Anope::string, Anope::string> > *Service::Aliases = NULL; +std::set<ReferenceBase *> *ReferenceBase::references = NULL; + +ReferenceBase::ReferenceBase() +{ + if (references == NULL) + references = new std::set<ReferenceBase *>(); + references->insert(this); +} + +ReferenceBase::~ReferenceBase() +{ + references->erase(this); +} + +void ReferenceBase::ResetAll() +{ + if (references) + for (ReferenceBase *b : *references) + b->Reset(); +} Base::Base() : references(NULL) { diff --git a/src/bots.cpp b/src/bots.cpp index 77b7d1c35..b2feb9c4e 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -18,6 +18,7 @@ #include "config.h" #include "language.h" #include "serialize.h" +#include "event.h" Serialize::Checker<botinfo_map> BotListByNick("BotInfo"), BotListByUID("BotInfo"); @@ -31,7 +32,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A if (!this->uid.empty()) (*BotListByUID)[this->uid] = this; - FOREACH_MOD(OnCreateBot, (this)); + Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this); // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) @@ -49,7 +50,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A BotInfo::~BotInfo() { - FOREACH_MOD(OnDelBot, (this)); + Event::OnDelBot(&Event::DelBot::OnDelBot, this); // If we're synchronised with the uplink already, send the bot. if (Me && Me->IsSynced()) @@ -152,7 +153,7 @@ const std::set<ChannelInfo *> &BotInfo::GetChannels() const void BotInfo::Assign(User *u, ChannelInfo *ci) { EventReturn MOD_RESULT; - FOREACH_RESULT(OnPreBotAssign, MOD_RESULT, (u, ci, this)); + MOD_RESULT = Event::OnPreBotAssign(&Event::PreBotAssign::OnPreBotAssign, u, ci, this); if (MOD_RESULT == EVENT_STOP) return; @@ -162,13 +163,13 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) ci->bi = this; this->channels->insert(ci); - FOREACH_MOD(OnBotAssign, (u, ci, this)); + Event::OnBotAssign(&Event::BotAssign::OnBotAssign, u, ci, this); } void BotInfo::UnAssign(User *u, ChannelInfo *ci) { EventReturn MOD_RESULT; - FOREACH_RESULT(OnBotUnAssign, MOD_RESULT, (u, ci)); + MOD_RESULT = Event::OnBotUnAssign(&Event::BotUnAssign::OnBotUnAssign, u, ci); if (MOD_RESULT == EVENT_STOP) return; @@ -198,7 +199,7 @@ void BotInfo::Join(Channel *c, ChannelStatus *status) if (IRCD) IRCD->SendJoin(this, c, status); - FOREACH_MOD(OnJoinChannel, (this, c)); + Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, this, c); } void BotInfo::Join(const Anope::string &chname, ChannelStatus *status) @@ -214,7 +215,7 @@ void BotInfo::Part(Channel *c, const Anope::string &reason) IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); - FOREACH_MOD(OnPartChannel, (this, c, c->name, reason)); + Event::OnPartChannel(&Event::PartChannel::OnPartChannel, this, c, c->name, reason); c->DeleteUser(this); } diff --git a/src/channels.cpp b/src/channels.cpp index 37d04c44e..94f7d49a6 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -25,6 +25,7 @@ #include "sockets.h" #include "language.h" #include "uplink.h" +#include "event.h" channel_map ChannelList; @@ -47,12 +48,12 @@ Channel::Channel(const Anope::string &nname, time_t ts) if (Me && Me->IsSynced()) Log(NULL, this, "create"); - FOREACH_MOD(OnChannelCreate, (this)); + Event::OnChannelCreate(&Event::ChannelCreate::OnChannelCreate, this); } Channel::~Channel() { - FOREACH_MOD(OnChannelDelete, (this)); + Event::OnChannelDelete(&Event::ChannelDelete::OnChannelDelete, this); ModeManager::StackerDel(this); @@ -98,7 +99,7 @@ void Channel::Reset() void Channel::Sync() { syncing = false; - FOREACH_MOD(OnChannelSync, (this)); + Event::OnChannelSync(&Event::ChannelSync::OnChannelSync, this); CheckModes(); } @@ -116,7 +117,7 @@ void Channel::CheckModes() } Reference<Channel> ref = this; - FOREACH_MOD(OnCheckModes, (ref)); + Event::OnCheckModes(&Event::CheckModes::OnCheckModes, ref); } bool Channel::CheckDelete() @@ -132,7 +133,7 @@ bool Channel::CheckDelete() return false; EventReturn MOD_RESULT; - FOREACH_RESULT(OnCheckDelete, MOD_RESULT, (this)); + MOD_RESULT = Event::OnCheckDelete(&Event::CheckDelete::OnCheckDelete, this); return MOD_RESULT != EVENT_STOP && this->users.empty(); } @@ -156,7 +157,7 @@ void Channel::DeleteUser(User *user) if (user->server && user->server->IsSynced() && !user->Quitting()) Log(user, this, "leave"); - FOREACH_MOD(OnLeaveChannel, (user, this)); + Event::OnLeaveChannel(&Event::LeaveChannel::OnLeaveChannel, user, this); ChanUserContainer *cu = user->FindChannel(this); if (!this->users.erase(user)) @@ -279,7 +280,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop if (cc) cc->status.AddMode(cm->mchar); - FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param); /* Enforce secureops, etc */ if (enforce_mlock && MOD_RESULT != EVENT_STOP) @@ -306,7 +307,7 @@ void Channel::SetModeInternal(MessageSource &setter, ChannelMode *cm, const Anop cml->OnAdd(this, param); } - FOREACH_RESULT(OnChannelModeSet, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param); /* Check if we should enforce mlock */ if (!enforce_mlock || MOD_RESULT == EVENT_STOP) @@ -347,7 +348,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A if (cc) cc->status.DelMode(cm->mchar); - FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param); if (enforce_mlock && MOD_RESULT != EVENT_STOP) this->SetCorrectModes(u, false); @@ -374,7 +375,7 @@ void Channel::RemoveModeInternal(MessageSource &setter, ChannelMode *cm, const A cml->OnDel(this, param); } - FOREACH_RESULT(OnChannelModeUnset, MOD_RESULT, (this, setter, cm, param)); + MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param); if (cm->name == "PERM") { @@ -738,9 +739,9 @@ void Channel::KickInternal(const MessageSource &source, const Anope::string &nic Anope::string this_name = this->name; ChannelStatus status = cu->status; - FOREACH_MOD(OnPreUserKicked, (source, cu, reason)); + Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason); this->DeleteUser(target); /* This can delete this; */ - FOREACH_MOD(OnUserKicked, (source, target, this_name, status, reason)); + Event::OnUserKicked(&Event::UserKicked::OnUserKicked, source, target, this_name, status, reason); } bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) @@ -759,7 +760,7 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) bi = this->ci->WhoSends(); EventReturn MOD_RESULT; - FOREACH_RESULT(OnBotKick, MOD_RESULT, (bi, this, u, buf)); + MOD_RESULT = Event::OnBotKick(&Event::BotKick::OnBotKick, bi, this, u, buf); if (MOD_RESULT == EVENT_STOP) return false; IRCD->SendKick(bi, this, u, "%s", buf); @@ -778,7 +779,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(OnTopicUpdated, (this, user, this->topic)); + Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, this, user, this->topic); } void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts) @@ -794,7 +795,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(OnTopicUpdated, (this, user, this->topic)); + Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, this, user, this->topic); } void Channel::SetCorrectModes(User *user, bool give_modes) @@ -812,7 +813,7 @@ void Channel::SetCorrectModes(User *user, bool give_modes) /* Initially only take modes if the channel is being created by a non netmerge */ bool take_modes = this->syncing && user->server->IsSynced(); - FOREACH_MOD(OnSetCorrectModes, (user, this, u_access, give_modes, take_modes)); + Event::OnSetCorrectModes(&Event::SetCorrectModes::OnSetCorrectModes, user, this, u_access, give_modes, take_modes); /* Never take modes from ulines */ if (user->server->IsULined()) @@ -884,7 +885,7 @@ bool Channel::CheckKick(User *user) Anope::string mask, reason; EventReturn MOD_RESULT; - FOREACH_RESULT(OnCheckKick, MOD_RESULT, (user, this, mask, reason)); + MOD_RESULT = Event::OnCheckKick(&Event::CheckKick::OnCheckKick, user, this, mask, reason); if (MOD_RESULT != EVENT_STOP) return false; diff --git a/src/command.cpp b/src/command.cpp index 6aa2f744b..5241e9316 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -17,6 +17,7 @@ #include "access.h" #include "regchannel.h" #include "channels.h" +#include "event.h" CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), c(NULL), service(bi) @@ -261,7 +262,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) source.permission = info.permission; EventReturn MOD_RESULT; - FOREACH_RESULT(OnPreCommand, MOD_RESULT, (source, c, params)); + MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, c, params); if (MOD_RESULT == EVENT_STOP) return; @@ -281,7 +282,7 @@ void Command::Run(CommandSource &source, const Anope::string &message) } c->Execute(source, params); - FOREACH_MOD(OnPostCommand, (source, c, params)); + Event::OnPostCommand(&Event::PostCommand::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 6473cf830..97abbbe0e 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -17,6 +17,7 @@ #include "opertype.h" #include "channels.h" #include "hashcomp.h" +#include "event.h" using namespace Configuration; @@ -130,7 +131,8 @@ Conf::Conf() : Block("") this->LoadConf(f); } - FOREACH_MOD(OnReload, (this)); + for (Module *m : ModuleManager::Modules) + m->OnReload(this); /* Check for modified values that aren't allowed to be modified */ if (Config) diff --git a/src/event.cpp b/src/event.cpp new file mode 100644 index 000000000..c13118dc4 --- /dev/null +++ b/src/event.cpp @@ -0,0 +1,103 @@ +/* Modular support + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#include "services.h" +#include "event.h" + +using namespace Event; + +EventHandlers<PreUserKicked> Event::OnPreUserKicked(nullptr, "OnPreUserKicked"); +EventHandlers<UserKicked> Event::OnUserKicked(nullptr, "OnUserKicked"); +EventHandlers<PreBotAssign> Event::OnPreBotAssign(nullptr, "OnPreBotAssign"); +EventHandlers<BotAssign> Event::OnBotAssign(nullptr, "OnBotAssign"); +EventHandlers<BotUnAssign> Event::OnBotUnAssign(nullptr, "OnBotUnAssign"); +EventHandlers<UserConnect> Event::OnUserConnect(nullptr, "OnUserConnect"); +EventHandlers<NewServer> Event::OnNewServer(nullptr, "OnNewServer"); +EventHandlers<UserNickChange> Event::OnUserNickChange(nullptr, "OnUserNickChange"); +EventHandlers<PreCommand> Event::OnPreCommand(nullptr, "OnPreCommand"); +EventHandlers<PostCommand> Event::OnPostCommand(nullptr, "OnPostCommand"); +EventHandlers<SaveDatabase> Event::OnSaveDatabase(nullptr, "OnSaveDatabase"); +EventHandlers<LoadDatabase> Event::OnLoadDatabase(nullptr, "OnLoadDatabase"); +EventHandlers<Encrypt> Event::OnEncrypt(nullptr, "OnEncrypt"); +EventHandlers<Decrypt> Event::OnDecrypt(nullptr, "OnDecrypt"); +EventHandlers<CreateBot> Event::OnCreateBot(nullptr, "OnCreateBot"); +EventHandlers<DelBot> Event::OnDelBot(nullptr, "OnDelBot"); +EventHandlers<BotKick> Event::OnBotKick(nullptr, "OnBotKick"); +EventHandlers<PrePartChannel> Event::OnPrePartChannel(nullptr, "OnPrePartChannel"); +EventHandlers<PartChannel> Event::OnPartChannel(nullptr, "OnPartChannel"); +EventHandlers<LeaveChannel> Event::OnLeaveChannel(nullptr, "OnLeaveChannel"); +EventHandlers<JoinChannel> Event::OnJoinChannel(nullptr, "OnJoinChannel"); +EventHandlers<TopicUpdated> Event::OnTopicUpdated(nullptr, "OnTopicUpdated"); +EventHandlers<PreServerConnect> Event::OnPreServerConnect(nullptr, "OnPreServerConnect"); +EventHandlers<ServerConnect> Event::OnServerConnect(nullptr, "OnServerConnect"); +EventHandlers<PreUplinkSync> Event::OnPreUplinkSync(nullptr, "OnPreUplinkSync"); +EventHandlers<ServerDisconnect> Event::OnServerDisconnect(nullptr, "OnServerDisconnect"); +EventHandlers<Restart> Event::OnRestart(nullptr, "OnRestart"); +EventHandlers<Shutdown> Event::OnShutdown(nullptr, "OnShutdown"); +EventHandlers<AddXLine> Event::OnAddXLine(nullptr, "OnAddXLine"); +EventHandlers<DelXLine> Event::OnDelXLine(nullptr, "OnDelXLine"); +EventHandlers<IsServicesOperEvent> Event::OnIsServicesOper(nullptr, "OnIsServicesOper"); +EventHandlers<ServerQuit> Event::OnServerQuit(nullptr, "OnServerQuit"); +EventHandlers<UserQuit> Event::OnUserQuit(nullptr, "OnUserQuit"); +EventHandlers<PreUserLogoff> Event::OnPreUserLogoff(nullptr, "OnPreUserLogoff"); +EventHandlers<PostUserLogoff> Event::OnPostUserLogoff(nullptr, "OnPostUserLogoff"); +EventHandlers<AccessDel> Event::OnAccessDel(nullptr, "OnAccessDel"); +EventHandlers<AccessAdd> Event::OnAccessAdd(nullptr, "OnAccessAdd"); +EventHandlers<AccessClear> Event::OnAccessClear(nullptr, "OnAccessClear"); +EventHandlers<ChanRegistered> Event::OnChanRegistered(nullptr, "OnChanRegistered"); +EventHandlers<CreateChan> Event::OnCreateChan(nullptr, "OnCreateChan"); +EventHandlers<DelChan> Event::OnDelChan(nullptr, "OnDelChan"); +EventHandlers<ChannelCreate> Event::OnChannelCreate(nullptr, "OnChannelCreate"); +EventHandlers<ChannelDelete> Event::OnChannelDelete(nullptr, "OnChannelDelete"); +EventHandlers<CheckKick> Event::OnCheckKick(nullptr, "OnCheckKick"); +EventHandlers<CheckPriv> Event::OnCheckPriv(nullptr, "OnCheckPriv"); +EventHandlers<GroupCheckPriv> Event::OnGroupCheckPriv(nullptr, "OnGroupCheckPriv"); +EventHandlers<NickIdentify> Event::OnNickIdentify(nullptr, "OnNickIdentify"); +EventHandlers<UserLogin> Event::OnUserLogin(nullptr, "OnUserLogin"); +EventHandlers<NickLogout> Event::OnNickLogout(nullptr, "OnNickLogout"); +EventHandlers<DelNick> Event::OnDelNick(nullptr, "OnDelNick"); +EventHandlers<NickCoreCreate> Event::OnNickCoreCreate(nullptr, "OnNickCoreCreate"); +EventHandlers<DelCore> Event::OnDelCore(nullptr, "OnDelCore"); +EventHandlers<ChangeCoreDisplay> Event::OnChangeCoreDisplay(nullptr, "OnChangeCoreDisplay"); +EventHandlers<NickClearAccess> Event::OnNickClearAccess(nullptr, "OnNickClearAccess"); +EventHandlers<NickAddAccess> Event::OnNickAddAccess(nullptr, "OnNickAddAccess"); +EventHandlers<NickEraseAccess> Event::OnNickEraseAccess(nullptr, "OnNickEraseAccess"); +EventHandlers<CheckAuthentication> Event::OnCheckAuthentication(nullptr, "OnCheckAuthentication"); +EventHandlers<Fingerprint> Event::OnFingerprint(nullptr, "OnFingerprint"); +EventHandlers<UserAway> Event::OnUserAway(nullptr, "OnUserAway"); +EventHandlers<Invite> Event::OnInvite(nullptr, "OnInvite"); +EventHandlers<SetVhost> Event::OnSetVhost(nullptr, "OnSetVhost"); +EventHandlers<SetDisplayedHost> Event::OnSetDisplayedHost(nullptr, "OnSetDisplayedHost"); +EventHandlers<ChannelModeSet> Event::OnChannelModeSet(nullptr, "OnChannelModeSet"); +EventHandlers<ChannelModeUnset> Event::OnChannelModeUnset(nullptr, "OnChannelModeUnset"); +EventHandlers<UserModeSet> Event::OnUserModeSet(nullptr, "OnUserModeSet"); +EventHandlers<UserModeUnset> Event::OnUserModeUnset(nullptr, "OnUserModeUnset"); +EventHandlers<ChannelModeAdd> Event::OnChannelModeAdd(nullptr, "OnChannelModeAdd"); +EventHandlers<UserModeAdd> Event::OnUserModeAdd(nullptr, "OnUserModeAdd"); +EventHandlers<ModuleLoad> Event::OnModuleLoad(nullptr, "OnModuleLoad"); +EventHandlers<ModuleUnload> Event::OnModuleUnload(nullptr, "OnModuleUnload"); +EventHandlers<ServerSync> Event::OnServerSync(nullptr, "OnServerSync"); +EventHandlers<UplinkSync> Event::OnUplinkSync(nullptr, "OnUplinkSync"); +EventHandlers<BotPrivmsg> Event::OnBotPrivmsg(nullptr, "OnBotPrivmsg"); +EventHandlers<BotNotice> Event::OnBotNotice(nullptr, "OnBotNotice"); +EventHandlers<Privmsg> Event::OnPrivmsg(nullptr, "OnPrivmsg"); +EventHandlers<Event::Log> Event::OnLog(nullptr, "OnLog"); +EventHandlers<LogMessage> Event::OnLogMessage(nullptr, "OnLogMessage"); +EventHandlers<CheckModes> Event::OnCheckModes(nullptr, "OnCheckModes"); +EventHandlers<ChannelSync> Event::OnChannelSync(nullptr, "OnChannelSync"); +EventHandlers<SetCorrectModes> Event::OnSetCorrectModes(nullptr, "OnSetCorrectModes"); +EventHandlers<SerializeCheck> Event::OnSerializeCheck(nullptr, "OnSerializeCheck"); +EventHandlers<SerializableConstruct> Event::OnSerializableConstruct(nullptr, "OnSerializableConstruct"); +EventHandlers<SerializableDestruct> Event::OnSerializableDestruct(nullptr, "OnSerializableDestruct"); +EventHandlers<SerializableUpdate> Event::OnSerializableUpdate(nullptr, "OnSerializableUpdate"); +EventHandlers<SerializeTypeCreate> Event::OnSerializeTypeCreate(nullptr, "OnSerializeTypeCreate"); +EventHandlers<Message> Event::OnMessage(nullptr, "OnMessage"); +EventHandlers<CanSet> Event::OnCanSet(nullptr, "OnCanSet"); +EventHandlers<CheckDelete> Event::OnCheckDelete(nullptr, "OnCheckDelete"); +EventHandlers<ExpireTick> Event::OnExpireTick(nullptr, "OnExpireTick"); diff --git a/src/init.cpp b/src/init.cpp index f62ef083a..cd06a5194 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -19,6 +19,7 @@ #include "socketengine.h" #include "servers.h" #include "language.h" +#include "event.h" #ifndef _WIN32 #include <sys/wait.h> @@ -535,7 +536,7 @@ void Anope::Init(int ac, char **av) /* Load up databases */ Log() << "Loading databases..."; EventReturn MOD_RESULT; - FOREACH_RESULT(OnLoadDatabase, MOD_RESULT, ()); + MOD_RESULT = Event::OnLoadDatabase(&Event::LoadDatabase::OnLoadDatabase); static_cast<void>(MOD_RESULT); Log() << "Databases loaded"; diff --git a/src/logger.cpp b/src/logger.cpp index 445e71949..1aa530f82 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -21,6 +21,7 @@ #include "servers.h" #include "uplink.h" #include "protocol.h" +#include "event.h" #ifndef _WIN32 #include <sys/time.h> @@ -129,7 +130,7 @@ Log::~Log() else if (this->type == LOG_TERMINAL) std::cout << this->BuildPrefix() << this->buf.str() << std::endl; - FOREACH_MOD(OnLog, (this)); + Event::OnLog(&Event::Log::OnLog, this); if (Config) for (unsigned i = 0; i < Config->LogInfos.size(); ++i) @@ -347,7 +348,7 @@ void LogInfo::ProcessMessage(const Log *l) const Anope::string &buffer = l->BuildPrefix() + l->buf.str(); - FOREACH_MOD(OnLogMessage, (this, l, buffer)); + Event::OnLogMessage(&Event::LogMessage::OnLogMessage, this, l, buffer); for (unsigned i = 0; i < this->targets.size(); ++i) { diff --git a/src/main.cpp b/src/main.cpp index 86d135ca8..8a61835b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -16,6 +16,7 @@ #include "bots.h" #include "socketengine.h" #include "uplink.h" +#include "event.h" #ifndef _WIN32 #include <limits.h> @@ -60,7 +61,7 @@ class ExpireTimer : public Timer void Tick(time_t) override { - FOREACH_MOD(OnExpireTick, ()); + Event::OnExpireTick(&Event::ExpireTick::OnExpireTick); } }; @@ -70,7 +71,7 @@ void Anope::SaveDatabases() return; Log(LOG_DEBUG) << "Saving databases"; - FOREACH_MOD(OnSaveDatabase, ()); + Event::OnSaveDatabase(&Event::SaveDatabase::OnSaveDatabase); } /** The following comes from InspIRCd to get the full path of the Anope executable @@ -181,11 +182,11 @@ int main(int ac, char **av, char **envp) if (Anope::Restarting) { - FOREACH_MOD(OnRestart, ()); + Event::OnRestart(&Event::Restart::OnRestart); } else { - FOREACH_MOD(OnShutdown, ()); + Event::OnShutdown(&Event::Shutdown::OnShutdown); } if (Anope::QuitReason.empty()) diff --git a/src/messages.cpp b/src/messages.cpp index bb699a18e..b4da470bf 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -20,12 +20,13 @@ #include "messages.h" #include "servers.h" #include "channels.h" +#include "event.h" using namespace Message; void Away::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) { - FOREACH_MOD(OnUserAway, (source.GetUser(), params.empty() ? "" : params[0])); + Event::OnUserAway(&Event::UserAway::OnUserAway, source.GetUser(), params.empty() ? "" : params[0]); } void Capab::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) @@ -57,7 +58,7 @@ void Invite::Run(MessageSource &source, const std::vector<Anope::string> ¶ms if (!targ || targ->server != Me || !c || c->FindUser(targ)) return; - FOREACH_MOD(OnInvite, (source.GetUser(), c, targ)); + Event::OnInvite(&Event::Invite::OnInvite, source.GetUser(), c, targ); } void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) @@ -79,9 +80,9 @@ void Join::Run(MessageSource &source, const std::vector<Anope::string> ¶ms) ++it; Anope::string channame = cc->chan->name; - FOREACH_MOD(OnPrePartChannel, (user, cc->chan)); + Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, user, cc->chan); cc->chan->DeleteUser(user); - FOREACH_MOD(OnPartChannel, (user, Channel::Find(channame), channame, "")); + Event::OnPartChannel(&Event::PartChannel::OnPartChannel, user, Channel::Find(channame), channame, ""); } continue; } @@ -140,7 +141,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co */ c->SetCorrectModes(u, true); - FOREACH_MOD(OnJoinChannel, (u, c)); + Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, u, c); } /* Channel is done syncing */ @@ -259,7 +260,7 @@ void Notice::Run(MessageSource &source, const std::vector<Anope::string> ¶ms BotInfo *bi = BotInfo::Find(params[0]); if (!bi) return; - FOREACH_MOD(OnBotNotice, (u, bi, message)); + Event::OnBotNotice(&Event::BotNotice::OnBotNotice, u, bi, message); } } @@ -279,10 +280,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(OnPrePartChannel, (u, c)); + Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, u, c); Anope::string ChannelName = c->name; c->DeleteUser(u); - FOREACH_MOD(OnPartChannel, (u, c, ChannelName, !reason.empty() ? reason : "")); + Event::OnPartChannel(&Event::PartChannel::OnPartChannel, u, c, ChannelName, !reason.empty() ? reason : ""); } } @@ -303,7 +304,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m Channel *c = Channel::Find(receiver); if (c) { - FOREACH_MOD(OnPrivmsg, (u, c, message)); + Event::OnPrivmsg(&Event::Privmsg::OnPrivmsg, u, c, message); } } else @@ -351,7 +352,7 @@ void Privmsg::Run(MessageSource &source, const std::vector<Anope::string> ¶m } EventReturn MOD_RESULT; - FOREACH_RESULT(OnBotPrivmsg, MOD_RESULT, (u, bi, message)); + MOD_RESULT = Event::OnBotPrivmsg(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message); if (MOD_RESULT == EVENT_STOP) return; diff --git a/src/misc.cpp b/src/misc.cpp index ee7724941..7e5121ed6 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -18,6 +18,7 @@ #include "bots.h" #include "language.h" #include "sockets.h" +#include "event.h" #include <errno.h> #include <sys/types.h> @@ -501,7 +502,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(OnEncrypt, MOD_RESULT, (src, dest)); + MOD_RESULT = Event::OnEncrypt(&Event::Encrypt::OnEncrypt, src, dest); static_cast<void>(MOD_RESULT); } @@ -516,7 +517,7 @@ bool Anope::Decrypt(const Anope::string &src, Anope::string &dest) Anope::string hashm(src.begin(), src.begin() + pos); EventReturn MOD_RESULT; - FOREACH_RESULT(OnDecrypt, MOD_RESULT, (hashm, src, dest)); + MOD_RESULT = Event::OnDecrypt(&Event::Decrypt::OnDecrypt, hashm, src, dest); if (MOD_RESULT == EVENT_ALLOW) return true; diff --git a/src/modes.cpp b/src/modes.cpp index 13cda797f..c8908820c 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -14,6 +14,7 @@ #include "protocol.h" #include "channels.h" #include "uplink.h" +#include "event.h" struct StackerInfo; @@ -138,7 +139,7 @@ ChannelMode::ChannelMode(const Anope::string &cm, char mch) : Mode(cm, MC_CHANNE bool ChannelMode::CanSet(User *u) const { EventReturn MOD_RESULT; - FOREACH_RESULT(OnCanSet, MOD_RESULT, (u, this)); + MOD_RESULT = Event::OnCanSet(&Event::CanSet::OnCanSet, u, this); return MOD_RESULT != EVENT_STOP; } @@ -335,7 +336,7 @@ bool ModeManager::AddUserMode(UserMode *um) UserModesByName[um->name] = um; - FOREACH_MOD(OnUserModeAdd, (um)); + Event::OnUserModeAdd(&Event::UserModeAdd::OnUserModeAdd, um); return true; } @@ -369,7 +370,7 @@ bool ModeManager::AddChannelMode(ChannelMode *cm) ChannelModesByName[cm->name] = cm; - FOREACH_MOD(OnChannelModeAdd, (cm)); + Event::OnChannelModeAdd(&Event::ChannelModeAdd::OnChannelModeAdd, cm); return true; } diff --git a/src/module.cpp b/src/module.cpp index d57538e59..eabf6c0aa 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -64,8 +64,6 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt Module::~Module() { - /* Detach all event hooks for this module */ - ModuleManager::DetachAll(this); IdentifyRequest::ModuleUnload(this); /* Clear any active timers this module has */ TimerManager::DeleteTimersFor(this); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index 07ac46ee1..c70e58ecf 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -12,6 +12,7 @@ #include "users.h" #include "regchannel.h" #include "config.h" +#include "event.h" #include <sys/types.h> #include <sys/stat.h> @@ -22,7 +23,6 @@ #endif std::list<Module *> ModuleManager::Modules; -std::vector<Module *> ModuleManager::EventHandlers[I_SIZE]; #ifdef _WIN32 void ModuleManager::CleanupRuntimeDirectory() @@ -243,17 +243,10 @@ ModuleReturn ModuleManager::LoadModule(const Anope::string &modname, User *u) DeleteModule(m); return MOD_ERR_EXCEPTION; } - catch (const NotImplementedException &ex) - { - } Log(LOG_DEBUG) << "Module " << modname << " loaded."; - /* Attach module to all events */ - for (unsigned i = 0; i < I_SIZE; ++i) - EventHandlers[i].push_back(m); - - FOREACH_MOD(OnModuleLoad, (u, m)); + Event::OnModuleLoad(&Event::ModuleLoad::OnModuleLoad, u, m); return MOD_ERR_OK; } @@ -263,7 +256,7 @@ ModuleReturn ModuleManager::UnloadModule(Module *m, User *u) if (!m) return MOD_ERR_PARAMS; - FOREACH_MOD(OnModuleUnload, (u, m)); + Event::OnModuleUnload(&Event::ModuleUnload::OnModuleUnload, u, m); return DeleteModule(m); } @@ -350,119 +343,6 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) return MOD_ERR_OK; } -void ModuleManager::DetachAll(Module *mod) -{ - for (unsigned i = 0; i < I_SIZE; ++i) - { - std::vector<Module *> &mods = EventHandlers[i]; - 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 (unsigned i = 0; i < I_SIZE; ++i) - SetPriority(mod, static_cast<Implementation>(i), s); - - return true; -} - -bool ModuleManager::SetPriority(Module *mod, Implementation 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 - * wants to be before/after. We pick off either the first or last of these depending |
