summaryrefslogtreecommitdiff
path: root/src/uplink.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/uplink.cpp')
-rw-r--r--src/uplink.cpp103
1 files changed, 51 insertions, 52 deletions
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 666c9dfa3..fb5f3ec23 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -1,12 +1,20 @@
/*
+ * Anope IRC Services
*
- * (C) 2003-2017 Anope Team
- * Contact us at team@anope.org
+ * Copyright (C) 2012-2017 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
{
@@ -30,7 +42,7 @@ class ReconnectTimer : public Timer
}
catch (const SocketException &ex)
{
- Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port << "): " << ex.GetReason();
+ Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, ex.GetReason());
}
}
};
@@ -39,7 +51,7 @@ void Uplink::Connect()
{
if (Config->Uplinks.empty())
{
- Log() << "Warning: There are no configured uplinks.";
+ Anope::Logger.Log(_("Warning: There are no configured uplinks."));
return;
}
@@ -49,11 +61,11 @@ 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;
+ Anope::Logger.Terminal(_("Attempting to connect to uplink #{0} {1} ({2}), port {3}"), Anope::CurrentUplink + 1, u.host, ip, u.port);
UplinkSock->Connect(ip, u.port);
}
@@ -70,14 +82,14 @@ UplinkSocket::~UplinkSocket()
this->OnError("");
Module *protocol = ModuleManager::FindFirstOf(PROTOCOL);
if (protocol && !protocol->name.find("inspircd"))
- Log(LOG_TERMINAL) << "Check that you have loaded m_spanningtree.so on InspIRCd, and are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)";
+ Anope::Logger.Terminal(_("Check that you have loaded m_spanningtree.so on InspIRCd, and are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)"));
else
- Log(LOG_TERMINAL) << "Check that you are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)";
+ Anope::Logger.Terminal(_("Check that you are not connecting Anope to an SSL enabled port without configuring SSL in Anope (or vice versa)"));
}
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,13 +99,13 @@ 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;
}
}
- IRCD->SendSquit(Me, Anope::QuitReason);
+ IRCD->Send<messages::SQuit>(Me, Anope::QuitReason);
this->ProcessWrite(); // Write out the last bit
}
@@ -123,7 +135,7 @@ UplinkSocket::~UplinkSocket()
{
time_t retry = Config->GetBlock("options")->Get<time_t>("retrywait");
- Log() << "Disconnected, retrying in " << retry << " seconds";
+ Anope::Logger.Log(_("Disconnected, retrying in {0} seconds"), retry);
new ReconnectTimer(retry);
}
}
@@ -142,72 +154,59 @@ bool UplinkSocket::ProcessRead()
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, ());
+ Anope::Logger.Terminal(_("Successfully connected to uplink #{0} {1}:{2}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port);
+ IRCD->Handshake();
+ EventManager::Get()->Dispatch(&Event::ServerConnect::OnServerConnect);
}
void UplinkSocket::OnError(const Anope::string &err)
{
- Anope::string what = !this->flags[SF_CONNECTED] ? "Unable to connect to" : "Lost connection from";
- Log(LOG_TERMINAL) << what << " uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].host << ":" << Config->Uplinks[Anope::CurrentUplink].port << ")" << (!err.empty() ? (": " + err) : "");
+ if (!this->flags[SF_CONNECTED])
+ Anope::Logger.Terminal(_("Unable to connect to uplink #{0} ({1}:{2}): {3}{4}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, !err.empty() ? (": " + err) : "");
+ else
+ Anope::Logger.Terminal(_("Lost connection from uplink #{0} ({1}:{2}): {3}{4}"), Anope::CurrentUplink + 1, Config->Uplinks[Anope::CurrentUplink].host, Config->Uplinks[Anope::CurrentUplink].port, !err.empty() ? (": " + 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?";
+ Anope::Logger.Debug("Attempted to send \"{0}\" from {1} who is not from me?", buffer, s->GetName());
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?";
+ Anope::Logger.Debug("Attempted to send \"{0}\" from {1} who is not from me?", buffer, u->nick);
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";
+ Anope::Logger.Debug("Attempted to send \"{0}\" from {1} when not introduced", buffer, bi->nick);
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";
+ Anope::Logger.Debug("Attempted to send \"{0}\" when not connected", buffer);
return;
}
- Anope::string sent = IRCD->Format(message_source, this->buffer.str());
- UplinkSock->Write(sent);
- Log(LOG_RAWIO) << "Sent: " << sent;
+ UplinkSock->Write(buffer);
+ Anope::Logger.RawIO("Sent: {0}", buffer);
}