brouznouf / fivem-mysql-async

MySql Async Library for FiveM
MIT License
111 stars 106 forks source link

Server crash if use API with "CancelEvent()" in "playerConnecting" even #58

Closed EagleonePrimo closed 4 years ago

EagleonePrimo commented 5 years ago

like topic if i use API with "CancelEvent()" it make server crash

i'm do every test with "CancelEvent()". if it not have to work with API it work fine.

if u don't understand my english i'm sorry about that.

Event

AddEventHandler('playerConnecting', function(name, setReason)
    local steamID = GetPlayerIdentifiers(source)[1]
    --Check ban
    if isBanned(steamID) then
        debugMsg('Banned player has join : ('..steamID ..') (Kicked)')
        setReason('ID has banned!')
        CancelEvent()
    end
end)

Function

function isBanned(id)
    local result = MySQL.Sync.fetchAll('SELECT * FROM bans WHERE steam = @steam', {['@steam'] = id['steam']})
    for _,v in pairs(result) do
        if v.expires > v.timestamp then
            return true
        end
    end
end
ghost commented 5 years ago

CancelEvent will not work in this place, since Sync needs one server tick to answer, e.g. your code waits in that if.

And canceling an event for the last tick, on the next tick, does obviously not work.