diff --git a/modules/s_conf.cc b/modules/s_conf.cc index cea3339b7..b35ed509f 100644 --- a/modules/s_conf.cc +++ b/modules/s_conf.cc @@ -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 &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 diff --git a/modules/s_control.cc b/modules/s_control.cc index 657c271c0..bc407de24 100644 --- a/modules/s_control.cc +++ b/modules/s_control.cc @@ -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 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; + using prototype = void (const string_view &key, + const closure &); + static import 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 {