diff options
Diffstat (limited to 'src')
43 files changed, 224 insertions, 2051 deletions
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<Privilege> 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<Privilege>::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<Privilege> &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<AccessProvider *>::iterator it = std::find(Providers.begin(), Providers.end(), this); - if (it != Providers.end()) - Providers.erase(it); -} - -std::list<AccessProvider *> AccessProvider::Providers; - -const std::list<AccessProvider *>& AccessProvider::GetProviders() -{ - return Providers; -} - -ChanAccess::ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p) -{ -} - -ChanAccess::~ChanAccess() -{ - if (this->ci) - { - std::vector<ChanAccess *>::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<AccessProvider> aprovider("AccessProvider", provider); - ChannelInfo *ci = ChannelInfo::Find(chan); - if (!aprovider || !ci) - return NULL; - - ChanAccess *access; - if (obj) - access = anope_dynamic_static_cast<ChanAccess *>(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<const ChanAccess *, const ChanAccess *> pair = std::make_pair(this, a); - - std::pair<Set::iterator, Set::iterator> 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<Privilege> &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<Privilege> &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<ChanAccess *>() -{ - 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<const ChanAccess *, const ChanAccess *> path; - std::pair<path::const_iterator, path::const_iterator> 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<Privilege> &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<Privilege> &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 *> 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<IdentifyRequest *>::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<botinfo_map> 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<ChannelInfo *>::iterator it = this->channels->begin(), it_end = this->channels->end(); it != it_end; ++it) + for (std::set<ChanServ::Channel *>::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<ChannelInfo *> &BotInfo::GetChannels() const +const std::set<ChanServ::Channel *> &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<ChannelModeList *>(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<block_map::iterator, block_map::iterator> 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<const Anope::string>("name"), - &desc = privilege->Get<const Anope::string>("desc"); - int rank = privilege->Get<int>("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<const Anope::string>("casemap", "ascii") == "ascii") Anope::casemap = std::locale(std::locale(), new Anope::ascii_ctype<char>()); @@ -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<block_map::iterator, block_map::iterator> 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<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"); 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<unsigned char>(c1st)] == case_map_upper[static_cast<unsigned char>(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 <libintl.h> @@ -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 <sys/time.h> @@ -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<const Anope::string>("sendmailpath")), send_from(sf), mail_to(mailto), addr(a), subject(s), message(m), dont_quote_addresses(Config->GetBlock("mail")->Get<bool>("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<bool>("usemail") || b->Get<const Anope::string>("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<bool>("usemail") || b->Get<const Anope::string>("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<Memo *>::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<Memo *>(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<Anope::string> ¶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<SJoinUser>::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<Anope::string> ¶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<Anope::string> ¶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<Anope::string> &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<std::pair<Mode *, Anope::string> > 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 <libintl.h> @@ -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<nickalias_map> 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<NickAlias *>::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<NickAlias *>(obj); - else - na = new NickAlias(snick, core); - - if (na->nc != core) - { - std::vector<NickAlias *>::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<bool>("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<nickcore_map> 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<User *>::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<NickCore *>(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<bool>("NS_SECURE"); - b = false; - data["extensible:PRIVATE"] >> b; - if (b) - nc->Extend<bool>("NS_PRIVATE"); - b = false; - data["extensible:AUTOOP"] >> b; - if (b) - nc->Extend<bool>("AUTOOP"); - b = false; - data["extensible:HIDE_EMAIL"] >> b; - if (b) - nc->Extend<bool>("HIDE_EMAIL"); - b = false; - data["extensible:HIDE_QUIT"] >> b; - if (b) - nc->Extend<bool>("HIDE_QUIT"); - b = false; - data["extensible:MEMO_RECEIVE"] >> b; - if (b) - nc->Extend<bool>("MEMO_RECEIVE"); - b = false; - data["extensible:MEMO_SIGNON"] >> b; - if (b) - nc->Extend<bool>("MEMO_SIGNON"); - b = false; - data["extensible:KILLPROTECT"] >> b; - if (b) - nc->Extend<bool>("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<ChannelInfo *> &queue) -{ - queue.clear(); - for (std::map<ChannelInfo *, int>::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 "servers.h" #include "users.h" -#include "regchannel.h" #include "event.h" void Anope::Process(const Anope::string &buffer) @@ -37,7 +36,7 @@ void Anope::Process(const Anope::string &buffer) Anope::string command; if (!buf_sep.GetToken(command)) return; - + Anope::string buf_token; std::vector<Anope::string> params; while (buf_sep.GetToken(buf_token)) @@ -69,7 +68,7 @@ void Anope::Process(const Anope::string &buffer) static const Anope::string proto_name = ModuleManager::FindFirstOf(PROTOCOL) ? ModuleManager::FindFirstOf(PROTOCOL)->name : ""; MessageSource src(source); - + EventReturn MOD_RESULT; MOD_RESULT = Event::OnMessage(&Event::Message::OnMessage, src, command, params); if (MOD_RESULT == EVENT_STOP) diff --git a/src/protocol.cpp b/src/protocol.cpp index b90c44400..d8fd9dc79 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -311,14 +311,14 @@ bool IRCDProto::IsNickValid(const Anope::string &nick) if (nick.empty()) return false; - + Anope::string special = "[]\\`_^{|}"; - + for (unsigned i = 0; i < nick.length(); ++i) if (!(nick[i] >= 'A' && nick[i] <= 'Z') && !(nick[i] >= 'a' && nick[i] <= 'z') && special.find(nick[i]) == Anope::string::npos && (!i || (!(nick[i] >= '0' && nick[i] <= '9') && nick[i] != '-'))) return false; - + return true; } diff --git a/src/regchannel.cpp b/src/regchannel.cpp deleted file mode 100644 index 7551266b0..000000000 --- a/src/regchannel.cpp +++ /dev/null @@ -1,689 +0,0 @@ -/* Registered channel 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 "regchannel.h" -#include "account.h" -#include "access.h" -#include "channels.h" -#include "config.h" -#include "bots.h" -#include "servers.h" -#include "event.h" - -Serialize::Checker<registered_channel_map> RegisteredChannelList("ChannelInfo"); - -AutoKick::AutoKick() : Serializable("AutoKick") -{ -} - -AutoKick::~AutoKick() -{ - if (this->ci) - { - std::vector<AutoKick *>::iterator it = std::find(this->ci->akick->begin(), this->ci->akick->end(), this); - if (it != this->ci->akick->end()) - this->ci->akick->erase(it); - - const NickAlias *na = NickAlias::Find(this->mask); - if (na != NULL) - na->nc->RemoveChannelReference(this->ci); - } -} - -void AutoKick::Serialize(Serialize::Data &data) const -{ - data["ci"] << this->ci->name; - if (this->nc) - data["nc"] << this->nc->display; - else - data["mask"] << this->mask; - data["reason"] << this->reason; - data["creator"] << this->creator; - data.SetType("addtime", Serialize::Data::DT_INT); data["addtime"] << this->addtime; - data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used; -} - -Serializable* AutoKick::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string sci, snc; - - data["ci"] >> sci; - data["nc"] >> snc; - - ChannelInfo *ci = ChannelInfo::Find(sci); - if (!ci) - return NULL; - - AutoKick *ak; - NickCore *nc = NickCore::Find(snc); - if (obj) - { - ak = anope_dynamic_static_cast<AutoKick *>(obj); - data["creator"] >> ak->creator; - data["reason"] >> ak->reason; - ak->nc = NickCore::Find(snc); - data["mask"] >> ak->mask; - data["addtime"] >> ak->addtime; - data["last_used"] >> ak->last_used; - } - else - { - time_t addtime, lastused; - data["addtime"] >> addtime; - data["last_used"] >> lastused; - - Anope::string screator, sreason, smask; - - data["creator"] >> screator; - data["reason"] >> sreason; - data["mask"] >> smask; - - if (nc) - ak = ci->AddAkick(screator, nc, sreason, addtime, lastused); - else - ak = ci->AddAkick(screator, smask, sreason, addtime, lastused); - } - - return ak; -} - -ChannelInfo::ChannelInfo(const Anope::string &chname) : Serializable("ChannelInfo"), - access("ChanAccess"), akick("AutoKick") -{ - if (chname.empty()) - throw CoreException("Empty channel passed to ChannelInfo constructor"); - - this->founder = NULL; - this->successor = NULL; - this->c = Channel::Find(chname); - if (this->c) - this->c->ci = this; - this->banexpire = 0; - this->bi = NULL; - this->last_topic_time = 0; - - this->name = chname; - - this->bantype = 2; - this->memos.memomax = 0; - this->last_used = this->time_registered = Anope::CurTime; - - size_t old = RegisteredChannelList->size(); - (*RegisteredChannelList)[this->name] = this; - if (old == RegisteredChannelList->size()) - Log(LOG_DEBUG) << "Duplicate channel " << this->name << " in registered channel table?"; - - Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); -} - -ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Serializable("ChannelInfo"), - access("ChanAccess"), akick("AutoKick") -{ - *this = ci; - - if (this->founder) - --this->founder->channelcount; - - this->access->clear(); - this->akick->clear(); - - for (unsigned i = 0; i < ci.GetAccessCount(); ++i) - { - const ChanAccess *taccess = ci.GetAccess(i); - AccessProvider *provider = taccess->provider; - - ChanAccess *newaccess = provider->Create(); - newaccess->ci = this; - newaccess->mask = taccess->mask; - newaccess->creator = taccess->creator; - newaccess->last_seen = taccess->last_seen; - newaccess->created = taccess->created; - newaccess->AccessUnserialize(taccess->AccessSerialize()); - - this->AddAccess(newaccess); - } - - for (unsigned i = 0; i < ci.GetAkickCount(); ++i) - { - const AutoKick *takick = ci.GetAkick(i); - if (takick->nc) - this->AddAkick(takick->creator, takick->nc, takick->reason, takick->addtime, takick->last_used); - else - this->AddAkick(takick->creator, takick->mask, takick->reason, takick->addtime, takick->last_used); - } - - Event::OnCreateChan(&Event::CreateChan::OnCreateChan, this); -} - -ChannelInfo::~ChannelInfo() -{ - Event::OnDelChan(&Event::DelChan::OnDelChan, this); - - Log(LOG_DEBUG) << "Deleting channel " << this->name; - - if (this->c) - { - if (this->bi && this->c->FindUser(this->bi)) - this->bi->Part(this->c); - - /* Parting the service bot can cause the channel to go away */ - - if (this->c) - { - if (this->c && this->c->CheckDelete()) - delete this->c; - - this->c = NULL; - } - } - - RegisteredChannelList->erase(this->name); - - this->SetFounder(NULL); - this->SetSuccessor(NULL); - - this->ClearAccess(); - this->ClearAkick(); - - 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(); - } - - if (this->founder) - --this->founder->channelcount; -} - -void ChannelInfo::Serialize(Serialize::Data &data) const -{ - data["name"] << this->name; - if (this->founder) - data["founder"] << this->founder->display; - if (this->successor) - data["successor"] << this->successor->display; - data["description"] << this->desc; - data.SetType("time_registered", Serialize::Data::DT_INT); data["time_registered"] << this->time_registered; - data.SetType("last_used", Serialize::Data::DT_INT); data["last_used"] << this->last_used; - data["last_topic"] << this->last_topic; - data["last_topic_setter"] << this->last_topic_setter; - data.SetType("last_topic_time", Serialize::Data::DT_INT); data["last_topic_time"] << this->last_topic_time; - data.SetType("bantype", Serialize::Data::DT_INT); data["bantype"] << this->bantype; - { - Anope::string levels_buffer; - for (Anope::map<int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it) - levels_buffer += it->first + " " + stringify(it->second) + " "; - data["levels"] << levels_buffer; - } - if (this->bi) - data["bi"] << this->bi->nick; - data.SetType("banexpire", Serialize::Data::DT_INT); data["banexpire"] << this->banexpire; - 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* ChannelInfo::Unserialize(Serializable *obj, Serialize::Data &data) -{ - Anope::string sname, sfounder, ssuccessor, slevels, sbi; - - data["name"] >> sname; - data["founder"] >> sfounder; - data["successor"] >> ssuccessor; - data["levels"] >> slevels; - data["bi"] >> sbi; - - ChannelInfo *ci; - if (obj) - ci = anope_dynamic_static_cast<ChannelInfo *>(obj); - else - ci = new ChannelInfo(sname); - - ci->SetFounder(NickCore::Find(sfounder)); - ci->SetSuccessor(NickCore::Find(ssuccessor)); - - data["description"] >> ci->desc; - data["time_registered"] >> ci->time_registered; - data["last_used"] >> ci->last_used; - data["last_topic"] >> ci->last_topic; - data["last_topic_setter"] >> ci->last_topic_setter; - data["last_topic_time"] >> ci->last_topic_time; - data["bantype"] >> ci->bantype; - { - std::vector<Anope::string> v; - spacesepstream(slevels).GetTokens(v); - for (unsigned i = 0; i + 1 < v.size(); i += 2) - try - { - ci->levels[v[i]] = convertTo<int16_t>(v[i + 1]); - } - catch (const ConvertException &) { } - } - BotInfo *bi = BotInfo::Find(sbi); - if (*ci->bi != bi) - { - if (bi) - bi->Assign(NULL, ci); - else if (ci->bi) - ci->bi->UnAssign(NULL, ci); - } - data["banexpire"] >> ci->banexpire; - data["memomax"] >> ci->memos.memomax; - { - Anope::string buf; - data["memoignores"] >> buf; - spacesepstream sep(buf); - ci->memos.ignores.clear(); - while (sep.GetToken(buf)) - ci->memos.ignores.push_back(buf); - } - - Extensible::ExtensibleUnserialize(ci, ci, data); - - /* compat */ - bool b; - b = false; - data["extensible:SECURE"] >> b; - if (b) - ci->Extend<bool>("CS_SECURE"); - b = false; - data["extensible:PRIVATE"] >> b; - if (b) - ci->Extend<bool>("CS_PRIVATE"); - b = false; - data["extensible:NO_EXPIRE"] >> b; - if (b) - ci->Extend<bool>("CS_NO_EXPIRE"); - b = false; - data["extensible:FANTASY"] >> b; - if (b) - ci->Extend<bool>("BS_FANTASY"); - b = false; - data["extensible:GREET"] >> b; - if (b) - ci->Extend<bool>("BS_GREET"); - b = false; - data["extensible:PEACE"] >> b; - if (b) - ci->Extend<bool>("PEACE"); - b = false; - data["extensible:SECUREFOUNDER"] >> b; - if (b) - ci->Extend<bool>("SECUREFOUNDER"); - b = false; - data["extensible:RESTRICTED"] >> b; - if (b) - ci->Extend<bool>("RESTRICTED"); - b = false; - data["extensible:KEEPTOPIC"] >> b; - if (b) - ci->Extend<bool>("KEEPTOPIC"); - b = false; - data["extensible:SIGNKICK"] >> b; - if (b) - ci->Extend<bool>("SIGNKICK"); - b = false; - data["extensible:SIGNKICK_LEVEL"] >> b; - if (b) - ci->Extend<bool>("SIGNKICK_LEVEL"); - /* end compat */ - - return ci; -} - - -void ChannelInfo::SetFounder(NickCore *nc) -{ - if (this->founder) - { - --this->founder->channelcount; - this->founder->RemoveChannelReference(this); - } - - this->founder = nc; - - if (this->founder) - { - ++this->founder->channelcount; - this->founder->AddChannelReference(this); - } -} - -NickCore *ChannelInfo::GetFounder() const -{ - return this->founder; -} - -void ChannelInfo::SetSuccessor(NickCore *nc) -{ - if (this->successor) - this->successor->RemoveChannelReference(this); - this->successor = nc; - if (this->successor) - this->successor->AddChannelReference(this); -} - -NickCore *ChannelInfo::GetSuccessor() const -{ - return this->successor; -} - -BotInfo *ChannelInfo::WhoSends() const -{ - if (this && this->bi) - return this->bi; - - BotInfo *ChanServ = Config->GetClient("ChanServ"); - if (ChanServ) - return ChanServ; - - if (!BotListByNick->empty()) - return BotListByNick->begin()->second; - - return NULL; -} - -void ChannelInfo::AddAccess(ChanAccess *taccess) -{ - this->access->push_back(taccess); - - const NickAlias *na = NickAlias::Find(taccess->mask); - if (na != NULL) - { - na->nc->AddChannelReference(this); - taccess->nc = na->nc; - } - else - { - ChannelInfo *ci = ChannelInfo::Find(taccess->mask); - if (ci != NULL) - ci->AddChannelReference(this->name); - } -} - -ChanAccess *ChannelInfo::GetAccess(unsigned index) const -{ - if (this->access->empty() || index >= this->access->size()) - return NULL; - - ChanAccess *acc = (*this->access)[index]; - acc->QueueUpdate(); - return acc; -} - -AccessGroup ChannelInfo::AccessFor(const User *u) -{ - AccessGroup group; - - if (u == NULL) - return group; - - const NickCore *nc = u->Account(); - if (nc == NULL && !this->HasExt("NS_SECURE") && u->IsRecognized()) - { - const NickAlias *na = NickAlias::Find(u->nick); - if (na != NULL) - nc = na->nc; - } - - group.super_admin = u->super_admin; - group.founder = IsFounder(u, this); - group.ci = this; - group.nc = nc; - - for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) - { - ChanAccess *a = this->GetAccess(i); - if (a->Matches(u, u->Account(), group.path)) - group.push_back(a); - } - - if (group.founder || !group.empty()) - { - this->last_used = Anope::CurTime; - - for (unsigned i = 0; i < group.size(); ++i) - group[i]->last_seen = Anope::CurTime; - } - - return group; -} - -AccessGroup ChannelInfo::AccessFor(const NickCore *nc) -{ - AccessGroup group; - - group.founder = (this->founder && this->founder == nc); - group.ci = this; - group.nc = nc; - - for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) - { - ChanAccess *a = this->GetAccess(i); - if (a->Matches(NULL, nc, group.path)) - group.push_back(a); - } - - if (group.founder || !group.empty()) - this->last_used = Anope::CurTime; - - /* don't update access last seen here, this isn't the user requesting access */ - - return group; -} - -unsigned ChannelInfo::GetAccessCount() const -{ - return this->access->size(); -} - -unsigned ChannelInfo::GetDeepAccessCount() const -{ - ChanAccess::Path path; - for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) - { - ChanAccess *a = this->GetAccess(i); - a->Matches(NULL, NULL, path); - } - - unsigned count = this->GetAccessCount(); - std::set<const ChannelInfo *> channels; - channels.insert(this); - for (ChanAccess::Set::iterator it = path.first.begin(); it != path.first.end(); ++it) - { - const ChannelInfo *ci = it->first->ci; - if (!channels.count(ci)) - { - channels.count(ci); - count += ci->GetAccessCount(); - } - } - return count; -} - -ChanAccess *ChannelInfo::EraseAccess(unsigned index) -{ - if (this->access->empty() || index >= this->access->size()) - return NULL; - - ChanAccess *ca = this->access->at(index); - this->access->erase(this->access->begin() + index); - return ca; -} - -void ChannelInfo::ClearAccess() -{ - for (unsigned i = this->access->size(); i > 0; --i) - delete this->GetAccess(i - 1); -} - -AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu) -{ - AutoKick *autokick = new AutoKick(); - autokick->ci = this; - autokick->nc = akicknc; - autokick->reason = reason; - autokick->creator = user; - autokick->addtime = t; - autokick->last_used = lu; - - this->akick->push_back(autokick); - - akicknc->AddChannelReference(this); - - return autokick; -} - -AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu) -{ - AutoKick *autokick = new AutoKick(); - autokick->ci = this; - autokick->mask = mask; - autokick->nc = NULL; - autokick->reason = reason; - autokick->creator = user; - autokick->addtime = t; - autokick->last_used = lu; - - this->akick->push_back(autokick); - - return autokick; -} - -AutoKick *ChannelInfo::GetAkick(unsigned index) const -{ - if (this->akick->empty() || index >= this->akick->size()) - return NULL; - - AutoKick *ak = (*this->akick)[index]; - ak->QueueUpdate(); - return ak; -} - -unsigned ChannelInfo::GetAkickCount() const -{ - return this->akick->size(); -} - -void ChannelInfo::EraseAkick(unsigned index) -{ - if (this->akick->empty() || index >= this->akick->size()) - return; - - delete this->GetAkick(index); -} - -void ChannelInfo::ClearAkick() -{ - while (!this->akick->empty()) - delete this->akick->back(); -} - -int16_t ChannelInfo::GetLevel(const Anope::string &priv) const -{ - if (PrivilegeManager::FindPrivilege(priv) == NULL) - { - Log(LOG_DEBUG) << "Unknown privilege " + priv; - return ACCESS_INVALID; - } - - Anope::map<int16_t>::const_iterator it = this->levels.find(priv); - if (it == this->levels.end()) - return 0; - return it->second; -} - -void ChannelInfo::SetLevel(const Anope::string &priv, int16_t level) -{ - this->levels[priv] = level; -} - -void ChannelInfo::RemoveLevel(const Anope::string &priv) -{ - this->levels.erase(priv); -} - -void ChannelInfo::ClearLevels() -{ - this->levels.clear(); -} - -Anope::string ChannelInfo::GetIdealBan(User *u) const -{ - int bt = this ? this->bantype : -1; - switch (bt) - { - case 0: - return "*!" + u->GetVIdent() + "@" + u->GetDisplayedHost(); - case 1: - if (u->GetVIdent()[0] == '~') - return "*!*" + u->GetVIdent() + "@" + u->GetDisplayedHost(); - else - return "*!" + u->GetVIdent() + "@" + u->GetDisplayedHost(); - case 3: - return "*!" + u->Mask(); - case 2: - default: - return "*!*@" + u->GetDisplayedHost(); - } -} - -ChannelInfo* ChannelInfo::Find(const Anope::string &name) -{ - registered_channel_map::const_iterator it = RegisteredChannelList->find(name); - if (it != RegisteredChannelList->end()) - { - it->second->QueueUpdate(); - return it->second; - } - - return NULL; -} - -bool IsFounder(const User *user, const ChannelInfo *ci) -{ - if (!user || !ci) - return false; - - if (user->super_admin) - return true; - - if (user->Account() && user->Account() == ci->GetFounder()) - return true; - - return false; -} - - -void ChannelInfo::AddChannelReference(const Anope::string &what) -{ - ++references[what]; -} - -void ChannelInfo::RemoveChannelReference(const Anope::string &what) -{ - int &i = references[what]; - if (--i <= 0) - references.erase(what); -} - -void ChannelInfo::GetChannelReferences(std::deque<Anope::string> &chans) -{ - chans.clear(); - for (Anope::map<int>::iterator it = references.begin(); it != references.end(); ++it) - chans.push_back(it->first); -} diff --git a/src/serialize.cpp b/src/serialize.cpp index 0cb6ec196..a24f6d0e3 100644 --- a/src/serialize.cpp +++ b/src/serialize.cpp @@ -15,11 +15,8 @@ #include "anope.h" #include "serialize.h" #include "modules.h" -#include "account.h" #include "bots.h" -#include "regchannel.h" #include "xline.h" -#include "access.h" #include "event.h" using namespace Serialize; @@ -30,9 +27,8 @@ std::list<Serializable *> *Serializable::SerializableItems; void Serialize::RegisterTypes() { - static Type nc("NickCore", NickCore::Unserialize), na("NickAlias", NickAlias::Unserialize), bi("BotInfo", BotInfo::Unserialize), - ci("ChannelInfo", ChannelInfo::Unserialize), access("ChanAccess", ChanAccess::Unserialize), - akick("AutoKick", AutoKick::Unserialize), memo("Memo", Memo::Unserialize), xline("XLine", XLine::Unserialize); + static Type bi("BotInfo", BotInfo::Unserialize), + xline("XLine", XLine::Unserialize); } void Serialize::CheckTypes() diff --git a/src/servers.cpp b/src/servers.cpp index 5e55d4c28..c4cb3665e 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -15,11 +15,11 @@ #include "xline.h" #include "servers.h" #include "bots.h" -#include "regchannel.h" #include "protocol.h" #include "config.h" #include "channels.h" #include "event.h" +#include "modules/chanserv.h" /* Anope */ Server *Me = NULL; @@ -82,7 +82,7 @@ Server::Server(Server *up, const Anope::string &sname, unsigned shops, const Ano } IRCD->SendBOB(); - + for (unsigned i = 0; i < Me->GetLinks().size(); ++i) { Server *s = Me->GetLinks()[i]; @@ -159,7 +159,7 @@ Server::~Server() for (unsigned i = this->links.size(); i > 0; --i) this->links[i - 1]->Delete(this->quit_reason); - + Servers::ByName.erase(this->name); if (!this->sid.empty()) Servers::ByID.erase(this->sid); @@ -338,18 +338,18 @@ void Server::Notice(BotInfo *source, const Anope::string &message) Server *Server::Find(const Anope::string &name, bool name_only) { Anope::map<Server *>::iterator it; - + if (!name_only) { it = Servers::ByID.find(name); if (it != Servers::ByID.end()) return it->second; } - + it = Servers::ByName.find(name); if (it != Servers::ByName.end()) return it->second; - + return NULL; } diff --git a/src/socket_transport.cpp b/src/socket_transport.cpp index 1476d0662..515d7f9a9 100644 --- a/src/socket_transport.cpp +++ b/src/socket_transport.cpp @@ -33,7 +33,7 @@ bool BufferedSocket::ProcessRead() return false; if (len < 0) return SocketEngine::IgnoreErrno(); - + tbuffer[len] = 0; this->read_buffer.append(tbuffer); this->recv_len = len; @@ -131,7 +131,7 @@ bool BinarySocket::ProcessRead() int len = this->io->Recv(this, tbuffer, sizeof(tbuffer)); if (len <= 0) return false; - + return this->Read(tbuffer, len); } diff --git a/src/socketengines/socketengine_epoll.cpp b/src/socketengines/socketengine_epoll.cpp index 8fe8d46a4..3c0c22f40 100644 --- a/src/socketengines/socketengine_epoll.cpp +++ b/src/socketengines/socketengine_epoll.cpp @@ -28,7 +28,7 @@ void SocketEngine::Init() if (EngineHandle == -1) throw SocketException("Could not initialize epoll socket engine: " + Anope::LastError()); - + events.resize(DefaultSize); } @@ -46,7 +46,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) bool before_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; s->flags[flag] = set; - + bool now_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; epoll_event ev; @@ -65,7 +65,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) mod = EPOLL_CTL_MOD; else return; - + if (epoll_ctl(EngineHandle, mod, ev.data.fd, &ev) == -1) throw SocketException("Unable to epoll_ctl() fd " + stringify(ev.data.fd) + " to epoll: " + Anope::LastError()); } diff --git a/src/socketengines/socketengine_kqueue.cpp b/src/socketengines/socketengine_kqueue.cpp index 977b84b96..5c5c99afe 100644 --- a/src/socketengines/socketengine_kqueue.cpp +++ b/src/socketengines/socketengine_kqueue.cpp @@ -39,7 +39,7 @@ void SocketEngine::Init() if (kq_fd < 0) throw SocketException("Unable to create kqueue engine: " + Anope::LastError()); - + change_events.resize(DefaultSize); event_events.resize(DefaultSize); } @@ -56,7 +56,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) return; s->flags[flag] = set; - + int mod; if (flag == SF_READABLE) mod = EVFILT_READ; diff --git a/src/socketengines/socketengine_poll.cpp b/src/socketengines/socketengine_poll.cpp index 944322c27..422959df2 100644 --- a/src/socketengines/socketengine_poll.cpp +++ b/src/socketengines/socketengine_poll.cpp @@ -113,7 +113,7 @@ void SocketEngine::Process() for (unsigned i = 0, processed = 0; i < events.size() && processed != static_cast<unsigned>(total); ++i) { pollfd *ev = &events[i]; - + if (ev->revents != 0) ++processed; diff --git a/src/socketengines/socketengine_select.cpp b/src/socketengines/socketengine_select.cpp index aab84e958..f1f4fb8d8 100644 --- a/src/socketengines/socketengine_select.cpp +++ b/src/socketengines/socketengine_select.cpp @@ -46,7 +46,7 @@ void SocketEngine::Change(Socket *s, bool set, SocketFlag flag) bool before_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; s->flags[flag] = set; - + bool now_registered = s->flags[SF_READABLE] || s->flags[SF_WRITABLE]; if (!before_registered && now_registered) diff --git a/src/sockets.cpp b/src/sockets.cpp index f047c5f44..5d84d1a3f 100644 --- a/src/sockets.cpp +++ b/src/sockets.cpp @@ -277,7 +277,7 @@ bool cidr::operator<(const cidr &other) const { if (this->addr.sa.sa_family != other.addr.sa.sa_family) return this->addr.sa.sa_family < other.addr.sa.sa_family; - + switch (this->addr.sa.sa_family) { case AF_INET: diff --git a/src/tools/anopesmtp.cpp b/src/tools/anopesmtp.cpp index 6ef8e6baf..04aaedc98 100644 --- a/src/tools/anopesmtp.cpp +++ b/src/tools/anopesmtp.cpp @@ -417,7 +417,7 @@ int main(int argc, char *argv[]) if (argc == 1) return 0; - + if (argc == 3 && !strcmp(argv[2], "--debug")) smtp_debug = 1; diff --git a/src/uplink.cpp b/src/uplink.cpp index 12b6c94f9..2f7a03ebd 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -16,6 +16,7 @@ #include "protocol.h" #include "servers.h" #include "event.h" +#include "bots.h" UplinkSocket *UplinkSock = NULL; diff --git a/src/users.cpp b/src/users.cpp index 560536ce4..3b874c0f2 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -14,7 +14,6 @@ #include "services.h" #include "modules.h" #include "users.h" -#include "account.h" #include "protocol.h" #include "servers.h" #include "channels.h" @@ -25,6 +24,7 @@ #include "sockets.h" #include "uplink.h" #include "event.h" +#include "modules/nickserv.h" user_map UserListByNick, UserListByUID; @@ -34,7 +34,7 @@ time_t MaxUserTime = 0; std::list<User *> User::quitting_users; -User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *account) +User::User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *account) { if (snick.empty() || sident.empty() || shost.empty()) throw CoreException("Bad args passed to User::User"); @@ -114,7 +114,7 @@ static void Collide(User *u, const Anope::string &id, const Anope::string &type) CollideKill(u, type); } -User* User::OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickCore *nc) +User* User::OnIntroduce(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &svhost, const Anope::string &sip, Server *sserver, const Anope::string &srealname, time_t ts, const Anope::string &smodes, const Anope::string &suid, NickServ::Account *nc) { // How IRCds handle collisions varies a lot, for safety well just always kill both sides // With properly set qlines, this can almost never happen anyway @@ -144,7 +144,7 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) /* Sanity check to make sure we don't segfault */ if (newnick.empty()) throw CoreException("User::ChangeNick() got a bad argument"); - + this->super_admin = false; Log(this, "nick") << "(" << this->realname << ") changed nick to " << newnick; @@ -155,10 +155,13 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) this->nick = newnick; else { - NickAlias *old_na = NickAlias::Find(this->nick); - if (old_na && (this->IsIdentified(true) || this->IsRecognized())) - old_na->last_seen = Anope::CurTime; - + if (NickServ::service) + { + NickServ::Nick *old_na = NickServ::service->FindNick(this->nick); + if (old_na && (this->IsIdentified(true) || this->IsRecognized())) + old_na->last_seen = Anope::CurTime; + } + UserListByNick.erase(this->nick); this->nick = newnick; @@ -173,14 +176,19 @@ void User::ChangeNick(const Anope::string &newnick, time_t ts) other = this; on_access = false; - NickAlias *na = NickAlias::Find(this->nick); - if (na) - on_access = na->nc->IsOnAccess(this); - - if (na && na->nc == this->Account()) + if (NickServ::service) { - na->last_seen = Anope::CurTime; - this->UpdateHost(); + NickServ::Nick *na = NickServ::service->FindNick(this->nick); + if (na) + { + on_access = na->nc->IsOnAccess(this); + + if (na->nc == this->Account()) + { + na->last_seen = Anope::CurTime; + this->UpdateHost(); + } + } } } @@ -283,10 +291,14 @@ void User::SetRealname(const Anope::string &srealname) throw CoreException("realname empty in SetRealname"); this->realname = srealname; - NickAlias *na = NickAlias::Find(this->nick); + if (NickServ::service) + { + //XXX event + NickServ::Nick *na = NickServ::service->FindNick(this->nick); - if (na && (this->IsIdentified(true) || this->IsRecognized())) - na->last_realname = srealname; + if (na && (this->IsIdentified(true) || this->IsRecognized())) + na->last_realname = srealname; + } Log(this, "realname") << "changed realname to " << srealname; } @@ -318,7 +330,7 @@ User::~User() Event::OnPostUserLogoff(&Event::PostUserLogoff::OnPostUserLogoff, this); } -void User::SendMessage(BotInfo *source, const char *fmt, ...) +void User::SendMessage(const MessageSource &source, const char *fmt, ...) { va_list args; char buf[BUFSIZE] = ""; @@ -333,7 +345,7 @@ void User::SendMessage(BotInfo *source, const char *fmt, ...) va_end(args); } -void User::SendMessage(BotInfo *source, const Anope::string &msg) +void User::SendMessage(const MessageSource &source, const Anope::string &msg) { const char *translated_message = Language::Translate(this, msg.c_str()); @@ -353,7 +365,7 @@ void User::SendMessage(BotInfo *source, const Anope::string &msg) } } -void User::Identify(NickAlias *na) +void User::Identify(NickServ::Nick *na) { if (this->nick.equals_ci(na->nick)) { @@ -374,14 +386,14 @@ void User::Identify(NickAlias *na) if (!this->nc->o->ot->modes.empty()) { this->SetModes(NULL, "%s", this->nc->o->ot->modes.c_str()); - this->SendMessage(NULL, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str()); + this->SendMessage(Me, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str()); UserMode *um = ModeManager::FindUserModeByName("OPER"); if (um && !this->HasMode("OPER") && this->nc->o->ot->modes.find(um->mchar) != Anope::string::npos) IRCD->SendOper(this); } if (IRCD->CanSetVHost && !this->nc->o->vhost.empty()) { - this->SendMessage(NULL, "Changing your vhost to \002%s\002", this->nc->o->vhost.c_str()); + this->SendMessage(Me, "Changing your vhost to \002%s\002", this->nc->o->vhost.c_str()); this->SetDisplayedHost(this->nc->o->vhost); IRCD->SendVhost(this, "", this->nc->o->vhost); } @@ -389,7 +401,7 @@ void User::Identify(NickAlias *na) } -void User::Login(NickCore *core) +void User::Login(NickServ::Account *core) { if (!core || core == this->nc) return; @@ -402,7 +414,7 @@ void User::Login(NickCore *core) if (this->server->IsSynced()) Log(this, "account") << "is now identified as " << this->nc->display; - + Event::OnUserLogin(&Event::UserLogin::OnUserLogin, this); } @@ -410,7 +422,7 @@ void User::Logout() { if (!this->nc) return; - + Log(this, "account") << "is no longer identified as " << this->nc->display; std::list<User *>::iterator it = std::find(this->nc->users.begin(), this->nc->users.end(), this); @@ -420,7 +432,7 @@ void User::Logout() this->nc = NULL; } -NickCore *User::Account() const +NickServ::Account *User::Account() const { return this->nc; } @@ -429,7 +441,7 @@ bool User::IsIdentified(bool check_nick) const { if (check_nick && this->nc) { - NickAlias *na = NickAlias::Find(this->nick); + NickServ::Nick *na = NickServ::service ? NickServ::service->FindNick(this->nick) : nullptr; return na && *na->nc == *this->nc; } @@ -440,7 +452,7 @@ bool User::IsRecognized(bool check_secure) const { if (check_secure && on_access) { - const NickAlias *na = NickAlias::Find(this->nick); + const NickServ::Nick *na = NickServ::service ? NickServ::service->FindNick(this->nick) : nullptr; if (!na || na->nc->HasExt("NS_SECURE")) return false; @@ -497,7 +509,8 @@ void User::UpdateHost() if (this->host.empty()) return; - NickAlias *na = NickAlias::Find(this->nick); + //XXX event + NickServ::Nick *na = NickServ::service ? NickServ::service->FindNick(this->nick) : nullptr; on_access = false; if (na) on_access = na->nc->IsOnAccess(this); diff --git a/src/win32/anope_windows.h b/src/win32/anope_windows.h index 8d6e7ef9e..f2a496c33 100644 --- a/src/win32/anope_windows.h +++ b/src/win32/anope_windows.h @@ -8,7 +8,7 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. */ - + #ifndef WINDOWS_H #define WINDOWS_H #ifdef _WIN32 @@ -71,7 +71,7 @@ namespace Anope { class string; } - + extern CoreExport void OnStartup(); extern CoreExport void OnShutdown(); extern CoreExport USHORT WindowsGetLanguage(const char *lang); diff --git a/src/win32/dir/dir.cpp b/src/win32/dir/dir.cpp index 21b80824b..16809bd9c 100644 --- a/src/win32/dir/dir.cpp +++ b/src/win32/dir/dir.cpp @@ -7,7 +7,7 @@ #include "dir.h" #include <stdio.h> - + DIR *opendir(const char *path) { char real_path[MAX_PATH]; diff --git a/src/win32/dir/dir.h b/src/win32/dir/dir.h index 5ddf71e7b..4d1433658 100644 --- a/src/win32/dir/dir.h +++ b/src/win32/dir/dir.h @@ -20,7 +20,7 @@ struct DIR WIN32_FIND_DATA data; bool read_first; }; - + DIR *opendir(const char *); dirent *readdir(DIR *); int closedir(DIR *); diff --git a/src/win32/pipe/pipe.cpp b/src/win32/pipe/pipe.cpp index 706ff655e..676909b9a 100644 --- a/src/win32/pipe/pipe.cpp +++ b/src/win32/pipe/pipe.cpp @@ -55,7 +55,7 @@ int pipe(int fds[2]) fds[0] = cfd; fds[1] = afd; - + return 0; } diff --git a/src/win32/resource.h b/src/win32/resource.h index cccb0b4f5..e4fa54b70 100644 --- a/src/win32/resource.h +++ b/src/win32/resource.h @@ -8,7 +8,7 @@ // Next default values for new objects -// +// #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NO_MFC 1 diff --git a/src/win32/sigaction/sigaction.cpp b/src/win32/sigaction/sigaction.cpp index d5a2d87d1..51615cf39 100644 --- a/src/win32/sigaction/sigaction.cpp +++ b/src/win32/sigaction/sigaction.cpp @@ -7,11 +7,11 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. */ - + #include <windows.h> #include "sigaction.h" #include <signal.h> - + int sigaction(int sig, struct sigaction *action, struct sigaction *old) { if (sig == -1) @@ -28,4 +28,3 @@ } return 0; } -
\ No newline at end of file diff --git a/src/win32/sigaction/sigaction.h b/src/win32/sigaction/sigaction.h index 0e9c2f246..9e74eeffa 100644 --- a/src/win32/sigaction/sigaction.h +++ b/src/win32/sigaction/sigaction.h @@ -7,22 +7,22 @@ * Based on the original code of Epona by Lara. * Based on the original code of Services by Andy Church. */ - + #define sigemptyset(x) memset((x), 0, sizeof(*(x))) - + #ifndef SIGHUP # define SIGHUP -1 #endif #ifndef SIGPIPE # define SIGPIPE -1 #endif - + struct sigaction { void (*sa_handler)(int); int sa_flags; int sa_mask; }; - + extern int sigaction(int, struct sigaction *, struct sigaction *); - + diff --git a/src/win32/socket.cpp b/src/win32/socket.cpp index d481515d3..320e46f48 100644 --- a/src/win32/socket.cpp +++ b/src/win32/socket.cpp @@ -85,7 +85,7 @@ int windows_inet_pton(int af, const char *src, void *dst) } return 1; } - + return 0; } diff --git a/src/win32/windows.cpp b/src/win32/windows.cpp index a9e0521d0..319bebf58 100644 --- a/src/win32/windows.cpp +++ b/src/win32/windows.cpp @@ -68,10 +68,10 @@ int gettimeofday(timeval *tv, void *) { SYSTEMTIME st; GetSystemTime(&st); - + tv->tv_sec = Anope::CurTime; tv->tv_usec = st.wMilliseconds; - + return 0; } @@ -243,7 +243,7 @@ int mkstemp(char *input) errno = EEXIST; return -1; } - + int fd = open(input, O_WRONLY | O_CREAT, S_IREAD | S_IWRITE); return fd; } |