From 8500fefe9137d8a933d8a4f229398dde7cb59304 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 19 Feb 2026 16:35:11 +0000 Subject: [PATCH] Allow importing custom Atheme metadata to {cs,ns}_set_misc. --- data/anope.example.conf | 28 +++++++++++++++ docs/CHANGES.md | 2 ++ modules/database/db_atheme.cpp | 66 ++++++++++++++++++++++++++++++++-- 3 files changed, 94 insertions(+), 2 deletions(-) diff --git a/data/anope.example.conf b/data/anope.example.conf index 427ca2cdc..258b0e9e4 100644 --- a/data/anope.example.conf +++ b/data/anope.example.conf @@ -1084,6 +1084,34 @@ mail * The file that db_atheme will import your main database from. */ database = "atheme.db" + + /* + * If you have custom data in your Atheme database that you want converted + * to Anope misc data to be shown with cs_set_misc you can configure that + * using one or more cs_set_misc blocks. + */ + #cs_set_misc + { + /* The key name used by Atheme. */ + atheme = "private:misc:data" + + /* The cs_set_misc entry to import into. */ + anope = "MISC_DATA" + } + + /* + * If you have custom data in your Atheme database that you want converted + * to Anope misc data to be shown with ns_set_misc you can configure that + * using one or more ns_set_misc blocks. + */ + #ns_set_misc + { + /* The key name used by Atheme. */ + atheme = "private:misc:data" + + /* The ns_set_misc entry to import into. */ + anope = "MISC_DATA" + } } /* diff --git a/docs/CHANGES.md b/docs/CHANGES.md index afc911b7c..cbcdd81e1 100644 --- a/docs/CHANGES.md +++ b/docs/CHANGES.md @@ -10,6 +10,8 @@ ## Changes +* The db_atheme module can now import arbitrary metadata to fields from the ns_set_misc module. + * The regex_posix module is now available on Windows (using the PCRE2 POSIX compatibility layer). * The regex_tre module is now available on Windows. diff --git a/modules/database/db_atheme.cpp b/modules/database/db_atheme.cpp index a475d8284..5175f2576 100644 --- a/modules/database/db_atheme.cpp +++ b/modules/database/db_atheme.cpp @@ -170,6 +170,8 @@ private: ServiceReference sglinemgr; ServiceReference snlinemgr; ServiceReference sqlinemgr; + Anope::map csmiscdata; + Anope::map nsmiscdata; Anope::map> rowhandlers = { { "AC", &DBAtheme::HandleIgnore }, @@ -1080,7 +1082,26 @@ private: data->data = value; } else - Log(this) << "Unknown channel metadata for " << ci->name << ": " << key << " = " << value; + { + auto it = csmiscdata.find(key); + if (it == csmiscdata.end()) + { + Log(this) << "Unknown channel metadata for " << ci->name << ": " << key << " = " << value; + return true; + } + + ExtensibleRef extref("cs_set_misc:" + it->second); + if (!extref) + { + Log(this) << "Unknown imported channel metadata for " << ci->name << ": " << it->second << " = " << value; + return true; + } + + auto *data = extref->Set(ci); + data->object = ci->name; + data->name = it->second; + data->data = value; + } return true; } @@ -1193,7 +1214,26 @@ private: data->data = value; } else - Log(this) << "Unknown account metadata for " << nc->display << ": " << key << " = " << value; + { + auto it = nsmiscdata.find(key); + if (it == nsmiscdata.end()) + { + Log(this) << "Unknown public account metadata for " << nc->display << ": " << key << " = " << value; + return true; + } + + ExtensibleRef extref("ns_set_misc:" + it->second); + if (!extref) + { + Log(this) << "Unknown imported account metadata for " << nc->display << ": " << key << " = " << value; + return true; + } + + auto *data = extref->Set(nc); + data->object = nc->display; + data->name = it->second; + data->data = value; + } return true; } @@ -1541,6 +1581,28 @@ public: void OnReload(Configuration::Conf &conf) override { + const auto &modconf = conf.GetModule(this); + + csmiscdata.clear(); + for (auto idx = 0; idx < modconf.CountBlock("cs_set_misc"); ++idx) + { + const auto &data = modconf.GetBlock("cs_set_misc", idx); + const auto &anope = data.Get("anope"); + const auto &atheme = data.Get("atheme"); + if (!anope.empty() && !atheme.empty()) + csmiscdata[atheme] = anope.upper(); + } + + nsmiscdata.clear(); + for (auto idx = 0; idx < modconf.CountBlock("ns_set_misc"); ++idx) + { + const auto &data = modconf.GetBlock("ns_set_misc", idx); + const auto &anope = data.Get("anope"); + const auto &atheme = data.Get("atheme"); + if (!anope.empty() && !atheme.empty()) + nsmiscdata[atheme] = anope.upper(); + } + flags.clear(); for (int i = 0; i < Config->CountBlock("privilege"); ++i) {