From f29e1cf383529a1a29f02b0669d973f5ee0b7a66 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 28 May 2014 12:07:29 -0400 Subject: Move most of the core pseudoclient logic to modules --- src/access.cpp | 441 ------------------- src/account.cpp | 80 ---- src/bots.cpp | 18 +- src/channels.cpp | 63 ++- src/command.cpp | 23 +- src/config.cpp | 61 ++- src/event.cpp | 1 - src/hashcomp.cpp | 2 +- src/init.cpp | 2 +- src/language.cpp | 7 +- src/logger.cpp | 12 +- src/mail.cpp | 9 +- src/memos.cpp | 133 ------ src/messages.cpp | 15 +- src/misc.cpp | 12 +- src/modes.cpp | 41 +- src/module.cpp | 4 +- src/modulemanager.cpp | 17 +- src/nickalias.cpp | 217 ---------- src/nickcore.cpp | 266 ------------ src/process.cpp | 5 +- src/protocol.cpp | 6 +- src/regchannel.cpp | 689 ------------------------------ src/serialize.cpp | 8 +- src/servers.cpp | 12 +- src/socket_transport.cpp | 4 +- src/socketengines/socketengine_epoll.cpp | 6 +- src/socketengines/socketengine_kqueue.cpp | 4 +- src/socketengines/socketengine_poll.cpp | 2 +- src/socketengines/socketengine_select.cpp | 2 +- src/sockets.cpp | 2 +- src/tools/anopesmtp.cpp | 2 +- src/uplink.cpp | 1 + src/users.cpp | 73 ++-- src/win32/anope_windows.h | 4 +- src/win32/dir/dir.cpp | 2 +- src/win32/dir/dir.h | 2 +- src/win32/pipe/pipe.cpp | 2 +- src/win32/resource.h | 2 +- src/win32/sigaction/sigaction.cpp | 5 +- src/win32/sigaction/sigaction.h | 10 +- src/win32/socket.cpp | 2 +- src/win32/windows.cpp | 6 +- 43 files changed, 224 insertions(+), 2051 deletions(-) delete mode 100644 src/access.cpp delete mode 100644 src/account.cpp delete mode 100644 src/memos.cpp delete mode 100644 src/nickalias.cpp delete mode 100644 src/nickcore.cpp delete mode 100644 src/regchannel.cpp (limited to 'src') diff --git a/src/access.cpp b/src/access.cpp deleted file mode 100644 index 26c8dee27..000000000 --- a/src/access.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "service.h" -#include "access.h" -#include "regchannel.h" -#include "users.h" -#include "account.h" -#include "protocol.h" -#include "event.h" - -static struct -{ - Anope::string name; - Anope::string desc; -} descriptions[] = { - {"ACCESS_CHANGE", _("Allowed to modify the access list")}, - {"ACCESS_LIST", _("Allowed to view the access list")}, - {"AKICK", _("Allowed to use the AKICK command")}, - {"ASSIGN", _("Allowed to assign/unassign a bot")}, - {"AUTOHALFOP", _("Automatic halfop upon join")}, - {"AUTOOP", _("Automatic channel operator status upon join")}, - {"AUTOOWNER", _("Automatic owner upon join")}, - {"AUTOPROTECT", _("Automatic protect upon join")}, - {"AUTOVOICE", _("Automatic voice on join")}, - {"BADWORDS", _("Allowed to modify channel badwords list")}, - {"BAN", _("Allowed to ban users")}, - {"FANTASIA", _("Allowed to use fantasy commands")}, - {"FOUNDER", _("Allowed to issue commands restricted to channel founders")}, - {"GETKEY", _("Allowed to use GETKEY command")}, - {"GREET", _("Greet message displayed on join")}, - {"HALFOP", _("Allowed to (de)halfop users")}, - {"HALFOPME", _("Allowed to (de)halfop him/herself")}, - {"INFO", _("Allowed to get full INFO output")}, - {"INVITE", _("Allowed to use the INVITE command")}, - {"KICK", _("Allowed to use the KICK command")}, - {"MEMO", _("Allowed to read channel memos")}, - {"MODE", _("Allowed to use the MODE command")}, - {"NOKICK", _("Prevents users being kicked by Services")}, - {"OP", _("Allowed to (de)op users")}, - {"OPME", _("Allowed to (de)op him/herself")}, - {"OWNER", _("Allowed to (de)owner users")}, - {"OWNERME", _("Allowed to (de)owner him/herself")}, - {"PROTECT", _("Allowed to (de)protect users")}, - {"PROTECTME", _("Allowed to (de)protect him/herself")}, - {"SAY", _("Allowed to use SAY and ACT commands")}, - {"SET", _("Allowed to set channel settings")}, - {"SIGNKICK", _("No signed kick when SIGNKICK LEVEL is used")}, - {"TOPIC", _("Allowed to change channel topics")}, - {"UNBAN", _("Allowed to unban users")}, - {"VOICE", _("Allowed to (de)voice users")}, - {"VOICEME", _("Allowed to (de)voice him/herself")} -}; - -Privilege::Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r) -{ - if (this->desc.empty()) - for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j) - if (descriptions[j].name.equals_ci(name)) - this->desc = descriptions[j].desc; -} - -bool Privilege::operator==(const Privilege &other) const -{ - return this->name.equals_ci(other.name); -} - -std::vector PrivilegeManager::Privileges; - -void PrivilegeManager::AddPrivilege(Privilege p) -{ - unsigned i; - for (i = 0; i < Privileges.size(); ++i) - { - Privilege &priv = Privileges[i]; - - if (priv.rank > p.rank) - break; - } - - Privileges.insert(Privileges.begin() + i, p); -} - -void PrivilegeManager::RemovePrivilege(Privilege &p) -{ - std::vector::iterator it = std::find(Privileges.begin(), Privileges.end(), p); - if (it != Privileges.end()) - Privileges.erase(it); - - for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit) - { - cit->second->QueueUpdate(); - cit->second->RemoveLevel(p.name); - } -} - -Privilege *PrivilegeManager::FindPrivilege(const Anope::string &name) -{ - for (unsigned i = Privileges.size(); i > 0; --i) - if (Privileges[i - 1].name.equals_ci(name)) - return &Privileges[i - 1]; - return NULL; -} - -std::vector &PrivilegeManager::GetPrivileges() -{ - return Privileges; -} - -void PrivilegeManager::ClearPrivileges() -{ - Privileges.clear(); -} - -AccessProvider::AccessProvider(Module *o, const Anope::string &n) : Service(o, "AccessProvider", n) -{ - Providers.push_back(this); -} - -AccessProvider::~AccessProvider() -{ - std::list::iterator it = std::find(Providers.begin(), Providers.end(), this); - if (it != Providers.end()) - Providers.erase(it); -} - -std::list AccessProvider::Providers; - -const std::list& AccessProvider::GetProviders() -{ - return Providers; -} - -ChanAccess::ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p) -{ -} - -ChanAccess::~ChanAccess() -{ - if (this->ci) - { - std::vector::iterator it = std::find(this->ci->access->begin(), this->ci->access->end(), this); - if (it != this->ci->access->end()) - this->ci->access->erase(it); - - const NickAlias *na = NickAlias::Find(this->mask); - if (na != NULL) - na->nc->RemoveChannelReference(this->ci); - else - { - ChannelInfo *c = ChannelInfo::Find(this->mask); - if (c) - c->RemoveChannelReference(this->ci->name); - } - } -} - -void ChanAccess::Serialize(Serialize::Data &data) const -{ - data["provider"] << this->provider->name; - data["ci"] << this->ci->name; - data["mask"] << this->mask; - data["creator"] << this->creator; - data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; - data.SetType("created", Serialize::Data::DT_INT); data["created"] << this->created; - data["data"] << this->AccessSerialize(); -} - -Serializable* ChanAccess::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string provider, chan; - - data["provider"] >> provider; - data["ci"] >> chan; - - ServiceReference aprovider("AccessProvider", provider); - ChannelInfo *ci = ChannelInfo::Find(chan); - if (!aprovider || !ci) - return NULL; - - ChanAccess *access; - if (obj) - access = anope_dynamic_static_cast(obj); - else - access = aprovider->Create(); - access->ci = ci; - data["mask"] >> access->mask; - data["creator"] >> access->creator; - data["last_seen"] >> access->last_seen; - data["created"] >> access->created; - - Anope::string adata; - data["data"] >> adata; - access->AccessUnserialize(adata); - - if (!obj) - ci->AddAccess(access); - return access; -} - -bool ChanAccess::Matches(const User *u, const NickCore *acc, Path &p) const -{ - if (this->nc) - return this->nc == acc; - - if (u) - { - bool is_mask = this->mask.find_first_of("!@?*") != Anope::string::npos; - if (is_mask && Anope::Match(u->nick, this->mask)) - return true; - else if (Anope::Match(u->GetDisplayedMask(), this->mask)) - return true; - } - - if (acc) - { - for (unsigned i = 0; i < acc->aliases->size(); ++i) - { - const NickAlias *na = acc->aliases->at(i); - if (Anope::Match(na->nick, this->mask)) - return true; - } - } - - if (IRCD->IsChannelValid(this->mask)) - { - ChannelInfo *tci = ChannelInfo::Find(this->mask); - if (tci) - { - for (unsigned i = 0; i < tci->GetAccessCount(); ++i) - { - ChanAccess *a = tci->GetAccess(i); - std::pair pair = std::make_pair(this, a); - - std::pair range = p.first.equal_range(this); - for (; range.first != range.second; ++range.first) - if (range.first->first == pair.first && range.first->second == pair.second) - goto cont; - - p.first.insert(pair); - if (a->Matches(u, acc, p)) - p.second.insert(pair); - - cont:; - } - - return p.second.count(this) > 0; - } - } - - return false; -} - -bool ChanAccess::operator>(const ChanAccess &other) const -{ - const std::vector &privs = PrivilegeManager::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 ChanAccess::operator<(const ChanAccess &other) const -{ - const std::vector &privs = PrivilegeManager::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 ChanAccess::operator>=(const ChanAccess &other) const -{ - return !(*this < other); -} - -bool ChanAccess::operator<=(const ChanAccess &other) const -{ - return !(*this > other); -} - -AccessGroup::AccessGroup() : std::vector() -{ - this->ci = NULL; - this->nc = NULL; - this->super_admin = this->founder = false; -} - -static bool HasPriv(const AccessGroup &ag, const ChanAccess *access, const Anope::string &name) -{ - EventReturn MOD_RESULT = Event::OnCheckPriv(&Event::CheckPriv::OnCheckPriv, access, name); - if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name)) - { - typedef std::multimap path; - std::pair it = ag.path.second.equal_range(access); - if (it.first != it.second) - /* check all of the paths for this entry */ - for (; it.first != it.second; ++it.first) - { - const ChanAccess *a = it.first->second; - /* if only one path fully matches then we are ok */ - if (HasPriv(ag, a, name)) - return true; - } - else - /* entry is the end of a chain, all entries match, ok */ - return true; - } - - /* entry does not match or none of the chains fully match */ - return false; -} - -bool AccessGroup::HasPriv(const Anope::string &name) const -{ - if (this->super_admin) - return true; - else if (!ci || ci->GetLevel(name) == 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 = !name.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; - MOD_RESULT = Event::OnGroupCheckPriv(&Event::GroupCheckPriv::OnGroupCheckPriv, this, name); - if (MOD_RESULT != EVENT_CONTINUE) - return MOD_RESULT == EVENT_ALLOW; - - for (unsigned i = this->size(); i > 0; --i) - { - ChanAccess *access = this->at(i - 1); - - if (::HasPriv(*this, access, name)) - return true; - } - - return false; -} - -const ChanAccess *AccessGroup::Highest() const -{ - 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>(const AccessGroup &other) const -{ - 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 &privs = PrivilegeManager::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<(const AccessGroup &other) const -{ - 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 &privs = PrivilegeManager::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>=(const AccessGroup &other) const -{ - return !(*this < other); -} - -bool AccessGroup::operator<=(const AccessGroup &other) const -{ - return !(*this > other); -} - diff --git a/src/account.cpp b/src/account.cpp deleted file mode 100644 index e58ee1646..000000000 --- a/src/account.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "services.h" -#include "account.h" -#include "modules.h" -#include "users.h" -#include "protocol.h" -#include "regchannel.h" - -std::set IdentifyRequest::Requests; - -IdentifyRequest::IdentifyRequest(Module *o, const Anope::string &acc, const Anope::string &pass) : owner(o), account(acc), password(pass), dispatched(false), success(false) -{ - Requests.insert(this); -} - -IdentifyRequest::~IdentifyRequest() -{ - Requests.erase(this); -} - -void IdentifyRequest::Hold(Module *m) -{ - holds.insert(m); -} - -void IdentifyRequest::Release(Module *m) -{ - holds.erase(m); - if (holds.empty() && dispatched) - { - if (!success) - this->OnFail(); - delete this; - } -} - -void IdentifyRequest::Success(Module *m) -{ - if (!success) - { - this->OnSuccess(); - success = true; - } -} - -void IdentifyRequest::Dispatch() -{ - if (holds.empty()) - { - if (!success) - this->OnFail(); - delete this; - } - else - dispatched = true; -} - -void IdentifyRequest::ModuleUnload(Module *m) -{ - for (std::set::iterator it = Requests.begin(), it_end = Requests.end(); it != it_end;) - { - IdentifyRequest *ir = *it; - ++it; - - ir->Release(m); - if (ir->owner == m) - delete ir; - } -} diff --git a/src/bots.cpp b/src/bots.cpp index b2feb9c4e..ea0bf4ec3 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -13,16 +13,16 @@ #include "servers.h" #include "protocol.h" #include "xline.h" -#include "regchannel.h" #include "channels.h" #include "config.h" #include "language.h" #include "serialize.h" #include "event.h" +#include "modules/chanserv.h" Serialize::Checker BotListByNick("BotInfo"), BotListByUID("BotInfo"); -BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Serializable("BotInfo"), channels("ChannelInfo"), botmodes(bmodes) +BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, "", "", Me, nreal, Anope::CurTime, "", Servers::TS6_UID_Retrieve(), NULL), Serializable("BotInfo"), channels("ChanServ::Channel"), botmodes(bmodes) { this->lastmsg = this->created = Anope::CurTime; this->introduced = false; @@ -31,7 +31,7 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A (*BotListByNick)[this->nick] = this; if (!this->uid.empty()) (*BotListByUID)[this->uid] = this; - + Event::OnCreateBot(&Event::CreateBot::OnCreateBot, this); // If we're synchronised with the uplink already, send the bot. @@ -61,9 +61,9 @@ BotInfo::~BotInfo() IRCD->SendSQLineDel(&x); } - for (std::set::iterator it = this->channels->begin(), it_end = this->channels->end(); it != it_end; ++it) + for (std::set::iterator it = this->channels->begin(), it_end = this->channels->end(); it != it_end; ++it) { - ChannelInfo *ci = *it; + ChanServ::Channel *ci = *it; this->UnAssign(NULL, ci); } @@ -145,12 +145,12 @@ void BotInfo::SetNewNick(const Anope::string &newnick) (*BotListByNick)[this->nick] = this; } -const std::set &BotInfo::GetChannels() const +const std::set &BotInfo::GetChannels() const { return this->channels; } -void BotInfo::Assign(User *u, ChannelInfo *ci) +void BotInfo::Assign(User *u, ChanServ::Channel *ci) { EventReturn MOD_RESULT; MOD_RESULT = Event::OnPreBotAssign(&Event::PreBotAssign::OnPreBotAssign, u, ci, this); @@ -159,14 +159,14 @@ void BotInfo::Assign(User *u, ChannelInfo *ci) if (ci->bi) ci->bi->UnAssign(u, ci); - + ci->bi = this; this->channels->insert(ci); Event::OnBotAssign(&Event::BotAssign::OnBotAssign, u, ci, this); } -void BotInfo::UnAssign(User *u, ChannelInfo *ci) +void BotInfo::UnAssign(User *u, ChanServ::Channel *ci) { EventReturn MOD_RESULT; MOD_RESULT = Event::OnBotUnAssign(&Event::BotUnAssign::OnBotUnAssign, u, ci); diff --git a/src/channels.cpp b/src/channels.cpp index 09b88a7e9..9ba886c30 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -12,20 +12,18 @@ #include "services.h" #include "channels.h" -#include "regchannel.h" #include "logger.h" #include "modules.h" #include "users.h" -#include "bots.h" #include "servers.h" #include "protocol.h" #include "users.h" #include "config.h" -#include "access.h" #include "sockets.h" #include "language.h" #include "uplink.h" #include "event.h" +#include "modules/chanserv.h" channel_map ChannelList; @@ -41,10 +39,6 @@ Channel::Channel(const Anope::string &nname, time_t ts) this->server_modetime = this->chanserv_modetime = 0; this->server_modecount = this->chanserv_modecount = this->bouncy_modes = this->topic_ts = this->topic_time = 0; - this->ci = ChannelInfo::Find(this->name); - if (this->ci) - this->ci->c = this; - if (Me && Me->IsSynced()) Log(NULL, this, "create"); @@ -89,7 +83,7 @@ void Channel::Reset() for (ChanUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it) this->SetCorrectModes(it->second->user, true); - + // If the channel is syncing now, do not force a sync due to Reset(), as we are probably iterating over users in Message::SJoin // A sync will come soon if (!syncing) @@ -127,7 +121,7 @@ bool Channel::CheckDelete() */ if (this->syncing) return false; - + /* Permanent channels never get deleted */ if (this->HasMode("PERM")) return false; @@ -332,8 +326,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *cm, c return; } - BotInfo *bi = BotInfo::Find(param); - User *u = bi ? bi : User::Find(param); + User *u = User::Find(param); if (!u) { @@ -368,7 +361,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *cm, c } else this->modes.erase(cm->name); - + if (cm->type == MODE_LIST) { ChannelModeList *cml = anope_dynamic_static_cast(cm); @@ -393,7 +386,7 @@ void Channel::RemoveModeInternal(const MessageSource &setter, ChannelMode *cm, c this->CheckModes(); } -void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) +void Channel::SetMode(User *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; @@ -438,12 +431,12 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, SetModeInternal(bi, cm, param, enforce_mlock); } -void Channel::SetMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) +void Channel::SetMode(User *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) { SetMode(bi, ModeManager::FindChannelModeByName(mname), param, enforce_mlock); } -void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) +void Channel::RemoveMode(User *bi, ChannelMode *cm, const Anope::string ¶m, bool enforce_mlock) { if (!cm) return; @@ -488,7 +481,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string ¶ RemoveModeInternal(bi, cm, realparam, enforce_mlock); } -void Channel::RemoveMode(BotInfo *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) +void Channel::RemoveMode(User *bi, const Anope::string &mname, const Anope::string ¶m, bool enforce_mlock) { RemoveMode(bi, ModeManager::FindChannelModeByName(mname), param, enforce_mlock); } @@ -508,7 +501,7 @@ bool Channel::GetParam(const Anope::string &mname, Anope::string &target) const return false; } -void Channel::SetModes(BotInfo *bi, bool enforce_mlock, const char *cmodes, ...) +void Channel::SetModes(User *bi, bool enforce_mlock, const char *cmodes, ...) { char buf[BUFSIZE] = ""; va_list args; @@ -688,7 +681,7 @@ void Channel::SetModesInternal(MessageSource &source, const Anope::string &mode, Log(setter, this, "mode") << modestring << paramstring; else Log(LOG_DEBUG) << source.GetName() << " is setting " << this->name << " to " << modestring << paramstring; - + if (enforce_mlock) this->CheckModes(); } @@ -710,14 +703,14 @@ bool Channel::MatchesList(User *u, const Anope::string &mode) return false; } -void Channel::KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason) +bool Channel::KickInternal(const MessageSource &source, const Anope::string &nick, const Anope::string &reason) { User *sender = source.GetUser(); User *target = User::Find(nick); if (!target) { Log(LOG_DEBUG) << "Channel::KickInternal got a nonexistent user " << nick << " on " << this->name << ": " << reason; - return; + return false; } if (sender) @@ -731,18 +724,23 @@ void Channel::KickInternal(const MessageSource &source, const Anope::string &nic if (cu == NULL) { Log(LOG_DEBUG) << "Channel::KickInternal got kick for user " << target->nick << " from " << source.GetSource() << " who isn't on channel " << this->name; - return; + return false; } Anope::string this_name = this->name; ChannelStatus status = cu->status; - Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason); + EventReturn MOD_RESULT = Event::OnPreUserKicked(&Event::PreUserKicked::OnPreUserKicked, source, cu, reason); + if ((sender && sender->server == Me) || source.GetServer() == Me) + if (MOD_RESULT == EVENT_STOP) + return false; + this->DeleteUser(target); /* This can delete this; */ Event::OnUserKicked(&Event::UserKicked::OnUserKicked, source, target, this_name, status, reason); + return true; } -bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) +bool Channel::Kick(User *source, User *u, const char *reason, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -753,16 +751,13 @@ bool Channel::Kick(BotInfo *bi, User *u, const char *reason, ...) /* Do not kick protected clients or Ulines */ if (u->IsProtected()) return false; - - if (bi == NULL) - bi = this->ci->WhoSends(); - EventReturn MOD_RESULT; - MOD_RESULT = Event::OnBotKick(&Event::BotKick::OnBotKick, bi, this, u, buf); - if (MOD_RESULT == EVENT_STOP) + if (source == NULL) + source = this->ci->WhoSends(); + + if (!this->KickInternal(source, u->nick, buf)) return false; - IRCD->SendKick(bi, this, u, "%s", buf); - this->KickInternal(bi, u->nick, buf); + IRCD->SendKick(source, this, u, "%s", buf); return true; } @@ -800,13 +795,13 @@ void Channel::SetCorrectModes(User *user, bool give_modes) { if (user == NULL) return; - + if (!this->ci) return; Log(LOG_DEBUG) << "Setting correct user modes for " << user->nick << " on " << this->name << " (" << (give_modes ? "" : "not ") << "giving modes)"; - AccessGroup u_access = ci->AccessFor(user); + ChanServ::AccessGroup u_access = ci->AccessFor(user); /* Initially only take modes if the channel is being created by a non netmerge */ bool take_modes = this->syncing && user->server->IsSynced(); @@ -886,7 +881,7 @@ bool Channel::CheckKick(User *user) MOD_RESULT = Event::OnCheckKick(&Event::CheckKick::OnCheckKick, user, this, mask, reason); if (MOD_RESULT != EVENT_STOP) return false; - + if (mask.empty()) mask = this->ci->GetIdealBan(user); if (reason.empty()) diff --git a/src/command.cpp b/src/command.cpp index 5241e9316..16070b221 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -12,14 +12,15 @@ #include "users.h" #include "language.h" #include "config.h" -#include "bots.h" #include "opertype.h" -#include "access.h" -#include "regchannel.h" #include "channels.h" #include "event.h" +#include "bots.h" +#include "protocol.h" +#include "modules/botserv.h" +#include "modules/chanserv.h" -CommandSource::CommandSource(const Anope::string &n, User *user, NickCore *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), +CommandSource::CommandSource(const Anope::string &n, User *user, NickServ::Account *core, CommandReply *r, BotInfo *bi) : nick(n), u(user), nc(core), reply(r), c(NULL), service(bi) { } @@ -34,25 +35,25 @@ User *CommandSource::GetUser() return this->u; } -NickCore *CommandSource::GetAccount() +NickServ::Account *CommandSource::GetAccount() { return this->nc; } -AccessGroup CommandSource::AccessFor(ChannelInfo *ci) +ChanServ::AccessGroup CommandSource::AccessFor(ChanServ::Channel *ci) { if (this->u) return ci->AccessFor(this->u); else if (this->nc) return ci->AccessFor(this->nc); else - return AccessGroup(); + return ChanServ::AccessGroup(); } -bool CommandSource::IsFounder(ChannelInfo *ci) +bool CommandSource::IsFounder(ChanServ::Channel *ci) { if (this->u) - return ::IsFounder(this->u, ci); + return ci->IsFounder(this->u); else if (this->nc) return *this->nc == ci->GetFounder(); return false; @@ -116,7 +117,7 @@ void CommandSource::Reply(const Anope::string &message) sepstream sep(translated_message, '\n', true); Anope::string tok; while (sep.GetToken(tok)) - this->reply->SendMessage(this->service, tok); + 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) @@ -306,7 +307,7 @@ bool Command::FindCommandFromService(const Anope::string &command_service, BotIn return true; } } - + return false; } diff --git a/src/config.cpp b/src/config.cpp index b2ec7789f..7e918e079 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -12,12 +12,12 @@ #include "services.h" #include "config.h" -#include "bots.h" -#include "access.h" #include "opertype.h" #include "channels.h" #include "hashcomp.h" #include "event.h" +#include "bots.h" +#include "modules/nickserv.h" using namespace Configuration; @@ -37,7 +37,7 @@ int Block::CountBlock(const Anope::string &bname) { if (!this) return 0; - + return blocks.count(bname); } @@ -45,7 +45,7 @@ Block* Block::GetBlock(const Anope::string &bname, int num) { if (!this) return NULL; - + std::pair it = blocks.equal_range(bname); for (int i = 0; it.first != it.second; ++it.first, ++i) @@ -280,7 +280,7 @@ Conf::Conf() : Block("") ValidateNotEmpty("oper", "name", nname); ValidateNotEmpty("oper", "type", type); - + OperType *ot = NULL; for (unsigned j = 0; j < this->MyOperTypes.size(); ++j) if (this->MyOperTypes[j]->GetName() == type) @@ -436,18 +436,6 @@ Conf::Conf() : Block("") ci.hide = hide; } - PrivilegeManager::ClearPrivileges(); - for (int i = 0; i < this->CountBlock("privilege"); ++i) - { - Block *privilege = this->GetBlock("privilege", i); - - const Anope::string &nname = privilege->Get("name"), - &desc = privilege->Get("desc"); - int rank = privilege->Get("rank"); - - PrivilegeManager::AddPrivilege(Privilege(nname, desc, rank)); - } - for (int i = 0; i < this->CountBlock("fantasy"); ++i) { Block *fantasy = this->GetBlock("fantasy", i); @@ -488,24 +476,29 @@ Conf::Conf() : Block("") if (Config) /* Clear existing conf opers */ - for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it) + if (NickServ::service) { - NickCore *nc = it->second; - if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) - nc->o = NULL; + NickServ::nickcore_map& ncmap = NickServ::service->GetAccountList(); + for (auto& it : ncmap) + { + NickServ::Account *nc = it.second; + if (nc->o && std::find(Config->Opers.begin(), Config->Opers.end(), nc->o) != Config->Opers.end()) + nc->o = NULL; + } } /* Apply new opers */ - for (unsigned i = 0; i < this->Opers.size(); ++i) - { - Oper *o = this->Opers[i]; + if (NickServ::service) + for (unsigned i = 0; i < this->Opers.size(); ++i) + { + Oper *o = this->Opers[i]; - NickAlias *na = NickAlias::Find(o->name); - if (!na) - continue; + NickServ::Nick *na = NickServ::service->FindNick(o->name); + if (!na) + continue; - na->nc->o = o; - Log() << "Tied oper " << na->nc->display << " to type " << o->ot->GetName(); - } + na->nc->o = o; + Log() << "Tied oper " << na->nc->display << " to type " << o->ot->GetName(); + } if (options->Get("casemap", "ascii") == "ascii") Anope::casemap = std::locale(std::locale(), new Anope::ascii_ctype()); @@ -591,7 +584,7 @@ Block *Conf::GetModule(Module *m) { if (!m) return NULL; - + return GetModule(m->name); } @@ -602,7 +595,7 @@ Block *Conf::GetModule(const Anope::string &mname) return it->second; Block* &block = modules[mname]; - + /* Search for the block */ for (std::pair iters = blocks.equal_range("module"); iters.first != iters.second; ++iters.first) { @@ -708,10 +701,10 @@ void Conf::LoadConf(File &file) Log(LOG_DEBUG) << "Start to read conf " << file.GetName(); // Start reading characters... while (!file.End()) - { + { Anope::string line = file.Read(); ++linenumber; - + /* If this line is completely empty and we are in a quote, just append a newline */ if (line.empty() && in_quote) wordbuffer += "\n"; diff --git a/src/event.cpp b/src/event.cpp index c13118dc4..cba56a314 100644 --- a/src/event.cpp +++ b/src/event.cpp @@ -28,7 +28,6 @@ EventHandlers Event::OnEncrypt(nullptr, "OnEncrypt"); EventHandlers Event::OnDecrypt(nullptr, "OnDecrypt"); EventHandlers Event::OnCreateBot(nullptr, "OnCreateBot"); EventHandlers Event::OnDelBot(nullptr, "OnDelBot"); -EventHandlers Event::OnBotKick(nullptr, "OnBotKick"); EventHandlers Event::OnPrePartChannel(nullptr, "OnPrePartChannel"); EventHandlers Event::OnPartChannel(nullptr, "OnPartChannel"); EventHandlers Event::OnLeaveChannel(nullptr, "OnLeaveChannel"); diff --git a/src/hashcomp.cpp b/src/hashcomp.cpp index 9f48bba29..beaf727ec 100644 --- a/src/hashcomp.cpp +++ b/src/hashcomp.cpp @@ -44,7 +44,7 @@ unsigned char Anope::toupper(unsigned char c) * which is a case-insensitive equivalent to std::string. * */ - + bool ci::ci_char_traits::eq(char c1st, char c2nd) { return case_map_upper[static_cast(c1st)] == case_map_upper[static_cast(c2nd)]; diff --git a/src/init.cpp b/src/init.cpp index cd06a5194..d31f79767 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -105,7 +105,7 @@ void Anope::Fork() { #ifndef _WIN32 kill(getppid(), SIGUSR2); - + freopen("/dev/null", "r", stdin); freopen("/dev/null", "w", stdout); freopen("/dev/null", "w", stderr); diff --git a/src/language.cpp b/src/language.cpp index fdfb4c15e..feaa0b242 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -15,6 +15,7 @@ #include "commands.h" #include "config.h" #include "language.h" +#include "modules/nickserv.h" #if GETTEXT_FOUND # include @@ -69,7 +70,7 @@ const char *Language::Translate(User *u, const char *string) return Translate("", string); } -const char *Language::Translate(const NickCore *nc, const char *string) +const char *Language::Translate(const NickServ::Account *nc, const char *string) { return Translate(nc ? nc->language.c_str() : "", string); } @@ -83,10 +84,10 @@ const char *Language::Translate(const char *lang, const char *string) { if (!string || !*string) return ""; - + if (!lang || !*lang) lang = Config->DefLanguage.c_str(); - + if (Anope::string(lang) == "en") return string; diff --git a/src/logger.cpp b/src/logger.cpp index 1aa530f82..86141ed8a 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -22,6 +22,8 @@ #include "uplink.h" #include "protocol.h" #include "event.h" +#include "modules/nickserv.h" +#include "modules/chanserv.h" #ifndef _WIN32 #include @@ -80,11 +82,11 @@ Log::Log(LogType t, const Anope::string &cat, BotInfo *b) : bi(b), u(NULL), nc(N { } -Log::Log(LogType t, CommandSource &src, Command *_c, ChannelInfo *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t) +Log::Log(LogType t, CommandSource &src, Command *_c, ChanServ::Channel *_ci) : u(src.GetUser()), nc(src.nc), c(_c), source(&src), chan(NULL), ci(_ci), s(NULL), m(NULL), type(t) { if (!c) throw CoreException("Invalid pointers passed to Log::Log"); - + if (type != LOG_COMMAND && type != LOG_OVERRIDE && type != LOG_ADMIN) throw CoreException("This constructor does not support this log type"); @@ -131,7 +133,7 @@ Log::~Log() std::cout << this->BuildPrefix() << this->buf.str() << std::endl; Event::OnLog(&Event::Log::OnLog, this); - + if (Config) for (unsigned i = 0; i < Config->LogInfos.size(); ++i) if (Config->LogInfos[i].HasType(this->type, this->category)) @@ -362,7 +364,7 @@ void LogInfo::ProcessMessage(const Log *l) if (!c) continue; - BotInfo *bi = l->bi; + User *bi = l->bi; if (!bi) bi = this->bot; if (!bi) @@ -379,7 +381,7 @@ void LogInfo::ProcessMessage(const Log *l) } } } - + tm *tm = localtime(&Anope::CurTime); if (tm->tm_mday != this->last_day) { diff --git a/src/mail.cpp b/src/mail.cpp index e514c19ec..342a49a24 100644 --- a/src/mail.cpp +++ b/src/mail.cpp @@ -13,6 +13,9 @@ #include "services.h" #include "mail.h" #include "config.h" +#include "bots.h" +#include "protocol.h" +#include "modules/nickserv.h" Mail::Message::Message(const Anope::string &sf, const Anope::string &mailto, const Anope::string &a, const Anope::string &s, const Anope::string &m) : Thread(), sendmail_path(Config->GetBlock("mail")->Get("sendmailpath")), send_from(sf), mail_to(mailto), addr(a), subject(s), message(m), dont_quote_addresses(Config->GetBlock("mail")->Get("dontquoteaddresses")), success(false) { @@ -51,13 +54,13 @@ void Mail::Message::Run() SetExitState(); } -bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message) +bool Mail::Send(User *u, NickServ::Account *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message) { if (!nc || !service || subject.empty() || message.empty()) return false; Configuration::Block *b = Config->GetBlock("mail"); - + if (!u) { if (!b->Get("usemail") || b->Get("sendfrom").empty()) @@ -90,7 +93,7 @@ bool Mail::Send(User *u, NickCore *nc, BotInfo *service, const Anope::string &su } } -bool Mail::Send(NickCore *nc, const Anope::string &subject, const Anope::string &message) +bool Mail::Send(NickServ::Account *nc, const Anope::string &subject, const Anope::string &message) { Configuration::Block *b = Config->GetBlock("mail"); if (!b->Get("usemail") || b->Get("sendfrom").empty() || !nc || nc->email.empty() || subject.empty() || message.empty()) diff --git a/src/memos.cpp b/src/memos.cpp deleted file mode 100644 index 8b2816f9a..000000000 --- a/src/memos.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* MemoServ functions. - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "services.h" -#include "modules.h" -#include "service.h" -#include "memo.h" -#include "users.h" -#include "account.h" -#include "regchannel.h" - -Memo::Memo() : Serializable("Memo") -{ - unread = receipt = false; -} - -Memo::~Memo() -{ - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(this->owner, ischan); - if (mi) - { - std::vector::iterator it = std::find(mi->memos->begin(), mi->memos->end(), this); - - if (it != mi->memos->end()) - mi->memos->erase(it); - } -} - -void Memo::Serialize(Serialize::Data &data) const -{ - data["owner"] << this->owner; - data.SetType("time", Serialize::Data::DT_INT); data["time"] << this->time; - data["sender"] << this->sender; - data["text"] << this->text; - data["unread"] << this->unread; - data["receipt"] << this->receipt; -} - -Serializable* Memo::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string owner; - - data["owner"] >> owner; - - bool ischan; - MemoInfo *mi = MemoInfo::GetMemoInfo(owner, ischan); - if (!mi) - return NULL; - - Memo *m; - if (obj) - m = anope_dynamic_static_cast(obj); - else - m = new Memo(); - - m->owner = owner; - data["time"] >> m->time; - data["sender"] >> m->sender; - data["text"] >> m->text; - data["unread"] >> m->unread; - data["receipt"] >> m->receipt; - - if (obj == NULL) - mi->memos->push_back(m); - return m; -} - -MemoInfo::MemoInfo() : memomax(0), memos("Memo") -{ -} - -Memo *MemoInfo::GetMemo(unsigned index) const -{ - if (index >= this->memos->size()) - return NULL; - Memo *m = (*memos)[index]; - m->QueueUpdate(); - return m; -} - -unsigned MemoInfo::GetIndex(Memo *m) const -{ - for (unsigned i = 0; i < this->memos->size(); ++i) - if (this->GetMemo(i) == m) - return i; - return -1; -} - -void MemoInfo::Del(unsigned index) -{ - if (index >= this->memos->size()) - return; - delete this->GetMemo(index); -} - -bool MemoInfo::HasIgnore(User *u) -{ - for (unsigned i = 0; i < this->ignores.size(); ++i) - if (u->nick.equals_ci(this->ignores[i]) || (u->Account() && u->Account()->display.equals_ci(this->ignores[i])) || Anope::Match(u->GetMask(), Anope::string(this->ignores[i]))) - return true; - return false; -} - -MemoInfo *MemoInfo::GetMemoInfo(const Anope::string &target, bool &ischan) -{ - if (!target.empty() && target[0] == '#') - { - ischan = true; - ChannelInfo *ci = ChannelInfo::Find(target); - if (ci != NULL) - return &ci->memos; - } - else - { - ischan = false; - NickAlias *na = NickAlias::Find(target); - if (na != NULL) - return &na->nc->memos; - } - - return NULL; -} - diff --git a/src/messages.cpp b/src/messages.cpp index b4da470bf..8ba37498e 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -21,6 +21,7 @@ #include "servers.h" #include "channels.h" #include "event.h" +#include "bots.h" using namespace Message; @@ -57,7 +58,7 @@ void Invite::Run(MessageSource &source, const std::vector ¶ms if (!targ || targ->server != Me || !c || c->FindUser(targ)) return; - + Event::OnInvite(&Event::Invite::OnInvite, source.GetUser(), c, targ); } @@ -115,14 +116,14 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co /* Their TS is newer, don't accept any modes from them */ else if (ts > c->creation_time) keep_their_modes = false; - + /* Update the modes for the channel */ if (keep_their_modes && !modes.empty()) /* If we are syncing, mlock is checked later in Channel::Sync. It is important to not check it here * so that Channel::SetCorrectModes can correctly detect the presence of channel mode +r. */ c->SetModesInternal(source, modes, ts, !c->syncing); - + for (std::list::const_iterator it = users.begin(), it_end = users.end(); it != it_end; ++it) { const ChannelStatus &status = it->first; @@ -140,7 +141,7 @@ void Join::SJoin(MessageSource &source, const Anope::string &chan, time_t ts, co * they aren't allowed to have (secureops etc). */ c->SetCorrectModes(u, true); - + Event::OnJoinChannel(&Event::JoinChannel::OnJoinChannel, u, c); } @@ -355,7 +356,7 @@ void Privmsg::Run(MessageSource &source, const std::vector ¶m MOD_RESULT = Event::OnBotPrivmsg(&Event::BotPrivmsg::OnBotPrivmsg, u, bi, message); if (MOD_RESULT == EVENT_STOP) return; - + bi->OnMessage(u, message); } } @@ -412,9 +413,7 @@ void Stats::Run(MessageSource &source, const std::vector ¶ms) { Oper *o = Oper::opers[i]; - const NickAlias *na = NickAlias::Find(o->name); - if (na) - IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); + IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); } IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); diff --git a/src/misc.cpp b/src/misc.cpp index 7e5121ed6..a68028a70 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -121,7 +121,7 @@ bool NumberList::InvalidRange(const Anope::string &) return true; } -ListFormatter::ListFormatter(NickCore *acc) : nc(acc) +ListFormatter::ListFormatter(NickServ::Account *acc) : nc(acc) { } @@ -215,7 +215,7 @@ void ListFormatter::Process(std::vector &buffer) } } -InfoFormatter::InfoFormatter(NickCore *acc) : nc(acc), longest(0) +InfoFormatter::InfoFormatter(NickServ::Account *acc) : nc(acc), longest(0) { } @@ -312,7 +312,7 @@ time_t Anope::DoTime(const Anope::string &s) return amount; } -Anope::string Anope::Duration(time_t t, const NickCore *nc) +Anope::string Anope::Duration(time_t t, const NickServ::Account *nc) { /* We first calculate everything */ time_t years = t / 31536000; @@ -353,7 +353,7 @@ Anope::string Anope::Duration(time_t t, const NickCore *nc) } } -Anope::string Anope::strftime(time_t t, const NickCore *nc, bool short_output) +Anope::string Anope::strftime(time_t t, const NickServ::Account *nc, bool short_output) { tm tm = *localtime(&t); char buf[BUFSIZE]; @@ -368,7 +368,7 @@ Anope::string Anope::strftime(time_t t, const NickCore *nc, bool short_output) return Anope::string(buf) + " " + Language::Translate(nc, _("(now)")); } -Anope::string Anope::Expires(time_t expires, const NickCore *nc) +Anope::string Anope::Expires(time_t expires, const NickServ::Account *nc) { if (!expires) return Language::Translate(nc, NO_EXPIRE); @@ -644,7 +644,7 @@ Anope::string Anope::VersionBuildString() if (!flags.empty()) s += ", flags " + flags; - + return s; } diff --git a/src/modes.cpp b/src/modes.cpp index c8908820c..cecab9d11 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -15,6 +15,7 @@ #include "channels.h" #include "uplink.h" #include "event.h" +#include "modules/chanserv.h" struct StackerInfo; @@ -42,7 +43,7 @@ struct StackerInfo /* Modes to be deleted */ std::list > DelModes; /* Bot this is sent from */ - BotInfo *bi; + User *bi; StackerInfo() : bi(NULL) { } @@ -322,7 +323,7 @@ bool ModeManager::AddUserMode(UserMode *um) { if (ModeManager::FindUserModeByChar(um->mchar) != NULL) return false; - + if (um->name.empty()) { um->name = stringify(++GenericUserModes); @@ -379,14 +380,14 @@ void ModeManager::RemoveUserMode(UserMode *um) { if (!um) return; - + unsigned want = um->mchar; if (want >= ModeManager::UserModes.size()) return; - + if (ModeManager::UserModes[want] != um) return; - + ModeManager::UserModes[want] = NULL; UserModesByName.erase(um->name); @@ -398,14 +399,14 @@ void ModeManager::RemoveChannelMode(ChannelMode *cm) { if (!cm) return; - + unsigned want = cm->mchar; if (want >= ModeManager::ChannelModes.size()) return; - + if (ModeManager::ChannelModes[want] != cm) return; - + ModeManager::ChannelModes[want] = NULL; if (cm->type == MODE_STATUS) @@ -434,7 +435,7 @@ ChannelMode *ModeManager::FindChannelModeByChar(char mode) unsigned want = mode; if (want >= ModeManager::ChannelModes.size()) return NULL; - + return ModeManager::ChannelModes[want]; } @@ -443,7 +444,7 @@ UserMode *ModeManager::FindUserModeByChar(char mode) unsigned want = mode; if (want >= ModeManager::UserModes.size()) return NULL; - + return ModeManager::UserModes[want]; } @@ -468,11 +469,11 @@ char ModeManager::GetStatusChar(char value) unsigned want = value; if (want >= ModeManager::ChannelModes.size()) return 0; - + ChannelMode *cm = ModeManager::ChannelModes[want]; if (cm == NULL || cm->type != MODE_STATUS || cm->mchar == value) return 0; - + return cm->mchar; } @@ -512,7 +513,7 @@ void ModeManager::RebuildStatusModes() std::sort(ChannelModesByStatus.begin(), ChannelModesByStatus.end(), statuscmp); } -void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) +void ModeManager::StackerAdd(User *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param) { StackerInfo *s = GetInfo(ChannelStackerObjects, c); s->AddMode(cm, Set, Param); @@ -526,7 +527,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, modePipe->Notify(); } -void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) +void ModeManager::StackerAdd(User *bi, User *u, UserMode *um, bool Set, const Anope::string &Param) { StackerInfo *s = GetInfo(UserStackerObjects, u); s->AddMode(um, Set, Param); @@ -671,21 +672,21 @@ Entry::Entry(const Anope::string &m, const Anope::string &fh) : name(m), mask(fh else this->nick = fh; } - + at = this->host.find('#'); if (at != Anope::string::npos) { this->real = this->host.substr(at + 1); this->host = this->host.substr(0, at); } - + /* If the mask is all *'s it will match anything, so just clear it */ if (this->nick.find_first_not_of("*") == Anope::string::npos) this->nick.clear(); - + if (this->user.find_first_not_of("*") == Anope::string::npos) this->user.clear(); - + if (this->host.find_first_not_of("*") == Anope::string::npos) this->host.clear(); else @@ -769,10 +770,10 @@ bool Entry::Matches(User *u, bool full) const else if (!this->host.empty() && !Anope::Match(u->GetDisplayedHost(), this->host) && !Anope::Match(u->GetCloakedHost(), this->host) && (!full || (!Anope::Match(u->host, this->host) && !Anope::Match(u->ip, this->host)))) ret = false; - + if (!this->real.empty() && !Anope::Match(u->realname, this->real)) ret = false; - + return ret; } diff --git a/src/module.cpp b/src/module.cpp index eabf6c0aa..1b19c976c 100644 --- a/src/module.cpp +++ b/src/module.cpp @@ -10,7 +10,6 @@ #include "services.h" #include "modules.h" #include "language.h" -#include "account.h" #ifdef GETTEXT_FOUND # include @@ -34,7 +33,7 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt if (ModuleManager::FindModule(this->name)) throw CoreException("Module already exists!"); - + if (Anope::NoThird && type & THIRD) throw ModuleException("Third party modules may not be loaded"); @@ -64,7 +63,6 @@ Module::Module(const Anope::string &modname, const Anope::string &, ModType modt Module::~Module() { - IdentifyRequest::ModuleUnload(this); /* Clear any active timers this module has */ TimerManager::DeleteTimersFor(this); diff --git a/src/modulemanager.cpp b/src/modulemanager.cpp index c70e58ecf..9e27eec26 100644 --- a/src/modulemanager.cpp +++ b/src/modulemanager.cpp @@ -10,7 +10,6 @@ #include "services.h" #include "modules.h" #include "users.h" -#include "regchannel.h" #include "config.h" #include "event.h" @@ -37,7 +36,7 @@ void ModuleManager::CleanupRuntimeDirectory() Log(LOG_DEBUG) << "Cannot open directory (" << dirbuf << ")"; return; } - + for (dirent *dp; (dp = readdir(dirp));) { if (!dp->d_ino) @@ -63,17 +62,17 @@ void ModuleManager::CleanupRuntimeDirectory() static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &output) { Anope::string input = Anope::ModuleDir + "/modules/" + name + ".so"; - + struct stat s; if (stat(input.c_str(), &s) == -1) return MOD_ERR_NOEXIST; else if (!S_ISREG(s.st_mode)) return MOD_ERR_NOEXIST; - + std::ifstream source(input.c_str(), std::ios_base::in | std::ios_base::binary); if (!source.is_open()) return MOD_ERR_NOEXIST; - + char *tmp_output = strdup(output.c_str()); int target_fd = mkstemp(tmp_output); if (target_fd == -1 || close(target_fd) == -1) @@ -86,7 +85,7 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out free(tmp_output); Log(LOG_DEBUG_2) << "Runtime module location: " << output; - + std::ofstream target(output.c_str(), std::ios_base::in | std::ios_base::binary); if (!target.is_open()) { @@ -104,7 +103,7 @@ static ModuleReturn moduleCopyFile(const Anope::string &name, Anope::string &out target.write(buffer, read_len); want -= read_len; } - + source.close(); target.close(); @@ -339,7 +338,7 @@ ModuleReturn ModuleManager::DeleteModule(Module *m) if (!filename.empty()) unlink(filename.c_str()); #endif - + return MOD_ERR_OK; } @@ -353,7 +352,7 @@ void ModuleManager::UnloadAll() if ((m->type & j) == m->type) modules.push_back(m->name); } - + for (unsigned i = 0; i < modules.size(); ++i) { Module *m = FindModule(modules[i]); diff --git a/src/nickalias.cpp b/src/nickalias.cpp deleted file mode 100644 index dfe06a176..000000000 --- a/src/nickalias.cpp +++ /dev/null @@ -1,217 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "services.h" -#include "account.h" -#include "modules.h" -#include "opertype.h" -#include "protocol.h" -#include "users.h" -#include "servers.h" -#include "config.h" -#include "event.h" - -Serialize::Checker NickAliasList("NickAlias"); - -NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Serializable("NickAlias") -{ - if (nickname.empty()) - throw CoreException("Empty nick passed to NickAlias constructor"); - else if (!nickcore) - throw CoreException("Empty nickcore passed to NickAlias constructor"); - - this->time_registered = this->last_seen = Anope::CurTime; - this->nick = nickname; - this->nc = nickcore; - nickcore->aliases->push_back(this); - - size_t old = NickAliasList->size(); - (*NickAliasList)[this->nick] = this; - if (old == NickAliasList->size()) - Log(LOG_DEBUG) << "Duplicate nick " << nickname << " in nickalias table"; - - if (this->nc->o == NULL) - { - Oper *o = Oper::Find(this->nick); - if (o == NULL) - o = Oper::Find(this->nc->display); - nickcore->o = o; - if (this->nc->o != NULL) - Log() << "Tied oper " << this->nc->display << " to type " << this->nc->o->ot->GetName(); - } -} - -NickAlias::~NickAlias() -{ - Event::OnDelNick(&Event::DelNick::OnDelNick, this); - - /* Accept nicks that have no core, because of database load functions */ - if (this->nc) - { - /* Next: see if our core is still useful. */ - std::vector::iterator it = std::find(this->nc->aliases->begin(), this->nc->aliases->end(), this); - if (it != this->nc->aliases->end()) - this->nc->aliases->erase(it); - if (this->nc->aliases->empty()) - { - delete this->nc; - this->nc = NULL; - } - else - { - /* Display updating stuff */ - if (this->nick.equals_ci(this->nc->display)) - this->nc->SetDisplay(this->nc->aliases->front()); - } - } - - /* Remove us from the aliases list */ - NickAliasList->erase(this->nick); -} - -void NickAlias::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created) -{ - this->vhost_ident = ident; - this->vhost_host = host; - this->vhost_creator = creator; - this->vhost_created = created; -} - -void NickAlias::RemoveVhost() -{ - this->vhost_ident.clear(); - this->vhost_host.clear(); - this->vhost_creator.clear(); - this->vhost_created = 0; -} - -bool NickAlias::HasVhost() const -{ - return !this->vhost_host.empty(); -} - -const Anope::string &NickAlias::GetVhostIdent() const -{ - return this->vhost_ident; -} - -const Anope::string &NickAlias::GetVhostHost() const -{ - return this->vhost_host; -} - -const Anope::string &NickAlias::GetVhostCreator() const -{ - return this->vhost_creator; -} - -time_t NickAlias::GetVhostCreated() const -{ - return this->vhost_created; -} - -NickAlias *NickAlias::Find(const Anope::string &nick) -{ - nickalias_map::const_iterator it = NickAliasList->find(nick); - if (it != NickAliasList->end()) - { - it->second->QueueUpdate(); - return it->second; - } - - return NULL; -} - -void NickAlias::Serialize(Serialize::Data &data) const -{ - data["nick"] << this->nick; - data["last_quit"] << this->last_quit; - data["last_realname"] << this->last_realname; - data["last_usermask"] << this->last_usermask; - data["last_realhost"] << this->last_realhost; - data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered; - data.SetType("last_seen", Serialize::Data::DT_INT); data["last_seen"] << this->last_seen; - data["nc"] << this->nc->display; - - if (this->HasVhost()) - { - data["vhost_ident"] << this->GetVhostIdent(); - data["vhost_host"] << this->GetVhostHost(); - data["vhost_creator"] << this->GetVhostCreator(); - data["vhost_time"] << this->GetVhostCreated(); - } - - Extensible::ExtensibleSerialize(this, this, data); -} - -Serializable* NickAlias::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string snc, snick; - - data["nc"] >> snc; - data["nick"] >> snick; - - NickCore *core = NickCore::Find(snc); - if (core == NULL) - return NULL; - - NickAlias *na; - if (obj) - na = anope_dynamic_static_cast(obj); - else - na = new NickAlias(snick, core); - - if (na->nc != core) - { - std::vector::iterator it = std::find(na->nc->aliases->begin(), na->nc->aliases->end(), na); - if (it != na->nc->aliases->end()) - na->nc->aliases->erase(it); - - if (na->nc->aliases->empty()) - delete na->nc; - else if (na->nick.equals_ci(na->nc->display)) - na->nc->SetDisplay(na->nc->aliases->front()); - - na->nc = core; - core->aliases->push_back(na); - } - - data["last_quit"] >> na->last_quit; - data["last_realname"] >> na->last_realname; - data["last_usermask"] >> na->last_usermask; - data["last_realhost"] >> na->last_realhost; - data["time_registered"] >> na->time_registered; - data["last_seen"] >> na->last_seen; - - Anope::string vhost_ident, vhost_host, vhost_creator; - time_t vhost_time; - - data["vhost_ident"] >> vhost_ident; - data["vhost_host"] >> vhost_host; - data["vhost_creator"] >> vhost_creator; - data["vhost_time"] >> vhost_time; - - na->SetVhost(vhost_ident, vhost_host, vhost_creator, vhost_time); - - Extensible::ExtensibleUnserialize(na, na, data); - - /* compat */ - bool b; - b = false; - data["extensible:NO_EXPIRE"] >> b; - if (b) - na->Extend("NS_NO_EXPIRE"); - /* end compat */ - - return na; -} - diff --git a/src/nickcore.cpp b/src/nickcore.cpp deleted file mode 100644 index dc20f2731..000000000 --- a/src/nickcore.cpp +++ /dev/null @@ -1,266 +0,0 @@ -/* - * - * (C) 2003-2014 Anope Team - * Contact us at team@anope.org - * - * Please read COPYING and README for further details. - * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. - * - */ - -#include "services.h" -#include "modules.h" -#include "account.h" -#include "config.h" -#include "event.h" - -Serialize::Checker NickCoreList("NickCore"); - -NickCore::NickCore(const Anope::string &coredisplay) : Serializable("NickCore"), chanaccess("ChannelInfo"), aliases("NickAlias") -{ - if (coredisplay.empty()) - throw CoreException("Empty display passed to NickCore constructor"); - - this->o = NULL; - this->channelcount = 0; - this->lastmail = 0; - - this->display = coredisplay; - - size_t old = NickCoreList->size(); - (*NickCoreList)[this->display] = this; - if (old == NickCoreList->size()) - Log(LOG_DEBUG) << "Duplicate account " << coredisplay << " in nickcore table?"; - - Event::OnNickCoreCreate(&Event::NickCoreCreate::OnNickCoreCreate, this); -} - -NickCore::~NickCore() -{ - Event::OnDelCore(&Event::DelCore::OnDelCore, this); - - if (!this->chanaccess->empty()) - Log(LOG_DEBUG) << "Non-empty chanaccess list in destructor!"; - - for (std::list::iterator it = this->users.begin(); it != this->users.end();) - { - User *user = *it++; - user->Logout(); - } - this->users.clear(); - - NickCoreList->erase(this->display); - - this->ClearAccess(); - - if (!this->memos.memos->empty()) - { - for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i) - delete this->memos.GetMemo(i); - this->memos.memos->clear(); - } -} - -void NickCore::Serialize(Serialize::Data &data) const -{ - data["display"] << this->display; - data["pass"] << this->pass; - data["email"] << this->email; - data["language"] << this->language; - for (unsigned i = 0; i < this->access.size(); ++i) - data["access"] << this->access[i] << " "; - data["memomax"] << this->memos.memomax; - for (unsigned i = 0; i < this->memos.ignores.size(); ++i) - data["memoignores"] << this->memos.ignores[i] << " "; - Extensible::ExtensibleSerialize(this, this, data); -} - -Serializable* NickCore::Unserialize(Serializable *obj, Serialize::Data &data) -{ - NickCore *nc; - - Anope::string sdisplay; - - data["display"] >> sdisplay; - - if (obj) - nc = anope_dynamic_static_cast(obj); - else - nc = new NickCore(sdisplay); - - data["pass"] >> nc->pass; - data["email"] >> nc->email; - data["language"] >> nc->language; - { - Anope::string buf; - data["access"] >> buf; - spacesepstream sep(buf); - nc->access.clear(); - while (sep.GetToken(buf)) - nc->access.push_back(buf); - } - data["memomax"] >> nc->memos.memomax; - { - Anope::string buf; - data["memoignores"] >> buf; - spacesepstream sep(buf); - nc->memos.ignores.clear(); - while (sep.GetToken(buf)) - nc->memos.ignores.push_back(buf); - } - - Extensible::ExtensibleUnserialize(nc, nc, data); - - /* compat */ - bool b; - b = false; - data["extensible:SECURE"] >> b; - if (b) - nc->Extend("NS_SECURE"); - b = false; - data["extensible:PRIVATE"] >> b; - if (b) - nc->Extend("NS_PRIVATE"); - b = false; - data["extensible:AUTOOP"] >> b; - if (b) - nc->Extend("AUTOOP"); - b = false; - data["extensible:HIDE_EMAIL"] >> b; - if (b) - nc->Extend("HIDE_EMAIL"); - b = false; - data["extensible:HIDE_QUIT"] >> b; - if (b) - nc->Extend("HIDE_QUIT"); - b = false; - data["extensible:MEMO_RECEIVE"] >> b; - if (b) - nc->Extend("MEMO_RECEIVE"); - b = false; - data["extensible:MEMO_SIGNON"] >> b; - if (b) - nc->Extend("MEMO_SIGNON"); - b = false; - data["extensible:KILLPROTECT"] >> b; - if (b) - nc->Extend("KILLPROTECT"); - /* end compat */ - - return nc; -} - -void NickCore::SetDisplay(const NickAlias *na) -{ - if (na->nc != this || na->nick == this->display) - return; - - Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->nick); - - /* Remove the core from the list */ - NickCoreList->erase(this->display); - - this->display = na->nick; - - (*NickCoreList)[this->display] = this; -} - -bool NickCore::IsServicesOper() const -{ - return this->o != NULL; -} - -void NickCore::AddAccess(const Anope::string &entry) -{ - this->access.push_back(entry); - Event::OnNickAddAccess(&Event::NickAddAccess::OnNickAddAccess, this, entry); -} - -Anope::string NickCore::GetAccess(unsigned entry) const -{ - if (this->access.empty() || entry >= this->access.size()) - return ""; - return this->access[entry]; -} - -unsigned NickCore::GetAccessCount() const -{ - return this->access.size(); -} - -bool NickCore::FindAccess(const Anope::string &entry) -{ - for (unsigned i = 0, end = this->access.size(); i < end; ++i) - if (this->access[i] == entry) - return true; - - return false; -} - -void NickCore::EraseAccess(const Anope::string &entry) -{ - for (unsigned i = 0, end = this->access.size(); i < end; ++i) - if (this->access[i] == entry) - { - Event::OnNickEraseAccess(&Event::NickEraseAccess::OnNickEraseAccess, this, entry); - this->access.erase(this->access.begin() + i); - break; - } -} - -void NickCore::ClearAccess() -{ - Event::OnNickClearAccess(&Event::NickClearAccess::OnNickClearAccess, this); - this->access.clear(); -} - -bool NickCore::IsOnAccess(const User *u) const -{ - Anope::string buf = u->GetIdent() + "@" + u->host, buf2, buf3; - if (!u->vhost.empty()) - buf2 = u->GetIdent() + "@" + u->vhost; - if (!u->GetCloakedHost().empty()) - buf3 = u->GetIdent() + "@" + u->GetCloakedHost(); - - for (unsigned i = 0, end = this->access.size(); i < end; ++i) - { - Anope::string a = this->GetAccess(i); - if (Anope::Match(buf, a) || (!buf2.empty() && Anope::Match(buf2, a)) || (!buf3.empty() && Anope::Match(buf3, a))) - return true; - } - return false; -} - -void NickCore::AddChannelReference(ChannelInfo *ci) -{ - ++(*this->chanaccess)[ci]; -} - -void NickCore::RemoveChannelReference(ChannelInfo *ci) -{ - int& i = (*this->chanaccess)[ci]; - if (--i <= 0) - this->chanaccess->erase(ci); -} - -void NickCore::GetChannelReferences(std::deque &queue) -{ - queue.clear(); - for (std::map::iterator it = this->chanaccess->begin(), it_end = this->chanaccess->end(); it != it_end; ++it) - queue.push_back(it->first); -} - -NickCore* NickCore::Find(const Anope::string &nick) -{ - nickcore_map::const_iterator it = NickCoreList->find(nick); - if (it != NickCoreList->end()) - { - it->second->QueueUpdate(); - return it->second; - } - - return NULL; -} - diff --git a/src/process.cpp b/src/process.cpp index 2308dc47d..70849243b 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -14,7 +14,6 @@ #include "protocol.h" #include "