From e3d61f12fe302e7e72d97d8c718c6a372b334ff6 Mon Sep 17 00:00:00 2001 From: Test_User Date: Wed, 6 Jul 2022 12:32:17 -0400 Subject: librenukes™ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- network.lua | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 82 insertions(+), 7 deletions(-) (limited to 'network.lua') diff --git a/network.lua b/network.lua index fbeb168..c581759 100644 --- a/network.lua +++ b/network.lua @@ -29,6 +29,73 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ]] +local function mode_snomask(current, mode, dir, arg) + if dir == "+" then + current[mode] = current[mode] or {} + parse_modes(arg, {}, {}, current[mode]) + if not next(current[mode]) then + current[mode] = nil + end + return true + else + current[mode] = nil + end +end + +local function mode_replace(current, mode, dir, arg) + if dir == "+" then + current[mode] = arg + return true + else + current[mode] = nil + end +end + +local function mode_multi(current, mode, dir, arg) + if dir == "+" then + current[mode] = current[mode] or {} + current[mode][arg] = true + else + if current[mode] == nil then + print("Invalid mode change attempt!\n") + current[mode] = {} + end + current[mode][arg] = nil + if next(current[mode]) == nil then + current[mode] = nil + end + end + return true +end + +local usermodes = { + ["s"] = mode_snomask, +} + +local chanmodes = { + ["l"] = mode_replace, + ["L"] = mode_replace, + ["v"] = mode_multi, + ["o"] = mode_multi, + ["h"] = mode_multi, + ["a"] = mode_multi, + ["q"] = mode_multi, + ["Y"] = mode_multi, + ["d"] = mode_replace, + ["f"] = mode_replace, + ["g"] = mode_multi, + ["b"] = mode_multi, + ["e"] = mode_multi, + ["I"] = mode_multi, + ["k"] = mode_replace, + ["w"] = mode_multi, + ["E"] = mode_replace, + ["F"] = mode_replace, + ["H"] = mode_replace, + ["J"] = mode_replace, + ["X"] = mode_multi, +} + local function parse_modes(modes, args, has_args, current) local dir = "-" for i = 1, #modes do @@ -82,6 +149,7 @@ message_handler = { if userlist[args[1]] then userlist[args[1]].metadata[args[2]] = args[3] else + print(("%q"):format(original)) print("Got metadata for an unknown user!\n") end end @@ -115,7 +183,6 @@ message_handler = { end, ["NICK"] = function(con, source, args, original) - print(string.format("%q", original)) if userlist[source] then userlist[source].nick = args[1] userlist[source].nick_ts = args[2] @@ -123,7 +190,6 @@ message_handler = { end, ["PRIVMSG"] = function(con, source, args, original) - print(string.format("%q", original)) local cmd_args = {} for part in args[2]:gmatch("[^ ]*") do table.insert(cmd_args, part) @@ -135,15 +201,16 @@ message_handler = { if args[1]:sub(1, 1) == "#" then resp = args[1] - if cmd:sub(1, 1) ~= "-" then return end + if cmd:sub(1, 3) ~= "\x0304" then return end - cmd = cmd:sub(2) -- remove leading '-' + cmd = cmd:sub(4) -- remove leading '-' else resp = source end if commands[cmd] then if has_permission(userlist[source], commands[cmd].privs) then + print(("%q"):format(userlist[source].nick.." executed command: "..cmd)) return commands[cmd].func(con, source, cmd, cmd_args, resp) else con:send(":1HC000000 NOTICE "..resp.." :You are not authorized to execute that command.\n") @@ -154,13 +221,12 @@ message_handler = { end, ["MODE"] = function(con, source, args, original) - print(string.format("%q", original)) if args[1]:sub(1, 1) == "#" then print("Channels not handled yet!\n") else if not userlist[args[1]] then print("Attempted to set mode on an unknown user!\n") - elseif not parse_modes(args[2], {table.unpack(args, 3)}, {["s"] = {["+"] = true, ["-"] = false}}, userlist[args[1]].modes) then + elseif not parse_modes(args[2], {table.unpack(args, 3)}, usermodes, userlist[args[1]].modes) then return true elseif not userlist[args[1]].modes.o then userlist[args[1]].opertype = nil @@ -169,7 +235,16 @@ message_handler = { end, ["QUIT"] = function(con, source, args, original) - print(string.format("%q", 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 end, + + ["FJOIN"] = function(con, source, args, original) + + end } -- cgit v1.2.3