summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/protocol.h8
-rw-r--r--modules/protocol/inspircd.cpp6
-rw-r--r--modules/protocol/ngircd.cpp2
-rw-r--r--src/messages.cpp45
-rw-r--r--src/protocol.cpp17
5 files changed, 39 insertions, 39 deletions
diff --git a/include/protocol.h b/include/protocol.h
index ec4570490..f2b510d96 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -40,7 +40,6 @@ public:
virtual void SendPartInternal(User *, const Channel *chan, const Anope::string &buf);
virtual void SendGlobopsInternal(const MessageSource &, const Anope::string &buf);
virtual void SendCTCPInternal(const MessageSource &, const Anope::string &dest, const Anope::string &buf);
- virtual void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf);
/** Parses an incoming message from the IRC server.
* @param message The message to parse.
@@ -248,7 +247,12 @@ public:
virtual void SendServer(const Server *) = 0;
virtual void SendSquit(Server *, const Anope::string &message);
- virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...) ATTR_FORMAT(4, 5);
+ virtual void SendNumericInternal(int numeric, const Anope::string &dest, const std::vector<Anope::string> &params);
+ template <typename... Args>
+ void SendNumeric(int numeric, const Anope::string &dest, Args &&...args)
+ {
+ SendNumericInternal(numeric, dest, { stringify(args)... });
+ }
virtual void SendLogin(User *u, NickAlias *na) = 0;
virtual void SendLogout(User *u) = 0;
diff --git a/modules/protocol/inspircd.cpp b/modules/protocol/inspircd.cpp
index a622d26e9..cef005f83 100644
--- a/modules/protocol/inspircd.cpp
+++ b/modules/protocol/inspircd.cpp
@@ -296,9 +296,11 @@ public:
SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->by, x->GetReason());
}
- void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) override
+ void SendNumericInternal(int numeric, const Anope::string &dest, const std::vector<Anope::string> &params) override
{
- UplinkSocket::Message() << "NUM " << Me->GetSID() << " " << dest << " " << numeric << " " << buf;
+ auto newparams = params;
+ newparams.insert(newparams.begin(), { Me->GetSID(), dest, numeric });
+ Uplink::SendInternal({}, Me, numeric, newparams);
}
void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override
diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp
index 28018e522..1ea020290 100644
--- a/modules/protocol/ngircd.cpp
+++ b/modules/protocol/ngircd.cpp
@@ -61,7 +61,7 @@ public:
/* Make myself known to myself in the serverlist */
SendServer(Me);
/* finish the enhanced server handshake and register the connection */
- this->SendNumeric(376, "*", ":End of MOTD command");
+ this->SendNumeric(376, "*", "End of MOTD command");
}
void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override
diff --git a/src/messages.cpp b/src/messages.cpp
index a57dcb6f9..5e96fee0f 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -243,18 +243,18 @@ void MOTD::Run(MessageSource &source, const std::vector<Anope::string> &params,
FILE *f = fopen(Config->GetBlock("serverinfo")->Get<const Anope::string>("motd").c_str(), "r");
if (f)
{
- IRCD->SendNumeric(375, source.GetSource(), ":- %s Message of the Day", s->GetName().c_str());
+ IRCD->SendNumeric(375, source.GetSource(), "- " + s->GetName() + " Message of the Day");
char buf[BUFSIZE];
while (fgets(buf, sizeof(buf), f))
{
buf[strlen(buf) - 1] = 0;
- IRCD->SendNumeric(372, source.GetSource(), ":- %s", buf);
+ IRCD->SendNumeric(372, source.GetSource(), Anope::printf("- %s", buf));
}
fclose(f);
- IRCD->SendNumeric(376, source.GetSource(), ":End of /MOTD command.");
+ IRCD->SendNumeric(376, source.GetSource(), "End of /MOTD command.");
}
else
- IRCD->SendNumeric(422, source.GetSource(), ":- MOTD file not found! Please contact your IRC administrator.");
+ IRCD->SendNumeric(422, source.GetSource(), "- MOTD file not found! Please contact your IRC administrator.");
}
void Notice::Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags)
@@ -414,40 +414,40 @@ void Stats::Run(MessageSource &source, const std::vector<Anope::string> &params,
if (u->HasMode("OPER"))
{
IRCD->SendNumeric(211, source.GetSource(), "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime");
- IRCD->SendNumeric(211, source.GetSource(), "%s %d %d %d %d %d %d %ld", Config->Uplinks[Anope::CurrentUplink].host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - Anope::StartTime));
+ IRCD->SendNumeric(211, source.GetSource(), Config->Uplinks[Anope::CurrentUplink].host, UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, Anope::CurTime - Anope::StartTime);
}
- IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ IRCD->SendNumeric(219, source.GetSource(), params[0][0], "End of /STATS report.");
break;
case 'o':
case 'O':
/* Check whether the user is an operator */
if (!u->HasMode("OPER") && Config->GetBlock("options")->Get<bool>("hidestatso"))
- IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ IRCD->SendNumeric(219, source.GetSource(), params[0][0], "End of /STATS report.");
else
{
for (auto *o : Oper::opers)
{
const NickAlias *na = NickAlias::Find(o->name);
if (na)
- IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->name.c_str(), o->ot->GetName().replace_all_cs(" ", "_").c_str());
+ IRCD->SendNumeric(243, source.GetSource(), 'O', '*', '*', o->name, o->ot->GetName().replace_all_cs(" ", "_"), '0');
}
- IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ IRCD->SendNumeric(219, source.GetSource(), params[0][0], "End of /STATS report.");
}
break;
case 'u':
{
long uptime = static_cast<long>(Anope::CurTime - Anope::StartTime);
- IRCD->SendNumeric(242, source.GetSource(), ":Services up %ld day%s, %02ld:%02ld:%02ld", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60);
- IRCD->SendNumeric(250, source.GetSource(), ":Current users: %zu (%d ops); maximum %u", UserListByNick.size(), OperCount, MaxUserCount);
- IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ IRCD->SendNumeric(242, source.GetSource(), Anope::printf("Services up %ld day%s, %02ld:%02ld:%02ld", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60));
+ IRCD->SendNumeric(250, source.GetSource(), Anope::printf("Current users: %zu (%d ops); maximum %u", UserListByNick.size(), OperCount, MaxUserCount));
+ IRCD->SendNumeric(219, source.GetSource(), params[0][0], "End of /STATS report.");
break;
} /* case 'u' */
default:
- IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]);
+ IRCD->SendNumeric(219, source.GetSource(), params[0][0], "End of /STATS report.");
}
return;
@@ -460,7 +460,7 @@ void Time::Run(MessageSource &source, const std::vector<Anope::string> &params,
struct tm *tm = localtime(&t);
char buf[64];
strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm);
- IRCD->SendNumeric(391, source.GetSource(), "%s :%s", Me->GetName().c_str(), buf);
+ IRCD->SendNumeric(391, source.GetSource(), Me->GetName(), buf);
return;
}
@@ -476,7 +476,8 @@ void Topic::Run(MessageSource &source, const std::vector<Anope::string> &params,
void Version::Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags)
{
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
- IRCD->SendNumeric(351, source.GetSource(), "Anope-%s %s :%s -(%s) -- %s", Anope::Version().c_str(), Me->GetName().c_str(), IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)", Anope::VersionBuildString().c_str());
+ IRCD->SendNumeric(351, source.GetSource(), "Anope-" + Anope::Version(), Me->GetName(), Anope::printf("%s -(%s) -- %s",
+ IRCD->GetProtocolName().c_str(), enc ? enc->name.c_str() : "(none)", Anope::VersionBuildString().c_str()));
}
void Whois::Run(MessageSource &source, const std::vector<Anope::string> &params, const Anope::map<Anope::string> &tags)
@@ -486,15 +487,15 @@ void Whois::Run(MessageSource &source, const std::vector<Anope::string> &params,
if (u && u->server == Me)
{
const BotInfo *bi = BotInfo::Find(u->GetUID());
- IRCD->SendNumeric(311, source.GetSource(), "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
+ IRCD->SendNumeric(311, source.GetSource(), u->nick, u->GetIdent(), u->host, '*', u->realname);
if (bi)
- IRCD->SendNumeric(307, source.GetSource(), "%s :is a registered nick", bi->nick.c_str());
- IRCD->SendNumeric(312, source.GetSource(), "%s %s :%s", u->nick.c_str(), Me->GetName().c_str(), Config->GetBlock("serverinfo")->Get<const Anope::string>("description").c_str());
+ IRCD->SendNumeric(307, source.GetSource(), bi->nick, "is a registered nick");
+ IRCD->SendNumeric(312, source.GetSource(), u->nick, Me->GetName(), Config->GetBlock("serverinfo")->Get<const Anope::string>("description"));
if (bi)
- IRCD->SendNumeric(317, source.GetSource(), "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(bi->signon));
- IRCD->SendNumeric(313, source.GetSource(), "%s :is a Network Service", u->nick.c_str());
- IRCD->SendNumeric(318, source.GetSource(), "%s :End of /WHOIS list.", u->nick.c_str());
+ IRCD->SendNumeric(317, source.GetSource(), bi->nick, Anope::CurTime - bi->lastmsg, bi->signon, "seconds idle, signon time");
+ IRCD->SendNumeric(313, source.GetSource(), u->nick, "is a Network Service");
+ IRCD->SendNumeric(318, source.GetSource(), u->nick, "End of /WHOIS list.");
}
else
- IRCD->SendNumeric(401, source.GetSource(), "%s :No such user.", params[0].c_str());
+ IRCD->SendNumeric(401, source.GetSource(), params[0], "No such user.");
}
diff --git a/src/protocol.cpp b/src/protocol.cpp
index 57742bf2c..41df1dadc 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -150,14 +150,17 @@ void IRCDProto::SendCTCPInternal(const MessageSource &source, const Anope::strin
this->SendNoticeInternal(source, dest, "\1" + s + "\1");
}
-void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf)
+void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, const std::vector<Anope::string> &params)
{
Anope::string n = stringify(numeric);
if (numeric < 10)
n = "0" + n;
if (numeric < 100)
n = "0" + n;
- UplinkSocket::Message(Me) << n << " " << dest << " " << buf;
+
+ auto newparams = params;
+ newparams.insert(newparams.begin(), dest);
+ Uplink::SendInternal({}, Me, n, newparams);
}
void IRCDProto::SendTopic(const MessageSource &source, Channel *c)
@@ -329,16 +332,6 @@ void IRCDProto::SendCTCP(const MessageSource &source, const Anope::string &dest,
SendCTCPInternal(source, dest, buf);
}
-void IRCDProto::SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...)
-{
- va_list args;
- char buf[BUFSIZE] = "";
- va_start(args, fmt);
- vsnprintf(buf, BUFSIZE - 1, fmt, args);
- va_end(args);
- SendNumericInternal(numeric, dest, buf);
-}
-
bool IRCDProto::IsNickValid(const Anope::string &nick)
{
/**