Bugfixes: player disconnecting while in queue crashed the server | player joining an ongoing match led to a crash

This commit is contained in:
Marco 2020-04-04 17:47:07 +02:00
parent 3a1ab732d4
commit 9344c0e643
3 changed files with 25 additions and 8 deletions

19
api.lua
View File

@ -457,7 +457,11 @@ end
function arena_lib.remove_player_from_arena(p_name) function arena_lib.remove_player_from_arena(p_name)
local arena_ID = players_in_game[p_name] local arena_ID
if players_in_game[p_name] == nil then arena_ID = players_in_queue[p_name]
else arena_ID = players_in_game[p_name]
end
local arena = arena_lib.arenas[arena_ID] local arena = arena_lib.arenas[arena_ID]
if arena == nil then return end if arena == nil then return end
@ -469,12 +473,23 @@ function arena_lib.remove_player_from_arena(p_name)
arena_lib.update_sign(arena.sign, arena) arena_lib.update_sign(arena.sign, arena)
arena_lib.send_message_players_in_arena(arena_ID, prefix .. p_name .. " ha abbandonato la partita") arena_lib.send_message_players_in_arena(arena_ID, prefix .. p_name .. " ha abbandonato la partita")
if arena_lib.get_arena_players_count(arena_ID) == 1 then if arena.in_queue then
local timer = minetest.get_node_timer(arena.sign)
if arena_lib.get_arena_players_count(arena_ID) < arena.min_players then
timer:stop()
arena.in_queue = false
arena_lib.send_message_players_in_arena(arena_ID, prefix .. "La coda è stata annullata per troppi pochi giocatori")
end
elseif arena_lib.get_arena_players_count(arena_ID) == 1 then
arena_lib.send_message_players_in_arena(arena_ID, prefix .. "Hai vinto la partita per troppi pochi giocatori") arena_lib.send_message_players_in_arena(arena_ID, prefix .. "Hai vinto la partita per troppi pochi giocatori")
for pl_name, stats in pairs(arena.players) do for pl_name, stats in pairs(arena.players) do
arena_lib.on_celebration(arena_ID, pl_name) arena_lib.on_celebration(arena_ID, pl_name)
end end
end end
end end

View File

@ -8,7 +8,9 @@ end)
minetest.register_on_leaveplayer(function(player) minetest.register_on_leaveplayer(function(player)
local p_name = player:get_player_name() local p_name = player:get_player_name()
if arena_lib.get_arenaID_by_player(p_name) == nil then return end if arena_lib.get_arenaID_by_player(p_name) == nil and arena_lib.get_queueID_by_player(p_name) == nil then return end
minetest.chat_send_player("Zughy", "Vado sul remove player")
arena_lib.remove_player_from_arena(p_name) arena_lib.remove_player_from_arena(p_name)
end) end)

View File

@ -45,7 +45,7 @@ minetest.override_item("default:sign_wall", {
-- se non ci sono più abbastanza giocatori, annullo la coda -- se non ci sono più abbastanza giocatori, annullo la coda
if arena_lib.get_arena_players_count(arenaID) < sign_arena.min_players and sign_arena.in_queue then if arena_lib.get_arena_players_count(arenaID) < sign_arena.min_players and sign_arena.in_queue then
--timer:stop() timer:stop()
arena_lib.send_message_players_in_arena(arenaID, prefix .. "La coda è stata annullata per troppi pochi giocatori") arena_lib.send_message_players_in_arena(arenaID, prefix .. "La coda è stata annullata per troppi pochi giocatori")
end end
end end
@ -61,6 +61,10 @@ minetest.override_item("default:sign_wall", {
minetest.chat_send_player(p_name, minetest.colorize("#e6482e", "[!] L'arena è in caricamento, riprova tra qualche secondo!")) minetest.chat_send_player(p_name, minetest.colorize("#e6482e", "[!] L'arena è in caricamento, riprova tra qualche secondo!"))
return end return end
-- aggiungo il giocatore e aggiorno il cartello
sign_arena.players[p_name] = {kills = 0, deaths = 0, killstreak = 0}
arena_lib.update_sign(pos, sign_arena)
-- notifico i vari giocatori del nuovo player -- notifico i vari giocatori del nuovo player
if sign_arena.in_game then if sign_arena.in_game then
arena_lib.join_arena(p_name, arenaID) arena_lib.join_arena(p_name, arenaID)
@ -73,10 +77,6 @@ minetest.override_item("default:sign_wall", {
minetest.chat_send_player(p_name, prefix .. "Ti sei aggiunto alla coda per " .. sign_arena.name) minetest.chat_send_player(p_name, prefix .. "Ti sei aggiunto alla coda per " .. sign_arena.name)
end end
-- aggiungo il giocatore e aggiorno il cartello
sign_arena.players[p_name] = {kills = 0, deaths = 0, killstreak = 0}
arena_lib.update_sign(pos, sign_arena)
local timer = minetest.get_node_timer(pos) local timer = minetest.get_node_timer(pos)
-- se ci sono abbastanza giocatori, parte il timer di attesa -- se ci sono abbastanza giocatori, parte il timer di attesa