supports chat.post() and nothing else: how useless

This commit is contained in:
arpruss 2015-09-24 22:35:25 -05:00
parent 8897c67f46
commit cfdb8f51fa

37
init.lua Normal file
View File

@ -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