summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-12-07 11:29:47 -0500
committerAdam <Adam@anope.org>2016-12-07 11:29:47 -0500
commita64ede8632e1e60aba9d04d2fea9d107e339b7f3 (patch)
tree8a2e6e6cc16bee5d9beb52b27b11e4e17962f68a
parent87ec095a89bbc73a4dd16858bea499f466066212 (diff)
Remove C style var args from Channel::Kick
-rw-r--r--include/channels.h7
-rw-r--r--modules/botserv/kick.cpp16
-rw-r--r--modules/chanserv/ban.cpp8
-rw-r--r--modules/chanserv/enforce.cpp10
-rw-r--r--modules/chanserv/kick.cpp8
-rw-r--r--modules/chanserv/suspend.cpp2
-rw-r--r--modules/operserv/forbid.cpp2
-rw-r--r--modules/operserv/kick.cpp2
-rw-r--r--modules/operserv/sxline.cpp2
-rw-r--r--src/channels.cpp14
10 files changed, 32 insertions, 39 deletions
diff --git a/include/channels.h b/include/channels.h
index 664f06a0a..d3161b7ae 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -245,7 +245,12 @@ class CoreExport Channel : public Base, public Extensible
* @param reason The reason for the kick
* @return true if the kick was scucessful, false if a module blocked the kick
*/
- bool Kick(User *bi, User *u, const char *reason = NULL, ...);
+ bool Kick(User *bi, User *u, const Anope::string &reason);
+
+ template<typename... Args> bool Kick(User *bi, User *u, const Anope::string &reason, Args&&... args)
+ {
+ return Kick(bi, u, Anope::Format(reason, std::forward<Args>(args)...));
+ }
/** Get all modes set on this channel, excluding status modes.
* @return a map of modes and their optional parameters.
diff --git a/modules/botserv/kick.cpp b/modules/botserv/kick.cpp
index 20af77d1c..a32656f62 100644
--- a/modules/botserv/kick.cpp
+++ b/modules/botserv/kick.cpp
@@ -1329,7 +1329,8 @@ class BSKick : public Module
return userdata.Require(uc);
}
- void TakeAction(ChanServ::Channel *ci, User *u, int ttb, TTBType ttbtype, const char *message, ...)
+ template<typename... Args>
+ void TakeAction(ChanServ::Channel *ci, User *u, int ttb, TTBType ttbtype, const Anope::string &message, Args&&... args)
{
/* Don't ban ulines or protected users */
if (u->IsProtected())
@@ -1351,15 +1352,8 @@ class BSKick : public Module
if (!ci->c->FindUser(u))
return;
- va_list args;
- char buf[1024];
-
- Anope::string fmt = Language::Translate(u, message);
- va_start(args, message);
- vsnprintf(buf, sizeof(buf), fmt.c_str(), args);
- va_end(args);
-
- ci->c->Kick(ci->GetBot(), u, "%s", buf);
+ Anope::string buf = Anope::Format(message, std::forward<Args>(args)...);
+ ci->c->Kick(ci->GetBot(), u, buf);
}
public:
@@ -1703,7 +1697,7 @@ class BSKick : public Module
if (Config->GetModule(me)->Get<bool>("gentlebadwordreason"))
TakeAction(ci, u, kd->GetTTBBadwords(), TTB_BADWORDS, _("Watch your language!"));
else
- TakeAction(ci, u, kd->GetTTBBadwords(), TTB_BADWORDS, _("Don't use the word \"%s\" on this channel!"), bw->GetWord().c_str());
+ TakeAction(ci, u, kd->GetTTBBadwords(), TTB_BADWORDS, _("Don't use the word \"{0}\" on this channel!"), bw->GetWord());
return;
}
diff --git a/modules/chanserv/ban.cpp b/modules/chanserv/ban.cpp
index 44e2752a5..2b73df8fb 100644
--- a/modules/chanserv/ban.cpp
+++ b/modules/chanserv/ban.cpp
@@ -173,11 +173,11 @@ class CommandCSBan : public Command
if (ci->IsSignKick() || (ci->IsSignKickLevel() && !source.AccessFor(ci).HasPriv("SIGNKICK")))
{
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), u2, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), u2, signkickformat);
}
else
{
- c->Kick(ci->WhoSends(), u2, "%s", reason.c_str());
+ c->Kick(ci->WhoSends(), u2, reason);
}
}
}
@@ -230,11 +230,11 @@ class CommandCSBan : public Command
{
reason += " (Matches " + mask + ")";
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), uc->user, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), uc->user, signkickformat);
}
else
{
- c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
+ c->Kick(ci->WhoSends(), uc->user, "{0} (Matches {1})", reason, mask);
}
}
}
diff --git a/modules/chanserv/enforce.cpp b/modules/chanserv/enforce.cpp
index c2a9fbe2d..e1d084075 100644
--- a/modules/chanserv/enforce.cpp
+++ b/modules/chanserv/enforce.cpp
@@ -73,7 +73,7 @@ class CommandCSEnforce : public Command
Anope::string mask = ci->GetIdealBan(user);
Anope::string reason = Language::Translate(user, _("RESTRICTED enforced by ")) + source.GetNick();
ci->c->SetMode(NULL, "BAN", mask);
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("\002Restricted\002 enforced on \002{0}\002."), ci->GetName());
@@ -105,7 +105,7 @@ class CommandCSEnforce : public Command
Anope::string reason = Language::Translate(user, _("REGONLY enforced by ")) + source.GetNick();
if (!ci->c->HasMode("REGISTEREDONLY"))
ci->c->SetMode(NULL, "BAN", mask);
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("\002Registered only\002 enforced on \002{0}\002."), ci->GetName());
@@ -137,7 +137,7 @@ class CommandCSEnforce : public Command
Anope::string reason = Language::Translate(user, _("SSLONLY enforced by ")) + source.GetNick();
if (!ci->c->HasMode("SSL"))
ci->c->SetMode(NULL, "BAN", mask);
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("\002SSL only\002 enforced on %s."), ci->GetName().c_str());
@@ -166,7 +166,7 @@ class CommandCSEnforce : public Command
User *user = users[i];
Anope::string reason = Language::Translate(user, _("BANS enforced by ")) + source.GetNick();
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("\002Bans\002 enforced on %s."), ci->GetName().c_str());
@@ -221,7 +221,7 @@ class CommandCSEnforce : public Command
User *user = users[i];
Anope::string reason = Language::Translate(user, _("LIMIT enforced by ")) + source.GetNick();
- ci->c->Kick(NULL, user, "%s", reason.c_str());
+ ci->c->Kick(NULL, user, reason);
}
source.Reply(_("LIMIT enforced on \002{0}\002, \002{1]\002 users removed."), ci->GetName(), users.size());
diff --git a/modules/chanserv/kick.cpp b/modules/chanserv/kick.cpp
index a1ac7f62f..505f74893 100644
--- a/modules/chanserv/kick.cpp
+++ b/modules/chanserv/kick.cpp
@@ -84,11 +84,11 @@ class CommandCSKick : public Command
if (ci->IsSignKick() || (ci->IsSignKickLevel() && !u_access.HasPriv("SIGNKICK")))
{
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), u2, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), u2, signkickformat);
}
else
{
- c->Kick(ci->WhoSends(), u2, "%s", reason.c_str());
+ c->Kick(ci->WhoSends(), u2, reason);
}
}
}
@@ -121,11 +121,11 @@ class CommandCSKick : public Command
{
reason += " (Matches " + mask + ")";
signkickformat = signkickformat.replace_all_cs("%m", reason);
- c->Kick(ci->WhoSends(), uc->user, "%s", signkickformat.c_str());
+ c->Kick(ci->WhoSends(), uc->user, signkickformat);
}
else
{
- c->Kick(ci->WhoSends(), uc->user, "%s (Matches %s)", reason.c_str(), mask.c_str());
+ c->Kick(ci->WhoSends(), uc->user, "{0} (Matches {1})", reason, mask);
}
}
}
diff --git a/modules/chanserv/suspend.cpp b/modules/chanserv/suspend.cpp
index c8c451548..7895aaa02 100644
--- a/modules/chanserv/suspend.cpp
+++ b/modules/chanserv/suspend.cpp
@@ -186,7 +186,7 @@ class CommandCSSuspend : public Command
}
for (unsigned i = 0; i < users.size(); ++i)
- ci->c->Kick(NULL, users[i], "%s", !reason.empty() ? reason.c_str() : Language::Translate(users[i], _("This channel has been suspended.")));
+ ci->c->Kick(NULL, users[i], !reason.empty() ? reason : Language::Translate(users[i], _("This channel has been suspended.")));
}
Log(LOG_ADMIN, source, this, ci) << "(" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never");
diff --git a/modules/operserv/forbid.cpp b/modules/operserv/forbid.cpp
index 22d927381..bf38fc2ac 100644
--- a/modules/operserv/forbid.cpp
+++ b/modules/operserv/forbid.cpp
@@ -340,7 +340,7 @@ class CommandOSForbid : public Command
reason = Anope::printf(Language::Translate(u, _("This channel has been forbidden: \002%s\002")), d->GetReason().c_str());
- c->Kick(source.service, u, "%s", reason.c_str());
+ c->Kick(source.service, u, reason);
}
}
diff --git a/modules/operserv/kick.cpp b/modules/operserv/kick.cpp
index 7f1c20670..37e186156 100644
--- a/modules/operserv/kick.cpp
+++ b/modules/operserv/kick.cpp
@@ -54,7 +54,7 @@ class CommandOSKick : public Command
return;
}
- if (!c->Kick(source.service, u2, "%s (%s)", source.GetNick().c_str(), s.c_str()))
+ if (!c->Kick(source.service, u2, "{0} ({1})", source.GetNick(), s))
{
source.Reply(_("Access denied."));
return;
diff --git a/modules/operserv/sxline.cpp b/modules/operserv/sxline.cpp
index bd0dc8910..2c98805f2 100644
--- a/modules/operserv/sxline.cpp
+++ b/modules/operserv/sxline.cpp
@@ -599,7 +599,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
}
for (unsigned i = 0; i < users.size(); ++i)
- c->Kick(NULL, users[i], "%s", reason.c_str());
+ c->Kick(NULL, users[i], reason);
}
}
else
diff --git a/src/channels.cpp b/src/channels.cpp
index 53c5ae81b..bb6bc3083 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -756,14 +756,8 @@ bool Channel::KickInternal(const MessageSource &source, const Anope::string &nic
return true;
}
-bool Channel::Kick(User *source, User *u, const char *reason, ...)
+bool Channel::Kick(User *source, User *u, const Anope::string &reason)
{
- va_list args;
- char buf[BUFSIZE] = "";
- va_start(args, reason);
- vsnprintf(buf, BUFSIZE - 1, reason, args);
- va_end(args);
-
/* Do not kick protected clients or Ulines */
if (u->IsProtected())
return false;
@@ -771,9 +765,9 @@ bool Channel::Kick(User *source, User *u, const char *reason, ...)
if (source == NULL)
source = this->ci->WhoSends();
- if (!this->KickInternal(source, u->nick, buf))
+ if (!this->KickInternal(source, u->nick, reason))
return false;
- IRCD->SendKick(source, this, u, buf);
+ IRCD->SendKick(source, this, u, reason);
return true;
}
@@ -901,7 +895,7 @@ bool Channel::CheckKick(User *user)
Log(LOG_DEBUG) << "Autokicking " << user->nick << " (" << mask << ") from " << this->name;
this->SetMode(NULL, "BAN", mask);
- this->Kick(NULL, user, "%s", reason.c_str());
+ this->Kick(NULL, user, reason);
return true;
}