forked from Mineclonia/Mineclonia
Fix server crash by client leaving after joining
When a player joins and immediately leaves the game before a function is called by minetest.after() in mods/PLAYER/wieldview/init.lua, it gets an invalidated player object. This results in the player methods returning nil (since Minetest 5.2); perhaps surprisingly, the player is not nil. Not checking that the result of player:get_pos() is not nil could lead to a server crash if a client crashed when joining. It has been reported that a syntax error in a client side mod was enough to trigger that.
This commit is contained in:
parent
3cd4ad5591
commit
10ce37d887
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue