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 - * on which they want, and we make sure our module is *at least* before or after - * the first or last of this subset, depending again on the type of priority. - */ - - /* Locate our module. This is O(n) but it only occurs on module load so we're - * not too bothered about it - */ - size_t source = 0; - bool found = false; - for (size_t x = 0, end = EventHandlers[i].size(); x != end; ++x) - if (EventHandlers[i][x] == mod) - { - source = x; - found = true; - break; - } - - /* Eh? this module doesnt exist, probably trying to set priority on an event - * theyre not attached to. - */ - if (!found) - return false; - - size_t swap_pos = 0; - bool swap = true; - switch (s) - { - /* Dummy value */ - case PRIORITY_DONTCARE: - swap = false; - break; - /* Module wants to be first, sod everything else */ - case PRIORITY_FIRST: - swap_pos = 0; - break; - /* Module is submissive and wants to be last... awww. */ - case PRIORITY_LAST: - if (EventHandlers[i].empty()) - swap_pos = 0; - else - swap_pos = EventHandlers[i].size() - 1; - break; - /* Place this module after a set of other modules */ - case PRIORITY_AFTER: - /* Find the latest possible position */ - swap_pos = 0; - swap = false; - for (size_t x = 0, end = EventHandlers[i].size(); x != end; ++x) - for (size_t n = 0; n < sz; ++n) - if (modules[n] && EventHandlers[i][x] == modules[n] && x >= swap_pos && source <= swap_pos) - { - swap_pos = x; - swap = true; - } - break; - /* Place this module before a set of other modules */ - case PRIORITY_BEFORE: - swap_pos = EventHandlers[i].size() - 1; - swap = false; - for (size_t x = 0, end = EventHandlers[i].size(); x != end; ++x) - for (size_t n = 0; n < sz; ++n) - if (modules[n] && EventHandlers[i][x] == modules[n] && x <= swap_pos && source >= swap_pos) - { - swap = true; - swap_pos = x; - } - } - - /* Do we need to swap? */ - if (swap && swap_pos != source) - { - /* Suggestion from Phoenix, "shuffle" the modules to better retain call order */ - int incrmnt = 1; - - if (source > swap_pos) - incrmnt = -1; - - for (unsigned j = source; j != swap_pos; j += incrmnt) - { - if (j + incrmnt > EventHandlers[i].size() - 1 || (!j && incrmnt == -1)) - continue; - - std::swap(EventHandlers[i][j], EventHandlers[i][j + incrmnt]); - } - } - - return true; -} - void ModuleManager::UnloadAll() { std::vector<Anope::string> modules; diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 9f3651c12..dfe06a176 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -18,6 +18,7 @@ #include "users.h" #include "servers.h" #include "config.h" +#include "event.h" Serialize::Checker<nickalias_map> NickAliasList("NickAlias"); @@ -51,7 +52,7 @@ NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Serial NickAlias::~NickAlias() { - FOREACH_MOD(OnDelNick, (this)); + Event::OnDelNick(&Event::DelNick::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 c055491db..dc20f2731 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -14,6 +14,7 @@ #include "modules.h" #include "account.h" #include "config.h" +#include "event.h" Serialize::Checker<nickcore_map> NickCoreList("NickCore"); @@ -33,12 +34,12 @@ NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), if (old == NickCoreList->size()) Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?"; - FOREACH_MOD(OnNickCoreCreate, (this)); + Event::OnNickCoreCreate(&Event::NickCoreCreate::OnNickCoreCreate, this); } NickCore::~NickCore() { - FOREACH_MOD(OnDelCore, (this)); + Event::OnDelCore(&Event::DelCore::OnDelCore, this); if (!this->chanaccess->empty()) Log(LOG_DEBUG) << "Non-empty chanaccess list in destructor!"; @@ -156,7 +157,7 @@ void NickCore::SetDisplay(const NickAlias *na) if (na->nc != this || na->nick == this->display) return; - FOREACH_MOD(OnChangeCoreDisplay, (this, na->nick)); + Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->nick); /* Remove the core from the list */ NickCoreList->erase(this->display); @@ -174,7 +175,7 @@ bool NickCore::IsServicesOper() const void NickCore::AddAccess(const Anope::string &entry) { this->access.push_back(entry); - FOREACH_MOD(OnNickAddAccess, (this, entry)); + Event::OnNickAddAccess(&Event::NickAddAccess::OnNickAddAccess, this, entry); } Anope::string NickCore::GetAccess(unsigned entry) const @@ -203,7 +204,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(OnNickEraseAccess, (this, entry)); + Event::OnNickEraseAccess(&Event::NickEraseAccess::OnNickEraseAccess, this, entry); this->access.erase(this->access.begin() + i); break; } @@ -211,7 +212,7 @@ void NickCore::EraseAccess(const Anope::string &entry) void NickCore::ClearAccess() { - FOREACH_MOD(OnNickClearAccess, (this)); + Event::OnNickClearAccess(&Event::NickClearAccess::OnNickClearAccess, this); this->access.clear(); } diff --git a/src/process.cpp b/src/process.cpp index 16373b144..2308dc47d 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -15,6 +15,7 @@ #include "servers.h" #include "users.h" #include "regchannel.h" +#include "event.h" void Anope::Process(const Anope::string &buffer) { @@ -70,7 +71,7 @@ void Anope::Process(const Anope::string &buffer) MessageSource src(source); EventReturn MOD_RESULT; - FOREACH_RESULT(OnMessage, MOD_RESULT, (src, command, params)); + MOD_RESULT = Event::OnMessage(&Event::Message::OnMessage, src, command, params); if (MOD_RESULT == EVENT_STOP) return; diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 0228196a0..7551266b0 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -19,6 +19,7 @@ #include "config.h" #include "bots.h" #include "servers.h" +#include "event.h" Serialize::Checker<registered_channel_map> RegisteredChannelList("ChannelInfo"); @@ -123,7 +124,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(OnCreateChan, (this)); + Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); } ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), @@ -162,12 +163,12 @@ ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), this->AddAkick(takick->creator, takick->mask, takick->reason, takick->addtime, takick->last_used); } - FOREACH_MOD(OnCreateChan, (this)); + Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); } ChannelInfo::~ChannelInfo() { - FOREACH_MOD(OnDelChan, (this)); + Event::OnDelChan(&Event::DelChan::OnDelChan, this); Log(LOG_DEBUG) << "Deleting channel " << this->name; diff --git a/src/serialize.cpp b/src/serialize.cpp index 521704df4..0cb6ec196 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -20,6 +20,7 @@ #include "regchannel.h" #include "xline.h" #include "access.h" +#include "event.h" using namespace Serialize; @@ -54,7 +55,7 @@ Serializable::Serializable(const Anope::string &serialize_type) : last_commit(0) this->s_iter = SerializableItems->end(); --this->s_iter; - FOREACH_MOD(OnSerializableConstruct, (this)); + Event::OnSerializableConstruct(&Event::SerializableConstruct::OnSerializableConstruct, this); } Serializable::Serializable(const Serializable &other) : last_commit(0), last_commit_time(0), id(0), redis_ignore(0) @@ -65,12 +66,12 @@ Serializable::Serializable(const Serializable &other) : last_commit(0), last_com this->s_type = other.s_type; - FOREACH_MOD(OnSerializableConstruct, (this)); + Event::OnSerializableConstruct(&Event::SerializableConstruct::OnSerializableConstruct, this); } Serializable::~Serializable() { - FOREACH_MOD(OnSerializableDestruct, (this)); + Event::OnSerializableDestruct(&Event::SerializableDestruct::OnSerializableDestruct, this); SerializableItems->erase(this->s_iter); } @@ -83,10 +84,10 @@ Serializable &Serializable::operator=(const Serializable &) void Serializable::QueueUpdate() { /* Schedule updater */ - FOREACH_MOD(OnSerializableUpdate, (this)); + Event::OnSerializableUpdate(&Event::SerializableUpdate::OnSerializableUpdate, this); /* Check for modifications now - this can delete this object! */ - FOREACH_MOD(OnSerializeCheck, (this->GetSerializableType())); + Event::OnSerializeCheck(&Event::SerializeCheck::OnSerializeCheck, this->GetSerializableType()); } bool Serializable::IsCached(Serialize::Data &data) @@ -119,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(OnSerializeTypeCreate, (this)); + Event::OnSerializeTypeCreate(&Event::SerializeTypeCreate::OnSerializeTypeCreate, this); } Type::~Type() @@ -137,7 +138,7 @@ Serializable *Type::Unserialize(Serializable *obj, Serialize::Data &data) void Type::Check() { - FOREACH_MOD(OnSerializeCheck, (this)); + Event::OnSerializeCheck(&Event::SerializeCheck::OnSerializeCheck, this); } time_t Type::GetTimestamp() const diff --git a/src/servers.cpp b/src/servers.cpp index 3f698815c..5e55d4c28 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -19,6 +19,7 @@ #include "protocol.h" #include "config.h" #include "channels.h" +#include "event.h" /* Anope */ Server *Me = NULL; @@ -133,7 +134,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano } } - FOREACH_MOD(OnNewServer, (this)); + Event::OnNewServer(&Event::NewServer::OnNewServer, this); } Server::~Server() @@ -168,7 +169,7 @@ void Server::Delete(const Anope::string &reason) { this->quit_reason = reason; this->quitting = true; - FOREACH_MOD(OnServerQuit, (this)); + Event::OnServerQuit(&Event::ServerQuit::OnServerQuit, this); delete this; } @@ -256,7 +257,7 @@ void Server::Sync(bool sync_links) Log(this, "sync") << "is done syncing"; - FOREACH_MOD(OnServerSync, (this)); + Event::OnServerSync(&Event::ServerSync::OnServerSync, this); if (sync_links && !this->links.empty()) { @@ -268,7 +269,7 @@ void Server::Sync(bool sync_links) if (me) { - FOREACH_MOD(OnPreUplinkSync, (this)); + Event::OnPreUplinkSync(&Event::PreUplinkSync::OnPreUplinkSync, this); } for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end;) @@ -285,7 +286,7 @@ void Server::Sync(bool sync_links) IRCD->SendEOB(); Me->Sync(false); - FOREACH_MOD(OnUplinkSync, (this)); + Event::OnUplinkSync(&Event::UplinkSync::OnUplinkSync, this); if (!Anope::NoFork && Anope::AtTerm()) { diff --git a/src/service.cpp b/src/service.cpp new file mode 100644 index 000000000..cfa9a17c7 --- /dev/null +++ b/src/service.cpp @@ -0,0 +1,126 @@ +/* + * + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + + +#include "services.h" +#include "service.h" + +void Service::check() +{ + if (Services || Aliases) + return; + + Services = new std::map<Anope::string, std::map<Anope::string, Service *> >(); + Aliases = new std::map<Anope::string, std::map<Anope::string, Anope::string> >; +} + +Service *Service::FindService(const std::map<Anope::string, Service *> &services, const std::map<Anope::string, Anope::string> *aliases, const Anope::string &n) +{ + std::map<Anope::string, Service *>::const_iterator it = services.find(n); + if (it != services.end()) + return it->second; + + if (aliases != NULL) + { + std::map<Anope::string, Anope::string>::const_iterator it2 = aliases->find(n); + if (it2 != aliases->end()) + return FindService(services, aliases, it2->second); + } + + return NULL; +} + +Service *Service::FindService(const Anope::string &t, const Anope::string &n) +{ + check(); + + std::map<Anope::string, std::map<Anope::string, Service *> >::const_iterator it = (*Services).find(t); + if (it == (*Services).end()) + return NULL; + + std::map<Anope::string, std::map<Anope::string, Anope::string> >::const_iterator it2 = (*Aliases).find(t); + if (it2 != (*Aliases).end()) + return FindService(it->second, &it2->second, n); + + return FindService(it->second, NULL, n); +} + +std::vector<Anope::string> Service::GetServiceKeys(const Anope::string &t) +{ + check(); + + std::vector<Anope::string> keys; + std::map<Anope::string, std::map<Anope::string, Service *> >::iterator it = (*Services).find(t); + if (it != (*Services).end()) + for (std::map<Anope::string, Service *>::iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) + keys.push_back(it2->first); + return keys; +} + +void Service::AddAlias(const Anope::string &t, const Anope::string &n, const Anope::string &v) +{ + check(); + + std::map<Anope::string, Anope::string> &smap = (*Aliases)[t]; + smap[n] = v; +} + +void Service::DelAlias(const Anope::string &t, const Anope::string &n) +{ + check(); + + std::map<Anope::string, Anope::string> &smap = (*Aliases)[t]; + smap.erase(n); + if (smap.empty()) + (*Aliases).erase(t); +} + +Service::Service(Module *o, const Anope::string &t, const Anope::string &n) : owner(o), type(t), name(n) +{ + this->Register(); +} + +Service::~Service() +{ + this->Unregister(); +} + +void Service::Register() +{ + check(); + + std::map<Anope::string, Service *> &smap = (*Services)[this->type]; + if (smap.find(this->name) != smap.end()) + throw ModuleException("Service " + this->type + " with name " + this->name + " already exists"); + smap[this->name] = this; + + ReferenceBase::ResetAll(); +} + +void Service::Unregister() +{ + check(); + + std::map<Anope::string, Service *> &smap = (*Services)[this->type]; + smap.erase(this->name); + if (smap.empty()) + (*Services).erase(this->type); +} + +ServiceAlias::ServiceAlias(const Anope::string &type, const Anope::string &from, const Anope::string &to) : t(type), f(from) +{ + Service::AddAlias(type, from, to); +} + +ServiceAlias::~ServiceAlias() +{ + Service::DelAlias(t, f); +} + + diff --git a/src/uplink.cpp b/src/uplink.cpp index 80727487a..12b6c94f9 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -15,6 +15,7 @@ #include "config.h" #include "protocol.h" #include "servers.h" +#include "event.h" UplinkSocket *UplinkSock = NULL; @@ -52,7 +53,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(OnPreServerConnect, ()); + Event::OnPreServerConnect(&Event::PreServerConnect::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); @@ -67,7 +68,7 @@ UplinkSocket::~UplinkSocket() { if (IRCD && Servers::GetUplink() && Servers::GetUplink()->IsSynced()) { - FOREACH_MOD(OnServerDisconnect, ()); + Event::OnServerDisconnect(&Event::ServerDisconnect::OnServerDisconnect); for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { @@ -133,7 +134,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(OnServerConnect, ()); + Event::OnServerConnect(&Event::ServerConnect::OnServerConnect); } void UplinkSocket::OnError(const Anope::string &error) diff --git a/src/users.cpp b/src/users.cpp index 97c850111..560536ce4 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -24,6 +24,7 @@ #include "language.h" #include "sockets.h" #include "uplink.h" +#include "event.h" user_map UserListByNick, UserListByUID; @@ -85,7 +86,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope: bool exempt = false; if (server && server->IsULined()) exempt = true; - FOREACH_MOD(OnUserConnect, (this, exempt)); + Event::OnUserConnect(&Event::UserConnect::OnUserConnect, this, exempt); } static void CollideKill(User *target, const Anope::string &reason) @@ -183,7 +184,7 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) } } - FOREACH_MOD(OnUserNickChange, (this, old)); + Event::OnUserNickChange(&Event::UserNickChange::OnUserNickChange, this, old); } void User::SetDisplayedHost(const Anope::string &shost) @@ -195,7 +196,7 @@ void User::SetDisplayedHost(const Anope::string &shost) Log(this, "host") << "changed vhost to " << shost; - FOREACH_MOD(OnSetDisplayedHost, (this)); + Event::OnSetDisplayedHost(&Event::SetDisplayedHost::OnSetDisplayedHost, this); this->UpdateHost(); } @@ -299,7 +300,7 @@ User::~User() --this->server->users; } - FOREACH_MOD(OnPreUserLogoff, (this)); + Event::OnPreUserLogoff(&Event::PreUserLogoff::OnPreUserLogoff, this); ModeManager::StackerDel(this); this->Logout(); @@ -314,7 +315,7 @@ User::~User() if (!this->uid.empty()) UserListByUID.erase(this->uid); - FOREACH_MOD(OnPostUserLogoff, (this)); + Event::OnPostUserLogoff(&Event::PostUserLogoff::OnPostUserLogoff, this); } void User::SendMessage(BotInfo *source, const char *fmt, ...) @@ -366,7 +367,7 @@ void User::Identify(NickAlias *na) this->Login(na->nc); - FOREACH_MOD(OnNickIdentify, (this)); + Event::OnNickIdentify(&Event::NickIdentify::OnNickIdentify, this); if (this->IsServicesOper()) { @@ -402,7 +403,7 @@ void User::Login(NickCore *core) if (this->server->IsSynced()) Log(this, "account") << "is now identified as " << this->nc->display; - FOREACH_MOD(OnUserLogin, (this)); + Event::OnUserLogin(&Event::UserLogin::OnUserLogin, this); } void User::Logout() @@ -470,7 +471,7 @@ bool User::IsServicesOper() } EventReturn MOD_RESULT; - FOREACH_RESULT(IsServicesOper, MOD_RESULT, (this)); + MOD_RESULT = Event::OnIsServicesOper(&Event::IsServicesOperEvent::IsServicesOper, this); if (MOD_RESULT == EVENT_STOP) return false; @@ -528,7 +529,7 @@ void User::SetModeInternal(const MessageSource &source, UserMode *um, const Anop if (um->name == "CLOAK" || um->name == "VHOST") this->UpdateHost(); - FOREACH_MOD(OnUserModeSet, (source, this, um->name)); + Event::OnUserModeSet(&Event::UserModeSet::OnUserModeSet, source, this, um->name); } void User::RemoveModeInternal(const MessageSource &source, UserMode *um) @@ -547,7 +548,7 @@ void User::RemoveModeInternal(const MessageSource &source, UserMode *um) this->UpdateHost(); } - FOREACH_MOD(OnUserModeUnset, (source, this, um->name)); + Event::OnUserModeUnset(&Event::UserModeUnset::OnUserModeUnset, source, this, um->name); } void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string ¶m) @@ -734,7 +735,7 @@ void User::Quit(const Anope::string &reason) return; } - FOREACH_MOD(OnUserQuit, (this, reason)); + Event::OnUserQuit(&Event::UserQuit::OnUserQuit, this, reason); this->quit = true; quitting_users.push_back(this); |