Bugfix: on_disconnect wasn't called | remove player callbacks are now called AFTER the removal

This commit is contained in:
Zughy 2020-11-09 01:37:57 +01:00
parent b7ee1dd971
commit bd661d6477
6 changed files with 18 additions and 18 deletions

View File

@ -352,7 +352,7 @@ There are also some other functions which might turn useful. They are:
* `arena_lib.is_player_in_same_team(arena, p_name, t_name)`: compares two players teams by the players names. Returns true if on the same team, false if not
* `arena_lib.is_team_declared(mod_ref, team_name)`: returns true if there is a team called `team_name`. Otherwise it returns false
* `arena_lib.force_arena_ending(mod, arena, <sender>)`: forcibly ends an ongoing game. It's usually called by `/forceend`, but it can be used, for instance, to annul a game.
* `arena_lib.remove_player_from_arena(p_name, <reason>, <executioner>)`: removes the player from the arena and it brings back the player to the lobby if still online. Reason is an int, and if specified equals to...
* `arena_lib.remove_player_from_arena(p_name, reason, <executioner>)`: removes the player from the arena and it brings back the player to the lobby if still online. Reason is an int, and it equals to...
* `0`: player disconnected. Calls `on_disconnect`
* `1`: player eliminated. Calls `on_eliminate` if declared. Otherwise calls `on_quit`
* `2`: player kicked. Calls `on_kick` if declared. Otherwise calls `on_quit`

26
api.lua
View File

@ -1037,9 +1037,6 @@ function arena_lib.end_arena(mod_ref, mod, arena)
players_in_game[pl_name] = nil
operations_before_leaving_arena(mod_ref, arena, pl_name)
-- svuoto lo storaggio temporaneo
players_temp_storage[pl_name] = nil
end
@ -1237,6 +1234,7 @@ function arena_lib.remove_player_from_arena(p_name, reason, executioner)
-- reason 2 = has been kicked
-- reason 3 = has quit the arena
-- reason 4 = has been forced to quit the arena
assert(reason, "[ARENA_LIB] 'remove_player_from_arena': A reason must be specified!")
-- se il giocatore non è in partita, annullo
if not arena_lib.is_player_in_arena(p_name) then return end
@ -1245,6 +1243,15 @@ function arena_lib.remove_player_from_arena(p_name, reason, executioner)
local mod_ref = arena_lib.mods[mod]
local arena = arena_lib.get_arena_by_player(p_name)
-- lo rimuovo
players_in_game[p_name] = nil
arena.players_amount = arena.players_amount - 1
if arena.teams_enabled then
local p_team_ID = arena.players[p_name].teamID
arena.players_amount_per_team[p_team_ID] = arena.players_amount_per_team[p_team_ID] - 1
end
arena.players[p_name] = nil
-- se una ragione è specificata
if reason ~= 0 then
@ -1297,16 +1304,6 @@ function arena_lib.remove_player_from_arena(p_name, reason, executioner)
end
end
-- lo rimuovo
players_in_game[p_name] = nil
players_temp_storage[p_name] = nil
arena.players_amount = arena.players_amount - 1
if arena.teams_enabled then
local p_team_ID = arena.players[p_name].teamID
arena.players_amount_per_team[p_team_ID] = arena.players_amount_per_team[p_team_ID] - 1
end
arena.players[p_name] = nil
-- se il termine dell'arena è stato forzato, non c'è bisogno di andare oltre
if reason == 4 then return end
@ -1933,6 +1930,9 @@ function operations_before_leaving_arena(mod_ref, arena, p_name)
-- riattivo la minimappa eventualmente disattivata
player:hud_set_flags({minimap = true})
-- svuoto lo storage temporaneo
players_temp_storage[p_name] = nil
end

View File

@ -1,4 +1,4 @@
local version = "4.1.0"
local version = "4.2.0-dev"
dofile(minetest.get_modpath("arena_lib") .. "/api.lua")
dofile(minetest.get_modpath("arena_lib") .. "/callbacks.lua")

View File

@ -1,4 +1,4 @@
# version 4.1.0
# version 4.2.0-dev
# author(s): Zughy
# reviewer(s):
# textdomain: arena_lib

View File

@ -1,4 +1,4 @@
# version 4.1.0
# version 4.2.0-dev
# author(s):
# reviewer(s):
# textdomain: arena_lib

View File

@ -28,7 +28,7 @@ minetest.register_on_leaveplayer(function(player)
local p_name = player:get_player_name()
if arena_lib.is_player_in_arena(p_name) then
arena_lib.remove_player_from_arena(p_name)
arena_lib.remove_player_from_arena(p_name, 0)
elseif arena_lib.is_player_in_queue(p_name) then
arena_lib.remove_from_queue(p_name)
elseif arena_lib.is_player_in_edit_mode(p_name) then