otland / forgottenserver

A free and open-source MMORPG server emulator written in C++
https://otland.net
GNU General Public License v2.0
1.57k stars 1.05k forks source link

onStepOut FIXED #4650

Closed MillhioreBT closed 4 months ago

MillhioreBT commented 4 months ago

Pull Request Prelude

Changes Proposed

Currently, there is a scenario where an onStepOut event moves the creature. So, when the creature is removed, the event is triggered, and immediately the onStepOut event will try to move the creature. However, when the creature is removed from the tile, the onStepOut event will call the Map::moveCreature method, which will try to remove the creature from the tile again and also attempt to update the new tile. This results in unexpected behavior and can lead to any undefined behavior, typically a crash.

This fixes the problem by ignoring the movements... perhaps more checks are needed?

Steps to reproduce the problem:

Connect any player. Place the character on top of anything that triggers the onStepOut event. Test onStepOut event:

local leave = MoveEvent()

function leave.onStepOut(creature, item, pos, fromPosition)
    local player = creature:getPlayer()
    if player then player:teleportTo(player:getTown():getTemplePosition()) end
    return true
end

leave:aid(3000)
leave:register()

local talkAction = TalkAction("!test")

function talkAction.onSay(player, words, param, type)
    player:remove()
    return false
end

--talkAction:accountType(ACCOUNT_TYPE_GOD)
--talkAction:access(true)
--talkAction:separator(" ")
talkAction:register()

Issues addressed: Nothing!

ranisalt commented 4 months ago

So this will trigger only if the onStepOut event also moves the player to a different location?

MillhioreBT commented 4 months ago

So this will trigger only if the onStepOut event also moves the player to a different location?

That is correct, although it can also happen with creatures in general, not only with players.