Improved ping command

This commit is contained in:
WillConker 2024-07-03 16:57:46 +01:00
parent 2bfdf57601
commit 786dd12dc6
1 changed files with 13 additions and 4 deletions

View File

@ -4,17 +4,26 @@ minetest.register_chatcommand("ping", {
params = "<message>", params = "<message>",
description = "pings the server from the client", description = "pings the server from the client",
func = function(param) func = function(param)
minetest.debug("Pinging...")
vl_client.send_message("ping", {type="request", content=param}) vl_client.send_message("ping", {type="request", content=param})
return true return true, "Client: pinged server: " .. param
end, end,
}) })
vl_client.register_on_message("ping", function(message) vl_client.register_on_message("ping", function(message)
if message.type == "request" then 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}) 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 else
minetest.debug("Client received server response to ping with content:", message.content) minetest.display_chat_message("Client: got malformed ping (message)")
end end
end) end)