beerchat/web/tx.lua

62 lines
1.5 KiB
Lua
Raw Normal View History

2020-01-18 15:09:05 +01:00
local http = beerchat.http
beerchat.on_channel_message = function(channel, playername, message)
local data = {
2020-01-20 10:43:35 +01:00
channel = channel,
username = playername,
2020-01-18 15:09:05 +01:00
message = message
}
local json = minetest.write_json(data)
http.fetch({
url = beerchat.url,
extra_headers = { "Content-Type: application/json" },
timeout = 5,
post_data = json
2020-01-21 13:57:13 +01:00
}, function()
2020-01-18 15:09:05 +01:00
-- ignore errors
end)
end
2020-01-21 13:57:13 +01:00
-- join player message
2020-01-18 15:09:05 +01:00
minetest.register_on_joinplayer(function(player)
beerchat.on_channel_message(nil, nil, "Player " .. player:get_player_name() ..
" joined the game")
end)
2020-01-21 13:57:13 +01:00
-- leave player message
2020-01-18 15:09:05 +01:00
minetest.register_on_leaveplayer(function(player, timed_out)
local msg = player:get_player_name() .. " left the game"
if timed_out then
msg = msg .. " (timed out)"
end
beerchat.on_channel_message(nil, nil, msg)
end)
2020-01-21 13:57:13 +01:00
-- initial message on start
2020-01-18 15:09:05 +01:00
beerchat.on_channel_message(nil, nil, "Minetest started!")
2020-01-21 13:57:13 +01:00
minetest.register_on_shutdown(function()
beerchat.on_channel_message(nil, nil, "Minetest shutting down!")
end)
-- auth fail
minetest.register_on_auth_fail(function(name, ip)
beerchat.on_channel_message("audit", nil, "Player '" .. name ..
"' from ip " .. ip .. " tried to connect with wrong password")
end)
-- anticheat
minetest.register_on_cheat(function(player, cheat)
local playername = player:get_player_name()
local type = cheat.type
beerchat.on_channel_message("audit", nil, "Player '" .. playername ..
"' triggered anticheat: '" .. (type or "<unknown>") ..
"' at position: " .. minetest.pos_to_string(vector.floor(player:get_pos())))
end)