summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/accessgroup.cpp106
-rw-r--r--src/base.cpp3
-rw-r--r--src/bots.cpp38
-rw-r--r--src/channels.cpp33
-rw-r--r--src/command.cpp17
-rw-r--r--src/config.cpp29
-rw-r--r--src/event.cpp101
-rw-r--r--src/extensible.cpp6
-rw-r--r--src/init.cpp10
-rw-r--r--src/logger.cpp20
-rw-r--r--src/main.cpp8
-rw-r--r--src/messages.cpp30
-rw-r--r--src/misc.cpp11
-rw-r--r--src/modes.cpp19
-rw-r--r--src/modulemanager.cpp8
-rw-r--r--src/opertype.cpp6
-rw-r--r--src/process.cpp7
-rw-r--r--src/serialize.cpp180
-rw-r--r--src/servers.cpp10
-rw-r--r--src/service.cpp106
-rw-r--r--src/service_manager.cpp144
-rw-r--r--src/uplink.cpp6
-rw-r--r--src/users.cpp57
-rw-r--r--src/xline.cpp70
24 files changed, 549 insertions, 476 deletions
diff --git a/src/accessgroup.cpp b/src/accessgroup.cpp
new file mode 100644
index 000000000..0d2f7bbe0
--- /dev/null
+++ b/src/accessgroup.cpp
@@ -0,0 +1,106 @@
+#include "modules/chanserv.h"
+#include "accessgroup.h"
+
+using namespace ChanServ;
+
+bool AccessGroup::HasPriv(const Anope::string &priv)
+{
+ if (this->super_admin)
+ return true;
+ else if (!ci || ci->GetLevel(priv) == ACCESS_INVALID)
+ return false;
+
+ /* Privileges prefixed with auto are understood to be given
+ * automatically. Sometimes founders want to not automatically
+ * obtain privileges, so we will let them */
+ bool auto_mode = !priv.find("AUTO");
+
+ /* Only grant founder privilege if this isn't an auto mode or if they don't match any entries in this group */
+ if ((!auto_mode || this->empty()) && this->founder)
+ return true;
+
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&::Event::GroupCheckPriv::OnGroupCheckPriv, this, priv);
+ if (MOD_RESULT != EVENT_CONTINUE)
+ return MOD_RESULT == EVENT_ALLOW;
+
+ for (unsigned i = this->size(); i > 0; --i)
+ {
+ ChanAccess *access = this->at(i - 1);
+
+ if (access->HasPriv(priv))
+ return true;
+ }
+
+ return false;
+}
+
+ChanAccess *AccessGroup::Highest()
+{
+ ChanAccess *highest = NULL;
+ for (unsigned i = 0; i < this->size(); ++i)
+ if (highest == NULL || *this->at(i) > *highest)
+ highest = this->at(i);
+ return highest;
+}
+
+bool AccessGroup::operator>(AccessGroup &other)
+{
+ if (other.super_admin)
+ return false;
+ else if (this->super_admin)
+ return true;
+ else if (other.founder)
+ return false;
+ else if (this->founder)
+ return true;
+
+ const std::vector<Privilege> &privs = service->GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ {
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
+
+ if (!this_p && !other_p)
+ continue;
+
+ return this_p && !other_p;
+ }
+
+ return false;
+}
+
+bool AccessGroup::operator<(AccessGroup &other)
+{
+ if (this->super_admin)
+ return false;
+ else if (other.super_admin)
+ return true;
+ else if (this->founder)
+ return false;
+ else if (other.founder)
+ return true;
+
+ const std::vector<Privilege> &privs = service->GetPrivileges();
+ for (unsigned i = privs.size(); i > 0; --i)
+ {
+ bool this_p = this->HasPriv(privs[i - 1].name),
+ other_p = other.HasPriv(privs[i - 1].name);
+
+ if (!this_p && !other_p)
+ continue;
+
+ return !this_p && other_p;
+ }
+
+ return false;
+}
+
+bool AccessGroup::operator>=(AccessGroup &other)
+{
+ return !(*this < other);
+}
+
+bool AccessGroup::operator<=(AccessGroup &other)
+{
+ return !(*this > other);
+} \ No newline at end of file
diff --git a/src/base.cpp b/src/base.cpp
index 0fcd868bc..61dcbdf60 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -10,9 +10,8 @@
#include "services.h"
#include "anope.h"
#include "service.h"
+#include "base.h"
-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()
diff --git a/src/bots.cpp b/src/bots.cpp
index f934676bb..6091756f7 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -26,7 +26,7 @@ ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, c
this->lastmsg = Anope::CurTime;
this->introduced = false;
- bi = botinfo.Create();
+ bi = Serialize::New<BotInfo *>();
bi->bot = this;
bi->SetNick(nnick);
@@ -35,7 +35,7 @@ ServiceBot::ServiceBot(const Anope::string &nnick, const Anope::string &nuser, c
bi->SetRealName(nreal);
bi->SetCreated(Anope::CurTime);
- Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this);
+ EventManager::Get()->Dispatch(&Event::CreateBot::OnCreateBot, this);
// If we're synchronised with the uplink already, send the bot.
if (Me && Me->IsSynced())
@@ -57,13 +57,13 @@ ServiceBot::~ServiceBot()
bi->bot = nullptr;
bi->Delete();
- Event::OnDelBot(&Event::DelBot::OnDelBot, this);
+ EventManager::Get()->Dispatch(&Event::DelBot::OnDelBot, this);
// If we're synchronised with the uplink already, send the bot.
if (Me && Me->IsSynced())
{
IRCD->SendQuit(this, "");
- Event::OnUserQuit(&Event::UserQuit::OnUserQuit, this, "");
+ EventManager::Get()->Dispatch(&Event::UserQuit::OnUserQuit, this, "");
this->introduced = false;
// XXX ?
//XLine x(this->nick);
@@ -106,13 +106,13 @@ void ServiceBot::SetNewNick(const Anope::string &newnick)
std::vector<ChanServ::Channel *> ServiceBot::GetChannels() const
{
- return bi->GetRefs<ChanServ::Channel *>(ChanServ::channel);
+ return bi->GetRefs<ChanServ::Channel *>();
}
void ServiceBot::Assign(User *u, ChanServ::Channel *ci)
{
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnPreBotAssign(&Event::PreBotAssign::OnPreBotAssign, u, ci, this);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreBotAssign::OnPreBotAssign, u, ci, this);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -121,13 +121,13 @@ void ServiceBot::Assign(User *u, ChanServ::Channel *ci)
ci->SetBot(this);
- Event::OnBotAssign(&Event::BotAssign::OnBotAssign, u, ci, this);
+ EventManager::Get()->Dispatch(&Event::BotAssign::OnBotAssign, u, ci, this);
}
void ServiceBot::UnAssign(User *u, ChanServ::Channel *ci)
{
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnBotUnAssign(&Event::BotUnAssign::OnBotUnAssign, u, ci);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::BotUnAssign::OnBotUnAssign, u, ci);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -156,7 +156,7 @@ void ServiceBot::Join(Channel *c, ChannelStatus *status)
if (IRCD)
IRCD->SendJoin(this, c, status);
- Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, this, c);
+ EventManager::Get()->Dispatch(&Event::JoinChannel::OnJoinChannel, this, c);
}
void ServiceBot::Join(const Anope::string &chname, ChannelStatus *status)
@@ -170,13 +170,13 @@ void ServiceBot::Part(Channel *c, const Anope::string &reason)
if (c->FindUser(this) == NULL)
return;
- Event::OnPrePartChannel(&Event::PrePartChannel::OnPrePartChannel, this, c);
+ EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, this, c);
IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : "");
c->DeleteUser(this);
- Event::OnPartChannel(&Event::PartChannel::OnPartChannel, this, c, c->name, reason);
+ EventManager::Get()->Dispatch(&Event::PartChannel::OnPartChannel, this, c, c->name, reason);
}
void ServiceBot::OnMessage(User *u, const Anope::string &message)
@@ -259,9 +259,9 @@ bool BotInfo::GetOperOnly()
return Get(&BotInfoType::operonly);
}
-void BotInfo::SetNick(const Anope::string &nick)
+void BotInfo::SetNick(const Anope::string &n)
{
- Set(&BotInfoType::nick, nick);
+ Set(&BotInfoType::nick, n);
}
Anope::string BotInfo::GetNick()
@@ -269,9 +269,9 @@ Anope::string BotInfo::GetNick()
return Get(&BotInfoType::nick);
}
-void BotInfo::SetUser(const Anope::string &user)
+void BotInfo::SetUser(const Anope::string &u)
{
- Set(&BotInfoType::user, user);
+ Set(&BotInfoType::user, u);
}
Anope::string BotInfo::GetUser()
@@ -279,9 +279,9 @@ Anope::string BotInfo::GetUser()
return Get(&BotInfoType::user);
}
-void BotInfo::SetHost(const Anope::string &host)
+void BotInfo::SetHost(const Anope::string &h)
{
- Set(&BotInfoType::host, host);
+ Set(&BotInfoType::host, h);
}
Anope::string BotInfo::GetHost()
@@ -289,9 +289,9 @@ Anope::string BotInfo::GetHost()
return Get(&BotInfoType::host);
}
-void BotInfo::SetRealName(const Anope::string &realname)
+void BotInfo::SetRealName(const Anope::string &r)
{
- Set(&BotInfoType::realname, realname);
+ Set(&BotInfoType::realname, r);
}
Anope::string BotInfo::GetRealName()
diff --git a/src/channels.cpp b/src/channels.cpp
index e1529b270..7a380b547 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -43,12 +43,12 @@ Channel::Channel(const Anope::string &nname, time_t ts)
if (Me && Me->IsSynced())
Log(NULL, this, "create");
- Event::OnChannelCreate(&Event::ChannelCreate::OnChannelCreate, this);
+ EventManager::Get()->Dispatch(&Event::ChannelCreate::OnChannelCreate, this);
}
Channel::~Channel()
{
- Event::OnChannelDelete(&Event::ChannelDelete::OnChannelDelete, this);
+ EventManager::Get()->Dispatch(&Event::ChannelDelete::OnChannelDelete, this);
ModeManager::StackerDel(this);
@@ -94,7 +94,7 @@ void Channel::Reset()
void Channel::Sync()
{
syncing = false;
- Event::OnChannelSync(&Event::ChannelSync::OnChannelSync, this);
+ EventManager::Get()->Dispatch(&Event::ChannelSync::OnChannelSync, this);
CheckModes();
}
@@ -112,7 +112,7 @@ void Channel::CheckModes()
}
Reference<Channel> ref = this;
- Event::OnCheckModes(&Event::CheckModes::OnCheckModes, ref);
+ EventManager::Get()->Dispatch(&Event::CheckModes::OnCheckModes, ref);
}
bool Channel::CheckDelete()
@@ -128,7 +128,7 @@ bool Channel::CheckDelete()
return false;
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnCheckDelete(&Event::CheckDelete::OnCheckDelete, this);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::CheckDelete::OnCheckDelete, this);
return MOD_RESULT != EVENT_STOP && this->users.empty();
}
@@ -152,7 +152,7 @@ void Channel::DeleteUser(User *user)
if (user->server && user->server->IsSynced() && !user->Quitting())
Log(user, this, "leave");
- Event::OnLeaveChannel(&Event::LeaveChannel::OnLeaveChannel, user, this);
+ EventManager::Get()->Dispatch(&Event::LeaveChannel::OnLeaveChannel, user, this);
ChanUserContainer *cu = user->FindChannel(this);
if (!this->users.erase(user))
@@ -286,7 +286,7 @@ void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, con
if (cc)
cc->status.AddMode(cm->mchar);
- MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
/* Enforce secureops, etc */
if (enforce_mlock && MOD_RESULT != EVENT_STOP)
@@ -307,7 +307,7 @@ void Channel::SetModeInternal(const MessageSource &setter, ChannelMode *ocm, con
return;
}
- MOD_RESULT = Event::OnChannelModeSet(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeSet::OnChannelModeSet, this, setter, cm, param);
/* Check if we should enforce mlock */
if (!enforce_mlock || MOD_RESULT == EVENT_STOP)
@@ -350,7 +350,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *ocm,
if (cc)
cc->status.DelMode(cm->mchar);
- MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
if (enforce_mlock && MOD_RESULT != EVENT_STOP)
this->SetCorrectModes(u, false);
@@ -370,7 +370,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *ocm,
else
this->modes.erase(cm->name);
- MOD_RESULT = Event::OnChannelModeUnset(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::ChannelModeUnset::OnChannelModeUnset, this, setter, cm, param);
if (cm->name == "PERM")
{
@@ -740,13 +740,13 @@ bool Channel::KickInternal(const MessageSource &source, const Anope::string &nic
ChannelStatus status = cu->status;
- EventReturn MOD_RESULT = Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason);
if ((sender && sender->server == Me) || source.GetServer() == Me)
if (MOD_RESULT == EVENT_STOP)
return false;
this->DeleteUser(target);
- Event::OnUserKicked(&Event::UserKicked::OnUserKicked, source, target, this->name, status, reason);
+ EventManager::Get()->Dispatch(&Event::UserKicked::OnUserKicked, source, target, this->name, status, reason);
return true;
}
@@ -780,7 +780,7 @@ void Channel::ChangeTopicInternal(User *u, const Anope::string &user, const Anop
Log(LOG_DEBUG) << "Topic of " << this->name << " changed by " << this->topic_setter << " to " << newtopic;
- Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, u, this, user, this->topic);
+ EventManager::Get()->Dispatch(&Event::TopicUpdated::OnTopicUpdated, u, this, user, this->topic);
}
void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts)
@@ -794,7 +794,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;
- Event::OnTopicUpdated(&Event::TopicUpdated::OnTopicUpdated, nullptr, this, user, this->topic);
+ EventManager::Get()->Dispatch(&Event::TopicUpdated::OnTopicUpdated, nullptr, this, user, this->topic);
}
void Channel::SetCorrectModes(User *user, bool give_modes)
@@ -812,7 +812,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();
- Event::OnSetCorrectModes(&Event::SetCorrectModes::OnSetCorrectModes, user, this, u_access, give_modes, take_modes);
+ EventManager::Get()->Dispatch(&Event::SetCorrectModes::OnSetCorrectModes, user, this, u_access, give_modes, take_modes);
/* Never take modes from ulines */
if (user->server->IsULined())
@@ -883,8 +883,7 @@ bool Channel::CheckKick(User *user)
Anope::string mask, reason;
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnCheckKick(&Event::CheckKick::OnCheckKick, user, this, mask, reason);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&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 f7de4ccec..825bc1bc8 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -105,7 +105,7 @@ void CommandSource::Reply(const Anope::string &message)
this->reply->SendMessage(*this->service, tok);
}
-Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(owner)
+Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(o)
{
allow_unregistered = require_user = false;
}
@@ -205,20 +205,20 @@ void Command::Run(CommandSource &source, const Anope::string &message)
if (it == source.service->commands.end())
{
if (has_help)
- source.Reply(_("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str());
+ source.Reply(_("Unknown command \002{0}\002. \"{1}{2} HELP\" for help."), message, Config->StrictPrivmsg, source.service->nick);
else
- source.Reply(_("Unknown command \002%s\002."), message.c_str());
+ source.Reply(_("Unknown command \002{0}\002."), message);
return;
}
const CommandInfo &info = it->second;
- ServiceReference<Command> c("Command", info.name);
+ ServiceReference<Command> c(info.name);
if (!c)
{
if (has_help)
- source.Reply(_("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->StrictPrivmsg.c_str(), source.service->nick.c_str());
+ source.Reply(_("Unknown command \002{0}\002. \"{1}{2} HELP\" for help."), message, Config->StrictPrivmsg, source.service->nick);
else
- source.Reply(_("Unknown command \002%s\002."), message.c_str());
+ source.Reply(_("Unknown command \002{0}\002."), message);
Log(source.service) << "Command " << it->first << " exists on me, but its service " << info.name << " was not found!";
return;
}
@@ -252,8 +252,7 @@ void Command::Run(CommandSource &source, const Anope::string &cmdname, const Com
source.command = cmdname;
source.permission = info.permission;
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnPreCommand(&Event::PreCommand::OnPreCommand, source, this, params);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::PreCommand::OnPreCommand, source, this, params);
if (MOD_RESULT == EVENT_STOP)
return;
@@ -276,7 +275,7 @@ void Command::Run(CommandSource &source, const Anope::string &cmdname, const Com
}
this->Execute(source, params);
- Event::OnPostCommand(&Event::PostCommand::OnPostCommand, source, this, params);
+ EventManager::Get()->Dispatch(&Event::PostCommand::OnPostCommand, source, this, params);
}
bool Command::FindCommandFromService(const Anope::string &command_service, ServiceBot* &bot, Anope::string &name)
diff --git a/src/config.cpp b/src/config.cpp
index 5042f1a47..ad73f8e59 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -315,7 +315,7 @@ Conf::Conf() : Block("")
if (ot == NULL)
throw ConfigException("Oper block for " + nname + " has invalid oper type " + type);
- Oper *o = operblock.Create();
+ Oper *o = Serialize::New<Oper *>();
o->conf = this;
o->SetName(nname);
o->SetType(ot);
@@ -326,7 +326,7 @@ Conf::Conf() : Block("")
o->SetVhost(vhost);
}
- for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo))
+ for (BotInfo *bi : Serialize::GetObjects<BotInfo *>())
bi->conf = nullptr;
for (int i = 0; i < this->CountBlock("service"); ++i)
{
@@ -502,7 +502,7 @@ Conf::Conf() : Block("")
if (status.length() > 1)
throw ConfigException("Channelmode status must be at most one character");
- if (list || !param_regex.empty() || param_unset || !status.empty())
+ if (list || !param_regex.empty() || !status.empty())
param = true;
Channelmode cm;
@@ -552,20 +552,19 @@ Conf::Conf() : Block("")
/* Clear existing conf opers */
if (Config)
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
if (o->conf == Config)
o->Delete();
/* Apply new opers */
- if (NickServ::service)
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
- {
- NickServ::Nick *na = NickServ::service->FindNick(o->GetName());
- if (!na)
- continue;
+ for (Oper *o : Serialize::GetObjects<Oper *>())
+ {
+ NickServ::Nick *na = NickServ::FindNick(o->GetName());
+ if (!na)
+ continue;
- na->GetAccount()->o = o;
- Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName();
- }
+ na->GetAccount()->o = o;
+ Log() << "Tied oper " << na->GetAccount()->GetDisplay() << " to type " << o->GetType()->GetName();
+ }
/* Check the user keys */
if (!options->Get<unsigned>("seed"))
@@ -613,7 +612,7 @@ void Conf::Post(Conf *old)
ModeManager::Apply(old);
/* Apply opertype changes, as non-conf opers still point to the old oper types */
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
+ for (Oper *o : Serialize::GetObjects<Oper *>())
{
/* Oper's type is in the old config, so update it */
if (std::find(old->MyOperTypes.begin(), old->MyOperTypes.end(), o->GetType()) != old->MyOperTypes.end())
@@ -633,7 +632,7 @@ void Conf::Post(Conf *old)
}
}
- for (BotInfo *bi : Serialize::GetObjects<BotInfo *>(botinfo))
+ for (BotInfo *bi : Serialize::GetObjects<BotInfo *>())
{
if (!bi->conf)
{
diff --git a/src/event.cpp b/src/event.cpp
index 3e313d5a0..89c60da13 100644
--- a/src/event.cpp
+++ b/src/event.cpp
@@ -1,6 +1,7 @@
-/* Modular support
+/*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2016 Adam <Adam@anope.org>
+ *
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -10,89 +11,15 @@
#include "services.h"
#include "event.h"
-using namespace Event;
+EventManager *EventManager::eventManager = nullptr;
+
+void EventManager::Init()
+{
+ eventManager = new EventManager();
+}
+
+EventManager *EventManager::Get()
+{
+ return eventManager;
+}
-EventHandlers<PreUserKicked> Event::OnPreUserKicked(nullptr);
-EventHandlers<UserKicked> Event::OnUserKicked(nullptr);
-EventHandlers<PreBotAssign> Event::OnPreBotAssign(nullptr);
-EventHandlers<BotAssign> Event::OnBotAssign(nullptr);
-EventHandlers<BotUnAssign> Event::OnBotUnAssign(nullptr);
-EventHandlers<UserConnect> Event::OnUserConnect(nullptr);
-EventHandlers<NewServer> Event::OnNewServer(nullptr);
-EventHandlers<UserNickChange> Event::OnUserNickChange(nullptr);
-EventHandlers<PreCommand> Event::OnPreCommand(nullptr);
-EventHandlers<PostCommand> Event::OnPostCommand(nullptr);
-EventHandlers<SaveDatabase> Event::OnSaveDatabase(nullptr);
-EventHandlers<LoadDatabase> Event::OnLoadDatabase(nullptr);
-EventHandlers<Encrypt> Event::OnEncrypt(nullptr);
-EventHandlers<Decrypt> Event::OnDecrypt(nullptr);
-EventHandlers<CreateBot> Event::OnCreateBot(nullptr);
-EventHandlers<DelBot> Event::OnDelBot(nullptr);
-EventHandlers<PrePartChannel> Event::OnPrePartChannel(nullptr);
-EventHandlers<PartChannel> Event::OnPartChannel(nullptr);
-EventHandlers<LeaveChannel> Event::OnLeaveChannel(nullptr);
-EventHandlers<JoinChannel> Event::OnJoinChannel(nullptr);
-EventHandlers<TopicUpdated> Event::OnTopicUpdated(nullptr);
-EventHandlers<PreServerConnect> Event::OnPreServerConnect(nullptr);
-EventHandlers<ServerConnect> Event::OnServerConnect(nullptr);
-EventHandlers<PreUplinkSync> Event::OnPreUplinkSync(nullptr);
-EventHandlers<ServerDisconnect> Event::OnServerDisconnect(nullptr);
-EventHandlers<Restart> Event::OnRestart(nullptr);
-EventHandlers<Shutdown> Event::OnShutdown(nullptr);
-EventHandlers<AddXLine> Event::OnAddXLine(nullptr);
-EventHandlers<DelXLine> Event::OnDelXLine(nullptr);
-EventHandlers<IsServicesOperEvent> Event::OnIsServicesOper(nullptr);
-EventHandlers<ServerQuit> Event::OnServerQuit(nullptr);
-EventHandlers<UserQuit> Event::OnUserQuit(nullptr);
-EventHandlers<PreUserLogoff> Event::OnPreUserLogoff(nullptr);
-EventHandlers<PostUserLogoff> Event::OnPostUserLogoff(nullptr);
-EventHandlers<AccessDel> Event::OnAccessDel(nullptr);
-EventHandlers<AccessAdd> Event::OnAccessAdd(nullptr);
-EventHandlers<AccessClear> Event::OnAccessClear(nullptr);
-EventHandlers<ChanRegistered> Event::OnChanRegistered(nullptr);
-EventHandlers<CreateChan> Event::OnCreateChan(nullptr);
-EventHandlers<DelChan> Event::OnDelChan(nullptr);
-EventHandlers<ChannelCreate> Event::OnChannelCreate(nullptr);
-EventHandlers<ChannelDelete> Event::OnChannelDelete(nullptr);
-EventHandlers<CheckKick> Event::OnCheckKick(nullptr);
-EventHandlers<CheckPriv> Event::OnCheckPriv(nullptr);
-EventHandlers<GroupCheckPriv> Event::OnGroupCheckPriv(nullptr);
-EventHandlers<NickIdentify> Event::OnNickIdentify(nullptr);
-EventHandlers<UserLogin> Event::OnUserLogin(nullptr);
-EventHandlers<NickLogout> Event::OnNickLogout(nullptr);
-EventHandlers<DelNick> Event::OnDelNick(nullptr);
-EventHandlers<NickCoreCreate> Event::OnNickCoreCreate(nullptr);
-EventHandlers<DelCore> Event::OnDelCore(nullptr);
-EventHandlers<ChangeCoreDisplay> Event::OnChangeCoreDisplay(nullptr);
-EventHandlers<NickClearAccess> Event::OnNickClearAccess(nullptr);
-EventHandlers<NickAddAccess> Event::OnNickAddAccess(nullptr);
-EventHandlers<NickEraseAccess> Event::OnNickEraseAccess(nullptr);
-EventHandlers<CheckAuthentication> Event::OnCheckAuthentication(nullptr);
-EventHandlers<Fingerprint> Event::OnFingerprint(nullptr);
-EventHandlers<UserAway> Event::OnUserAway(nullptr);
-EventHandlers<Invite> Event::OnInvite(nullptr);
-EventHandlers<SetVhost> Event::OnSetVhost(nullptr);
-EventHandlers<SetDisplayedHost> Event::OnSetDisplayedHost(nullptr);
-EventHandlers<ChannelModeSet> Event::OnChannelModeSet(nullptr);
-EventHandlers<ChannelModeUnset> Event::OnChannelModeUnset(nullptr);
-EventHandlers<UserModeSet> Event::OnUserModeSet(nullptr);
-EventHandlers<UserModeUnset> Event::OnUserModeUnset(nullptr);
-EventHandlers<ChannelModeAdd> Event::OnChannelModeAdd(nullptr);
-EventHandlers<UserModeAdd> Event::OnUserModeAdd(nullptr);
-EventHandlers<ModuleLoad> Event::OnModuleLoad(nullptr);
-EventHandlers<ModuleUnload> Event::OnModuleUnload(nullptr);
-EventHandlers<ServerSync> Event::OnServerSync(nullptr);
-EventHandlers<UplinkSync> Event::OnUplinkSync(nullptr);
-EventHandlers<BotPrivmsg> Event::OnBotPrivmsg(nullptr);
-EventHandlers<BotNotice> Event::OnBotNotice(nullptr);
-EventHandlers<Privmsg> Event::OnPrivmsg(nullptr);
-EventHandlers<Event::Log> Event::OnLog(nullptr);
-EventHandlers<LogMessage> Event::OnLogMessage(nullptr);
-EventHandlers<CheckModes> Event::OnCheckModes(nullptr);
-EventHandlers<ChannelSync> Event::OnChannelSync(nullptr);
-EventHandlers<SetCorrectModes> Event::OnSetCorrectModes(nullptr);
-EventHandlers<Message> Event::OnMessage(nullptr);
-EventHandlers<CanSet> Event::OnCanSet(nullptr);
-EventHandlers<CheckDelete> Event::OnCheckDelete(nullptr);
-EventHandlers<ExpireTick> Event::OnExpireTick(nullptr);
-EventHandlers<SerializeEvents> Event::OnSerialize(nullptr);
diff --git a/src/extensible.cpp b/src/extensible.cpp
index c3c56abf8..a014d6bd0 100644
--- a/src/extensible.cpp
+++ b/src/extensible.cpp
@@ -18,12 +18,10 @@ ExtensibleBase::ExtensibleBase(Module *m, const Anope::string &t, const Anope::s
{
}
-ExtensibleBase::~ExtensibleBase()
-{
-}
-
Extensible::~Extensible()
{
+ while (!extension_items.empty())
+ (*extension_items.begin())->Unset(this);
}
bool Extensible::HasExtOK(const Anope::string &name)
diff --git a/src/init.cpp b/src/init.cpp
index e64bf0eff..f0f793839 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -481,8 +481,11 @@ void Anope::Init(int ac, char **av)
/* Initialize the socket engine. Note that some engines can not survive a fork(), so this must be here. */
SocketEngine::Init();
+ ServiceManager::Init();
+ EventManager::Init();
+
new BotInfoType();
- new XLineType(nullptr, "XLine");
+ new XLineType(nullptr);
new OperBlockType();
/* Read configuration file; exit if there are problems. */
@@ -567,14 +570,11 @@ void Anope::Init(int ac, char **av)
/* Load up databases */
Log() << "Loading databases...";
- EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnLoadDatabase(&Event::LoadDatabase::OnLoadDatabase);
+ EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::LoadDatabase::OnLoadDatabase);;
static_cast<void>(MOD_RESULT);
Log() << "Databases loaded";
for (channel_map::const_iterator it = ChannelList.begin(), it_end = ChannelList.end(); it != it_end; ++it)
it->second->Sync();
-
- //Serialize::CheckTypes();
}
diff --git a/src/logger.cpp b/src/logger.cpp
index 3a735d48d..7be130d0b 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -90,11 +90,11 @@ Log::Log(LogType t, CommandSource &src, Command *_c, ChanServ::Channel *_ci) : u
if (type != LOG_COMMAND && type != LOG_OVERRIDE && type != LOG_ADMIN)
throw CoreException("This constructor does not support this log type");
- size_t sl = c->name.find('/');
+ size_t sl = c->GetName().find('/');
this->bi = NULL;
if (sl != Anope::string::npos)
- this->bi = ServiceBot::Find(c->name.substr(0, sl), true);
- this->category = c->name;
+ this->bi = ServiceBot::Find(c->GetName().substr(0, sl), true);
+ this->category = c->GetName();
}
Log::Log(User *_u, Channel *ch, const Anope::string &cat) : bi(NULL), u(_u), nc(NULL), c(NULL), source(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), m(NULL), type(LOG_CHANNEL), category(cat)
@@ -132,7 +132,15 @@ Log::~Log()
else if (this->type == LOG_TERMINAL)
std::cout << this->BuildPrefix() << this->buf.str() << std::endl;
- Event::OnLog(&Event::Log::OnLog, this);
+ /* Some of the higher debug messages are in the event/service system which manages event dispatch,
+ * so firing off the log event here can cause them to be in weird states
+ */
+ if (this->type <= LOG_NORMAL)
+ {
+ EventManager *em = EventManager::Get();
+ if (em != nullptr)
+ em->Dispatch(&Event::Log::OnLog, this);
+ }
if (Config)
for (unsigned i = 0; i < Config->LogInfos.size(); ++i)
@@ -154,7 +162,7 @@ Anope::string Log::FormatSource() const
Anope::string Log::FormatCommand() const
{
- Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->name) + " ";
+ Anope::string buffer = FormatSource() + " used " + (source != NULL && !source->command.empty() ? source->command : this->c->GetName()) + " ";
if (this->ci)
buffer += "on " + this->ci->GetName() + " ";
@@ -348,7 +356,7 @@ void LogInfo::ProcessMessage(const Log *l)
const Anope::string &buffer = l->BuildPrefix() + l->buf.str();
- Event::OnLogMessage(&Event::LogMessage::OnLogMessage, this, l, buffer);
+ EventManager::Get()->Dispatch(&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 65fb8d3f6..b6a41fd53 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -62,7 +62,7 @@ class ExpireTimer : public Timer
void Tick(time_t) override
{
- Event::OnExpireTick(&Event::ExpireTick::OnExpireTick);
+ EventManager::Get()->Dispatch(&Event::ExpireTick::OnExpireTick);
}
};
@@ -72,7 +72,7 @@ void Anope::SaveDatabases()
return;
Log(LOG_DEBUG) << "Saving databases";
- Event::OnSaveDatabase(&Event::SaveDatabase::OnSaveDatabase);
+ EventManager::Get()->Dispatch(&Event::SaveDatabase::OnSaveDatabase);
}
/** The following comes from InspIRCd to get the full path of the Anope executable
@@ -180,11 +180,11 @@ int main(int ac, char **av, char **envp)
if (Anope::Restarting)
{
- Event::OnRestart(&Event::Restart::OnRestart);
+ EventManager::Get()->Dispatch(&Event::Restart::OnRestart);
}
else
{
- Event::OnShutdown(&Event::