From 87ec095a89bbc73a4dd16858bea499f466066212 Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 6 Dec 2016 21:02:48 -0500 Subject: Remove many more old C style format strings in the protocol functions --- include/anope.h | 7 +- include/module.h | 1 + include/modules/protocol/charybdis.h | 2 +- include/modules/protocol/hybrid.h | 4 +- include/modules/protocol/plexus.h | 2 +- include/modules/protocol/ratbox.h | 2 +- include/modules/protocol/rfc1459.h | 6 +- include/modules/protocol/unreal.h | 2 +- include/numeric.h | 42 +++++++ include/protocol.h | 211 +++++++++++++++++++++++------------ include/uplink.h | 2 +- include/version.cpp | 20 ++-- modules/botserv/control.cpp | 4 +- modules/botserv/main/botserv.cpp | 2 +- modules/chanserv/log.cpp | 4 +- modules/greet.cpp | 2 +- modules/protocol/bahamut.cpp | 18 +-- modules/protocol/charybdis.cpp | 10 +- modules/protocol/hybrid.cpp | 16 +-- modules/protocol/inspircd20.cpp | 22 ++-- modules/protocol/ngircd.cpp | 37 ++---- modules/protocol/plexus.cpp | 12 +- modules/protocol/ratbox.cpp | 12 +- modules/protocol/rfc1459.cpp | 67 ++++++----- modules/protocol/unreal.cpp | 18 +-- src/bots.cpp | 2 +- src/channels.cpp | 2 +- src/init.cpp | 6 +- src/logger.cpp | 4 +- src/misc.cpp | 28 +++-- src/modes.cpp | 6 +- src/process.cpp | 2 +- src/protocol.cpp | 190 +++++-------------------------- src/users.cpp | 12 +- 34 files changed, 366 insertions(+), 411 deletions(-) create mode 100644 include/numeric.h diff --git a/include/anope.h b/include/anope.h index 19d9f9501..02a8c3fef 100644 --- a/include/anope.h +++ b/include/anope.h @@ -147,6 +147,8 @@ namespace Anope */ inline void push_back(char c) { return this->_string.push_back(c); } + inline string& insert(const_iterator p, char c) { this->_string.insert(p, c); return *this; } + inline string& append(const string &s) { this->_string.append(s.str()); return *this; } inline string& append(const char *s, size_t n) { this->_string.append(s, n); return *this; } @@ -353,7 +355,7 @@ namespace Anope template using locale_hash_map = std::unordered_map; #ifndef REPRODUCIBLE_BUILD - static const char *const compiled = __TIME__ " " __DATE__; + static const char *const COMPILED = __DATE__ " " __TIME__; #endif /** The time Anope started. @@ -406,7 +408,8 @@ namespace Anope */ extern CoreExport string Version(); extern CoreExport string VersionShort(); - extern CoreExport string VersionBuildString(); + extern CoreExport string VersionBuildTime(); + extern CoreExport string VersionFlags(); extern CoreExport int VersionMajor(); extern CoreExport int VersionMinor(); extern CoreExport int VersionPatch(); diff --git a/include/module.h b/include/module.h index 6371eb336..58b012fce 100644 --- a/include/module.h +++ b/include/module.h @@ -34,6 +34,7 @@ #include "mail.h" #include "modes.h" #include "modules.h" +#include "numeric.h" #include "opertype.h" #include "protocol.h" #include "serialize.h" diff --git a/include/modules/protocol/charybdis.h b/include/modules/protocol/charybdis.h index 4d525c49d..d65e094a0 100644 --- a/include/modules/protocol/charybdis.h +++ b/include/modules/protocol/charybdis.h @@ -43,7 +43,7 @@ class EUID : public IRCDMessage class ServerMessage : public IRCDMessage { public: - ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { } // SERVER dev.anope.de 1 :charybdis test server void Run(MessageSource &source, const std::vector ¶ms) override; diff --git a/include/modules/protocol/hybrid.h b/include/modules/protocol/hybrid.h index 9c1444f4d..943480f54 100644 --- a/include/modules/protocol/hybrid.h +++ b/include/modules/protocol/hybrid.h @@ -67,7 +67,7 @@ class Pong : public IRCDMessage class ServerMessage : public IRCDMessage { public: - ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { } void Run(MessageSource &source, const std::vector ¶ms) override; }; @@ -75,7 +75,7 @@ class ServerMessage : public IRCDMessage class SID : public IRCDMessage { public: - SID(Module *creator) : IRCDMessage(creator, "SID", 4) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + SID(Module *creator) : IRCDMessage(creator, "SID", 4) { } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/modules/protocol/plexus.h b/include/modules/protocol/plexus.h index b87f3e6c7..0c5d8d8c0 100644 --- a/include/modules/protocol/plexus.h +++ b/include/modules/protocol/plexus.h @@ -33,7 +33,7 @@ class Encap : public IRCDMessage class ServerMessage : public IRCDMessage { public: - ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/modules/protocol/ratbox.h b/include/modules/protocol/ratbox.h index 32710fbea..2ad4a5529 100644 --- a/include/modules/protocol/ratbox.h +++ b/include/modules/protocol/ratbox.h @@ -44,7 +44,7 @@ class Join : public rfc1459::Join class ServerMessage : public IRCDMessage { public: - ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/modules/protocol/rfc1459.h b/include/modules/protocol/rfc1459.h index 635e151c8..4ef8f0313 100644 --- a/include/modules/protocol/rfc1459.h +++ b/include/modules/protocol/rfc1459.h @@ -164,7 +164,7 @@ class Stats : public IRCDMessage class Time : public IRCDMessage { public: - Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Time(Module *creator, const Anope::string &mname = "TIME") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } void Run(MessageSource &source, const std::vector ¶ms) override; }; @@ -180,7 +180,7 @@ class Topic : public IRCDMessage class Version : public IRCDMessage { public: - Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Version(Module *creator, const Anope::string &mname = "VERSION") : IRCDMessage(creator, mname, 0) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } void Run(MessageSource &source, const std::vector ¶ms) override; }; @@ -188,7 +188,7 @@ class Version : public IRCDMessage class Whois : public IRCDMessage { public: - Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); } + Whois(Module *creator, const Anope::string &mname = "WHOIS") : IRCDMessage(creator, mname, 1) { SetFlag(IRCDMESSAGE_SOFT_LIMIT); SetFlag(IRCDMESSAGE_REQUIRE_USER); } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/modules/protocol/unreal.h b/include/modules/protocol/unreal.h index 305d52bd0..88ed05997 100644 --- a/include/modules/protocol/unreal.h +++ b/include/modules/protocol/unreal.h @@ -139,7 +139,7 @@ struct SetName : IRCDMessage class ServerMessage : public IRCDMessage { public: - ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { SetFlag(IRCDMESSAGE_REQUIRE_SERVER); } + ServerMessage(Module *creator) : IRCDMessage(creator, "SERVER", 3) { } void Run(MessageSource &source, const std::vector ¶ms) override; }; diff --git a/include/numeric.h b/include/numeric.h new file mode 100644 index 000000000..57de4433f --- /dev/null +++ b/include/numeric.h @@ -0,0 +1,42 @@ +/* + * Anope IRC Services + * + * Copyright (C) 2016 Anope Team + * + * This file is part of Anope. Anope is free software; you can + * redistribute it and/or modify it under the terms of the GNU + * General Public License as published by the Free Software + * Foundation, version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see see . + */ + +#pragma once + +enum +{ + RPL_STATSLINKINFO = 211, + RPL_ENDOFSTATS = 219, + RPL_STATSUPTIME = 242, + RPL_STATSOLINE = 243, + RPL_STATSCONN = 250, + RPL_WHOISREGNICK = 307, + RPL_WHOISUSER = 311, + RPL_WHOISSERVER = 312, + RPL_WHOISIDLE = 317, + RPL_ENDOFWHOIS = 318, + RPL_VERSION = 351, + RPL_MOTD = 372, + RPL_MOTDSTART = 375, + RPL_ENDOFMOTD = 376, + RPL_YOUREOPER = 381, + RPL_TIME = 391, + ERR_NOSUCHNICK = 401, + ERR_NOMOTD = 422 +}; diff --git a/include/protocol.h b/include/protocol.h index 7475fed21..50d16d7b3 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -22,6 +22,8 @@ #include "services.h" #include "anope.h" #include "service.h" +#include "servers.h" +#include "users.h" class IRCMessage; @@ -30,57 +32,62 @@ class CoreExport IRCDProto : public Service { Anope::string proto_name; - protected: - IRCDProto(Module *creator, const Anope::string &proto_name); - public: +public: static constexpr const char *NAME = "ircdproto"; - - virtual ~IRCDProto(); - - virtual void SendSVSKillInternal(const MessageSource &, User *, const Anope::string &); - virtual void SendModeInternal(const MessageSource &, const Channel *, const Anope::string &); - virtual void SendModeInternal(const MessageSource &, User *, const Anope::string &); - virtual void SendKickInternal(const MessageSource &, const Channel *, User *, const Anope::string &); - virtual void SendNoticeInternal(const MessageSource &, const Anope::string &dest, const Anope::string &msg); - virtual void SendPrivmsgInternal(const MessageSource &, const Anope::string &dest, const Anope::string &buf); - virtual void SendQuitInternal(User *, const Anope::string &buf); - 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); - - const Anope::string &GetProtocolName(); - virtual void Parse(const Anope::string &, Anope::string &, Anope::string &, std::vector &); - virtual Anope::string Format(IRCMessage &); /* Modes used by default by our clients */ - Anope::string DefaultPseudoclientModes; + Anope::string DefaultPseudoclientModes = "+io"; /* Can we force change a users's nick? */ - bool CanSVSNick; + bool CanSVSNick = false; /* Can we force join or part users? */ - bool CanSVSJoin; + bool CanSVSJoin = false; /* Can we set vhosts/vidents on users? */ - bool CanSetVHost, CanSetVIdent; + bool CanSetVHost = false, CanSetVIdent = false; /* Can we ban specific gecos from being used? */ - bool CanSNLine; + bool CanSNLine = false; /* Can we ban specific nicknames from being used? */ - bool CanSQLine; + bool CanSQLine = false; /* Can we ban sepcific channel names from being used? */ - bool CanSQLineChannel; + bool CanSQLineChannel = false; /* Can we ban by IP? */ - bool CanSZLine; + bool CanSZLine = false; /* Can we place temporary holds on specific nicknames? */ - bool CanSVSHold; + bool CanSVSHold = false; /* See ns_cert */ - bool CanCertFP; + bool CanCertFP = false; /* Whether this IRCd requires unique IDs for each user or server. See TS6/P10. */ - bool RequiresID; + bool RequiresID = false; /* If this IRCd has unique ids, whether the IDs and nicknames are ambiguous */ - bool AmbiguousID; + bool AmbiguousID = false; /* The maximum number of modes we are allowed to set with one MODE command */ - unsigned MaxModes; + unsigned int MaxModes = 3; /* The maximum number of bytes a line may have */ - unsigned MaxLine; + unsigned int MaxLine = 512; + + IRCDProto(Module *creator, const Anope::string &proto_name); + virtual ~IRCDProto(); + + const Anope::string &GetProtocolName() const; + + virtual void Parse(const Anope::string &, Anope::string &, Anope::string &, std::vector &); + virtual Anope::string Format(IRCMessage &); + + /** Kills a user + * @param source Who is doing the kill + * @param user The target to be killed + * @param reason Kill reason + */ + virtual void SendSVSKill(const MessageSource &source, User *user, const Anope::string &reason); + virtual void SendMode(const MessageSource &, Channel *, const Anope::string &); + virtual void SendMode(const MessageSource &, User *, const Anope::string &); + virtual void SendKick(const MessageSource &, Channel *, User *, const Anope::string &); + virtual void SendNotice(const MessageSource &, const Anope::string &dest, const Anope::string &msg); + virtual void SendPrivmsg(const MessageSource &, const Anope::string &dest, const Anope::string &msg); + virtual void SendQuit(User *, const Anope::string &reason); + virtual void SendPart(User *, Channel *chan, const Anope::string &reason); + virtual void SendGlobops(const MessageSource &, const Anope::string &buf); + virtual void SendCTCPReply(const MessageSource &, const Anope::string &dest, const Anope::string &buf); + virtual void SendNumeric(int numeric, User *dest, IRCMessage &); /* Retrieves the next free UID or SID */ virtual Anope::string UID_Retrieve(); @@ -91,7 +98,7 @@ class CoreExport IRCDProto : public Service * @param s The server * @param mode Whether to turn NOOP on or off */ - virtual void SendSVSNOOP(const Server *s, bool mode) { } + virtual void SendSVSNOOP(Server *s, bool mode) { } /** Sets the topic on a channel * @param bi The bot to set the topic from @@ -130,32 +137,18 @@ class CoreExport IRCDProto : public Service virtual void SendKill(const MessageSource &source, const Anope::string &target, const Anope::string &reason); - /** Kills a user - * @param source Who is doing the kill - * @param user The user to be killed - * @param fmt Kill reason - */ - virtual void SendSVSKill(const MessageSource &source, User *user, const char *fmt, ...); - - virtual void SendMode(const MessageSource &source, const Channel *dest, const char *fmt, ...); - virtual void SendMode(const MessageSource &source, User *u, const char *fmt, ...); - /** Introduces a client to the rest of the network * @param u The client to introduce */ virtual void SendClientIntroduction(User *u) anope_abstract; - virtual void SendKick(const MessageSource &source, const Channel *chan, User *user, const char *fmt, ...); - virtual void SendNotice(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); - virtual void SendPrivmsg(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); - virtual void SendAction(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); - virtual void SendCTCP(const MessageSource &source, const Anope::string &dest, const char *fmt, ...); + virtual void SendAction(const MessageSource &source, const Anope::string &dest, const Anope::string &message); + + virtual void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) anope_abstract; + virtual void SendGlobalPrivmsg(ServiceBot *bi, Server *desc, const Anope::string &msg) anope_abstract; - virtual void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) anope_abstract; - virtual void SendGlobalPrivmsg(ServiceBot *bi, const Server *desc, const Anope::string &msg) anope_abstract; - virtual void SendQuit(User *u, const char *fmt, ...); virtual void SendPing(const Anope::string &servname, const Anope::string &who); /** @@ -174,7 +167,6 @@ class CoreExport IRCDProto : public Service * stacker to be set "soon". */ virtual void SendJoin(User *u, Channel *c, const ChannelStatus *status) anope_abstract; - virtual void SendPart(User *u, const Channel *chan, const char *fmt, ...); /** Force joins a user that isn't ours to a channel. * @param bi The source of the message @@ -192,8 +184,8 @@ class CoreExport IRCDProto : public Service */ virtual void SendSVSPart(const MessageSource &source, User *u, const Anope::string &chan, const Anope::string ¶m) { } - virtual void SendInvite(const MessageSource &source, const Channel *c, User *u); - virtual void SendGlobops(const MessageSource &source, const char *fmt, ...); + virtual void SendInvite(const MessageSource &source, Channel *c, User *u); + /** Sends a nick change of one of our clients. */ @@ -221,10 +213,9 @@ class CoreExport IRCDProto : public Service /** Introduces a server to the uplink */ - virtual void SendServer(const Server *) anope_abstract; + virtual void SendServer(Server *) anope_abstract; virtual void SendSquit(Server *, const Anope::string &message); - virtual void SendNumeric(int numeric, const Anope::string &dest, const char *fmt, ...); virtual void SendLogin(User *u, NickServ::Nick *na) anope_abstract; virtual void SendLogout(User *u) anope_abstract; @@ -252,16 +243,74 @@ class CoreExport IRCDProto : public Service /** Retrieve the maximum number of list modes settable on this channel * Defaults to Config->ListSize */ - virtual unsigned GetMaxListFor(Channel *c); + virtual unsigned int GetMaxListFor(Channel *c); virtual Anope::string NormalizeMask(const Anope::string &mask); + + /* Templated functions which overload the normal functions to provide format strings */ + template void SendSVSKill(const MessageSource &source, User *user, const Anope::string &reason, Args&&... args) + { + SendSVSKill(source, user, Anope::Format(reason, std::forward(args)...)); + } + + template void SendMode(const MessageSource &source, Channel *chan, const Anope::string &modes, Args&&... args) + { + SendMode(source, chan, Anope::Format(modes, std::forward(args)...)); + } + + template void SendMode(const MessageSource &source, User *u, const Anope::string &modes, Args&&... args) + { + SendMode(source, u, Anope::Format(modes, std::forward(args)...)); + } + + template void SendKick(const MessageSource &source, const Channel *chan, User *user, const Anope::string &reason, Args&&... args) + { + SendKick(source, chan, user, Anope::Format(reason, std::forward(args)...)); + } + + template void SendNotice(const MessageSource &source, const Anope::string &dest, const Anope::string &message, Args&&... args) + { + SendNotice(source, dest, Anope::Format(message, std::forward(args)...)); + } + + template void SendPrivmsg(const MessageSource &source, const Anope::string &dest, const Anope::string &message, Args&&... args) + { + SendPrivmsg(source, dest, Anope::Format(message, std::forward(args)...)); + } + + template void SendAction(const MessageSource &source, const Anope::string &dest, const Anope::string &message, Args&&... args) + { + SendAction(source, dest, Anope::Format(message, std::forward(args)...)); + } + + template void SendCTCPReply(const MessageSource &source, const Anope::string &dest, const Anope::string &message, Args&&... args) + { + SendCTCPReply(source, dest, Anope::Format(message, std::forward(args)...)); + } + + template void SendGlobops(const MessageSource &source, const Anope::string &msg, Args&&... args) + { + SendGlobops(source, Anope::Format(msg, std::forward(args)...)); + } + + template void SendNumeric(int numeric, User *dest, Args&&... args); + + template void SendQuit(User *u, const Anope::string &reason, Args&&... args) + { + SendQuit(u, Anope::Format(reason, std::forward(args)...)); + } + + template void SendPart(User *u, Channel *chan, const Anope::string &reason, Args&&... args) + { + SendPart(u, chan, Anope::Format(reason, std::forward(args)...)); + } }; class CoreExport MessageSource { Anope::string source; - User *u; - Server *s; + User *u = nullptr; + Server *s = nullptr; public: MessageSource(const Anope::string &); @@ -289,9 +338,9 @@ class CoreExport IRCDMessage : public Service std::set flags; public: static constexpr const char *NAME = "IRCDMessage"; - - IRCDMessage(Module *owner, const Anope::string &n, unsigned p = 0); - unsigned GetParamCount() const; + + IRCDMessage(Module *owner, const Anope::string &n, unsigned int p = 0); + unsigned int GetParamCount() const; virtual void Run(MessageSource &, const std::vector ¶ms) anope_abstract; void SetFlag(IRCDMessageFlag f) { flags.insert(f); } @@ -305,9 +354,7 @@ class IRCMessage MessageSource source; Anope::string command; std::vector parameters; - - void Push() { } - + public: template IRCMessage(const MessageSource &_source, const Anope::string &_command, Args&&... args) @@ -315,10 +362,10 @@ class IRCMessage , command(_command) { parameters.reserve(sizeof...(args)); - + Push(std::forward(args)...); } - + template void Push(const T& t, Args&&... args) { @@ -326,7 +373,9 @@ class IRCMessage Push(std::forward(args)...); } - + + void Push() { } + void TokenizeAndPush(const Anope::string &buf, char sepToken = ' ') { sepstream sep(buf, sepToken); @@ -334,7 +383,7 @@ class IRCMessage while (sep.GetToken(token)) Push(token); } - + const MessageSource &GetSource() const { return source; @@ -344,14 +393,28 @@ class IRCMessage { this->source = _source; } - + const Anope::string &GetCommand() const { return command; } - + const std::vector &GetParameters() const { return parameters; } }; + +template +void IRCDProto::SendNumeric(int numeric, User *dest, Args&&... args) +{ + Anope::string numstr = stringify(numeric); + if (numeric < 10) + numstr.insert(numstr.begin(), '0'); + if (numeric < 100) + numstr.insert(numstr.begin(), '0'); + + IRCMessage message(Me, numstr, dest->nick); + message.Push(std::forward(args)...); + SendNumeric(numeric, dest, message); +} diff --git a/include/uplink.h b/include/uplink.h index 0075b5d44..c999f4de1 100644 --- a/include/uplink.h +++ b/include/uplink.h @@ -37,7 +37,7 @@ namespace Uplink template void Send(const Anope::string &command, Args&&... args) { - IRCMessage message(MessageSource(""), command, std::forward(args)...); + IRCMessage message(Me, command, std::forward(args)...); SendMessage(message); } } diff --git a/include/version.cpp b/include/version.cpp index 7dc0b3402..b2340153b 100644 --- a/include/version.cpp +++ b/include/version.cpp @@ -85,26 +85,31 @@ static bool write_build_h(const std::string &buildh, const std::string &git_vers { std::fstream fd(buildh.c_str(), std::ios::in); - std::string build = "#define BUILD 1"; + std::string existing_version; if (fd.is_open()) { for (std::string filebuf; getline(fd, filebuf);) { - if (!filebuf.find("#define BUILD")) + if (!filebuf.find("#define VERSION_GIT")) { - size_t tab = filebuf.find(' '); + std::size_t q = filebuf.find('"'); + if (q == std::string::npos) + break; - int ibuild = atoi(filebuf.substr(tab + 1).c_str()) + 1; + std::size_t q2 = filebuf.find('"', q + 1); + if (q2 == std::string::npos) + break; - std::stringstream ss; - ss << "#define BUILD " << ibuild; - build = ss.str(); + existing_version = filebuf.substr(q + 1, q2 - q - 1); } } fd.close(); } + if (existing_version == git_version) + return true; + fd.clear(); fd.open(buildh.c_str(), std::ios::out); if (!fd.is_open()) @@ -114,7 +119,6 @@ static bool write_build_h(const std::string &buildh, const std::string &git_vers } fd << "/* This file is automatically generated by version.cpp - do not edit it! */" << std::endl; - fd << build << std::endl; if (!git_version.empty()) fd << "#define VERSION_GIT \"" << git_version << "\"" << std::endl; fd.close(); diff --git a/modules/botserv/control.cpp b/modules/botserv/control.cpp index 86b4ed829..448a28baf 100644 --- a/modules/botserv/control.cpp +++ b/modules/botserv/control.cpp @@ -71,7 +71,7 @@ class CommandBSSay : public Command return; } - IRCD->SendPrivmsg(ci->GetBot(), ci->GetName(), "%s", text.c_str()); + IRCD->SendPrivmsg(ci->GetBot(), ci->GetName(), text); ci->GetBot()->lastmsg = Anope::CurTime; bool override = !source.AccessFor(ci).HasPriv("SAY"); @@ -141,7 +141,7 @@ class CommandBSAct : public Command if (message.empty()) return; - IRCD->SendAction(ci->GetBot(), ci->GetName(), "%s", message.c_str()); + IRCD->SendAction(ci->GetBot(), ci->GetName(), message); ci->GetBot()->lastmsg = Anope::CurTime; bool override = !source.AccessFor(ci).HasPriv("SAY"); diff --git a/modules/botserv/main/botserv.cpp b/modules/botserv/main/botserv.cpp index c6e1c6413..4f3d4c92b 100644 --- a/modules/botserv/main/botserv.cpp +++ b/modules/botserv/main/botserv.cpp @@ -101,7 +101,7 @@ class BotServCore : public Module, public BotServ::BotServService { ChannelMode *cm = ModeManager::FindChannelModeByName("OP"); char symbol = cm ? anope_dynamic_static_cast(cm)->symbol : 0; - IRCD->SendNotice(bi, (symbol ? Anope::string(symbol) : "") + c->name, "%s invited %s into the channel.", user->nick.c_str(), user->nick.c_str()); + IRCD->SendNotice(bi, (symbol ? Anope::string(symbol) : "") + c->name, "{0} invited {1} into the channel.", user->nick, user->nick); } ModeManager::ProcessModes(); diff --git a/modules/chanserv/log.cpp b/modules/chanserv/log.cpp index f2d782c1c..4cbc66c7e 100644 --- a/modules/chanserv/log.cpp +++ b/modules/chanserv/log.cpp @@ -456,12 +456,12 @@ class CSLog : public Module /* Sending a channel message or notice in response to a fantasy command */; else if (log->GetMethod().equals_ci("MESSAGE") && l->ci->c) { - IRCD->SendPrivmsg(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, "%s", buffer.c_str()); + IRCD->SendPrivmsg(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, buffer); #warning "fix idletimes" //l->ci->WhoSends()->lastmsg = Anope::CurTime; } else if (log->GetMethod().equals_ci("NOTICE") && l->ci->c) - IRCD->SendNotice(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, "%s", buffer.c_str()); + IRCD->SendNotice(l->ci->WhoSends(), log->GetExtra() + l->ci->c->name, buffer); } } }; diff --git a/modules/greet.cpp b/modules/greet.cpp index 462824e19..58d37d4c4 100644 --- a/modules/greet.cpp +++ b/modules/greet.cpp @@ -194,7 +194,7 @@ class Greet : public Module Anope::string greet = user->Account()->GetGreet(); if (c->ci->IsGreet() && !greet.empty() && c->FindUser(c->ci->GetBot()) && c->ci->AccessFor(user).HasPriv("GREET")) { - IRCD->SendPrivmsg(c->ci->GetBot(), c->name, "[%s] %s", user->Account()->GetDisplay().c_str(), greet.c_str()); + IRCD->SendPrivmsg(c->ci->GetBot(), c->name, "[{0}] {1}", user->Account()->GetDisplay(), greet); c->ci->GetBot()->lastmsg = Anope::CurTime; } } diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp index 8e753b443..7ab9dd9b2 100644 --- a/modules/protocol/bahamut.cpp +++ b/modules/protocol/bahamut.cpp @@ -57,7 +57,7 @@ class BahamutIRCdProto : public IRCDProto MaxModes = 60; } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override + void SendMode(const MessageSource &source, Channel *dest, const Anope::string &buf) override { if (Servers::Capab.count("TSMODE") > 0) { @@ -67,23 +67,23 @@ class BahamutIRCdProto : public IRCDProto } else { - IRCDProto::SendModeInternal(source, dest, buf); + IRCDProto::SendMode(source, dest, buf); } } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendMode(const MessageSource &source, User *u, const Anope::string &buf) override { IRCMessage message(source, "SVSMODE", u->nick, u->timestamp); message.TokenizeAndPush(buf); Uplink::SendMessage(message); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } @@ -135,7 +135,7 @@ class BahamutIRCdProto : public IRCDProto } /* SVSNOOP */ - void SendSVSNOOP(const Server *server, bool set) override + void SendSVSNOOP(Server *server, bool set) override { Uplink::Send("SVSNOOP", server->GetName(), set ? "+" : "-"); } @@ -255,7 +255,7 @@ class BahamutIRCdProto : public IRCDProto /* Note: if the stamp is null 0, the below usage is correct of Bahamut */ - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override + void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override { Uplink::Send(source, "SVSKILL", user->nick, buf); } @@ -277,7 +277,7 @@ class BahamutIRCdProto : public IRCDProto } /* SERVER */ - void SendServer(const Server *server) override + void SendServer(Server *server) override { Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } @@ -309,7 +309,7 @@ class BahamutIRCdProto : public IRCDProto void SendLogin(User *u, NickServ::Nick *) override { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d {0}", u->signon); } void SendLogout(User *u) override diff --git a/modules/protocol/charybdis.cpp b/modules/protocol/charybdis.cpp index 5cc9f4c62..c111a31d3 100644 --- a/modules/protocol/charybdis.cpp +++ b/modules/protocol/charybdis.cpp @@ -61,10 +61,10 @@ class CharybdisProto : public IRCDProto MaxModes = 4; } - void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) override { ratbox->SendSVSKillInternal(source, targ, reason); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { ratbox->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { ratbox->SendGlobalPrivmsg(bi, dest, msg); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override { ratbox->SendGlobopsInternal(source, buf); } + void SendSVSKill(const MessageSource &source, User *targ, const Anope::string &reason) override { ratbox->SendSVSKill(source, targ, reason); } + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { ratbox->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { ratbox->SendGlobalPrivmsg(bi, dest, msg); } + void SendGlobops(const MessageSource &source, const Anope::string &buf) override { ratbox->SendGlobops(source, buf); } void SendSGLine(User *u, XLine *x) override { ratbox->SendSGLine(u, x); } void SendSGLineDel(XLine *x) override { ratbox->SendSGLineDel(x); } void SendAkill(User *u, XLine *x) override { ratbox->SendAkill(u, x); } @@ -72,7 +72,7 @@ class CharybdisProto : public IRCDProto void SendSQLine(User *u, XLine *x) override { ratbox->SendSQLine(u, x); } void SendSQLineDel(XLine *x) override { ratbox->SendSQLineDel(x); } void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { ratbox->SendJoin(user, c, status); } - void SendServer(const Server *server) override { ratbox->SendServer(server); } + void SendServer(Server *server) override { ratbox->SendServer(server); } void SendChannel(Channel *c) override { ratbox->SendChannel(c); } void SendTopic(const MessageSource &source, Channel *c) override { ratbox->SendTopic(source, c); } bool IsIdentValid(const Anope::string &ident) override { return ratbox->IsIdentValid(ident); } diff --git a/modules/protocol/hybrid.cpp b/modules/protocol/hybrid.cpp index c28c9ebf5..2af72ed4c 100644 --- a/modules/protocol/hybrid.cpp +++ b/modules/protocol/hybrid.cpp @@ -47,9 +47,9 @@ class HybridProto : public IRCDProto return NULL; } - void SendSVSKillInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendSVSKill(const MessageSource &source, User *u, const Anope::string &buf) override { - IRCDProto::SendSVSKillInternal(source, u, buf); + IRCDProto::SendSVSKill(source, u, buf); u->KillInternal(source, buf); } @@ -70,17 +70,17 @@ class HybridProto : public IRCDProto MaxModes = 6; } - void SendInvite(const MessageSource &source, const Channel *c, User *u) override + void SendInvite(const MessageSource &source, Channel *c, User *u) override { Uplink::Send(source, "INVITE", u->GetUID(), c->name, c->creation_time); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "NOTICE", "$$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "PRIVMSG", "$$" + dest->GetName(), msg); } @@ -193,7 +193,7 @@ class HybridProto : public IRCDProto Uplink::Send(Config->GetClient("OperServ"), "KLINE", timeleft, x->GetUser(), x->GetHost(), x->GetReason()); } - void SendServer(const Server *server) override + void SendServer(Server *server) override { if (server == Me) Uplink::Send("SERVER", server->GetName(), server->GetHops() + 1, server->GetDescription()); @@ -238,7 +238,7 @@ class HybridProto : public IRCDProto Uplink::Send(Me, "EOB"); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendMode(const MessageSource &source, User *u, const Anope::string &buf) override { IRCMessage message(source, "SVSMODE", u->GetUID(), u->timestamp); message.TokenizeAndPush(buf); @@ -247,7 +247,7 @@ class HybridProto : public IRCDProto void SendLogin(User *u, NickServ::Nick *na) override { - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->GetAccount()->GetDisplay().c_str()); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d {0}", na->GetAccount()->GetDisplay()); } void SendLogout(User *u) override diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp index 0f5469cea..d7bff8be0 100644 --- a/modules/protocol/inspircd20.cpp +++ b/modules/protocol/inspircd20.cpp @@ -40,9 +40,9 @@ static unsigned int spanningtree_proto_ver = 0; class InspIRCd20Proto : public IRCDProto { private: - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override + void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override { - IRCDProto::SendSVSKillInternal(source, user, buf); + IRCDProto::SendSVSKill(source, user, buf); user->KillInternal(source, buf); } @@ -96,12 +96,12 @@ class InspIRCd20Proto : public IRCDProto SendServer(Me); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } @@ -221,13 +221,12 @@ class InspIRCd20Proto : public IRCDProto SendAddLine("G", x->GetUser() + "@" + x->GetHost(), timeleft, x->GetBy(), x->GetReason()); } - void SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) override + void SendNumeric(int numeric, User *dest, IRCMessage &message) { - User *u = User::Find(dest); - Uplink::Send("PUSH", dest, ":" + Me->GetName() + " " + numeric + " " + (u ? u->nick : dest) + " " + buf); + Uplink::Send("PUSH", dest->GetUID(), Format(message)); } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override + void SendMode(const MessageSource &source, Channel *dest, const Anope::string &buf) override { IRCMessage message(source, "FMODE", dest->name, dest->creation_time); message.TokenizeAndPush(buf); @@ -243,7 +242,7 @@ class InspIRCd20Proto : public IRCDProto } /* SERVER services-dev.chatspike.net password 0 :Description here */ - void SendServer(const Server *server) override + void SendServer(Server *server) override { /* if rsquit is set then we are waiting on a squit */ if (rsquit_id.empty() && rsquit_server.empty()) @@ -370,7 +369,8 @@ class InspIRCd20Proto : public IRCDProto { Uplink::Send(Me, "BURST", Anope::CurTime); Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); - Uplink::Send(Me, "VERSION", "Anope-" + Anope::Version() + " " + Me->GetName() + " :" + IRCD->GetProtocolName() + " - (" + (enc ? enc->name : "none") + ") -- " + Anope::VersionBuildString()); + Uplink::Send(Me, "VERSION", Anope::Format("Anope-{0} {1} {2} - {3} - Built: {4} - Flags: {5}", + Anope::Version(), Me->GetName(), IRCD->GetProtocolName(), enc ? enc->name : "(none)", Anope::VersionBuildTime(), Anope::VersionFlags())); } void SendEOB() override @@ -378,7 +378,7 @@ class InspIRCd20Proto : public IRCDProto Uplink::Send(Me, "ENDBURST"); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override + void SendGlobops(const MessageSource &source, const Anope::string &buf) override { if (Servers::Capab.count("GLOBOPS")) Uplink::Send(source, "SNONOTICE", "g", buf); diff --git a/modules/protocol/ngircd.cpp b/modules/protocol/ngircd.cpp index 6ce997e2a..98509f9a1 100644 --- a/modules/protocol/ngircd.cpp +++ b/modules/protocol/ngircd.cpp @@ -26,9 +26,9 @@ class ngIRCdProto : public IRCDProto { - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override + void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override { - IRCDProto::SendSVSKillInternal(source, user, buf); + IRCDProto::SendSVSKill(source, user, buf); user->KillInternal(source, buf); } @@ -75,7 +75,7 @@ class ngIRCdProto : public IRCDProto /* 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"); + Uplink::Send("376", "*", "End of MOTD command"); } void SendForceNickChange(User *u, const Anope::string &newnick, time_t when) override @@ -83,17 +83,17 @@ class ngIRCdProto : public IRCDProto Uplink::Send(Me, "SVSNICK", u->nick, newnick); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override + void SendGlobops(const MessageSource &source, const Anope::string &buf) override { Uplink::Send(source, "WALLOPS", buf); } @@ -121,14 +121,6 @@ class ngIRCdProto : public IRCDProto } } - void SendKickInternal(const MessageSource &source, const Channel *chan, User *user, const Anope::string &buf) override - { - if (!buf.empty()) - Uplink::Send(source, "KICK", chan->name, user->nick, buf); - else - Uplink::Send(source, "KICK", chan->name, user->nick); - } - void SendLogin(User *u, NickServ::Nick *na) override { Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", na->GetAccount()->GetDisplay()); @@ -139,23 +131,8 @@ class ngIRCdProto : public IRCDProto Uplink::Send(Me, "METADATA", u->GetUID(), "accountname", ""); } - void SendModeInternal(const MessageSource &source, const Channel *dest, const Anope::string &buf) override - { - IRCMessage message(source, "MODE", dest->name); - message.TokenizeAndPush(buf); - Uplink::SendMessage(message); - } - - void SendPartInternal(User *u, const Channel *chan, const Anope::string &buf) override - { - if (!buf.empty()) - Uplink::Send(u, "PART", chan->name, buf); - else - Uplink::Send(u, "PART", chan->name); - } - /* SERVER name hop descript */ - void SendServer(const Server *server) override + void SendServer(Server *server) override { Uplink::Send("SERVER", server->GetName(), server->GetHops(), server->GetDescription()); } diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp index f3d147be8..cb1509a5e 100644 --- a/modules/protocol/plexus.cpp +++ b/modules/protocol/plexus.cpp @@ -47,21 +47,21 @@ class PlexusProto : public IRCDProto MaxModes = 4; } - void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKillInternal(source, targ, reason); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } + void SendSVSKill(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKill(source, targ, reason); } + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } void SendSQLine(User *u, XLine *x) override { hybrid->SendSQLine(u, x); } void SendSQLineDel(XLine *x) override { hybrid->SendSQLineDel(x); } void SendSGLineDel(XLine *x) override { hybrid->SendSGLineDel(x); } void SendSGLine(User *u, XLine *x) override { hybrid->SendSGLine(u, x); } void SendAkillDel(XLine *x) override { hybrid->SendAkillDel(x); } void SendAkill(User *u, XLine *x) override { hybrid->SendAkill(u, x); } - void SendServer(const Server *server) override { hybrid->SendServer(server); } + void SendServer(Server *server) override { hybrid->SendServer(server); } void SendChannel(Channel *c) override { hybrid->SendChannel(c); } void SendSVSHold(const Anope::string &nick, time_t t) override { hybrid->SendSVSHold(nick, t); } void SendSVSHoldDel(const Anope::string &nick) override { hybrid->SendSVSHoldDel(nick); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override + void SendGlobops(const MessageSource &source, const Anope::string &buf) override { Uplink::Send(source, "OPERWALL", buf); } @@ -153,7 +153,7 @@ class PlexusProto : public IRCDProto Uplink::Send(Me, "UID", u->nick, 1, u->timestamp, modes, u->GetIdent(), u->host, "255.255.255.255", u->GetUID(), 0, u->host, u->realname); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendMode(const MessageSource &source, User *u, const Anope::string &buf) override { Uplink::Send(source, "ENCAP", "*", "SVSMODE", u->GetUID(), u->timestamp, buf); } diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp index 6d4c29f03..04f1314cc 100644 --- a/modules/protocol/ratbox.cpp +++ b/modules/protocol/ratbox.cpp @@ -62,20 +62,20 @@ class RatboxProto : public IRCDProto MaxModes = 4; } - void SendSVSKillInternal(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKillInternal(source, targ, reason); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } + void SendSVSKill(const MessageSource &source, User *targ, const Anope::string &reason) override { hybrid->SendSVSKill(source, targ, reason); } + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { hybrid->SendGlobalNotice(bi, dest, msg); } + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { hybrid->SendGlobalPrivmsg(bi, dest, msg); } void SendSGLine(User *u, XLine *x) override { hybrid->SendSGLine(u, x); } void SendSGLineDel(XLine *x) override { hybrid->SendSGLineDel(x); } void SendAkill(User *u, XLine *x) override { hybrid->SendAkill(u, x); } void SendAkillDel(XLine *x) override { hybrid->SendAkillDel(x); } void SendJoin(User *user, Channel *c, const ChannelStatus *status) override { hybrid->SendJoin(user, c, status); } - void SendServer(const Server *server) override { hybrid->SendServer(server); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override { hybrid->SendModeInternal(source, u, buf); } + void SendServer(Server *server) override { hybrid->SendServer(server); } + void SendMode(const MessageSource &source, User *u, const Anope::string &buf) override { hybrid->SendMode(source, u, buf); } void SendChannel(Channel *c) override { hybrid->SendChannel(c); } bool IsIdentValid(const Anope::string &ident) override { return hybrid->IsIdentValid(ident); } - void SendGlobopsInternal(const MessageSource &source, const Anope::string &buf) override + void SendGlobops(const MessageSource &source, const Anope::string &buf) override { Uplink::Send(source, "OPERWALL", buf); } diff --git a/modules/protocol/rfc1459.cpp b/modules/protocol/rfc1459.cpp index 5d48691dc..1314f7d39 100644 --- a/modules/protocol/rfc1459.cpp +++ b/modules/protocol/rfc1459.cpp @@ -235,28 +235,28 @@ void rfc1459::Mode::Run(MessageSource &source, const std::vector } } -/* XXX We should cache the file somewhere not open/read/close it on every request */ void MOTD::Run(MessageSource &source, const std::vector ¶ms) { Server *s = Server::Find(params[0]); if (s != Me) return; + /* XXX We should cache the file somewhere not open/read/close it on every request */ FILE *f = fopen(Config->GetBlock("serverinfo")->Get("motd").c_str(), "r"); if (f) { - IRCD->SendNumeric(375, source.GetSource(), ":- %s Message of the Day", s->GetName().c_str()); + IRCD->SendNumeric(RPL_MOTDSTART, source.GetUser(), Anope::Format("- {0} Message of the Day", s->GetName())); char buf[BUFSIZE]; while (fgets(buf, sizeof(buf), f)) { buf[strlen(buf) - 1] = 0; - IRCD->SendNumeric(372, source.GetSource(), ":- %s", buf); + IRCD->SendNumeric(RPL_MOTD, source.GetUser(), Anope::Format("- {0}", buf)); } fclose(f); - IRCD->SendNumeric(376, source.GetSource(), ":End of /MOTD command."); + IRCD->SendNumeric(RPL_YOUREOPER, source.GetUser(), "End of /MOTD command."); } else - IRCD->SendNumeric(422, source.GetSource(), ":- MOTD file not found! Please contact your IRC administrator."); + IRCD->SendNumeric(ERR_NOMOTD, source.GetUser(), "- MOTD file not found! Please contact your IRC administrator."); } void Notice::Run(MessageSource &source, const std::vector ¶ms) @@ -354,12 +354,12 @@ void Privmsg::Run(MessageSource &source, const std::vector ¶m Anope::string buf = message; buf.erase(buf.begin()); buf.erase(buf.end() - 1); - IRCD->SendCTCP(bi, u->nick, "%s", buf.c_str()); + IRCD->SendCTCPReply(bi, u->nick, buf); } else if (message.substr(0, 9).equals_ci("\1VERSION\1")) { Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); - IRCD->SendCTCP(bi, u->nick, "VERSION 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->SendCTCPReply(bi, u->nick, "VERSION Anope-{0}", Anope::Version()); } return; } @@ -413,50 +413,42 @@ void rfc1459::Stats::Run(MessageSource &source, const std::vector case 'l': 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(Anope::CurTime - Anope::StartTime)); + IRCD->SendNumeric(RPL_STATSLINKINFO, u, "Server", "SendBuf", "SentBytes", "SentMsgs", "RecvBuf", "RecvBytes", "RecvMsgs", "ConnTime"); + IRCD->SendNumeric(RPL_STATSLINKINFO, u, 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]); break; case 'o': case 'O': /* Check whether the user is an operator */ - if (!u->HasMode("OPER") && Config->GetBlock("options")->Get("hidestatso")) - IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); - else + if (u->HasMode("OPER") || !Config->GetBlock("options")->Get("hidestatso")) { for (Oper *o : Serialize::GetObjects()) - IRCD->SendNumeric(243, source.GetSource(), "O * * %s %s 0", o->GetName().c_str(), o->GetType()->GetName().replace_all_cs(" ", "_").c_str()); - - IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); + IRCD->SendNumeric(RPL_STATSOLINE, u, "O", "*", "*", o->GetName(), o->GetType()->GetName().replace_all_cs(" ", "_"), "0"); } - break; case 'u': { ::Stats *s = Serialize::GetObject<::Stats *>(); long uptime = static_cast(Anope::CurTime - Anope::StartTime); - IRCD->SendNumeric(242, source.GetSource(), ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60); - IRCD->SendNumeric(250, source.GetSource(), ":Current users: %d (%d ops); maximum %d", UserListByNick.size(), OperCount, s ? s->GetMaxUserCount() : 0); - IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); + IRCD->SendNumeric(RPL_STATSUPTIME, u, Anope::Format("Services up {0} day{1}, {2}", + uptime / 86400, uptime / 86400 == 1 ? "" : "s", + Anope::printf("%02d:%02d:%02d", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60))); + IRCD->SendNumeric(RPL_STATSCONN, u, Anope::Format("Current users: {0} ({1} ops); maximum {2}", UserListByNick.size(), OperCount, s ? s->GetMaxUserCount() : 0)); break; - } /* case 'u' */ - - default: - IRCD->SendNumeric(219, source.GetSource(), "%c :End of /STATS report.", params[0][0]); + } } + + IRCD->SendNumeric(RPL_ENDOFSTATS, u, params[0][0], "End of /STATS report."); } void Time::Run(MessageSource &source, const std::vector ¶ms) { - time_t t; - time(&t); + time_t t = time(NULL); 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(RPL_TIME, source.GetUser(), Me->GetName(), buf); } void Topic::Run(MessageSource &source, const std::vector ¶ms) @@ -469,26 +461,31 @@ void Topic::Run(MessageSource &source, const std::vector ¶ms) void Version::Run(MessageSource &source, const std::vector ¶ms) { 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(RPL_VERSION, source.GetUser(), "Anope-" + Anope::Version(), Me->GetName(), + Anope::Format("{0} - {1} - Built: {2} - Flags: {3}", + IRCD->GetProtocolName(), enc ? enc->name : "(none)", Anope::VersionBuildTime(), Anope::VersionFlags())); } void Whois::Run(MessageSource &source, const std::vector ¶ms) { + User *src = source.GetUser(); User *u = User::Find(params[0]); if (u && u->server == Me) { const ServiceBot *bi = ServiceBot::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(RPL_WHOISUSER, src, 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("description").c_str()); + IRCD->SendNumeric(RPL_WHOISREGNICK, src, bi->nick, "is a registered nick"); + IRCD->SendNumeric(RPL_WHOISSERVER, src, u->nick, Me->GetName(), Config->GetBlock("serverinfo")->Get("description")); if (bi) - IRCD->SendNumeric(317, source.GetSource(), "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast(Anope::CurTime - bi->lastmsg), static_cast(bi->signon)); - IRCD->SendNumeric(318, source.GetSource(), "%s :End of /WHOIS list.", u->nick.c_str()); + IRCD->SendNumeric(RPL_WHOISIDLE, src, bi->nick, Anope::CurTime - bi->lastmsg, bi->signon, "seconds idle, signon time"); + IRCD->SendNumeric(RPL_ENDOFWHOIS, src, u->nick, "End of /WHOIS list."); } else - IRCD->SendNumeric(401, source.GetSource(), "%s :No such user.", params[0].c_str()); + { + IRCD->SendNumeric(ERR_NOSUCHNICK, src, params[0], "No such user."); + } } class ProtoRFC1459 : public Module diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp index d601b0479..259a64c9c 100644 --- a/modules/protocol/unreal.cpp +++ b/modules/protocol/unreal.cpp @@ -49,7 +49,7 @@ class UnrealIRCdProto : public IRCDProto private: /* SVSNOOP */ - void SendSVSNOOP(const Server *server, bool set) override + void SendSVSNOOP(Server *server, bool set) override { Uplink::Send("SVSNOOP", server->GetSID(), set ? "+" : "-"); } @@ -78,12 +78,12 @@ class UnrealIRCdProto : public IRCDProto Uplink::Send(source, "TOPIC", c->name, c->topic_setter, c->topic_ts, c->topic); } - void SendGlobalNotice(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalNotice(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "NOTICE", "$" + dest->GetName(), msg); } - void SendGlobalPrivmsg(ServiceBot *bi, const Server *dest, const Anope::string &msg) override + void SendGlobalPrivmsg(ServiceBot *bi, Server *dest, const Anope::string &msg) override { Uplink::Send(bi, "PRIVMSG", "$" + dest->GetName(), msg); } @@ -147,13 +147,13 @@ class UnrealIRCdProto : public IRCDProto Uplink::Send("TKL", "+", "G", x->GetUser(), x->GetHost(), x->GetBy(), Anope::CurTime + timeleft, x->GetCreated(), x->GetReason()); } - void SendSVSKillInternal(const MessageSource &source, User *user, const Anope::string &buf) override + void SendSVSKill(const MessageSource &source, User *user, const Anope::string &buf) override { Uplink::Send(source, "SVSKILL", user->GetUID(), buf); user->KillInternal(source, buf); } - void SendModeInternal(const MessageSource &source, User *u, const Anope::string &buf) override + void SendMode(const MessageSource &source, User *u, const Anope::string &buf) override { IRCMessage message(source, "SVS2MODE", u->GetUID()); message.TokenizeAndPush(buf); @@ -168,7 +168,7 @@ class UnrealIRCdProto : public IRCDProto /* SERVER name hop descript */ /* Unreal 3.2 actually sends some info about itself in the descript area */ - void SendServer(const Server *server) override + void SendServer(Server *server) override { if (!server->GetSID().empty() && server == Me) Uplink::Send("SERVER", server->GetName(), server->GetHops() + 1, server->GetDescription()); @@ -356,9 +356,9 @@ class UnrealIRCdProto : public IRCDProto { /* 3.2.10.4+ treats users logged in with accounts as fully registered, even if -r, so we can not set this here. Just use the timestamp. */ if (Servers::Capab.count("ESVID") > 0 && !na->GetAccount()->IsUnconfirmed()) - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %s", na->GetAccount()->GetDisplay().c_str()); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d {0}", na->GetAccount()->GetDisplay()); else - IRCD->SendMode(Config->GetClient("NickServ"), u, "+d %d", u->signon); + IRCD->SendMode(Config->GetClient("NickServ"), u, "+d {0}", u->signon); } void SendLogout(User *u) override @@ -582,7 +582,7 @@ class ChannelModeFlood : public ChannelModeParam try { Anope::string rest; - if (value[0] != ':' && convertTo(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo(rest.substr(1), rest, false) > 0 && rest.empty()) + if (value[0] != ':' && convertTo(value[0] == '*' ? value.substr(1) : value, rest, false) > 0 && rest[0] == ':' && rest.length() > 1 && convertTo(rest.substr(1), rest, false) > 0 && rest.empty()) return true; } catch (const ConvertException &) { } diff --git a/src/bots.cpp b/src/bots.cpp index 2ba7bda67..091caa12f 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -178,7 +178,7 @@ void ServiceBot::Part(Channel *c, const Anope::string &reason) EventManager::Get()->Dispatch(&Event::PrePartChannel::OnPrePartChannel, this, c); - IRCD->SendPart(this, c, "%s", !reason.empty() ? reason.c_str() : ""); + IRCD->SendPart(this, c, reason); c->DeleteUser(this); diff --git a/src/channels.cpp b/src/channels.cpp index 98ecfe127..53c5ae81b 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -773,7 +773,7 @@ bool Channel::Kick(User *source, User *u, const char *reason, ...) if (!this->KickInternal(source, u->nick, buf)) return false; - IRCD->SendKick(source, this, u, "%s", buf); + IRCD->SendKick(source, this, u, buf); return true; } diff --git a/src/init.cpp b/src/init.cpp index 0967baa33..8bd6683b9 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -303,13 +303,13 @@ void Anope::Init(int ac, char **av) if (GetCommandLineArgument("version", 'v')) { - Log(LOG_TERMINAL) << "Anope-" << Anope::Version() << " -- " << Anope::VersionBuildString(); + Log(LOG_TERMINAL) << "Anope-" << Anope::Version() << " -- Built: " << Anope::VersionBuildTime() << " -- Flags: " << Anope::VersionFlags(); throw CoreException(); } if (GetCommandLineArgument("help", 'h')) { - Log(LOG_TERMINAL) << "Anope-" << Anope::Version() << " -- " << Anope::VersionBuildString(); + Log(LOG_TERMINAL) << "Anope-" << Anope::Version(); Log(LOG_TERMINAL) << "Anope IRC Services (http://www.anope.org)"; Log(LOG_TERMINAL) << "Usage ./" << Anope::ServicesBin << " [options] ..."; Log(LOG_TERMINAL) << "-c, --config=filename.conf"; @@ -417,7 +417,7 @@ void Anope::Init(int ac, char **av) throw CoreException("Unable to chdir to " + Anope::ServicesDir + ": " + Anope::LastError()); } - Log(LOG_TERMINAL) << "Anope " << Anope::Version() << ", " << Anope::VersionBuildString(); + Log(LOG_TERMINAL) << "Anope-" << Anope::Version() << " -- Built: " << Anope::VersionBuildTime() << " -- Flags: " << Anope::VersionFlags(); #ifdef _WIN32 if (!SupportedWindowsVersion()) diff --git a/src/logger.cpp b/src/logger.cpp index 0d379e568..4949860a3 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -383,14 +383,14 @@ void LogInfo::ProcessMessage(const Log *l) if (!bi) bi = c->ci->WhoSends(); if (bi) - IRCD->SendPrivmsg(bi, c->name, "%s", buffer.c_str()); + IRCD->SendPrivmsg(bi, c->name, buffer); } } else if (target == "globops") { if (UplinkSock && l->bi && l->type <= LOG_NORMAL && Me && Me->IsSynced()) { - IRCD->SendGlobops(l->bi, "%s", buffer.c_str()); + IRCD->SendGlobops(l->bi, buffer); } } } diff --git a/src/misc.cpp b/src/misc.cpp index 3b044d9fa..863bca2b7 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -579,40 +579,44 @@ const Anope::string Anope::LastError() Anope::string Anope::Version() { #ifdef VERSION_GIT - return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH) + VERSION_EXTRA + " (" + VERSION_GIT + ")"; + return Anope::Format("{0}.{1}.{2}{3}-{4}", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_EXTRA, VERSION_GIT); #else - return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH) + VERSION_EXTRA; + return Anope::Format("{0}.{1}.{2}{3}", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH, VERSION_EXTRA); #endif } Anope::string Anope::VersionShort() { - return stringify(VERSION_MAJOR) + "." + stringify(VERSION_MINOR) + "." + stringify(VERSION_PATCH); + return Anope::Format("{0}.{1}.{2}", VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH); } -Anope::string Anope::VersionBuildString() +Anope::string Anope::VersionBuildTime() { #ifdef REPRODUCIBLE_BUILD - Anope::string s = "build #" + stringify(BUILD); + return "unknown"; #else - Anope::string s = "build #" + stringify(BUILD) + ", compiled " + Anope::compiled; + return Anope::COMPILED; #endif +} + +Anope::string Anope::VersionFlags() +{ Anope::string flags; #ifdef DEBUG_BUILD - flags += "D"; + flags.append('D'); #endif #ifdef VERSION_GIT - flags += "G"; + flags.append('G'); #endif #ifdef _WIN32 - flags += "W"; + flags.append('W'); #endif - if (!flags.empty()) - s += ", flags " + flags; + if (flags.empty()) + flags = "none"; - return s; + return flags; } int Anope::VersionMajor() { return VERSION_MAJOR; } diff --git a/src/modes.cpp b/src/modes.cpp index b41bece1d..348ec4542 100644 --- a/src/modes.cpp +++ b/src/modes.cpp @@ -629,7 +629,7 @@ void ModeManager::ProcessModes() std::list ModeStrings = BuildModeStrings(s); for (std::list::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(s->bi, u, lit->c_str()); + IRCD->SendMode(s->bi, u, *lit); delete it->second; } UserStackerObjects.clear(); @@ -644,7 +644,7 @@ void ModeManager::ProcessModes() std::list ModeStrings = BuildModeStrings(s); for (std::list::iterator lit = ModeStrings.begin(), lit_end = ModeStrings.end(); lit != lit_end; ++lit) - IRCD->SendMode(s->bi, c, lit->c_str()); + IRCD->SendMode(s->bi, c, *lit); delete it->second; } ChannelStackerObjects.clear(); @@ -660,7 +660,7 @@ static void StackerDel(std::map &map, T *obj)