henoireil

Untitled

Aug 21st, 2017
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local ban_list = {}
  2.  
  3. AddEventHandler('onMySQLReady', function()
  4.     MySQL.Async.fetchAll("SELECT banned,reason,expires FROM bans", {}, function(result)
  5.         for k, v in pairs (result) do
  6.             ban_list[v.banned] = {reason = v.reason, expires = v.expires}
  7.         end
  8.     end)
  9. end)
  10.  
  11. RegisterServerEvent("hav_ban_check:AddBan")
  12. AddEventHandler("hav_ban_check:AddBan", function(identifier, reason, expires)
  13.     ban_list[identifier] = {reason = reason, expires = expires}
  14. end)
  15.  
  16. function isIdentifierBanned(id)
  17.     if ban_list[id] ~= nil then
  18.         local expire = tostring(ban_list[id].expires)
  19.         expire = expire:sub(1, -4)
  20.         expire = tonumber(expire)
  21.         if expire > os.time() then
  22.             return ban_list[id].reason
  23.         else
  24.             MySQL.Sync.execute("DELETE FROM bans WHERE banned = @banned",{['@banned'] = id})
  25.             ban_list[id] = nil
  26.         end
  27.     end
  28.  
  29.     return false
  30. end
  31.  
  32. AddEventHandler('playerConnecting', function(name, setCallback)
  33.     local identifier = GetPlayerIdentifiers(source)[1]
  34.     print('Checking user ban: ' .. identifier .. " (" .. name .. ")")
  35.     local banned = isIdentifierBanned(identifier)
  36.     if banned ~= false then
  37.         print("(" .. identifier .. ") " .. name .. " has been kicked because it is on the banlist")
  38.         setCallback(banned)
  39.         CancelEvent()
  40.     end
  41. end)
Add Comment
Please, Sign In to add comment