ElCeejo / draconis

Adds Dragons and related resources and equipment to Minetest Game
MIT License
18 stars 23 forks source link

Add missing null check for player in both fire_dragon.lua and ice_dragon.lua at line 92 #15

Closed mightyjoe781 closed 2 years ago

mightyjoe781 commented 2 years ago

Server stack traceback

2022-01-27 02:57:07: ERROR[Main]: ServerError: AsyncErr: ServerThread::run Lua: Runtime error from mod '??' in callback luaentity_Step(): ...ds/adventure/worldmods/draconis/mobs/fire_dragon.lua:92: attempt to index local 'player' (a nil value)
2022-01-27 02:57:07: ERROR[Main]: stack traceback:
2022-01-27 02:57:07: ERROR[Main]:       ...ds/adventure/worldmods/draconis/mobs/fire_dragon.lua:92: in function 'logic'
2022-01-27 02:57:07: ERROR[Main]:       ...me/prismo/worlds/adventure/worldmods/mobkit/init.lua:847: in function 'stepfunc'
2022-01-27 02:57:07: ERROR[Main]:       ...e/prismo/worlds/adventure/worldmods/mob_core/api.lua:1172: in function 'on_step'
2022-01-27 02:57:07: ERROR[Main]:       ...ismo/worlds/adventure/worldmods/draconis/api/api.lua:1276: in function <...ismo/worlds/adventure/worldmods/draconis/api/api.lua:1263>

Issue can be replicated by hatching a baby dragon and putting it on your shoulder and then leaving the server, global step runs and tries to get the player which is null because he left.

Note : I tried adding null check to error lines and that fixes the crash but issue is that dragon disappears when the player rejoins.

mightyjoe781 commented 2 years ago

I tried this fix, please review if you feel this is correct then i can open up a PR :) in file mobs/fire_dragon.lua and ice_dragon.lua. NOTE : this fix preserves dragon in world even though player logs out.

    if self.shoulder_mounted then
        local player = minetest.get_player_by_name(self.owner)
        if not player then
            self.object:set_detach()
            self.shoulder_mounted = mobkit.remember(self, "shoulder_mounted", false)
            self.object:set_properties({
                physical = true,
                collide_with_objects = true
            })
        end
        if player and player:get_player_control().sneak == true
        or self.age > 4 then
            self.object:set_detach()
            self.shoulder_mounted = mobkit.remember(self, "shoulder_mounted", false)
            self.object:set_properties({
                physical = true,
                collide_with_objects = true
            })
        end
    end

This logic checks if the dragon is attached to a player but player is nil (cause he logged out) then we detach the dragon and place it in world.

mightyjoe781 commented 2 years ago

Been fixed in latest commit for 2.0 releases