Added informative return value to vl_client.send_message

This commit is contained in:
WillConker 2024-07-03 17:06:19 +01:00
parent 786dd12dc6
commit a00df30676
2 changed files with 6 additions and 3 deletions

View File

@ -16,7 +16,7 @@ vl_client = {
-- data: table to be sent to server, must be json serialisable
local function send_data(data)
-- TODO: Should channel ever be nil?
if not channel then return end
if not vl_client.is_active then return end
local string_data = minetest.write_json(data)
--minetest.debug("Sending data to server:", string_data)
@ -27,7 +27,7 @@ end
-- opname: the name of the category of this message
-- message: any json-serialisable object (not necessarily table)
function vl_client.send_message(opname, message)
send_data({opname, message})
return send_data({opname, message})
end
-- ON MESSAGE RECEIVED

View File

@ -4,7 +4,10 @@ minetest.register_chatcommand("ping", {
params = "<message>",
description = "pings the server from the client",
func = function(param)
vl_client.send_message("ping", {type="request", content=param})
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,
})