summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSadie Powell <sadie@witchery.services>2025-03-02 15:40:17 +0000
committerSadie Powell <sadie@witchery.services>2025-03-02 15:42:25 +0000
commit4526fbed960085e3996fcd70195887f462c430d8 (patch)
tree6016748659945b240e216675dbe70ff80aa961af
parentf9911dde529adf3dc03f4f14bbd70756ac2f665c (diff)
Add a helper method for getting a description of an uplink.
-rw-r--r--include/config.h1
-rw-r--r--src/config.cpp18
-rw-r--r--src/main.cpp2
-rw-r--r--src/uplink.cpp8
4 files changed, 24 insertions, 5 deletions
diff --git a/include/config.h b/include/config.h
index d705fd422..7d12d602d 100644
--- a/include/config.h
+++ b/include/config.h
@@ -144,6 +144,7 @@ namespace Configuration
Uplink(const Anope::string &_host, int _port, const Anope::string &_password, int _protocol) : host(_host), port(_port), password(_password), protocol(_protocol) { }
inline bool operator==(const Uplink &other) const { return host == other.host && port == other.port && password == other.password && protocol == other.protocol; }
inline bool operator!=(const Uplink &other) const { return !(*this == other); }
+ Anope::string str() const;
};
}
diff --git a/src/config.cpp b/src/config.cpp
index 33d7a8de8..e9096599c 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -23,6 +23,7 @@
using Configuration::File;
using Configuration::Conf;
using Configuration::Internal::Block;
+using Configuration::Uplink;
File ServicesConf("anope.conf", false); // Configuration file name
Conf *Config = NULL;
@@ -619,6 +620,23 @@ void Conf::Post(Conf *old)
}
}
+Anope::string Uplink::str() const
+{
+ switch (protocol)
+ {
+ case AF_INET:
+ return Anope::printf("%s:%u", this->host.c_str(), this->port);
+ case AF_INET6:
+ return Anope::printf("[%s]:%u", this->host.c_str(), this->port);
+ case AF_UNIX:
+ return this->host;
+ }
+
+ // Should never be reached.
+ return "";
+}
+
+
Block &Conf::GetModule(const Module *m)
{
if (!m)
diff --git a/src/main.cpp b/src/main.cpp
index 32329043e..ad4a72443 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -162,7 +162,7 @@ int main(int ac, char **av, char **envp)
}
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();
+ Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].str() << "): " << ex.GetReason();
}
/* Set up timers */
diff --git a/src/uplink.cpp b/src/uplink.cpp
index 100217291..6e39f163e 100644
--- a/src/uplink.cpp
+++ b/src/uplink.cpp
@@ -34,7 +34,7 @@ public:
}
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();
+ Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].str() << "): " << ex.GetReason();
}
}
};
@@ -57,7 +57,7 @@ void Uplink::Connect()
UplinkSock->Bind(Config->GetBlock("serverinfo").Get<const Anope::string>("localhost"));
FOREACH_MOD(OnPreServerConnect, ());
Anope::string ip = Anope::Resolve(u.host, u.protocol);
- Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << u.host << " (" << ip << '/' << u.port << ") with protocol " << IRCD->GetProtocolName();
+ Log(LOG_TERMINAL) << "Attempting to connect to uplink #" << (Anope::CurrentUplink + 1) << " " << ip << " (" << u.str() << ") with protocol " << IRCD->GetProtocolName();
UplinkSock->Connect(ip, u.port);
}
@@ -185,7 +185,7 @@ 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;
+ Log(LOG_TERMINAL) << "Successfully connected to uplink #" << (Anope::CurrentUplink + 1) << " " << Config->Uplinks[Anope::CurrentUplink].str();
IRCD->SendConnect();
FOREACH_MOD(OnServerConnect, ());
}
@@ -193,6 +193,6 @@ void UplinkSocket::OnConnect()
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) : "");
+ Log(LOG_TERMINAL) << what << " uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].str() << ")" << (!err.empty() ? (": " + err) : "");
error |= !err.empty();
}