0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 00:14:07 +01:00

modules: Export conf item get/set in s_conf; import for s_control interface.

This commit is contained in:
Jason Volk 2018-03-22 14:43:18 -07:00
parent a68d97d22d
commit 9d69e5a405
2 changed files with 54 additions and 13 deletions

View file

@ -16,7 +16,7 @@ IRCD_MODULE
"Server Configuration"
};
const ircd::m::room::id::buf
const m::room::id::buf
conf_room_id
{
"conf", ircd::my_host()
@ -28,6 +28,33 @@ conf_room
conf_room_id
};
extern "C" m::event::id::buf
set_conf_item(const m::user::id &sender,
const string_view &key,
const string_view &val)
{
return send(conf_room, sender, "ircd.conf.item", key,
{
{ "value", val }
});
}
extern "C" void
get_conf_item(const string_view &key,
const std::function<void (const string_view &)> &closure)
{
conf_room.get("ircd.conf.item", key, [&closure]
(const m::event &event)
{
const auto &value
{
unquote(at<"content"_>(event).at("value"))
};
closure(value);
});
}
static void
update_conf(const m::event &event)
noexcept

View file

@ -40,12 +40,23 @@ _conf_set(const m::event &event,
const string_view &val)
try
{
const auto &sender
{
at<"sender"_>(event)
};
using prototype = m::event::id::buf (const m::user::id &,
const string_view &key,
const string_view &val);
static import<prototype> set_conf_item
{
"s_conf", "set_conf_item"
};
const auto event_id
{
send(conf_room_id, at<"sender"_>(event), "ircd.conf.item", key,
{
{ "value", val }
})
set_conf_item(sender, key, val)
};
char kvbuf[768];
@ -64,15 +75,18 @@ _conf_get(const m::event &event,
const string_view &key)
try
{
const m::room conf_room{conf_room_id};
conf_room.get("ircd.conf.item", key, [&key]
(const m::event &event)
{
const auto &value
{
unquote(at<"content"_>(event).at("value"))
};
using closure = std::function<void (const string_view &val)>;
using prototype = void (const string_view &key,
const closure &);
static import<prototype> get_conf_item
{
"s_conf", "get_conf_item"
};
get_conf_item(key, [&key]
(const string_view &value)
{
char kvbuf[256];
notice(control_room, fmt::sprintf
{