diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.cpp | 54 | ||||
| -rw-r--r-- | src/protocol.cpp | 50 | ||||
| -rw-r--r-- | src/send.cpp | 93 | ||||
| -rw-r--r-- | src/servers.cpp | 13 |
4 files changed, 92 insertions, 118 deletions
diff --git a/src/main.cpp b/src/main.cpp index 03920424a..ed31febf8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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()) diff --git a/src/protocol.cpp b/src/protocol.cpp index 2bbad4adb..d855e41d8 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -30,47 +30,49 @@ void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest void IRCDProto::SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :%s", dest.c_str(), msg.c_str()); + UplinkSocket::Message(bi->nick) << "NOTICE " << dest << " :" << msg; } void IRCDProto::SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s :%s", dest.c_str(), buf.c_str()); + UplinkSocket::Message(bi->nick) << "PRIVMSG " << dest << " :" << buf; } void IRCDProto::SendQuitInternal(const User *u, const Anope::string &buf) { if (!buf.empty()) - send_cmd(ircd->ts6 ? u->GetUID() : u->nick, "QUIT :%s", buf.c_str()); + UplinkSocket::Message(u->nick) << "QUIT :" << buf; else - send_cmd(ircd->ts6 ? u->GetUID() : u->nick, "QUIT"); + UplinkSocket::Message(u->nick) << "QUIT"; } void IRCDProto::SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf) { if (!buf.empty()) - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s :%s", chan->name.c_str(), buf.c_str()); + UplinkSocket::Message(bi->nick) << "PART " << chan->name << " :" << buf; else - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PART %s", chan->name.c_str()); + UplinkSocket::Message(bi->nick) << "PART " << chan->name; } void IRCDProto::SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) { - if (source) - send_cmd(ircd->ts6 ? source->GetUID() : source->nick, "GLOBOPS :%s", buf.c_str()); - else - send_cmd(Config->ServerName, "GLOBOPS :%s", buf.c_str()); + UplinkSocket::Message(source ? source->nick : Config->ServerName) << "GLOBOPS :" << buf; } void IRCDProto::SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { Anope::string s = normalizeBuffer(buf); - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s :\1%s\1", dest.c_str(), s.c_str()); + this->SendNoticeInternal(bi, dest, "\1" + s + "\1"); } void IRCDProto::SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) { - send_cmd(source, "%03d %s %s", numeric, dest.c_str(), buf.c_str()); + Anope::string n = stringify(numeric); + if (numeric < 10) + n = "0" + n; + if (numeric < 100) + n = "0" + n; + UplinkSocket::Message(source) << n << " " << dest << " " << buf; } void IRCDProto::SendSVSKill(const BotInfo *source, const User *user, const char *fmt, ...) @@ -162,12 +164,12 @@ void IRCDProto::SendPrivmsg(const BotInfo *bi, const Anope::string &dest, const void IRCDProto::SendGlobalNotice(const BotInfo *bi, const Server *dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NOTICE %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str()); + UplinkSocket::Message(bi->nick) << "NOTICE " << ircd->globaltldprefix << dest->GetName() << " :" << msg; } void IRCDProto::SendGlobalPrivmsg(const BotInfo *bi, const Server *dest, const Anope::string &msg) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "PRIVMSG %s%s :%s", ircd->globaltldprefix, dest->GetName().c_str(), msg.c_str()); + UplinkSocket::Message(bi->nick) << "PRIVMSG " << ircd->globaltldprefix << dest->GetName() << " :" << msg; } void IRCDProto::SendQuit(const User *u, const char *fmt, ...) @@ -183,9 +185,9 @@ void IRCDProto::SendQuit(const User *u, const char *fmt, ...) void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who) { if (servname.empty()) - send_cmd(ircd->ts6 ? Config->Numeric : Config->ServerName, "PING %s", who.c_str()); + UplinkSocket::Message(Config->ServerName) << "PING " << who; else - send_cmd(ircd->ts6 ? Config->Numeric : Config->ServerName, "PING %s %s", servname.c_str(), who.c_str()); + UplinkSocket::Message(Config->ServerName) << "PING " << servname << " " << who; } /** @@ -197,14 +199,14 @@ void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who void IRCDProto::SendPong(const Anope::string &servname, const Anope::string &who) { if (servname.empty()) - send_cmd(ircd->ts6 ? Config->Numeric : Config->ServerName, "PONG %s", who.c_str()); + UplinkSocket::Message(Config->ServerName) << "PONG " << who; else - send_cmd(ircd->ts6 ? Config->Numeric : Config->ServerName, "PONG %s %s", servname.c_str(), who.c_str()); + UplinkSocket::Message(Config->ServerName) << "PONG " << servname << " " << who; } void IRCDProto::SendInvite(const BotInfo *bi, const Anope::string &chan, const Anope::string &nick) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "INVITE %s %s", nick.c_str(), chan.c_str()); + UplinkSocket::Message(bi->nick) << "INVITE " << nick << " " << chan; } void IRCDProto::SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...) @@ -232,19 +234,19 @@ void IRCDProto::SendGlobops(const BotInfo *source, const char *fmt, ...) SendGlobopsInternal(source, buf); } -void IRCDProto::SendSquit(const Anope::string &servname, const Anope::string &message) +void IRCDProto::SendSquit(Server *s, const Anope::string &message) { - send_cmd("", "SQUIT %s :%s", servname.c_str(), message.c_str()); + UplinkSocket::Message() << "SQUIT " << s->GetName() << " :" << message; } void IRCDProto::SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick) { - send_cmd(ircd->ts6 ? bi->GetUID() : bi->nick, "NICK %s %ld", newnick.c_str(), static_cast<long>(Anope::CurTime)); + UplinkSocket::Message(bi->nick) << "NICK " << newnick << " " << Anope::CurTime; } void IRCDProto::SendForceNickChange(const User *u, const Anope::string &newnick, time_t when) { - send_cmd("", "SVSNICK %s %s :%ld", u->nick.c_str(), newnick.c_str(), static_cast<long>(when)); + UplinkSocket::Message() << "SVSNICK " << u->nick << " " << newnick << " " << when; } void IRCDProto::SendCTCP(const BotInfo *bi, const Anope::string &dest, const char *fmt, ...) @@ -480,7 +482,7 @@ bool IRCdMessage::OnSQuit(const Anope::string &source, const std::vector<Anope:: { Log(LOG_DEBUG) << "Sending UNCONNECT SQUIT for " << s->GetName(); /* need to fix */ - ircdproto->SendSquit(s->GetName(), buf); + ircdproto->SendSquit(s, buf); } s->Delete(buf); diff --git a/src/send.cpp b/src/send.cpp deleted file mode 100644 index 28c1ca08c..000000000 --- a/src/send.cpp +++ /dev/null @@ -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); - } -} - diff --git a/src/servers.cpp b/src/servers.cpp index 582fb6908..51a7608e1 100644 --- a/src/servers.cpp +++ b/src/servers.cpp @@ -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 |
