summaryrefslogtreecommitdiff
path: root/modules/commands
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2013-04-07 23:46:44 -0500
committerAdam <Adam@anope.org>2013-04-07 23:46:44 -0500
commitfb7fef7a849342ab8463743497e781c5c3e6ae88 (patch)
tree5d230a68b6eed70c7b4f718410dd62fea779654c /modules/commands
parent36602224b8b1a11326a224779d16bcb12f0ed532 (diff)
Optimizations of much of the more commonly used code
Diffstat (limited to 'modules/commands')
-rw-r--r--modules/commands/bs_kick.cpp4
-rw-r--r--modules/commands/cs_access.cpp4
-rw-r--r--modules/commands/cs_akick.cpp5
-rw-r--r--modules/commands/cs_ban.cpp3
-rw-r--r--modules/commands/cs_enforce.cpp12
-rw-r--r--modules/commands/cs_kick.cpp3
-rw-r--r--modules/commands/cs_mode.cpp11
-rw-r--r--modules/commands/cs_seen.cpp15
-rw-r--r--modules/commands/cs_set.cpp3
-rw-r--r--modules/commands/cs_suspend.cpp2
-rw-r--r--modules/commands/cs_sync.cpp2
-rw-r--r--modules/commands/cs_updown.cpp15
-rw-r--r--modules/commands/ns_recover.cpp6
-rw-r--r--modules/commands/os_chankill.cpp2
-rw-r--r--modules/commands/os_dns.cpp10
-rw-r--r--modules/commands/os_forbid.cpp62
-rw-r--r--modules/commands/os_forbid.h6
-rw-r--r--modules/commands/os_jupe.cpp2
-rw-r--r--modules/commands/os_list.cpp4
-rw-r--r--modules/commands/os_mode.cpp6
-rw-r--r--modules/commands/os_noop.cpp2
-rw-r--r--modules/commands/os_session.cpp174
-rw-r--r--modules/commands/os_session.h6
-rw-r--r--modules/commands/os_sxline.cpp2
24 files changed, 181 insertions, 180 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)