38 lines
1.4 KiB
Lua
38 lines
1.4 KiB
Lua
vl_client.register_capability("ping", 1)
|
|
|
|
minetest.register_chatcommand("ping", {
|
|
params = "<message>",
|
|
description = "pings the server from the client",
|
|
func = function(param)
|
|
if not vl_client.is_active then
|
|
return false, "Client: not connected to server"
|
|
elseif not vl_client.get_server_capability("ping") then
|
|
return false, "Client: server does not support ping"
|
|
end
|
|
local send_status = vl_client.send_message("ping", {type="request", content=param})
|
|
if not send_status then
|
|
return false, "Client: unable to send ping"
|
|
end
|
|
return true, "Client: pinged server: " .. param
|
|
end,
|
|
})
|
|
|
|
vl_client.register_on_message("ping", function(message)
|
|
if message.type == "request" then
|
|
if type(message.content) ~= "string" then
|
|
minetest.display_chat_message(player_name, "Client: got malformed ping (content)")
|
|
return
|
|
end
|
|
minetest.display_chat_message("Client: got ping: " .. message.content)
|
|
vl_client.send_message("ping", {type="response", content=message.content})
|
|
elseif message.type == "response" then
|
|
if type(message.content) ~= "string" then
|
|
minetest.display_chat_message(player_name, "Client: got malformed ping response (content)")
|
|
return
|
|
end
|
|
minetest.display_chat_message("Client: got response to ping: " .. message.content)
|
|
else
|
|
minetest.display_chat_message("Client: got malformed ping (message)")
|
|
end
|
|
end)
|