diff options
author | Adam <Adam@anope.org> | 2012-02-19 20:54:55 -0500 |
---|---|---|
committer | Adam <Adam@anope.org> | 2012-02-19 20:54:55 -0500 |
commit | b84e0804636d3868684c6ec2670207e7ae1cadeb (patch) | |
tree | 059be9a9da7b530970bc44f2c8eee5f61497a82e /src | |
parent | 0ba58d7d0eea4e2a0e0d18a66880f84af6fea60e (diff) |
Made our message sources actual clients/servers, and put in a few more default messages for very standard things (KICK etc)
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 71 | ||||
-rw-r--r-- | src/messages.cpp | 32 | ||||
-rw-r--r-- | src/protocol.cpp | 78 |
3 files changed, 114 insertions, 67 deletions
diff --git a/src/main.cpp b/src/main.cpp index 55f185057..1d0a3e963 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,50 +178,71 @@ 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() : server(NULL), user(NULL) { } -UplinkSocket::Message::Message(const Anope::string &s) : source(s) +UplinkSocket::Message::Message(const Server *s) : server(s), user(NULL) { } +UplinkSocket::Message::Message(const User *u) : server(NULL), user(u) +{ + if (!u) + server = Me; +} + 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; - } + Anope::string message_source = ""; - if (this->source == Me->GetName()) + if (this->server != NULL) { + if (this->server != Me && !this->server->HasFlag(SERVER_JUPED)) + { + Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->server->GetName() << " who is not from me?"; + return; + } + if (ircd->ts6) - this->source = Me->GetSID(); + message_source = this->server->GetSID(); + else + message_source = this->server->GetName(); } - else if (!this->source.empty() && this->source != Me->GetSID()) + else if (this->user != NULL) { - BotInfo *bi = findbot(this->source); - if (bi != NULL) + if (this->user->server != Me && !this->user->server->HasFlag(SERVER_JUPED)) { - if (bi->introduced == false) - { - Log(LOG_DEBUG) << "Attempted to send \"" << this->source << " " << this->buffer.str() << "\" with source not introduced"; - return; - } + Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << this->user->nick << " who is not from me?"; + return; + } - if (ircd->ts6) - this->source = bi->GetUID(); + BotInfo *bi = findbot(this->user->nick); + if (bi != NULL && bi->introduced == false) + { + Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced"; + return; } + + if (ircd->ts6) + message_source = this->user->GetUID(); + else + message_source = this->user->nick; + } + + if (!UplinkSock) + { + if (!message_source.empty()) + Log(LOG_DEBUG) << "Attempted to send \"" << message_source << " " << this->buffer.str() << "\" with UplinkSock NULL"; + else + Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" with UplinkSock NULL"; + return; } - if (!this->source.empty()) + if (!message_source.empty()) { - UplinkSock->Write(":" + this->source + " " + this->buffer.str()); - Log(LOG_RAWIO) << "Sent: :" << this->source << " " << this->buffer.str(); + UplinkSock->Write(":" + message_source + " " + this->buffer.str()); + Log(LOG_RAWIO) << "Sent: :" << message_source << " " << this->buffer.str(); } else { diff --git a/src/messages.cpp b/src/messages.cpp index fa93e528c..52e7c57c1 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -30,17 +30,17 @@ bool OnStats(const Anope::string &source, const std::vector<Anope::string> ¶ case 'l': if (u && u->HasMode(UMODE_OPER)) { - ircdproto->SendNumeric(Config->ServerName, 211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime"); - ircdproto->SendNumeric(Config->ServerName, 211, source, "%s %d %d %d %d %d %d %ld", Config->Uplinks[CurrentUplink]->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - start_time)); + ircdproto->SendNumeric(211, source, "Server SendBuf SentBytes SentMsgs RecvBuf RecvBytes RecvMsgs ConnTime"); + ircdproto->SendNumeric(211, source, "%s %d %d %d %d %d %d %ld", Config->Uplinks[CurrentUplink]->host.c_str(), UplinkSock->WriteBufferLen(), TotalWritten, -1, UplinkSock->ReadBufferLen(), TotalRead, -1, static_cast<long>(Anope::CurTime - start_time)); } - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); + ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]); break; case 'o': case 'O': /* Check whether the user is an operator */ if (u && !u->HasMode(UMODE_OPER) && Config->HideStatsO) - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); + ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]); else { for (unsigned i = 0; i < Config->Opers.size(); ++i) @@ -49,10 +49,10 @@ bool OnStats(const Anope::string &source, const std::vector<Anope::string> ¶ NickAlias *na = findnick(o->name); if (na) - ircdproto->SendNumeric(Config->ServerName, 243, source, "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); + ircdproto->SendNumeric(243, source, "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str()); } - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); + ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]); } break; @@ -60,14 +60,14 @@ bool OnStats(const Anope::string &source, const std::vector<Anope::string> ¶ case 'u': { time_t uptime = Anope::CurTime - start_time; - ircdproto->SendNumeric(Config->ServerName, 242, source, ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60); - ircdproto->SendNumeric(Config->ServerName, 250, source, ":Current users: %d (%d ops); maximum %d", usercnt, opcnt, maxusercnt); - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); + ircdproto->SendNumeric(242, source, ":Services up %d day%s, %02d:%02d:%02d", uptime / 86400, uptime / 86400 == 1 ? "" : "s", (uptime / 3600) % 24, (uptime / 60) % 60, uptime % 60); + ircdproto->SendNumeric(250, source, ":Current users: %d (%d ops); maximum %d", usercnt, opcnt, maxusercnt); + ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]); break; } /* case 'u' */ default: - ircdproto->SendNumeric(Config->ServerName, 219, source, "%c :End of /STATS report.", params[0][0]); + ircdproto->SendNumeric(219, source, "%c :End of /STATS report.", params[0][0]); } return true; @@ -83,14 +83,14 @@ bool OnTime(const Anope::string &source, const std::vector<Anope::string> &) struct tm *tm = localtime(&t); char buf[64]; strftime(buf, sizeof(buf), "%a %b %d %H:%M:%S %Y %Z", tm); - ircdproto->SendNumeric(Config->ServerName, 391, source, "%s :%s", Config->ServerName.c_str(), buf); + ircdproto->SendNumeric(391, source, "%s :%s", Config->ServerName.c_str(), buf); return true; } bool OnVersion(const Anope::string &source, const std::vector<Anope::string> &) { Module *enc = ModuleManager::FindFirstOf(ENCRYPTION); - ircdproto->SendNumeric(Config->ServerName, 351, source, "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()); + ircdproto->SendNumeric(351, source, "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()); return true; } @@ -103,18 +103,18 @@ bool OnMotd(const Anope::string &source, const std::vector<Anope::string> &) FILE *f = fopen(Config->MOTDFilename.c_str(), "r"); if (f) { - ircdproto->SendNumeric(Config->ServerName, 375, source, ":- %s Message of the Day", Config->ServerName.c_str()); + ircdproto->SendNumeric(375, source, ":- %s Message of the Day", Config->ServerName.c_str()); char buf[BUFSIZE]; while (fgets(buf, sizeof(buf), f)) { buf[strlen(buf) - 1] = 0; - ircdproto->SendNumeric(Config->ServerName, 372, source, ":- %s", buf); + ircdproto->SendNumeric(372, source, ":- %s", buf); } fclose(f); - ircdproto->SendNumeric(Config->ServerName, 376, source, ":End of /MOTD command."); + ircdproto->SendNumeric(376, source, ":End of /MOTD command."); } else - ircdproto->SendNumeric(Config->ServerName, 422, source, ":- MOTD file not found! Please contact your IRC administrator."); + ircdproto->SendNumeric(422, source, ":- MOTD file not found! Please contact your IRC administrator."); return true; } diff --git a/src/protocol.cpp b/src/protocol.cpp index 051f6f2d1..f51880bbe 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -39,6 +39,24 @@ void pmodule_ircd_message(IRCdMessage *message) ircdmessage = message; } +void IRCDProto::SendSVSKillInternal(const BotInfo *source, const User *user, const Anope::string &buf) +{ + UplinkSocket::Message(source) << "KILL " << (ircd->ts6 ? user->GetUID() : user->nick) << " :" << buf; +} + +void IRCDProto::SendModeInternal(const BotInfo *bi, const Channel *dest, const Anope::string &buf) +{ + UplinkSocket::Message(bi) << "MODE " << dest->name << " " << buf; +} + +void IRCDProto::SendKickInternal(const BotInfo *bi, const Channel *c, const User *u, const Anope::string &r) +{ + if (!r.empty()) + UplinkSocket::Message(bi) << "KICK " << c->name << " " << (ircd->ts6 ? u->GetUID() : u->nick) << " :" << r; + else + UplinkSocket::Message(bi) << "KICK " << c->name << " " << (ircd->ts6 ? u->GetUID() : u->nick); +} + void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { if (Config->NSDefFlags.HasFlag(NI_MSG)) @@ -49,33 +67,36 @@ void IRCDProto::SendMessageInternal(const BotInfo *bi, const Anope::string &dest void IRCDProto::SendNoticeInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &msg) { - UplinkSocket::Message(bi->nick) << "NOTICE " << dest << " :" << msg; + UplinkSocket::Message(bi) << "NOTICE " << dest << " :" << msg; } void IRCDProto::SendPrivmsgInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf) { - UplinkSocket::Message(bi->nick) << "PRIVMSG " << dest << " :" << buf; + UplinkSocket::Message(bi) << "PRIVMSG " << dest << " :" << buf; } void IRCDProto::SendQuitInternal(const User *u, const Anope::string &buf) { if (!buf.empty()) - UplinkSocket::Message(u->nick) << "QUIT :" << buf; + UplinkSocket::Message(u) << "QUIT :" << buf; else - UplinkSocket::Message(u->nick) << "QUIT"; + UplinkSocket::Message(u) << "QUIT"; } void IRCDProto::SendPartInternal(const BotInfo *bi, const Channel *chan, const Anope::string &buf) { if (!buf.empty()) - UplinkSocket::Message(bi->nick) << "PART " << chan->name << " :" << buf; + UplinkSocket::Message(bi) << "PART " << chan->name << " :" << buf; else - UplinkSocket::Message(bi->nick) << "PART " << chan->name; + UplinkSocket::Message(bi) << "PART " << chan->name; } void IRCDProto::SendGlobopsInternal(const BotInfo *source, const Anope::string &buf) { - UplinkSocket::Message(source ? source->nick : Config->ServerName) << "GLOBOPS :" << buf; + if (source) + UplinkSocket::Message(source) << "GLOBOPS :" << buf; + else + UplinkSocket::Message(Me) << "GLOBOPS :" << buf; } void IRCDProto::SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, const Anope::string &buf) @@ -84,14 +105,19 @@ void IRCDProto::SendCTCPInternal(const BotInfo *bi, const Anope::string &dest, c this->SendNoticeInternal(bi, dest, "\1" + s + "\1"); } -void IRCDProto::SendNumericInternal(const Anope::string &source, int numeric, const Anope::string &dest, const Anope::string &buf) +void IRCDProto::SendNumericInternal(int numeric, const Anope::string &dest, const Anope::string &buf) { Anope::string n = stringify(numeric); if (numeric < 10) n = "0" + n; if (numeric < 100) n = "0" + n; - UplinkSocket::Message(source) << n << " " << dest << " " << buf; + UplinkSocket::Message(Me) << n << " " << dest << " " << buf; +} + +void IRCDProto::SendTopic(BotInfo *bi, Channel *c) +{ + UplinkSocket::Message(bi) << "TOPIC " << c->name << " :" << c->topic; } void IRCDProto::SendSVSKill(const BotInfo *source, const User *user, const char *fmt, ...) @@ -183,12 +209,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) { - UplinkSocket::Message(bi->nick) << "NOTICE " << ircd->globaltldprefix << dest->GetName() << " :" << msg; + UplinkSocket::Message(bi) << "NOTICE " << ircd->globaltldprefix << dest->GetName() << " :" << msg; } void IRCDProto::SendGlobalPrivmsg(const BotInfo *bi, const Server *dest, const Anope::string &msg) { - UplinkSocket::Message(bi->nick) << "PRIVMSG " << ircd->globaltldprefix << dest->GetName() << " :" << msg; + UplinkSocket::Message(bi) << "PRIVMSG " << ircd->globaltldprefix << dest->GetName() << " :" << msg; } void IRCDProto::SendQuit(const User *u, const char *fmt, ...) @@ -204,9 +230,9 @@ void IRCDProto::SendQuit(const User *u, const char *fmt, ...) void IRCDProto::SendPing(const Anope::string &servname, const Anope::string &who) { if (servname.empty()) - UplinkSocket::Message(Config->ServerName) << "PING " << who; + UplinkSocket::Message(Me) << "PING " << who; else - UplinkSocket::Message(Config->ServerName) << "PING " << servname << " " << who; + UplinkSocket::Message(Me) << "PING " << servname << " " << who; } /** @@ -218,14 +244,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()) - UplinkSocket::Message(Config->ServerName) << "PONG " << who; + UplinkSocket::Message(Me) << "PONG " << who; else - UplinkSocket::Message(Config->ServerName) << "PONG " << servname << " " << who; + UplinkSocket::Message(Me) << "PONG " << servname << " " << who; } -void IRCDProto::SendInvite(const BotInfo *bi, const Anope::string &chan, const Anope::string &nick) +void IRCDProto::SendInvite(const BotInfo *bi, const Channel *c, const User *u) { - UplinkSocket::Message(bi->nick) << "INVITE " << nick << " " << chan; + UplinkSocket::Message(bi) << "INVITE " << (ircd->ts6 ? u->GetUID() : u->nick) << " " << c->name; } void IRCDProto::SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...) @@ -260,7 +286,7 @@ void IRCDProto::SendSquit(Server *s, const Anope::string &message) void IRCDProto::SendChangeBotNick(const BotInfo *bi, const Anope::string &newnick) { - UplinkSocket::Message(bi->nick) << "NICK " << newnick << " " << Anope::CurTime; + UplinkSocket::Message(bi) << "NICK " << newnick << " " << Anope::CurTime; } void IRCDProto::SendForceNickChange(const User *u, const Anope::string &newnick, time_t when) @@ -278,14 +304,14 @@ void IRCDProto::SendCTCP(const BotInfo *bi, const Anope::string &dest, const cha SendCTCPInternal(bi, dest, buf); } -void IRCDProto::SendNumeric(const Anope::string &source, int numeric, const Anope::string &dest, const char *fmt, ...) +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(source, numeric, dest, buf); + SendNumericInternal(numeric, dest, buf); } bool IRCDProto::IsChannelValid(const Anope::string &chan) @@ -518,16 +544,16 @@ bool IRCdMessage::OnWhois(const Anope::string &source, const std::vector<Anope:: if (u && u->server == Me) { BotInfo *bi = findbot(u->nick); - ircdproto->SendNumeric(Config->ServerName, 311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str()); + ircdproto->SendNumeric(311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str()); if (bi) - ircdproto->SendNumeric(Config->ServerName, 307, source, "%s :is a registered nick", bi->nick.c_str()); - ircdproto->SendNumeric(Config->ServerName, 312, source, "%s %s :%s", u->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str()); + ircdproto->SendNumeric(307, source, "%s :is a registered nick", bi->nick.c_str()); + ircdproto->SendNumeric(312, source, "%s %s :%s", u->nick.c_str(), Config->ServerName.c_str(), Config->ServerDesc.c_str()); if (bi) - ircdproto->SendNumeric(Config->ServerName, 317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(start_time)); - ircdproto->SendNumeric(Config->ServerName, 318, source, "%s :End of /WHOIS list.", params[0].c_str()); + ircdproto->SendNumeric(317, source, "%s %ld %ld :seconds idle, signon time", bi->nick.c_str(), static_cast<long>(Anope::CurTime - bi->lastmsg), static_cast<long>(start_time)); + ircdproto->SendNumeric(318, source, "%s :End of /WHOIS list.", params[0].c_str()); } else - ircdproto->SendNumeric(Config->ServerName, 401, source, "%s :No such user.", params[0].c_str()); + ircdproto->SendNumeric(401, source, "%s :No such user.", params[0].c_str()); } return true; |