diff options
author | Adam <Adam@anope.org> | 2013-04-07 23:46:44 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2013-04-07 23:46:44 -0500 |
commit | fb7fef7a849342ab8463743497e781c5c3e6ae88 (patch) | |
tree | 5d230a68b6eed70c7b4f718410dd62fea779654c /modules | |
parent | 36602224b8b1a11326a224779d16bcb12f0ed532 (diff) |
Optimizations of much of the more commonly used code
Diffstat (limited to 'modules')
40 files changed, 264 insertions, 348 deletions
diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp index 3f7cc16c2..97f6b6035 100644 --- a/modules/commands/bs_kick.cpp +++ b/modules/commands/bs_kick.cpp @@ -808,7 +808,7 @@ class BSKick : public Module { Channel *c = cit->second; for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) - (*it)->Shrink("bs_main_userdata"); + it->second->Shrink("bs_main_userdata"); c->Shrink("bs_main_bandata"); } } @@ -1033,7 +1033,7 @@ class BSKick : public Module { for (User::ChanUserList::iterator it = u->chans.begin(); it != u->chans.end();) { - Channel *chan = (*it)->chan; + Channel *chan = it->second->chan; ++it; if (chan->ci && chan->ci->HasExt("BS_KICK_AMSGS") && !chan->ci->AccessFor(u).HasPriv("NOKICK")) diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp index 239c344ab..3a4bdff54 100644 --- a/modules/commands/cs_access.cpp +++ b/modules/commands/cs_access.cpp @@ -326,7 +326,7 @@ class CommandCSAccess : public Command Anope::string timebuf; if (ci->c) for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) - if (access->Matches((*cit)->user, (*cit)->user->Account())) + if (access->Matches(cit->second->user, cit->second->user->Account())) timebuf = "Now"; if (timebuf.empty()) { @@ -360,7 +360,7 @@ class CommandCSAccess : public Command Anope::string timebuf; if (ci->c) for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end; ++cit) - if (access->Matches((*cit)->user, (*cit)->user->Account())) + if (access->Matches(cit->second->user, cit->second->user->Account())) timebuf = "Now"; if (timebuf.empty()) { diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp index a3133b8e9..f2bd603f9 100644 --- a/modules/commands/cs_akick.cpp +++ b/modules/commands/cs_akick.cpp @@ -390,9 +390,10 @@ class CommandCSAKick : public Command return; } - for (User::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) + for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { - ChanUserContainer *uc = *it++; + ChanUserContainer *uc = it->second; + ++it; if (ci->CheckKick(uc->user)) ++count; diff --git a/modules/commands/cs_ban.cpp b/modules/commands/cs_ban.cpp index 06c8de95a..5aad394a3 100644 --- a/modules/commands/cs_ban.cpp +++ b/modules/commands/cs_ban.cpp @@ -160,7 +160,8 @@ class CommandCSBan : public Command int matched = 0, kicked = 0; for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end;) { - ChanUserContainer *uc = *it++; + ChanUserContainer *uc = it->second; + ++it; if (Anope::Match(uc->user->nick, target) || Anope::Match(uc->user->GetDisplayedMask(), target)) { diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp index 4d5ba0242..fd5caf613 100644 --- a/modules/commands/cs_enforce.cpp +++ b/modules/commands/cs_enforce.cpp @@ -31,7 +31,7 @@ class CommandCSEnforce : public Command for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; ci->c->SetCorrectModes(uc->user, false, false); } @@ -50,7 +50,7 @@ class CommandCSEnforce : public Command std::vector<User *> users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -81,7 +81,7 @@ class CommandCSEnforce : public Command std::vector<User *> users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -113,7 +113,7 @@ class CommandCSEnforce : public Command std::vector<User *> users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -145,7 +145,7 @@ class CommandCSEnforce : public Command std::vector<User *> users; for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) @@ -195,7 +195,7 @@ class CommandCSEnforce : public Command /* The newer users are at the end of the list, so kick users starting from the end */ for (Channel::ChanUserList::reverse_iterator it = ci->c->users.rbegin(), it_end = ci->c->users.rend(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; User *user = uc->user; if (user->IsProtected()) diff --git a/modules/commands/cs_kick.cpp b/modules/commands/cs_kick.cpp index 03beaf0a8..870c18f0c 100644 --- a/modules/commands/cs_kick.cpp +++ b/modules/commands/cs_kick.cpp @@ -79,7 +79,8 @@ class CommandCSKick : public Command int matched = 0, kicked = 0; for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end;) { - ChanUserContainer *uc = *it++; + ChanUserContainer *uc = it->second; + ++it; if (Anope::Match(uc->user->nick, target) || Anope::Match(uc->user->GetDisplayedMask(), target)) { diff --git a/modules/commands/cs_mode.cpp b/modules/commands/cs_mode.cpp index 7edc4eddc..1d0f0985b 100644 --- a/modules/commands/cs_mode.cpp +++ b/modules/commands/cs_mode.cpp @@ -253,9 +253,11 @@ class CommandCSMode : public Command case '*': if (adding == -1 || !has_access) break; - for (unsigned j = 0; j < ModeManager::ChannelModes.size(); ++j) + for (unsigned j = 0; j < ModeManager::GetChannelModes().size(); ++j) { - ChannelMode *cm = ModeManager::ChannelModes[j]; + ChannelMode *cm = ModeManager::GetChannelModes()[j]; + if (!cm) + continue; if (!u || cm->CanSet(u)) { if (cm->type == MODE_REGULAR || (!adding && cm->type == MODE_PARAM)) @@ -309,9 +311,10 @@ class CommandCSMode : public Command break; } - for (Channel::ChanUserList::const_iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) + for (Channel::ChanUserList::const_iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end;) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; + ++it; AccessGroup targ_access = ci->AccessFor(uc->user); diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp index 10c23dd53..66706c8fb 100644 --- a/modules/commands/cs_seen.cpp +++ b/modules/commands/cs_seen.cpp @@ -60,10 +60,10 @@ struct SeenInfo : Serializable s = anope_dynamic_static_cast<SeenInfo *>(obj); else { - /* ignore duplicate entries in the db, created by an old bug */ - s = FindInfo(snick); - if (!s) - s = new SeenInfo(); + SeenInfo* &info = database[snick]; + if (!info) + info = new SeenInfo(); + s = info; } data["nick"] >> s->nick; @@ -388,12 +388,9 @@ class CSSeen : public Module if (!u->server->IsSynced()) return; - SeenInfo *info = FindInfo(nick); + SeenInfo* &info = database[nick]; if (!info) - { - info = new SeenInfo; - database.insert(std::pair<Anope::string, SeenInfo *>(nick, info)); - } + info = new SeenInfo(); info->nick = nick; info->vhost = u->GetVIdent() + "@" + u->GetDisplayedHost(); info->type = Type; diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp index cfc2c4767..67d024c9f 100644 --- a/modules/commands/cs_set.cpp +++ b/modules/commands/cs_set.cpp @@ -544,7 +544,8 @@ class CommandCSSetPersist : public Command /* Channel doesn't exist, create it */ if (!ci->c) { - Channel *c = new Channel(ci->name); + bool created; + Channel *c = Channel::FindOrCreate(ci->name, created); if (ci->bi) ci->bi->Join(c); } diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp index fdfd2d55a..0ea54879e 100644 --- a/modules/commands/cs_suspend.cpp +++ b/modules/commands/cs_suspend.cpp @@ -66,7 +66,7 @@ class CommandCSSuspend : public Command for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; User *user = uc->user; if (!user->HasMode("OPER") && user->server != Me) users.push_back(user); diff --git a/modules/commands/cs_sync.cpp b/modules/commands/cs_sync.cpp index 1a02c813c..3983a52d1 100644 --- a/modules/commands/cs_sync.cpp +++ b/modules/commands/cs_sync.cpp @@ -35,7 +35,7 @@ class CommandCSSync : public Command Log(LOG_COMMAND, source, this, ci); for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) - ci->c->SetCorrectModes((*it)->user, true, false); + ci->c->SetCorrectModes(it->second->user, true, false); source.Reply(_("All user modes on \002%s\002 have been synced."), ci->name.c_str()); } diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp index 27e1984d1..ecce1e51d 100644 --- a/modules/commands/cs_updown.cpp +++ b/modules/commands/cs_updown.cpp @@ -30,7 +30,7 @@ class CommandCSUp : public Command return; for (User::ChanUserList::iterator it = source.GetUser()->chans.begin(); it != source.GetUser()->chans.end(); ++it) { - Channel *c = (*it)->chan; + Channel *c = it->second->chan; c->SetCorrectModes(source.GetUser(), true, false); } } @@ -87,13 +87,10 @@ class CommandCSDown : public Command { void RemoveAll(User *u, Channel *c) { - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - { - ChannelMode *cm = ModeManager::ChannelModes[i]; - - if (cm != NULL && cm->type == MODE_STATUS) - c->RemoveMode(NULL, cm, u->nick); - } + ChanUserContainer *cu = c->FindUser(u); + if (cu != NULL) + for (size_t i = 0; i < cu->status.Modes().length(); ++i) + c->RemoveMode(NULL, ModeManager::FindChannelModeByChar(cu->status.Modes()[i]), u->GetUID()); } public: @@ -111,7 +108,7 @@ class CommandCSDown : public Command return; for (User::ChanUserList::iterator it = source.GetUser()->chans.begin(); it != source.GetUser()->chans.end(); ++it) { - Channel *c = (*it)->chan; + Channel *c = it->second->chan; RemoveAll(source.GetUser(), c); } } diff --git a/modules/commands/ns_recover.cpp b/modules/commands/ns_recover.cpp index 33a97646c..ee54f3b3f 100644 --- a/modules/commands/ns_recover.cpp +++ b/modules/commands/ns_recover.cpp @@ -62,7 +62,7 @@ class NSRecoverRequest : public IdentifyRequest { NSRecoverExtensibleInfo *ei = new NSRecoverExtensibleInfo; for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it) - (*ei)[(*it)->chan->name] = (*it)->status; + (*ei)[it->first->name] = it->second->status; source.GetUser()->Extend("ns_recover_info", ei); } @@ -265,8 +265,8 @@ class NSRecover : public Module std::map<Anope::string, ChannelStatus>::iterator it = ei->find(c->name); if (it != ei->end()) { - for (std::set<Anope::string>::iterator it2 = it->second.modes.begin(), it2_end = it->second.modes.end(); it2 != it2_end; ++it2) - c->SetMode(c->ci->WhoSends(), ModeManager::FindChannelModeByName(*it2), u->GetUID()); + for (size_t i = 0; i < it->second.Modes().length(); ++i) + c->SetMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(it->second.Modes()[i]), u->GetUID()); ei->erase(it); if (ei->empty()) diff --git a/modules/commands/os_chankill.cpp b/modules/commands/os_chankill.cpp index 3fea40043..c88011b5b 100644 --- a/modules/commands/os_chankill.cpp +++ b/modules/commands/os_chankill.cpp @@ -74,7 +74,7 @@ class CommandOSChanKill : public Command { for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ) { - ChanUserContainer *uc = *it++; + ChanUserContainer *uc = it->second; if (uc->user->server == Me || uc->user->HasMode("OPER")) continue; diff --git a/modules/commands/os_dns.cpp b/modules/commands/os_dns.cpp index d690ae55a..666baefdf 100644 --- a/modules/commands/os_dns.cpp +++ b/modules/commands/os_dns.cpp @@ -214,7 +214,7 @@ class CommandOSDNS : public Command for (unsigned i = 0; i < dns_servers->size(); ++i) { DNSServer *s = dns_servers->at(i); - Server *srv = Server::Find(s->GetName()); + Server *srv = Server::Find(s->GetName(), true); ListFormatter::ListEntry entry; entry["Server"] = s->GetName(); @@ -351,7 +351,7 @@ class CommandOSDNS : public Command return; } - Server *serv = Server::Find(params[1]); + Server *serv = Server::Find(params[1], true); if (!serv || serv == Me || serv->IsJuped()) { source.Reply(_("Server %s is not linked to the network."), params[1].c_str()); @@ -411,7 +411,7 @@ class CommandOSDNS : public Command source.Reply(_("Removed server %s from zone %s."), s->GetName().c_str(), z->name.c_str()); return; } - else if (Server::Find(s->GetName())) + else if (Server::Find(s->GetName(), true)) { source.Reply(_("Server %s must be quit before it can be deleted."), s->GetName().c_str()); return; @@ -543,7 +543,7 @@ class CommandOSDNS : public Command source.Reply(_("Server %s does not exist."), params[1].c_str()); return; } - else if (!Server::Find(s->GetName())) + else if (!Server::Find(s->GetName(), true)) { source.Reply(_("Server %s is not currently linked."), s->GetName().c_str()); return; @@ -676,7 +676,7 @@ class ModuleDNS : public Module for (unsigned j = 0; j < dns_servers->size(); ++j) { DNSServer *s = dns_servers->at(j); - if (s->Pooled() && Server::Find(s->GetName())) + if (s->Pooled() && Server::Find(s->GetName(), true)) s->SetActive(true); } } diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp index e3a0c42b8..a33ef66f2 100644 --- a/modules/commands/os_forbid.cpp +++ b/modules/commands/os_forbid.cpp @@ -16,60 +16,64 @@ class MyForbidService : public ForbidService { - Serialize::Checker<std::vector<ForbidData *> > forbid_data; + Serialize::Checker<std::vector<ForbidData *>[FT_SIZE]> forbid_data; public: MyForbidService(Module *m) : ForbidService(m), forbid_data("ForbidData") { } void AddForbid(ForbidData *d) anope_override { - this->forbid_data->push_back(d); + this->forbid_data[d->type].push_back(d); } void RemoveForbid(ForbidData *d) anope_override { - std::vector<ForbidData *>::iterator it = std::find(this->forbid_data->begin(), this->forbid_data->end(), d); - if (it != this->forbid_data->end()) - this->forbid_data->erase(it); + std::vector<ForbidData *>::iterator it = std::find(this->forbid_data[d->type].begin(), this->forbid_data[d->type].end(), d); + if (it != this->forbid_data[d->type].end()) + this->forbid_data[d->type].erase(it); delete d; } ForbidData *FindForbid(const Anope::string &mask, ForbidType ftype) anope_override { - const std::vector<ForbidData *> &forbids = this->GetForbids(); + const std::vector<ForbidData *> &forbids = this->forbid_data[ftype]; for (unsigned i = forbids.size(); i > 0; --i) { ForbidData *d = forbids[i - 1]; - if ((ftype == FT_NONE || ftype == d->type) && Anope::Match(mask, d->mask, false, true)) + if (Anope::Match(mask, d->mask, false, true)) return d; } return NULL; } - const std::vector<ForbidData *> &GetForbids() anope_override + std::vector<ForbidData *> GetForbids() anope_override { - for (unsigned i = this->forbid_data->size(); i > 0; --i) - { - ForbidData *d = this->forbid_data->at(i - 1); - - if (d->expires && Anope::CurTime >= d->expires) + std::vector<ForbidData *> forbids; + for (unsigned j = 0; j < FT_SIZE; ++j) + for (unsigned i = this->forbid_data[j].size(); i > 0; --i) { - Anope::string ftype = "none"; - if (d->type == FT_NICK) - ftype = "nick"; - else if (d->type == FT_CHAN) - ftype = "chan"; - else if (d->type == FT_EMAIL) - ftype = "email"; - - Log(LOG_NORMAL, "expire/forbid") << "Expiring forbid for " << d->mask << " type " << ftype; - this->forbid_data->erase(this->forbid_data->begin() + i - 1); - delete d; + ForbidData *d = this->forbid_data[j].at(i - 1); + + if (d->expires && Anope::CurTime >= d->expires) + { + Anope::string ftype = "none"; + if (d->type == FT_NICK) + ftype = "nick"; + else if (d->type == FT_CHAN) + ftype = "chan"; + else if (d->type == FT_EMAIL) + ftype = "email"; + + Log(LOG_NORMAL, "expire/forbid") << "Expiring forbid for " << d->mask << " type " << ftype; + this->forbid_data[j].erase(this->forbid_data[j].begin() + i - 1); + delete d; + } + else + forbids.push_back(d); } - } - return this->forbid_data; + return forbids; } }; @@ -93,7 +97,7 @@ class CommandOSForbid : public Command const Anope::string &command = params[0]; const Anope::string &subcommand = params.size() > 1 ? params[1] : ""; - ForbidType ftype = FT_NONE; + ForbidType ftype = FT_SIZE; if (subcommand.equals_ci("NICK")) ftype = FT_NICK; else if (subcommand.equals_ci("CHAN")) @@ -103,7 +107,7 @@ class CommandOSForbid : public Command else if (subcommand.equals_ci("REGISTER")) ftype = FT_REGISTER; - if (command.equals_ci("ADD") && params.size() > 3 && ftype != FT_NONE) + if (command.equals_ci("ADD") && params.size() > 3 && ftype != FT_SIZE) { const Anope::string &expiry = params[2][0] == '+' ? params[2] : ""; const Anope::string &entry = !expiry.empty() ? params[3] : params[2]; @@ -156,7 +160,7 @@ class CommandOSForbid : public Command Log(LOG_ADMIN, source, this) << "to add a forbid on " << entry << " of type " << subcommand; source.Reply(_("Added a forbid on %s to expire on %s."), entry.c_str(), d->expires ? Anope::strftime(d->expires).c_str() : "never"); } - else if (command.equals_ci("DEL") && params.size() > 2 && ftype != FT_NONE) + else if (command.equals_ci("DEL") && params.size() > 2 && ftype != FT_SIZE) { const Anope::string &entry = params[2]; diff --git a/modules/commands/os_forbid.h b/modules/commands/os_forbid.h index b4d1ce7ce..00827c559 100644 --- a/modules/commands/os_forbid.h +++ b/modules/commands/os_forbid.h @@ -3,11 +3,11 @@ enum ForbidType { - FT_NONE, FT_NICK, FT_CHAN, FT_EMAIL, - FT_REGISTER + FT_REGISTER, + FT_SIZE }; struct ForbidData : Serializable @@ -35,7 +35,7 @@ class ForbidService : public Service virtual ForbidData *FindForbid(const Anope::string &mask, ForbidType type) = 0; - virtual const std::vector<ForbidData *> &GetForbids() = 0; + virtual std::vector<ForbidData *> GetForbids() = 0; }; static ServiceReference<ForbidService> forbid_service("ForbidService", "forbid"); diff --git a/modules/commands/os_jupe.cpp b/modules/commands/os_jupe.cpp index fa79c9098..fbe5bac12 100644 --- a/modules/commands/os_jupe.cpp +++ b/modules/commands/os_jupe.cpp @@ -26,7 +26,7 @@ class CommandOSJupe : public Command { const Anope::string &jserver = params[0]; const Anope::string &reason = params.size() > 1 ? params[1] : ""; - Server *server = Server::Find(jserver); + Server *server = Server::Find(jserver, true); if (!IRCD->IsHostValid(jserver) || jserver.find('.') == Anope::string::npos) source.Reply(_("Please use a valid server name when juping.")); diff --git a/modules/commands/os_list.cpp b/modules/commands/os_list.cpp index f4de45203..6880bbbc0 100644 --- a/modules/commands/os_list.cpp +++ b/modules/commands/os_list.cpp @@ -44,7 +44,7 @@ class CommandOSChanList : public Command for (User::ChanUserList::iterator uit = u2->chans.begin(), uit_end = u2->chans.end(); uit != uit_end; ++uit) { - ChanUserContainer *cc = *uit; + ChanUserContainer *cc = uit->second; if (!modes.empty()) for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) @@ -142,7 +142,7 @@ class CommandOSUserList : public Command for (Channel::ChanUserList::iterator cuit = c->users.begin(), cuit_end = c->users.end(); cuit != cuit_end; ++cuit) { - ChanUserContainer *uc = *cuit; + ChanUserContainer *uc = cuit->second; if (!modes.empty()) for (std::set<Anope::string>::iterator it = modes.begin(), it_end = modes.end(); it != it_end; ++it) diff --git a/modules/commands/os_mode.cpp b/modules/commands/os_mode.cpp index 33387bff6..db0ac73b5 100644 --- a/modules/commands/os_mode.cpp +++ b/modules/commands/os_mode.cpp @@ -45,13 +45,13 @@ class CommandOSMode : public Command { for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; if (uc->user->HasMode("OPER")) continue; - for (std::set<Anope::string>::iterator it2 = uc->status.modes.begin(), it2_end = uc->status.modes.end(); it2 != it2_end; ++it2) - c->RemoveMode(c->ci->WhoSends(), *it2, uc->user->GetUID(), false); + for (size_t i = 0; i < uc->status.Modes().length(); ++i) + c->RemoveMode(c->ci->WhoSends(), ModeManager::FindChannelModeByChar(uc->status.Modes()[i]), uc->user->GetUID(), false); } source.Reply(_("All modes cleared on %s."), c->name.c_str()); diff --git a/modules/commands/os_noop.cpp b/modules/commands/os_noop.cpp index 9e9af1398..082294f22 100644 --- a/modules/commands/os_noop.cpp +++ b/modules/commands/os_noop.cpp @@ -28,7 +28,7 @@ class CommandOSNOOP : public Command const Anope::string &cmd = params[0]; const Anope::string &server = params[1]; - Server *s = Server::Find(server); + Server *s = Server::Find(server, true); if (s == NULL) source.Reply(_("Server %s does not exist."), server.c_str()); else if (s == Me || s->IsJuped()) diff --git a/modules/commands/os_session.cpp b/modules/commands/os_session.cpp index 1edda00d6..31846c9db 100644 --- a/modules/commands/os_session.cpp +++ b/modules/commands/os_session.cpp @@ -61,11 +61,6 @@ class MySessionService : public SessionService return this->Exceptions; } - void AddSession(Session *s) anope_override - { - this->Sessions[s->addr] = s; - } - void DelSession(Session *s) anope_override { this->Sessions.erase(s->addr); @@ -80,6 +75,18 @@ class MySessionService : public SessionService return NULL; } + SessionMap::iterator FindSessionIterator(const Anope::string &ip) + { + cidr c(ip, ip.find(':') != Anope::string::npos ? Config->SessionIPv6CIDR : Config->SessionIPv4CIDR); + return this->Sessions.find(c); + } + + Session* &FindOrCreateSession(const Anope::string &ip) + { + cidr c(ip, ip.find(':') != Anope::string::npos ? Config->SessionIPv6CIDR : Config->SessionIPv4CIDR); + return this->Sessions[c]; + } + SessionMap &GetSessions() anope_override { return this->Sessions; @@ -611,124 +618,117 @@ class OSSession : public Module CommandOSException commandosexception; ServiceReference<XLineManager> akills; - void AddSession(User *u, bool exempt) + public: + OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), + exception_type("Exception", Exception::Unserialize), ss(this), commandossession(this), commandosexception(this), akills("XLineManager", "xlinemanager/sgline") { - Session *session; - try - { - session = this->ss.FindSession(u->ip); - } - catch (const SocketException &) - { + this->SetAuthor("Anope"); + this->SetPermanent(true); + + Implementation i[] = { I_OnUserConnect, I_OnPreUserLogoff }; + ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); + ModuleManager::SetPriority(this, PRIORITY_FIRST); + } + + void OnUserConnect(User *u, bool &exempt) anope_override + { + if (u->Quitting() || !Config->LimitSessions || exempt || !u->server || u->server->IsULined()) return; - } - if (session) + try { - bool kill = false; - if (Config->DefSessionLimit && session->count >= Config->DefSessionLimit) + Session* &session = this->ss.FindOrCreateSession(u->ip); + + if (session) { - kill = true; - Exception *exception = this->ss.FindException(u); - if (exception) + bool kill = false; + if (Config->DefSessionLimit && session->count >= Config->DefSessionLimit) { - kill = false; - if (exception->limit && session->count >= exception->limit) - kill = true; + kill = true; + Exception *exception = this->ss.FindException(u); + if (exception) + { + kill = false; + if (exception->limit && session->count >= exception->limit) + kill = true; + } } - } - /* Previously on IRCds that send a QUIT (InspIRCD) when a user is killed, the session for a host was - * decremented in do_quit, which caused problems and fixed here - * - * Now, we create the user struture before calling this to fix some user tracking issues, - * so we must increment this here no matter what because it will either be - * decremented in do_kill or in do_quit - Adam - */ - ++session->count; + /* Previously on IRCds that send a QUIT (InspIRCD) when a user is killed, the session for a host was + * decremented in do_quit, which caused problems and fixed here + * + * Now, we create the user struture before calling this to fix some user tracking issues, + * so we must increment this here no matter what because it will either be + * decremented in do_kill or in do_quit - Adam + */ + ++session->count; - if (kill && !exempt) - { - if (OperServ) + if (kill && !exempt) { - if (!Config->SessionLimitExceeded.empty()) - u->SendMessage(OperServ, Config->SessionLimitExceeded.c_str(), u->ip.c_str()); - if (!Config->SessionLimitDetailsLoc.empty()) - u->SendMessage(OperServ, "%s", Config->SessionLimitDetailsLoc.c_str()); - } + if (OperServ) + { + if (!Config->SessionLimitExceeded.empty()) + u->SendMessage(OperServ, Config->SessionLimitExceeded.c_str(), u->ip.c_str()); + if (!Config->SessionLimitDetailsLoc.empty()) + u->SendMessage(OperServ, "%s", Config->SessionLimitDetailsLoc.c_str()); + } - ++session->hits; - if (Config->MaxSessionKill && session->hits >= Config->MaxSessionKill && akills) - { - const Anope::string &akillmask = "*@" + u->ip; - XLine *x = new XLine(akillmask, Config->OperServ, Anope::CurTime + Config->SessionAutoKillExpiry, "Session limit exceeded", XLineManager::GenerateUID()); - akills->AddXLine(x); - akills->Send(NULL, x); - Log(OperServ, "akill/session") << "Added a temporary AKILL for \002" << akillmask << "\002 due to excessive connections"; - } - else - { - u->Kill(Config->OperServ, "Session limit exceeded"); - u = NULL; /* No guarentee u still exists */ + ++session->hits; + if (Config->MaxSessionKill && session->hits >= Config->MaxSessionKill && akills) + { + const Anope::string &akillmask = "*@" + u->ip; + XLine *x = new XLine(akillmask, Config->OperServ, Anope::CurTime + Config->SessionAutoKillExpiry, "Session limit exceeded", XLineManager::GenerateUID()); + akills->AddXLine(x); + akills->Send(NULL, x); + Log(OperServ, "akill/session") << "Added a temporary AKILL for \002" << akillmask << "\002 due to excessive connections"; + } + else + { + u->Kill(Config->OperServ, "Session limit exceeded"); + } } } + else + { + session = new Session(u->ip, u->ip.find(':') != Anope::string::npos ? Config->SessionIPv6CIDR : Config->SessionIPv4CIDR); + } } - else - { - session = new Session(u->ip, u->ip.find(':') != Anope::string::npos ? Config->SessionIPv6CIDR : Config->SessionIPv4CIDR); - this->ss.AddSession(session); - } + catch (const SocketException &) { } } - void DelSession(User *u) + void OnPreUserLogoff(User *u) anope_override { - Session *session; + if (!Config->LimitSessions || !u->server || u->server->IsULined()) + return; + + SessionService::SessionMap::iterator sit; try { - session = this->ss.FindSession(u->ip); + sit = this->ss.FindSessionIterator(u->ip); } catch (const SocketException &) { return; } - if (!session) + + SessionService::SessionMap &sessions = this->ss.GetSessions(); + + if (sit == sessions.end()) { Log(LOG_DEBUG) << "Tried to delete non-existant session: " << u->ip; return; } + Session *session = sit->second; + if (session->count > 1) { --session->count; return; } - this->ss.DelSession(session); delete session; - } - - public: - OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE), - exception_type("Exception", Exception::Unserialize), ss(this), commandossession(this), commandosexception(this), akills("XLineManager", "xlinemanager/sgline") - { - this->SetAuthor("Anope"); - this->SetPermanent(true); - - Implementation i[] = { I_OnUserConnect, I_OnPreUserLogoff }; - ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation)); - ModuleManager::SetPriority(this, PRIORITY_FIRST); - } - - void OnUserConnect(User *user, bool &exempt) anope_override - { - if (!user->Quitting() && Config->LimitSessions) - this->AddSession(user, exempt); - } - - void OnPreUserLogoff(User *u) anope_override - { - if (Config->LimitSessions && (!u->server || !u->server->IsULined())) - this->DelSession(u); + sessions.erase(sit); } }; diff --git a/modules/commands/os_session.h b/modules/commands/os_session.h index 6d1dd917d..f3077d0ac 100644 --- a/modules/commands/os_session.h +++ b/modules/commands/os_session.h @@ -42,11 +42,7 @@ class SessionService : public Service virtual ExceptionVector &GetExceptions() = 0; - virtual void AddSession(Session *s) = 0; - - virtual void DelSession(Session *s) = 0; - - virtual Session *FindSession(const Anope::string &mask) = 0; + virtual Session *FindSession(const Anope::string &ip) = 0; virtual SessionMap &GetSessions() = 0; }; diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp index 2a98edf1d..e76a611db 100644 --- a/modules/commands/os_sxline.cpp +++ b/modules/commands/os_sxline.cpp @@ -599,7 +599,7 @@ class CommandOSSQLine : public CommandOSSXLineBase std::vector<User *> users; for (Channel::ChanUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; User *user = uc->user; if (!user->HasMode("OPER") && user->server != Me) diff --git a/modules/extra/cs_statusupdate.cpp b/modules/extra/cs_statusupdate.cpp index 97faae851..4a53956d7 100644 --- a/modules/extra/cs_statusupdate.cpp +++ b/modules/extra/cs_statusupdate.cpp @@ -36,7 +36,7 @@ class StatusUpdate : public Module if (ci->c) for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - User *user = (*it)->user; + User *user = it->second->user; if (access->Matches(user, user->Account())) { @@ -53,7 +53,7 @@ class StatusUpdate : public Module if (ci->c) for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - User *user = (*it)->user; + User *user = it->second->user; if (access->Matches(user, user->Account())) { diff --git a/modules/extra/m_xmlrpc_main.cpp b/modules/extra/m_xmlrpc_main.cpp index e4b761cc7..9166f27df 100644 --- a/modules/extra/m_xmlrpc_main.cpp +++ b/modules/extra/m_xmlrpc_main.cpp @@ -174,7 +174,7 @@ class MyXMLRPCEvent : public XMLRPCEvent Anope::string users; for (Channel::ChanUserList::const_iterator it = c->users.begin(); it != c->users.end(); ++it) { - ChanUserContainer *uc = *it; + ChanUserContainer *uc = it->second; users += uc->status.BuildModePrefixList() + uc->user->nick + " "; } if (!users.empty()) @@ -226,7 +226,7 @@ class MyXMLRPCEvent : public XMLRPCEvent Anope::string channels; for (User::ChanUserList::const_iterator it = u->chans.begin(); it != u->chans.end(); ++it) { - ChanUserContainer *cc = *it; + ChanUserContainer *cc = it->second; channels += cc->status.BuildModePrefixList() + cc->chan->name + " "; } if (!channels.empty()) diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 8c2c131a6..1f15e3c06 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -143,16 +143,14 @@ class BahamutIRCdProto : public IRCDProto return; /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") + if (x->GetUser() == "*" && x->GetHost().find_first_not_of("0123456789:.") == Anope::string::npos) + try { sockaddrs(x->GetHost()); IRCD->SendSZLineDel(x); return; } - } - catch (const SocketException &) { } + catch (const SocketException &) { } UplinkSocket::Message() << "RAKILL " << x->GetHost() << " " << x->GetUser(); } @@ -170,7 +168,7 @@ class BahamutIRCdProto : public IRCDProto } /* JOIN - SJOIN */ - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { UplinkSocket::Message(user) << "SJOIN " << c->creation_time << " " << c->name; if (status) @@ -182,12 +180,11 @@ class BahamutIRCdProto : public IRCDProto */ ChanUserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->status.modes.clear(); + uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->nick); - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.modes.count(ModeManager::ChannelModes[i]->name)) - c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); } } @@ -217,16 +214,14 @@ class BahamutIRCdProto : public IRCDProto } /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") + if (x->GetUser() == "*" && x->GetHost().find_first_not_of("0123456789:.") == Anope::string::npos) + try { sockaddrs(x->GetHost()); IRCD->SendSZLine(u, x); return; } - } - catch (const SocketException &) { } + catch (const SocketException &) { } // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->expires - Anope::CurTime; @@ -448,14 +443,7 @@ struct IRCDMessageSJoin : IRCDMessage for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { buf.erase(buf.begin()); - ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); - if (!cm) - { - Log() << "Received unknown mode prefix " << cm << " in SJOIN string"; - continue; - } - - sju.first.modes.insert(cm->name); + sju.first.AddMode(ch); } sju.second = User::Find(buf); diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index 6f41abcc5..e91478c7f 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -52,7 +52,7 @@ class CharybdisProto : public IRCDProto void SendAkill(User *u, XLine *x) anope_override { ratbox->SendAkill(u, x); } void SendAkillDel(const XLine *x) anope_override { ratbox->SendAkillDel(x); } void SendSQLineDel(const XLine *x) anope_override { ratbox->SendSQLineDel(x); } - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override { ratbox->SendJoin(user, c, status); } + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { ratbox->SendJoin(user, c, status); } void SendServer(const Server *server) anope_override { ratbox->SendServer(server); } void SendChannel(Channel *c) anope_override { ratbox->SendChannel(c); } void SendTopic(BotInfo *bi, Channel *c) anope_override { ratbox->SendTopic(bi, c); } diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index ac3f88c41..3247787f1 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -88,7 +88,7 @@ class HybridProto : public IRCDProto UplinkSocket::Message(OperServ) << "UNRESV * " << x->mask; } - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { /* * Note that we must send our modes with the SJOIN and @@ -234,7 +234,7 @@ class HybridProto : public IRCDProto { ChannelStatus status; - status.modes.insert("OP"); + status.AddMode('o'); bi->Join(c, &status); } @@ -271,24 +271,14 @@ struct IRCDMessageBMask : IRCDMessage void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { Channel *c = Channel::Find(params[1]); + ChannelMode *mode = ModeManager::FindChannelModeByChar(params[2][0]); - if (c) + if (c && mode) { - ChannelMode *ban = ModeManager::FindChannelModeByName("BAN"), - *except = ModeManager::FindChannelModeByName("EXCEPT"), - *invex = ModeManager::FindChannelModeByName("INVITEOVERRIDE"); - spacesepstream bans(params[3]); Anope::string token; while (bans.GetToken(token)) - { - if (ban && params[2].equals_cs("b")) - c->SetModeInternal(source, ban, token); - else if (except && params[2].equals_cs("e")) - c->SetModeInternal(source, except, token); - else if (invex && params[2].equals_cs("I")) - c->SetModeInternal(source, invex, token); - } + c->SetModeInternal(source, mode, token); } } }; @@ -412,15 +402,7 @@ struct IRCDMessageSJoin : IRCDMessage for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { buf.erase(buf.begin()); - ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); - - if (!cm) - { - Log() << "Received unknown mode prefix " << ch << " in SJOIN string"; - continue; - } - - sju.first.modes.insert(cm->name); + sju.first.AddMode(ch); } sju.second = User::Find(buf); diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp index 0761f478c..b6cb905c2 100644 --- a/modules/protocol/inspircd11.cpp +++ b/modules/protocol/inspircd11.cpp @@ -80,16 +80,14 @@ class InspIRCdProto : public IRCDProto return; /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") + if (x->GetUser() == "*" && x->GetHost().find_first_not_of("0123456789:.") == Anope::string::npos) + try { sockaddrs(x->GetHost()); IRCD->SendSZLineDel(x); return; } - } - catch (const SocketException &) { } + catch (const SocketException &) { } UplinkSocket::Message(OperServ) << "GLINE " << x->mask; } @@ -136,16 +134,14 @@ class InspIRCdProto : public IRCDProto } /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") + if (x->GetUser() == "*" && x->GetHost().find_first_not_of("0123456789:.") == Anope::string::npos) + try { sockaddrs(x->GetHost()); IRCD->SendSZLine(u, x); return; } - } - catch (const SocketException &) { } + catch (const SocketException &) { } // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->expires - Anope::CurTime; @@ -203,7 +199,7 @@ class InspIRCdProto : public IRCDProto } /* JOIN */ - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { UplinkSocket::Message(user) << "JOIN " << c->name << " " << c->creation_time; if (status) @@ -215,12 +211,11 @@ class InspIRCdProto : public IRCDProto */ ChanUserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->status.modes.clear(); + uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->nick); - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.modes.count(ModeManager::ChannelModes[i]->name)) - c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); } } @@ -653,7 +648,7 @@ struct IRCDMessageFJoin : IRCDMessage continue; } - sju.first.modes.insert(cm->name); + sju.first.AddMode(cm->mchar); } /* Erase the , */ buf.erase(buf.begin()); diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp index a79edf291..deb7bbbf1 100644 --- a/modules/protocol/inspircd12.cpp +++ b/modules/protocol/inspircd12.cpp @@ -180,16 +180,15 @@ class InspIRCd12Proto : public IRCDProto } /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") + if (x->GetUser() == "*" && x->GetHost().find_first_not_of("0123456789:.") == Anope::string::npos) + try { sockaddrs(x->GetHost()); IRCD->SendSZLine(u, x); return; } - } - catch (const SocketException &) { } + catch (const SocketException &) { } + SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->by, x->GetReason()); } @@ -221,7 +220,7 @@ class InspIRCd12Proto : public IRCDProto } /* JOIN */ - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID(); /* Note that we can send this with the FJOIN but choose not to @@ -237,19 +236,11 @@ class InspIRCd12Proto : public IRCDProto */ ChanUserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->status.modes.clear(); + uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->nick); - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - { - ChannelMode *cm = ModeManager::ChannelModes[i]; - - if (cs.modes.count(cm->name) || cs.modes.count(cm->mchar)) - { - c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); - cs.modes.insert(cm->name); - } - } + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); } } @@ -386,7 +377,7 @@ class InspIRCdExtBan : public ChannelModeList public: InspIRCdExtBan(const Anope::string &mname, char modeChar) : ChannelModeList(mname, modeChar) { } - bool Matches(const User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) anope_override { const Anope::string &mask = e->GetMask(); @@ -839,20 +830,14 @@ struct IRCDMessageFJoin : IRCDMessage Message::Join::SJoinUser sju; /* Loop through prefixes and find modes for them */ - for (char c; (c = buf[0]) != ',';) + for (char c; (c = buf[0]) != ',' && c;) { buf.erase(buf.begin()); - ChannelMode *cm = ModeManager::FindChannelModeByChar(c); - if (!cm) - { - Log() << "Received unknown mode prefix " << c << " in FJOIN string"; - continue; - } - - sju.first.modes.insert(cm->name); + sju.first.AddMode(c); } /* Erase the , */ - buf.erase(buf.begin()); + if (!buf.empty()) + buf.erase(buf.begin()); sju.second = User::Find(buf); if (!sju.second) diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index bbe069466..0af696bf0 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -55,7 +55,7 @@ class InspIRCd20Proto : public IRCDProto void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override { insp12->SendModeInternal(bi, u, buf); } void SendClientIntroduction(const User *u) anope_override { insp12->SendClientIntroduction(u); } void SendServer(const Server *server) anope_override { insp12->SendServer(server); } - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); } + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { insp12->SendJoin(user, c, status); } void SendSQLineDel(const XLine *x) anope_override { insp12->SendSQLineDel(x); } void SendSQLine(User *u, const XLine *x) anope_override { insp12->SendSQLine(u, x); } void SendVhost(User *u, const Anope::string &vident, const Anope::string &vhost) anope_override { insp12->SendVhost(u, vident, vhost); } @@ -80,7 +80,7 @@ class InspIRCdExtBan : public ChannelModeList public: InspIRCdExtBan(const Anope::string &mname, char modeChar) : ChannelModeList(mname, modeChar) { } - bool Matches(const User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) anope_override { const Anope::string &mask = e->GetMask(); @@ -111,7 +111,7 @@ class InspIRCdExtBan : public ChannelModeList { ChanUserContainer *uc = c->FindUser(u); if (uc != NULL) - if (cm == NULL || uc->status.modes.count(cm->name)) + if (cm == NULL || uc->status.HasMode(cm->mchar)) return true; } } diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index e54a4f8f7..ef226f87e 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -83,7 +83,7 @@ class ngIRCdProto : public IRCDProto UplinkSocket::Message(Me) << "WALLOPS :" << buf; } - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { UplinkSocket::Message(user) << "JOIN " << c->name; if (status) @@ -95,12 +95,11 @@ class ngIRCdProto : public IRCDProto */ ChanUserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->status.modes.clear(); + uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->nick); - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.modes.count(ModeManager::ChannelModes[i]->name)) - c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); } } @@ -245,10 +244,8 @@ struct IRCDMessageChaninfo : IRCDMessage */ void Run(MessageSource &source, const std::vector<Anope::string> ¶ms) anope_override { - - Channel *c = Channel::Find(params[0]); - if (!c) - c = new Channel(params[0]); + bool created; + Channel *c = Channel::FindOrCreate(params[0], created); Anope::string modes = params[1]; @@ -470,15 +467,8 @@ struct IRCDMessageNJoin : IRCDMessage /* Get prefixes from the nick */ for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { - ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); buf.erase(buf.begin()); - if (!cm) - { - Log(LOG_DEBUG) << "Received unknown mode prefix " << ch << " in NJOIN string."; - continue; - } - - sju.first.modes.insert(cm->name); + sju.first.AddMode(ch); } sju.second = User::Find(buf); diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index d117389e7..c22c43192 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -48,7 +48,7 @@ class PlexusProto : public IRCDProto void SendSVSHold(const Anope::string &nick) anope_override { hybrid->SendSVSHold(nick); } void SendSVSHoldDel(const Anope::string &nick) anope_override { hybrid->SendSVSHoldDel(nick); } - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID(); if (status) @@ -60,12 +60,11 @@ class PlexusProto : public IRCDProto */ ChanUserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->status.modes.clear(); + uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->nick); - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.modes.count(ModeManager::ChannelModes[i]->name)) - c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); } } diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 247b8777a..129752c06 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -37,7 +37,7 @@ class RatboxProto : public IRCDProto void SendAkill(User *u, XLine *x) anope_override { hybrid->SendAkill(u, x); } void SendAkillDel(const XLine *x) anope_override { hybrid->SendAkillDel(x); } void SendSQLineDel(const XLine *x) anope_override { hybrid->SendSQLineDel(x); } - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override { hybrid->SendJoin(user, c, status); } + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { hybrid->SendJoin(user, c, status); } void SendServer(const Server *server) anope_override { hybrid->SendServer(server); } void SendModeInternal(const BotInfo *bi, const User *u, const Anope::string &buf) anope_override { hybrid->SendModeInternal(bi, u, buf); } void SendChannel(Channel *c) anope_override { hybrid->SendChannel(c); } diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index 984277c14..25094a24d 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -44,16 +44,14 @@ class UnrealIRCdProto : public IRCDProto return; /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") + if (x->GetUser() == "*" && x->GetHost().find_first_not_of("0123456789:.") == Anope::string::npos) + try { sockaddrs(x->GetHost()); IRCD->SendSZLineDel(x); return; } - } - catch (const SocketException &) { } + catch (const SocketException &) { } UplinkSocket::Message() << "TKL - G " << x->GetUser() << " " << x->GetHost() << " " << Config->OperServ; } @@ -108,16 +106,14 @@ class UnrealIRCdProto : public IRCDProto } /* ZLine if we can instead */ - try - { - if (x->GetUser() == "*") + if (x->GetUser() == "*" && x->GetHost().find_first_not_of("0123456789:.") == Anope::string::npos) + try { sockaddrs(x->GetHost()); IRCD->SendSZLine(u, x); return; } - } - catch (const SocketException &) { } + catch (const SocketException &) { } // Calculate the time left before this would expire, capping it at 2 days time_t timeleft = x->expires - Anope::CurTime; @@ -154,7 +150,7 @@ class UnrealIRCdProto : public IRCDProto } /* JOIN */ - void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override + void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override { UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " :" << user->nick; if (status) @@ -166,12 +162,11 @@ class UnrealIRCdProto : public IRCDProto */ ChanUserContainer *uc = c->FindUser(user); if (uc != NULL) - uc->status.modes.clear(); + uc->status.Clear(); BotInfo *setter = BotInfo::Find(user->nick); - for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i) - if (cs.modes.count(ModeManager::ChannelModes[i]->name)) - c->SetMode(setter, ModeManager::ChannelModes[i], user->GetUID(), false); + for (size_t i = 0; i < cs.Modes().length(); ++i) + c->SetMode(setter, ModeManager::FindChannelModeByChar(cs.Modes()[i]), user->GetUID(), false); } } @@ -384,7 +379,7 @@ class UnrealExtBan : public ChannelModeList public: UnrealExtBan(const Anope::string &mname, char modeChar) : ChannelModeList(mname, modeChar) { } - bool Matches(const User *u, const Entry *e) anope_override + bool Matches(User *u, const Entry *e) anope_override { const Anope::string &mask = e->GetMask(); @@ -407,7 +402,7 @@ class UnrealExtBan : public ChannelModeList { ChanUserContainer *uc = c->FindUser(u); if (uc != NULL) - if (cm == NULL || uc->status.modes.count(cm->name)) + if (cm == NULL || uc->status.HasMode(cm->mchar)) return true; } } @@ -1050,15 +1045,8 @@ struct IRCDMessageSJoin : IRCDMessage /* Get prefixes from the nick */ for (char ch; (ch = ModeManager::GetStatusChar(buf[0]));) { + sju.first.AddMode(ch); buf.erase(buf.begin()); - ChannelMode *cm = ModeManager::FindChannelModeByChar(ch); - if (!cm) - { - Log(LOG_DEBUG) << "Received unknown mode prefix " << ch << " in SJOIN string"; - continue; - } - - sju.first.modes.insert(cm->name); } sju.second = User::Find(buf); diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv.cpp index 7b59c0597..21a2f75f7 100644 --- a/modules/pseudoclients/chanserv.cpp +++ b/modules/pseudoclients/chanserv.cpp @@ -35,8 +35,8 @@ class ExpireCallback : public Timer if (ci->c) { time_t last_used = ci->last_used; - for (User::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end && last_used == ci->last_used; ++cit) - ci->AccessFor((*cit)->user); + for (Channel::ChanUserList::const_iterator cit = ci->c->users.begin(), cit_end = ci->c->users.end(); cit != cit_end && last_used == ci->last_used; ++cit) + ci->AccessFor(cit->second->user); expire = last_used == ci->last_used; } else diff --git a/modules/pseudoclients/memoserv.cpp b/modules/pseudoclients/memoserv.cpp index 73dd48b94..d28774e34 100644 --- a/modules/pseudoclients/memoserv.cpp +++ b/modules/pseudoclients/memoserv.cpp @@ -81,7 +81,7 @@ class MyMemoServService : public MemoServService { for (Channel::ChanUserList::iterator it = ci->c->users.begin(), it_end = ci->c->users.end(); it != it_end; ++it) { - ChanUserContainer *cu = *it; + ChanUserContainer *cu = it->second; if (ci->AccessFor(cu->user).HasPriv("MEMO")) { @@ -171,7 +171,7 @@ class MemoServCore : public Module void OnJoinChannel(User *u, Channel *c) anope_override { - if (c->ci && c->ci->AccessFor(u).HasPriv("MEMO") && c->ci->memos.memos->size() > 0) + if (c->ci && !c->ci->memos.memos->empty() && c->ci->AccessFor(u).HasPriv("MEMO")) { if (c->ci->memos.memos->size() == 1) u->SendMessage(MemoServ, _("There is \002%d\002 memo on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str()); diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp index e221c19c0..35319e552 100644 --- a/modules/pseudoclients/nickserv.cpp +++ b/modules/pseudoclients/nickserv.cpp @@ -257,7 +257,7 @@ class NickServCore : public Module if (Config->NSModeOnID) for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it) { - ChanUserContainer *cc = *it; + ChanUserContainer *cc = it->second; Channel *c = cc->chan; if (c) c->SetCorrectModes(u, true, true); @@ -296,7 +296,7 @@ class NickServCore : public Module { for (User::ChanUserList::iterator it = u->chans.begin(), it_end = u->chans.end(); it != it_end; ++it) { - ChanUserContainer *cc = *it; + ChanUserContainer *cc = it->second; Channel *c = cc->chan; if (c) c->SetCorrectModes(u, true, true); diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp index 10908ef03..b2463dc4f 100644 --- a/modules/pseudoclients/operserv.cpp +++ b/modules/pseudoclients/operserv.cpp @@ -35,19 +35,7 @@ class SGLineManager : public XLineManager void SendDel(XLine *x) anope_override { - try - { - if (!IRCD->CanSZLine) - throw SocketException("SZLine is not supported"); - else if (x->GetUser() != "*") - throw SocketException("Can not ZLine a username"); - sockaddrs(x->GetHost()); - IRCD->SendSZLineDel(x); - } - catch (const SocketException &) - { - IRCD->SendAkillDel(x); - } + IRCD->SendAkillDel(x); } bool Check(User *u, const XLine *x) anope_override @@ -70,7 +58,7 @@ class SGLineManager : public XLineManager if (!x->GetReal().empty() && !Anope::Match(u->realname, x->GetReal())) return false; - if (!x->GetHost().empty()) + if (x->GetHost().find('/') != Anope::string::npos) { try { @@ -82,7 +70,7 @@ class SGLineManager : public XLineManager catch (const SocketException &) { } } - if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost())) + if (x->GetHost().empty() || Anope::Match(u->host, x->GetHost()) || Anope::Match(u->ip, x->GetHost())) return true; return false; |