Merge pull request 'PLAYER/wieldview: Fix server crash by client leaving after joining' (#138) from fix-server-crash-by-client-leaving-after-joining into master

Reviewed-on: Mineclonia/Mineclonia#138
Reviewed-by: cora <cora@noreply.git.minetest.land>
This commit is contained in:
cora 2021-08-22 17:26:32 +00:00
commit 78634d4c90
1 changed files with 15 additions and 1 deletions

View File

@ -70,8 +70,22 @@ minetest.register_on_joinplayer(function(player)
local name = player:get_player_name()
wieldview.wielded_item[name] = ""
minetest.after(0, function(player)
-- When a player joins and immediately leaves the game
-- before this function is called by minetest.after(),
-- the player object is invalidated. This results in
-- its methods returning nil (since Minetest 5.2);
-- perhaps surprisingly, the player is not nil.
--
-- Not checking that the position is not nil can lead
-- to a server crash if a client crashes while it is
-- joining. It has been reported that a syntax error
-- in a client side mod was enough to trigger that.
local pos = player:get_pos()
if pos == nil then
return
end
wieldview:update_wielded_item(player)
local itementity = minetest.add_entity(player:get_pos(), "wieldview:wieldnode")
local itementity = minetest.add_entity(pos, "wieldview:wieldnode")
itementity:set_attach(player, "Hand_Right", vector.new(0, 0, 0), vector.new(15, 45, 0))
itementity:get_luaentity().wielder = name
end, player)