From c3c84a3c6aa633d0833f74d6ce1c99397a7fa8e2 Mon Sep 17 00:00:00 2001 From: Test_User Date: Fri, 5 Aug 2022 00:03:52 -0400 Subject: fix missing license to old CoupServ.py --- network.lua | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) (limited to 'network.lua') diff --git a/network.lua b/network.lua index c581759..84cb712 100644 --- a/network.lua +++ b/network.lua @@ -122,6 +122,28 @@ local function parse_modes(modes, args, has_args, current) return true end +local function mode_to_string(modes) + local res = "+" + local args = {} + for mode, arg in pairs(modes) do + if arg == true then + res = res..mode + elseif type(arg) == "string" then + res = res..mode + table.insert(args, arg) + elseif type(arg) == "table" then + for _, a in pairs(arg) do + res = res..mode + table.insert(args, a) + end + end + end + + res = res.." "..table.concat(args, " ") + + return res +end + message_handler = { ["PING"] = function(con, source, args, original) con:send(":"..args[2].." PONG "..args[2].." "..source.."\n") @@ -190,6 +212,10 @@ message_handler = { end, ["PRIVMSG"] = function(con, source, args, original) + if args[1] == cur_channel then + print(("%q"):format("<"..userlist[source].nick.."> "..args[2])) + end + local cmd_args = {} for part in args[2]:gmatch("[^ ]*") do table.insert(cmd_args, part) @@ -244,7 +270,41 @@ message_handler = { end end, - ["FJOIN"] = function(con, source, args, original) + ["KILL"] = function(con, source, args, original) + if args[1]:sub(1,3) ~= "1HC" then + print("Kill remote", original) + userlist[source] = nil + for name, chan in pairs(chanlist) do + chan["users"][source] = nil + if next(chan["users"]) == nil and not chan["modes"]["P"] then + chanlist[name] = nil + end + end + else + print("Kill local", original) + local user = userlist[args[1]] + if type(user) == "table" then + con:send("UID "..args[1].." "..user.nick_ts.." "..user.nick.." "..user.hostname.." "..user.vhost.." "..user.ident.." "..user.ip.." "..user.user_ts.." "..mode_to_string(user.modes).." :"..user.realname.."\n") + + -- temporary before I handle channels + for channel, _ in pairs(config.channels) do + con:send(":"..args[1].." JOIN "..channel.."\n") + con:send("MODE "..channel.." +o "..args[1].."\n") + end + end + end + end, + + ["KICK"] = function(con, soure, args, original) + if args[2]:sub(1,3) == "1HC" then + con:send(":"..args[2].." JOIN "..args[1].."\n") + con:send("MODE "..args[1].." +o "..args[2].."\n") + else + print("Channels not yet handled: "..("%q"):format(original)) + end + end, + +--[[ ["FJOIN"] = function(con, source, args, original) - end + end]] } -- cgit v1.2.3