aboutsummaryrefslogtreecommitdiffstats
path: root/modules/services.cpp
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-11-10 11:15:29 +0000
committerGravatar Sadie Powell2024-08-06 19:02:09 +0100
commit826b565714652f8ebeb7ac095d6a21a5690dc0ee (patch)
tree8d76e9be8aa5b19ffbf620f995ee4b6b249f652b /modules/services.cpp
parentMerge branch 'insp4' into master. (diff)
Add a skeleton of the account provider API.
Diffstat (limited to 'modules/services.cpp')
-rw-r--r--modules/services.cpp76
1 files changed, 76 insertions, 0 deletions
diff --git a/modules/services.cpp b/modules/services.cpp
index 4d9c84de4..85c1659b6 100644
--- a/modules/services.cpp
+++ b/modules/services.cpp
@@ -26,6 +26,74 @@
#include "timeutils.h"
#include "xline.h"
+class ServicesAccountProvider final
+ : public Account::ProviderAPIBase
+ , public ServerProtocol::LinkEventListener
+{
+private:
+ std::string target;
+
+ void OnServerLink(const Server* server) override
+ {
+ UpdateStatus(server, true);
+ }
+
+ void OnServerSplit(const Server* server, bool error) override
+ {
+ UpdateStatus(server, false);
+ }
+
+ void SetAvailable(bool online)
+ {
+ auto api = ServerInstance->Modules.FindService(SERVICE_DATA, "accountproviderapi");
+ if (online && api != this)
+ ServerInstance->Modules.AddService(*this);
+ else if (!online && api == this)
+ ServerInstance->Modules.DelService(*this);
+ }
+
+ void UpdateStatus(const Server* server, bool online)
+ {
+ if (irc::equals(target, server->GetName()))
+ {
+ ServerInstance->Logs.Debug(MODNAME, "Services server %s (%s) %s.", server->GetName().c_str(),
+ server->GetId().c_str(), online ? "came online" : "went offline");
+ SetAvailable(online);
+ }
+ }
+
+public:
+ ServicesAccountProvider(Module* mod)
+ : Account::ProviderAPIBase(mod)
+ , ServerProtocol::LinkEventListener(mod)
+ {
+ }
+
+ void SetTarget(const std::string& newtarget)
+ {
+ if (target == newtarget)
+ return; // Nothing has changed.
+
+ target = newtarget;
+ ProtocolInterface::ServerList servers;
+ ServerInstance->PI->GetServerList(servers);
+ for (const auto& server : servers)
+ {
+ if (irc::equals(target, server.servername))
+ {
+ ServerInstance->Logs.Debug(MODNAME, "Changed the services server to %s.",
+ server.servername.c_str());
+ SetAvailable(true);
+ return;
+ }
+ }
+
+ ServerInstance->Logs.Debug(MODNAME, "The services server (%s) is currently unavailable.",
+ target.c_str());
+ SetAvailable(false);
+ }
+};
+
enum
{
// From UnrealIRCd.
@@ -520,6 +588,7 @@ class ModuleServices final
{
private:
Account::API accountapi;
+ ServicesAccountProvider accountprovapi;
RegisteredChannel registeredcmode;
RegisteredUser registeredumode;
ServiceTag servicetag;
@@ -581,6 +650,7 @@ public:
, ServerProtocol::RouteEventListener(this)
, Stats::EventListener(this)
, accountapi(this)
+ , accountprovapi(this)
, registeredcmode(this)
, registeredumode(this)
, servicetag(this)
@@ -612,6 +682,12 @@ public:
void ReadConfig(ConfigStatus& status) override
{
const auto& tag = ServerInstance->Config->ConfValue("servicesintegration");
+
+ const auto target = tag->getString("server", ServerInstance->Config->ConfValue("sasl")->getString("target"));
+ if (target.empty())
+ throw ModuleException(this, "<servicesintegration:server> must be set to the name of your services server!");
+
+ accountprovapi.SetTarget(target);
accountoverrideshold = tag->getBool("accountoverrideshold");
}