2019-01-28 21:09:16 +01:00
|
|
|
local http_api = minetest.request_http_api()
|
|
|
|
|
2019-01-22 14:29:16 +01:00
|
|
|
function send_messages(res)
|
|
|
|
for message in string.gmatch(res["data"], "[^\n]+") do
|
2019-01-28 21:35:39 +01:00
|
|
|
if message == "list" then
|
|
|
|
local x = minetest.get_connected_players()
|
|
|
|
local text = "List of Players:\n"
|
|
|
|
for j, i in ipairs(x) do
|
2019-01-29 06:41:19 +01:00
|
|
|
text = text .. "\n" .. i.get_player_name(i)
|
2019-01-28 21:35:39 +01:00
|
|
|
end
|
|
|
|
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
|
|
|
|
post_data = {message = text}})
|
2019-01-28 22:27:31 +01:00
|
|
|
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}})
|
2019-01-28 21:35:39 +01:00
|
|
|
else
|
|
|
|
minetest.chat_send_all(message)
|
|
|
|
end
|
2019-01-22 14:29:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-28 21:09:16 +01:00
|
|
|
function main()
|
2019-01-22 14:29:16 +01:00
|
|
|
port = minetest.settings:get("chat_server_port")
|
|
|
|
if port == nil then
|
|
|
|
port = "9876"
|
|
|
|
end
|
|
|
|
http_api.fetch({url = "http://localhost:" .. port .. "/get"}, send_messages)
|
2019-01-28 21:09:16 +01:00
|
|
|
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."}})
|
2019-01-22 14:29:16 +01:00
|
|
|
end
|
|
|
|
|
2019-01-29 05:27:16 +01:00
|
|
|
function join(player)
|
|
|
|
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
|
|
|
|
post_data = {message = player.get_player_name(player) ..
|
|
|
|
" joined the server."}})
|
|
|
|
end
|
|
|
|
|
|
|
|
function left(player)
|
|
|
|
http_api.fetch_async({url = "http://localhost:" .. port .. "/sendCode",
|
|
|
|
post_data = {message = player.get_player_name(player) ..
|
|
|
|
" left the server."}})
|
|
|
|
end
|
|
|
|
|
|
|
|
function chat(name, message)
|
|
|
|
http_api.fetch_async({url = "http://localhost:" .. port .. "/send",
|
|
|
|
post_data = {message = "<" .. name .. "> " .. message}})
|
|
|
|
end
|
|
|
|
|
2019-01-22 14:35:04 +01:00
|
|
|
if http_api == nil then
|
|
|
|
minetest.log("error", "Chat Mod is not in secure.http_mods or secure.trusted_mods. Exiting.")
|
|
|
|
else
|
2019-01-28 21:09:16 +01:00
|
|
|
main()
|
2019-01-22 14:35:04 +01:00
|
|
|
end
|
2019-01-28 21:09:16 +01:00
|
|
|
minetest.register_on_dieplayer(dead)
|
2019-01-29 05:27:16 +01:00
|
|
|
minetest.register_on_joinplayer(join)
|
|
|
|
minetest.register_on_leaveplayer(left)
|
|
|
|
minetest.register_on_chat_message(chat)
|