From 61adb9f8b0fd35270a95eebd4c555d8b5b0fd6e8 Mon Sep 17 00:00:00 2001 From: Egor Date: Thu, 25 Jan 2024 06:02:34 +0200 Subject: [PATCH] irccloud.lua: read from text database --- data/.gitignore | 1 + lua/irccloud.lua | 8 ++------ src/admin.c | 14 ++++++++++++-- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/data/.gitignore b/data/.gitignore index 2a04b68..fc5f977 100644 --- a/data/.gitignore +++ b/data/.gitignore @@ -9,3 +9,4 @@ help.txt motd.txt certfp.txt nicks.txt +irccloud.txt diff --git a/lua/irccloud.lua b/lua/irccloud.lua index 35dd918..49af559 100644 --- a/lua/irccloud.lua +++ b/lua/irccloud.lua @@ -38,13 +38,9 @@ local function isirccloudnetwork(netid) return netid >= 0x2a035180000f0000 and netid <= 0x2a035180000f0006 end -local uidmap = { - [635723] = "samson", -} - hook_add("newuser", "irccloud_auth", function(hook, cl1, cl2, chan, txt) local netid, ifaceid = parseipv6(cl1.peername) - if netid and isirccloudnetwork(netid) and uidmap[ifaceid] then - client_chghost(cl1, uidmap[ifaceid], cl1.hostname) + if netid and isirccloudnetwork(netid) then + client_chghost(cl1, db_read_rhs(tostring(ifaceid), "irccloud.txt")) end end) diff --git a/src/admin.c b/src/admin.c index 420b3c9..eb18fe5 100644 --- a/src/admin.c +++ b/src/admin.c @@ -1,6 +1,7 @@ #include "admin.h" #include "irc.h" #include "ircfmt.h" +#include "passwd.h" #include #include static lua_State *GL = 0; @@ -267,8 +268,8 @@ static int fn_channel_part(lua_State *L) static int fn_client_chghost(lua_State *L) { struct client_data *cl = *(struct client_data **)luaL_checkudata(L, 1, "client"); - const char *newusername = luaL_checkstring(L, 2); - const char *newhostname = luaL_checkstring(L, 3); + const char *newusername = luaL_optstring(L, 2, 0); + const char *newhostname = luaL_optstring(L, 3, 0); client_chghost(cl, newusername, newhostname); return 0; } @@ -279,6 +280,13 @@ static int fn_rpl_whoisspecial(lua_State *L) { rpl_whoisspecial(cl1, cl2, "", text), sendbuf(cl1); return 0; } +static int fn_db_read_rhs(lua_State *L) { + const char *key = luaL_checkstring(L, 1); + const char *fn = luaL_checkstring(L, 2); + const char *res = db_read_rhs(key, getdatafile(fn)); + lua_pushstring(L, res); + return 1; +} void admin_init(void) { @@ -342,6 +350,8 @@ void admin_init(void) lua_setglobal(L, "client_chghost"); lua_pushcfunction(L, fn_rpl_whoisspecial); lua_setglobal(L, "rpl_whoisspecial"); + lua_pushcfunction(L, fn_db_read_rhs); + lua_setglobal(L, "db_read_rhs"); } void admin_fini(void) { -- 2.56.0