1
0
mirror of https://github.com/anope/anope.git synced 2026-06-28 16:25:44 +02:00

Remove send_cmd and replace it with a stringstream

This commit is contained in:
Adam
2011-11-25 00:44:31 -05:00
parent 12d0a7302f
commit cef3eb78df
17 changed files with 417 additions and 581 deletions
+15 -6
View File
@@ -117,6 +117,21 @@ class UplinkSocket : public ConnectionSocket, public BufferedSocket
bool Read(const Anope::string &);
void OnConnect();
void OnError(const Anope::string &);
class CoreExport Message
{
Anope::string source;
std::stringstream buffer;
public:
Message();
Message(const Anope::string &);
~Message();
template<typename T> Message &operator<<(const T &val)
{
this->buffer << val;
return *this;
}
};
};
E UplinkSocket *UplinkSock;
E int CurrentUplink;
@@ -200,12 +215,6 @@ E bool is_on_access(const User *u, const NickCore *nc);
E void process(const Anope::string &buf);
/**** send.c ****/
E void send_cmd(const Anope::string &source, const char *fmt, ...) FORMAT(printf, 2, 3);
E void notice_server(const Anope::string &source, const Server *s, const char *fmt, ...) FORMAT(printf, 3, 4);
/**** sockets.cpp ****/
E int32_t TotalRead;
+6
View File
@@ -152,6 +152,12 @@ class CoreExport Server : public Flags<ServerFlag>
*/
bool IsULined() const;
/** Send a message to alll users on this server
* @param source The source of the message
* @param message The message
*/
void Notice(BotInfo *source, const Anope::string &message);
/** Find a server
* @param name The name or SID/numeric
* @param s The server list to search for this server on, defaults to our Uplink
+1 -1
View File
@@ -792,7 +792,7 @@ class CoreExport IRCDProto
virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...);
virtual void SendGlobops(const BotInfo *source, const char *fmt, ...);
virtual void SendSQLine(User *, const XLine *x) { }
virtual void SendSquit(const Anope::string &servname, const Anope::string &message);
virtual void SendSquit(Server *, const Anope::string &message);
virtual void SendSVSO(const Anope::string &, const Anope::string &, const Anope::string &) { }
virtual void SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick);
virtual void SendForceNickChange(const User *u, const Anope::string &newnick, time_t when);
+1 -1
View File
@@ -37,7 +37,7 @@ class CommandOSJupe : public Command
{
Anope::string rbuf = "Juped by " + u->nick + (!reason.empty() ? ": " + reason : "");
if (server)
ircdproto->SendSquit(jserver, rbuf);
ircdproto->SendSquit(server, rbuf);
Server *juped_server = new Server(Me, jserver, 1, rbuf, ircd->ts6 ? ts6_sid_retrieve() : "", SERVER_JUPED);
ircdproto->SendServer(juped_server);
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+3 -46
View File
@@ -54,28 +54,6 @@ static bool has_servicesmod = false;
static bool has_svsholdmod = false;
static bool has_hidechansmod = false;
/* CHGHOST */
void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
if (!has_chghostmod)
{
Log() << "CHGHOST not loaded!";
return;
}
User *u = finduser(nick);
send_cmd(u ? u->GetUID() : Config->Numeric, "CHGHOST %s %s", nick.c_str(), vhost.c_str());
}
bool event_idle(const Anope::string &source, const std::vector<Anope::string> &params)
{
BotInfo *bi = findbot(params[0]);
send_cmd(bi ? bi->GetUID() : params[0], "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), bi ? (static_cast<long>(Anope::CurTime - bi->lastmsg)) : 0);
return true;
}
bool event_ftopic(const Anope::string &source, const std::vector<Anope::string> &params)
{
/* :source FTOPIC channel ts setby :topic */
@@ -144,27 +122,6 @@ bool event_fmode(const Anope::string &source, const std::vector<Anope::string> &
return ircdmessage->OnMode(source, newparams);
}
bool event_time(const Anope::string &source, const std::vector<Anope::string> &params)
{
if (params.size() < 2)
return true;
send_cmd(Config->Numeric, "TIME %s %s %ld", source.c_str(), params[1].c_str(), static_cast<long>(Anope::CurTime));
return true;
}
bool event_rsquit(const Anope::string &source, const std::vector<Anope::string> &params)
{
/* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */
Server *s = Server::Find(params[0]);
if (s && s->HasFlag(SERVER_JUPED))
send_cmd(Config->Numeric, "SQUIT %s :%s", s->GetSID().c_str(), params.size() > 1 ? params[1].c_str() : "");
ircdmessage->OnSQuit(source, params);
return true;
}
bool event_setname(const Anope::string &source, const std::vector<Anope::string> &params)
{
User *u = finduser(source);
@@ -693,21 +650,21 @@ class Inspircd12IRCdMessage : public InspircdIRCdMessage
{
if (!has_globopsmod)
{
send_cmd("", "ERROR :m_globops is not loaded. This is required by Anope");
UplinkSocket::Message() << "ERROR :m_globops is not loaded. This is required by Anope";
quitmsg = "Remote server does not have the m_globops module loaded, and this is required.";
quitting = true;
return false;
}
if (!has_servicesmod)
{
send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope");
UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope";
quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required.";
quitting = true;
return false;
}
if (!has_hidechansmod)
{
send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope");
UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope";
quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required.";
quitting = true;
return false;
+8 -50
View File
@@ -53,38 +53,17 @@ IRCDVar myIrcd[] = {
static bool has_servicesmod = false;
static bool has_svsholdmod = false;
/* CHGHOST */
void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
if (!has_chghostmod)
{
Log() << "CHGHOST not loaded!";
return;
}
User *u = finduser(nick);
send_cmd(u ? u->GetUID() : Config->Numeric, "CHGHOST %s %s", nick.c_str(), vhost.c_str());
}
bool event_idle(const Anope::string &source, const std::vector<Anope::string> &params)
{
BotInfo *bi = findbot(params[0]);
send_cmd(bi ? bi->GetUID() : params[0], "IDLE %s %ld %ld", source.c_str(), static_cast<long>(start_time), bi ? (static_cast<long>(Anope::CurTime - bi->lastmsg)) : 0);
return true;
}
class InspIRCdProto : public InspIRCdTS6Proto
{
void SendConnect()
{
send_cmd("", "CAPAB START 1202");
send_cmd("", "CAPAB CAPABILITIES :PROTOCOL=1202");
send_cmd("", "CAPAB END");
UplinkSocket::Message() << "CAPAB START 1202";
UplinkSocket::Message() << "CAPAB CAPABILITIES :PROTOCOL=1202";
UplinkSocket::Message() << "CAPAB END";
SendServer(Me);
send_cmd(Config->Numeric, "BURST");
UplinkSocket::Message(Config->Numeric) << "BURST";
Module *enc = ModuleManager::FindFirstOf(ENCRYPTION);
send_cmd(Config->Numeric, "VERSION :Anope-%s %s :%s - (%s) -- %s", Anope::Version().c_str(), Config->ServerName.c_str(), ircd->name, enc ? enc->name.c_str() : "unknown", Anope::VersionBuildString().c_str());
UplinkSocket::Message(Config->Numeric) << "VERSION :Anope-" << Anope::Version() << " " << Me->GetName() << " :" << ircd->name <<" - (" << (enc ? enc->name : "unknown") << ") -- " << Anope::VersionBuildString();
}
};
@@ -155,27 +134,6 @@ bool event_fmode(const Anope::string &source, const std::vector<Anope::string> &
return ircdmessage->OnMode(source, newparams);
}
bool event_time(const Anope::string &source, const std::vector<Anope::string> &params)
{
if (params.size() < 2)
return true;
send_cmd(Config->Numeric, "TIME %s %s %ld", source.c_str(), params[1].c_str(), static_cast<long>(Anope::CurTime));
return true;
}
bool event_rsquit(const Anope::string &source, const std::vector<Anope::string> &params)
{
/* On InspIRCd we must send a SQUIT when we recieve RSQUIT for a server we have juped */
Server *s = Server::Find(params[0]);
if (s && s->HasFlag(SERVER_JUPED))
send_cmd(Config->Numeric, "SQUIT %s :%s", s->GetSID().c_str(), params.size() > 1 ? params[1].c_str() : "");
ircdmessage->OnSQuit(source, params);
return true;
}
bool event_setname(const Anope::string &source, const std::vector<Anope::string> &params)
{
User *u = finduser(source);
@@ -429,7 +387,7 @@ class Inspircd20IRCdMessage : public InspircdIRCdMessage
{
if (params.size() < 2 || (Anope::string(params[1]).is_pos_number_only() ? convertTo<unsigned>(params[1]) : 0) < 1202)
{
send_cmd("", "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START");
UplinkSocket::Message() << "ERROR :Protocol mismatch, no or invalid protocol version given in CAPAB START";
quitmsg = "Protocol mismatch, no or invalid protocol version given in CAPAB START";
quitting = true;
return false;
@@ -713,14 +671,14 @@ class Inspircd20IRCdMessage : public InspircdIRCdMessage
{
if (!has_servicesmod)
{
send_cmd("", "ERROR :m_services_account.so is not loaded. This is required by Anope");
UplinkSocket::Message() << "ERROR :m_services_account.so is not loaded. This is required by Anope";
quitmsg = "ERROR: Remote server does not have the m_services_account module loaded, and this is required.";
quitting = true;
return false;
}
if (!ModeManager::FindUserModeByName(UMODE_PRIV))
{
send_cmd("", "ERROR :m_hidechans.so is not loaded. This is required by Anope");
UplinkSocket::Message() << "ERROR :m_hidechans.so is not loaded. This is required by Anope";
quitmsg = "ERROR: Remote server does not have the m_hidechans module loaded, and this is required.";
quitting = true;
return false;
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -19,7 +19,7 @@ class MyGlobalService : public GlobalService
void ServerGlobal(Server *s, const Anope::string &message)
{
if (s != Me && !s->HasFlag(SERVER_JUPED))
notice_server(Config->Global, s, "%s", message.c_str());
s->Notice(findbot(Config->Global), message);
for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
this->ServerGlobal(s->GetLinks()[i], message);
}
@@ -76,7 +76,7 @@ class GlobalCore : public Module
void OnNewServer(Server *s)
{
if (Config->GlobalOnCycle && !Config->GlobalOnCycleUP.empty())
notice_server(Config->Global, s, "%s", Config->GlobalOnCycleUP.c_str());
s->Notice(findbot(Config->Global), Config->GlobalOnCycleUP);
}
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params)
+53 -1
View File
@@ -125,7 +125,7 @@ UplinkSocket::~UplinkSocket()
}
}
ircdproto->SendSquit(Config->ServerName, quitmsg);
ircdproto->SendSquit(Me, quitmsg);
this->ProcessWrite(); // Write out the last bit
}
@@ -172,6 +172,58 @@ void UplinkSocket::OnError(const Anope::string &error)
Log(LOG_TERMINAL) << "Unable to connect to server " << Config->Uplinks[CurrentUplink]->host << ":" << Config->Uplinks[CurrentUplink]->port << (!error.empty() ? (": " + error) : "");
}
UplinkSocket::Message::Message()
{
}
UplinkSocket::Message::Message(const Anope::string &s) : source(s)
{
}
UplinkSocket::Message::~Message()
{
if (!UplinkSock)
{
if (!this->source.empty())
Log(LOG_DEBUG) << "Attempted to send \"" << this->source << " " << this->buffer.str() << "\" with UplinkSock NULL";
else
Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" with UplinkSock NULL";
return;
}
if (this->source == Me->GetName())
{
if (ircd->ts6)
this->source = Me->GetSID();
}
else if (!this->source.empty() && this->source != Me->GetSID())
{
BotInfo *bi = findbot(this->source);
if (bi != NULL)
{
if (bi->introduced == false)
{
Log(LOG_DEBUG) << "Attempted to send \"" << this->source << " " << this->buffer.str() << "\" with source not introduced";
return;
}
if (ircd->ts6)
this->source = bi->GetUID();
}
}
if (!this->source.empty())
{
UplinkSock->Write(":" + this->source + " " + this->buffer.str());
Log(LOG_RAWIO) << "Sent: :" << this->source << " " << this->buffer.str();
}
else
{
UplinkSock->Write(this->buffer.str());
Log(LOG_RAWIO) << "Sent: " << this->buffer.str();
}
}
static void Connect()
{
if (static_cast<unsigned>(++CurrentUplink) >= Config->Uplinks.size())
+26 -24
View File
File diff suppressed because it is too large Load Diff
-93
View File
@@ -1,93 +0,0 @@
/* Routines for sending stuff to the network.
*
* (C) 2003-2011 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
*/
#include "services.h"
/*************************************************************************/
/**
* Send a command to the server. The two forms here are like
* printf()/vprintf() and friends.
* @param source Orgin of the Message (some times NULL)
* @param fmt Format of the Message
* @param ... any number of parameters
* @return void
*/
void send_cmd(const Anope::string &source, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
if (!UplinkSock)
{
if (!source.empty())
Log(LOG_DEBUG) << "Attempted to send \"" << source << " " << buf << "\" with UplinkSock NULL";
else
Log(LOG_DEBUG) << "Attempted to send \"" << buf << "\" with UplinkSock NULL";
return;
}
if (!source.empty() && source.find(".") == Anope::string::npos)
{
BotInfo *bi = findbot(source);
if (bi != NULL && bi->introduced == false)
{
Log(LOG_DEBUG) << "Attempted to send \"" << source << " " << buf << "\" with source not introduced";
return;
}
}
if (!source.empty())
{
UplinkSock->Write(":%s %s", source.c_str(), buf);
Log(LOG_RAWIO) << "Sent: :" << source << " " << buf;
}
else
{
UplinkSock->Write(buf);
Log(LOG_RAWIO) << "Sent: " << buf;
}
va_end(args);
}
/*************************************************************************/
/**
* Send a server notice
* @param source Orgin of the Message
* @param s Server Struct
* @param fmt Format of the Message
* @param ... any number of parameters
* @return void
*/
void notice_server(const Anope::string &source, const Server *s, const char *fmt, ...)
{
if (fmt)
{
va_list args;
char buf[BUFSIZE] = "";
va_start(args, fmt);
vsnprintf(buf, BUFSIZE - 1, fmt, args);
if (Config->NSDefFlags.HasFlag(NI_MSG))
ircdproto->SendGlobalPrivmsg(findbot(source), s, buf);
else
ircdproto->SendGlobalNotice(findbot(source), s, buf);
va_end(args);
}
}
+13
View File
@@ -352,6 +352,19 @@ bool Server::IsULined() const
return false;
}
/** Send a message to alll users on this server
* @param source The source of the message
* @param message The message
*/
void Server::Notice(BotInfo *source, const Anope::string &message)
{
if (Config->NSDefFlags.HasFlag(NI_MSG))
ircdproto->SendGlobalPrivmsg(source, this, message);
else
ircdproto->SendGlobalNotice(source, this, message);
}
/** Find a server
* @param name The name or SID/numeric
* @param s The server list to search for this server on, defaults to our Uplink