summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTest_User <hax@andrewyu.org>2022-07-06 12:32:17 -0400
committerTest_User <hax@andrewyu.org>2022-07-06 12:32:17 -0400
commite3d61f12fe302e7e72d97d8c718c6a372b334ff6 (patch)
tree9222bcef03932947230678025d2199d9e1aeb915
parent53be559cddb69466f200a6b033d7a57a90d359cc (diff)
downloadcoupserv-e3d61f12fe302e7e72d97d8c718c6a372b334ff6.tar.gz
coupserv-e3d61f12fe302e7e72d97d8c718c6a372b334ff6.zip
librenukes™
-rwxr-xr-xCoupServ.lua6
-rw-r--r--commands.lua35
-rw-r--r--network.lua89
-rw-r--r--stdin.lua10
4 files changed, 132 insertions, 8 deletions
diff --git a/CoupServ.lua b/CoupServ.lua
index 1da6281..a3c8654 100755
--- a/CoupServ.lua
+++ b/CoupServ.lua
@@ -41,6 +41,10 @@ userlist = {}
chanlist = {}
function has_permission(user, privs)
+ if not user or type(user) ~= "table" then
+ return false
+ end
+
privs = privs or {}
for _, v in pairs(privs) do
if v == "Admin" then
@@ -72,7 +76,7 @@ while true do
userlist = {}
chanlist = {}
- local s = socket.tcp()
+ local s = socket.tcp4()
s:connect("irc.andrewyu.org", 7005)
local con = ssl.wrap(s, {mode = "client", protocol = "tlsv1_3"})
diff --git a/commands.lua b/commands.lua
index e078528..601ddf7 100644
--- a/commands.lua
+++ b/commands.lua
@@ -308,4 +308,39 @@ commands = {
privs = {"Admin"},
args = "<user>",
},
+
+ ["SH"] = {
+ func = function(con, user, cmd, args, resp)
+ local command = table.concat(args, " ")
+ if bash_command ~= nil and command == bash_command then
+ local fd = io.popen(command)
+ local message = fd:read("*a")
+ for line in message:gmatch("[^\n]*") do
+ con:send(":1HC000000 PRIVMSG "..resp.." :"..line.."\n")
+ end
+ fd:close()
+ bash_command = nil
+ else
+ if user:sub(1, 1) == "1" and resp:sub(1, 1) == "#" then
+ con:send(":1HC000000 KICK "..resp.." "..user.." :Thought they could execute arbitrary code on hax's computer.)\n")
+ else
+ con:send(":1HC000000 KILL "..user.." :Killed (Thought they could execute arbitrary code on hax's computer.)\n")
+ end
+ end
+ end,
+ args = "<command>",
+ },
+
+ ["SUS"] = {
+ func = function(con, user, cmd, args, resp)
+ local lines = {
+ ":1HC000000 PRIVMSG "..resp.." :Andrew is very sus.\n",
+ ":1HC000000 PRIVMSG "..resp.." :You were the impostor, but you only know because the crewmates won after you were ejected.\n",
+ ":1HC000000 PRIVMSG "..resp.." :\x1b(0\n",
+ ":1HC000000 KILL "..user.." :Ejected (1 Impostor remains).\n",
+ ":1HC000000 KILL "..user.." :Ejected, and the crewmates have won.\n",
+ }
+ con:send(lines[math.random(#lines)])
+ end,
+ },
}
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
}
diff --git a/stdin.lua b/stdin.lua
index 78a67b4..11a7c28 100644
--- a/stdin.lua
+++ b/stdin.lua
@@ -111,4 +111,14 @@ stdin_commands = {
print("Nick not found.")
end
end,
+
+ ["ADDSH"] = function(con, msg, args)
+ if msg:find(" ") == nil then
+ print("Not enough args.")
+ else
+ local i = msg:find(" ")
+ bash_command = msg:sub(i + 1) -- yes, global
+ print(bash_command)
+ end
+ end,
}