summaryrefslogtreecommitdiff
path: root/src/users.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/users.cpp')
-rw-r--r--src/users.cpp67
1 files changed, 41 insertions, 26 deletions
diff --git a/src/users.cpp b/src/users.cpp
index 09529bb5f..fc509ee0a 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1,6 +1,6 @@
/* Routines to maintain a list of online users.
*
- * (C) 2003-2023 Anope Team
+ * (C) 2003-2024 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -50,7 +50,7 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
this->server = sserver;
this->realname = srealname;
this->timestamp = this->signon = ts;
- this->SetModesInternal(sserver, "%s", smodes.c_str());
+ this->SetModesInternal(sserver, smodes);
this->uid = suid;
this->super_admin = false;
this->nc = NULL;
@@ -372,7 +372,7 @@ void User::Identify(NickAlias *na)
{
if (!this->nc->o->ot->modes.empty())
{
- this->SetModes(NULL, "%s", this->nc->o->ot->modes.c_str());
+ this->SetModes(NULL, this->nc->o->ot->modes);
this->SendMessage(NULL, "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)
@@ -448,6 +448,11 @@ bool User::IsRecognized(bool check_secure) const
return on_access;
}
+bool User::IsSecurelyConnected() const
+{
+ return HasMode("SSL") || HasExt("ssl");
+}
+
bool User::IsServicesOper()
{
if (!this->nc || !this->nc->IsServicesOper())
@@ -463,9 +468,8 @@ bool User::IsServicesOper()
bool match = false;
Anope::string match_host = this->GetIdent() + "@" + this->host;
Anope::string match_ip = this->GetIdent() + "@" + this->ip.addr();
- for (unsigned i = 0; i < this->nc->o->hosts.size(); ++i)
+ for (const auto &userhost : this->nc->o->hosts)
{
- const Anope::string &userhost = this->nc->o->hosts[i];
if (Anope::Match(match_host, userhost) || Anope::Match(match_ip, userhost))
{
match = true;
@@ -539,7 +543,7 @@ void User::SetModeInternal(const MessageSource &source, UserMode *um, const Anop
{
if (!this->nc->o->ot->modes.empty())
{
- this->SetModes(NULL, "%s", this->nc->o->ot->modes.c_str());
+ this->SetModes(NULL, this->nc->o->ot->modes);
this->SendMessage(NULL, "Changing your usermodes to \002%s\002", this->nc->o->ot->modes.c_str());
UserMode *oper = ModeManager::FindUserModeByName("OPER");
if (oper && !this->HasMode("OPER") && this->nc->o->ot->modes.find(oper->mchar) != Anope::string::npos)
@@ -616,19 +620,24 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
- Anope::string modebuf, sbuf;
- int add = -1;
va_start(args, umodes);
vsnprintf(buf, BUFSIZE - 1, umodes, args);
va_end(args);
- spacesepstream sep(buf);
+ SetModes(bi, Anope::string(buf));
+}
+
+void User::SetModes(BotInfo *bi, const Anope::string &umodes)
+{
+ Anope::string modebuf, sbuf;
+ int add = -1;
+ spacesepstream sep(umodes);
sep.GetToken(modebuf);
- for (unsigned i = 0, end = modebuf.length(); i < end; ++i)
+ for (auto mode : modebuf)
{
UserMode *um;
- switch (modebuf[i])
+ switch (mode)
{
case '+':
add = 1;
@@ -639,7 +648,7 @@ void User::SetModes(BotInfo *bi, const char *umodes, ...)
default:
if (add == -1)
continue;
- um = ModeManager::FindUserModeByChar(modebuf[i]);
+ um = ModeManager::FindUserModeByChar(mode);
if (!um)
continue;
}
@@ -660,22 +669,27 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ...
{
char buf[BUFSIZE] = "";
va_list args;
- Anope::string modebuf, sbuf;
- int add = -1;
va_start(args, umodes);
vsnprintf(buf, BUFSIZE - 1, umodes, args);
va_end(args);
- if (this->server && this->server->IsSynced() && Anope::string(buf) != "+")
- Log(this, "mode") << "changes modes to " << buf;
+ SetModesInternal(source, Anope::string(buf));
+}
+
+void User::SetModesInternal(const MessageSource &source, const Anope::string &umodes)
+{
+ if (this->server && this->server->IsSynced() && Anope::string(umodes) != "+")
+ Log(this, "mode") << "changes modes to " << umodes;
- spacesepstream sep(buf);
+ int add = -1;
+ Anope::string modebuf;
+ spacesepstream sep(umodes);
sep.GetToken(modebuf);
- for (unsigned i = 0, end = modebuf.length(); i < end; ++i)
+ for (auto mode : modebuf)
{
UserMode *um;
- switch (modebuf[i])
+ switch (mode)
{
case '+':
add = 1;
@@ -686,13 +700,14 @@ void User::SetModesInternal(const MessageSource &source, const char *umodes, ...
default:
if (add == -1)
continue;
- um = ModeManager::FindUserModeByChar(modebuf[i]);
+ um = ModeManager::FindUserModeByChar(mode);
if (!um)
continue;
}
if (add)
{
+ Anope::string sbuf;
if (um->type == MODE_PARAM && sep.GetToken(sbuf))
this->SetModeInternal(source, um, sbuf);
else
@@ -707,16 +722,16 @@ Anope::string User::GetModes() const
{
Anope::string m, params;
- for (ModeList::const_iterator it = this->modes.begin(), it_end = this->modes.end(); it != it_end; ++it)
+ for (const auto &[mode, value] : this->modes)
{
- UserMode *um = ModeManager::FindUserModeByName(it->first);
+ UserMode *um = ModeManager::FindUserModeByName(mode);
if (um == NULL)
continue;
m += um->mchar;
- if (!it->second.empty())
- params += " " + it->second;
+ if (!value.empty())
+ params += " " + value;
}
return m + params;
@@ -847,7 +862,7 @@ User* User::Find(const Anope::string &name, bool nick_only)
void User::QuitUsers()
{
- for (std::list<User *>::iterator it = quitting_users.begin(), it_end = quitting_users.end(); it != it_end; ++it)
- delete *it;
+ for (const auto *quitting_user : quitting_users)
+ delete quitting_user;
quitting_users.clear();
}