]> PatchyGit - patchyircd.git/commitdiff
add associated lua data for clients
authorEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 11:14:19 +0000 (13:14 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 23 Jan 2024 11:15:04 +0000 (13:15 +0200)
lua/init.lua
src/irc.c
src/net.c

index 165e133..053f6b6 100644 (file)
@@ -44,6 +44,22 @@ end
 hook_setfold("sendtochannel", fold_sendtox)
 hook_setfold("sendtoclient", fold_sendtox)
 hook_setfold("newuser", fold_sendtox)
+hook_setfold("nickadd", fold_sendtox)
+hook_setfold("nickdel", fold_sendtox)
+hook_setfold("nickchange", fold_sendtox)
+if not client_data then
+       client_data = {}
+end
+hook_add("nickadd", "irccloud_auth", function(hook, cl1, cl2, chan, txt)
+       client_data[txt] = {}
+end)
+hook_add("nickdel", "irccloud_auth", function(hook, cl1, cl2, chan, txt)
+       client_data[txt] = nil
+end)
+hook_add("nickchange", "irccloud_auth", function(hook, cl1, cl2, chan, txt)
+       client_data[txt] = client_data[cl1.key]
+       client_data[cl1.key] = nil
+end)
 
 function commands.echo(client, source, command, args)
        client_notice(client, "client = "..tostring(client))
index 3b55bfd..a6d10f7 100644 (file)
--- a/src/irc.c
+++ b/src/irc.c
@@ -1329,6 +1329,9 @@ void setNick(struct client_data *client, char* nickname) {
 
        // Update nickname
        if(client->nick) {
+#ifdef HAS_LUA
+               admin_hook("nickchange", client, 0, 0, key);
+#endif
                msg_nick(client, nickname);
                sendbuf(client);
                sendbuf_visible(client);
@@ -1351,6 +1354,10 @@ void setNick(struct client_data *client, char* nickname) {
                }
                free(client->nick);
                free(client->key);
+       } else {
+#ifdef HAS_LUA
+               admin_hook("nickadd", client, 0, 0, key);
+#endif
        }
 
        client->nick = mystrdup(nickname);
index 834baa5..f8311ba 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -68,6 +68,9 @@ void killConnection(struct client_data *cl, int byChoice)
                channel_part(cl, chan, NULL, NULL);
        /* Remove from client_map and get rid of the pending invites */
        if (cl->key) {
+#ifdef HAS_LUA
+               admin_hook("nickdel", cl, 0, 0, cl->key);
+#endif
                map_unset(&client_map, cl->key, NULL);
                rpl_monoffline(0, cl->key), sendbuf_monitor(cl->key, 0, 0, 0);
                struct channel *chan;