From cfdb8f51facb0f06e38c89fedeeb0fe3bce4d5e5 Mon Sep 17 00:00:00 2001 From: arpruss Date: Thu, 24 Sep 2015 22:35:25 -0500 Subject: [PATCH] supports chat.post() and nothing else: how useless --- init.lua | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 init.lua diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..6709135 --- /dev/null +++ b/init.lua @@ -0,0 +1,37 @@ +local socket = require("socket") +local server = socket.bind("*", 4711) +server:settimeout(0) + +local clientlist = {} + +minetest.register_globalstep(function(dtime) + local newclient,err = server:accept() + if not err then + newclient:settimeout(0) + table.insert(clientlist, newclient) + print("RJM client connected") + end + for i = 1, #clientlist do + local line,err = clientlist[i]:receive() + if err == "closed" then + table.remove(clientlist, i) + print("RJM client disconnected") + break -- The other clients won't be processed on this tick, alas + elseif not err then + handlecommand(clientlist[i], line) + end + end +end) + +function handlecommand(client, line) + print("Command received: "..line) + local cmd, argtext = string.match(line, "([^(]+)%((.*)%)") + local args = {} + for arg in string.gmatch(argtext, "([^,]+)") do + table.insert(args, arg) + end + if cmd == "chat.post" then + minetest.chat_send_all(argtext) + end +end +