45 lines
1.3 KiB
Lua
45 lines
1.3 KiB
Lua
local http_api = minetest.request_http_api()
|
|
|
|
function send_messages(res)
|
|
for message in string.gmatch(res["data"], "[^\n]+") do
|
|
if message == "list" then
|
|
local x = minetest.get_connected_players()
|
|
local text = "List of Players:\n"
|
|
for j, i in ipairs(x) do
|
|
local text = text .. i.get_player_name(i)
|
|
end
|
|
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
|
|
post_data = {message = text}})
|
|
elseif message == "time" then
|
|
local x = minetest.get_timeofday()
|
|
local text = string.format("%02d:%02d", math.floor(x*24), math.floor((x*24*60) % 60))
|
|
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
|
|
post_data = {message = text}})
|
|
else
|
|
minetest.chat_send_all(message)
|
|
end
|
|
end
|
|
end
|
|
|
|
function main()
|
|
port = minetest.settings:get("chat_server_port")
|
|
if port == nil then
|
|
port = "9876"
|
|
end
|
|
http_api.fetch({url = "http://localhost:" .. port .. "/get"}, send_messages)
|
|
minetest.after(0.5, main)
|
|
end
|
|
|
|
function dead(player)
|
|
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
|
|
post_data = {message = player.get_player_name(player) ..
|
|
" died."}})
|
|
end
|
|
|
|
if http_api == nil then
|
|
minetest.log("error", "Chat Mod is not in secure.http_mods or secure.trusted_mods. Exiting.")
|
|
else
|
|
main()
|
|
end
|
|
minetest.register_on_dieplayer(dead)
|