diff options
Diffstat (limited to 'src/uplink.cpp')
-rw-r--r-- | src/uplink.cpp | 79 |
1 files changed, 38 insertions, 41 deletions
diff --git a/src/uplink.cpp b/src/uplink.cpp index df38f98f2..c2b7579c5 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -1,12 +1,20 @@ /* + * Anope IRC Services * - * (C) 2003-2016 Anope Team - * Contact us at team@anope.org + * Copyright (C) 2012-2016 Anope Team <team@anope.org> * - * Please read COPYING and README for further details. + * 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. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. + * 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 <http://www.gnu.org/licenses/>. */ #include "uplink.h" @@ -14,6 +22,10 @@ #include "config.h" #include "protocol.h" #include "servers.h" +#include "event.h" +#include "bots.h" +#include "timers.h" +#include "modules.h" UplinkSocket *UplinkSock = NULL; @@ -22,7 +34,7 @@ class ReconnectTimer : public Timer public: ReconnectTimer(int wait) : Timer(wait) { } - void Tick(time_t) + void Tick(time_t) override { try { @@ -49,9 +61,9 @@ void Uplink::Connect() Configuration::Uplink &u = Config->Uplinks[Anope::CurrentUplink]; new UplinkSocket(); - if (!Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost").empty()) - UplinkSock->Bind(Config->GetBlock("serverinfo")->Get<const Anope::string>("localhost")); - FOREACH_MOD(OnPreServerConnect, ()); + if (!Config->GetBlock("serverinfo")->Get<Anope::string>("localhost").empty()) + UplinkSock->Bind(Config->GetBlock("serverinfo")->Get<Anope::string>("localhost")); + EventManager::Get()->Dispatch(&Event::PreServerConnect::OnPreServerConnect); Anope::string ip = Anope::Resolve(u.host, u.ipv6 ? AF_INET6 : AF_INET); Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << "), port " << u.port; UplinkSock->Connect(ip, u.port); @@ -77,7 +89,7 @@ UplinkSocket::~UplinkSocket() if (IRCD && Servers::GetUplink() && Servers::GetUplink()->IsSynced()) { - FOREACH_MOD(OnServerDisconnect, ()); + EventManager::Get()->Dispatch(&Event::ServerDisconnect::OnServerDisconnect); for (user_map::const_iterator it = UserListByNick.begin(); it != UserListByNick.end(); ++it) { @@ -87,7 +99,7 @@ UplinkSocket::~UplinkSocket() { /* Don't use quitmsg here, it may contain information you don't want people to see */ IRCD->SendQuit(u, "Shutting down"); - BotInfo* bi = BotInfo::Find(u->GetUID()); + ServiceBot* bi = ServiceBot::Find(u->GetUID()); if (bi != NULL) bi->introduced = false; } @@ -144,7 +156,7 @@ void UplinkSocket::OnConnect() { Log(LOG_TERMINAL) << "Successfully connected to uplink #" << (Anope::CurrentUplink + 1) << " " << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port; IRCD->SendConnect(); - FOREACH_MOD(OnServerConnect, ()); + EventManager::Get()->Dispatch(&Event::ServerConnect::OnServerConnect); } void UplinkSocket::OnError(const Anope::string &err) @@ -154,60 +166,45 @@ void UplinkSocket::OnError(const Anope::string &err) error |= !err.empty(); } -UplinkSocket::Message::Message() : source(Me) -{ -} - -UplinkSocket::Message::Message(const MessageSource &src) : source(src) -{ -} - -UplinkSocket::Message::~Message() +void Uplink::SendMessage(IRCMessage &message) { - Anope::string message_source; + const MessageSource &source = message.GetSource(); + Anope::string buffer = IRCD->Format(message); - if (this->source.GetServer() != NULL) + if (source.GetServer() != NULL) { - const Server *s = this->source.GetServer(); + const Server *s = source.GetServer(); if (s != Me && !s->IsJuped()) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << s->GetName() << " who is not from me?"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << s->GetName() << " who is not from me?"; return; } - - message_source = s->GetSID(); } - else if (this->source.GetUser() != NULL) + else if (source.GetUser() != NULL) { - const User *u = this->source.GetUser(); + const User *u = source.GetUser(); if (u->server != Me && !u->server->IsJuped()) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << u->nick << " who is not from me?"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << u->nick << " who is not from me?"; return; } - const BotInfo *bi = this->source.GetBot(); + const ServiceBot *bi = source.GetBot(); if (bi != NULL && bi->introduced == false) { - Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" from " << bi->nick << " when not introduced"; return; } - - message_source = u->GetUID(); } 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"; + Log(LOG_DEBUG) << "Attempted to send \"" << buffer << "\" with UplinkSock NULL"; return; } - Anope::string sent = IRCD->Format(message_source, this->buffer.str()); - UplinkSock->Write(sent); - Log(LOG_RAWIO) << "Sent: " << sent; + UplinkSock->Write(buffer); + Log(LOG_RAWIO) << "Sent: " << buffer; } |