]> PatchyGit - patchyircd.git/commitdiff
irccloud.lua: read from text database
authorEgor <egor@patchysicp.xyz>
Thu, 25 Jan 2024 04:02:34 +0000 (06:02 +0200)
committerEgor <egor@patchysicp.xyz>
Thu, 25 Jan 2024 04:02:34 +0000 (06:02 +0200)
data/.gitignore
lua/irccloud.lua
src/admin.c

index 2a04b68..fc5f977 100644 (file)
@@ -9,3 +9,4 @@ help.txt
 motd.txt
 certfp.txt
 nicks.txt
+irccloud.txt
index 35dd918..49af559 100644 (file)
@@ -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)
index 420b3c9..eb18fe5 100644 (file)
@@ -1,6 +1,7 @@
 #include "admin.h"
 #include "irc.h"
 #include "ircfmt.h"
+#include "passwd.h"
 #include <lauxlib.h>
 #include <lualib.h>
 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)
 {