Improved ping command
This commit is contained in:
parent
2bfdf57601
commit
786dd12dc6
17
ping.lua
17
ping.lua
|
@ -4,17 +4,26 @@ minetest.register_chatcommand("ping", {
|
|||
params = "<message>",
|
||||
description = "pings the server from the client",
|
||||
func = function(param)
|
||||
minetest.debug("Pinging...")
|
||||
vl_client.send_message("ping", {type="request", content=param})
|
||||
return true
|
||||
return true, "Client: pinged server: " .. param
|
||||
end,
|
||||
})
|
||||
|
||||
vl_client.register_on_message("ping", function(message)
|
||||
if message.type == "request" then
|
||||
minetest.debug("Client received ping with content:", message.content)
|
||||
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.debug("Client received server response to ping with content:", message.content)
|
||||
minetest.display_chat_message("Client: got malformed ping (message)")
|
||||
end
|
||||
end)
|
||||
|
|
Loading…
Reference in New Issue