Skip to content

Commit

Permalink
Improved Data Get & Ban
Browse files Browse the repository at this point in the history
Fix Xbl, Live,Discord info go in playerip data sql.
Improve Data get from player when ban online.
Add MigrateTo1.0.5.sql
Version change to 1.0.5
  • Loading branch information
RedAlex committed Feb 18, 2019
1 parent 6142631 commit 8536246
Show file tree
Hide file tree
Showing 4 changed files with 139 additions and 49 deletions.
7 changes: 7 additions & 0 deletions MigrateTo1.0.5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE `banlist` ADD `liveid` varchar(21) COLLATE utf8mb4_bin NOT NULL AFTER `license`;
ALTER TABLE `banlist` ADD `xblid` varchar(21) COLLATE utf8mb4_bin NOT NULL AFTER `liveid`;
ALTER TABLE `banlist` ADD `discord` varchar(30) COLLATE utf8mb4_bin NOT NULL AFTER `xblid`;

ALTER TABLE `banlisthistory` ADD `liveid` varchar(21) COLLATE utf8mb4_bin NOT NULL AFTER `license`;
ALTER TABLE `banlisthistory` ADD `xblid` varchar(21) COLLATE utf8mb4_bin NOT NULL AFTER `liveid`;
ALTER TABLE `banlisthistory` ADD `discord` varchar(30) COLLATE utf8mb4_bin NOT NULL AFTER `xblid`;
2 changes: 1 addition & 1 deletion __resource.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resource_manifest_version "44febabe-d386-4d18-afbe-5e627f4af937"

version '1.0.3'
version '1.0.5'

server_scripts {
'@async/async.lua',
Expand Down
16 changes: 12 additions & 4 deletions database.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
DROP TABLE IF EXISTS banlist;
CREATE TABLE IF NOT EXISTS banlist (
identifier varchar(50) COLLATE utf8mb4_bin PRIMARY KEY,
identifier varchar(25) COLLATE utf8mb4_bin PRIMARY KEY,
license varchar(50) COLLATE utf8mb4_bin DEFAULT NULL,
playerip varchar(50) COLLATE utf8mb4_bin DEFAULT NULL,
liveid varchar(21) COLLATE utf8mb4_bin DEFAULT NULL,
xblid varchar(21) COLLATE utf8mb4_bin DEFAULT NULL,
discord varchar(30) COLLATE utf8mb4_bin DEFAULT NULL,
playerip varchar(25) COLLATE utf8mb4_bin DEFAULT NULL,
targetplayername varchar(32) COLLATE utf8mb4_bin NOT NULL,
sourceplayername varchar(32) COLLATE utf8mb4_bin NOT NULL,
reason varchar(255) NOT NULL,
Expand All @@ -11,11 +15,15 @@ CREATE TABLE IF NOT EXISTS banlist (
permanent int(1) NOT NULL DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;

DROP TABLE IF EXISTS banlisthistory;
CREATE TABLE IF NOT EXISTS banlisthistory (
id int(11) AUTO_INCREMENT PRIMARY KEY,
identifier varchar(50) NOT NULL,
identifier varchar(25) NOT NULL,
license varchar(50) COLLATE utf8mb4_bin DEFAULT NULL,
playerip varchar(50) COLLATE utf8mb4_bin DEFAULT NULL,
liveid varchar(21) COLLATE utf8mb4_bin DEFAULT NULL,
xblid varchar(21) COLLATE utf8mb4_bin DEFAULT NULL,
discord varchar(30) COLLATE utf8mb4_bin DEFAULT NULL,
playerip varchar(25) COLLATE utf8mb4_bin DEFAULT NULL,
targetplayername varchar(32) COLLATE utf8mb4_bin NOT NULL,
sourceplayername varchar(32) COLLATE utf8mb4_bin NOT NULL,
reason varchar(255) NOT NULL,
Expand Down
163 changes: 119 additions & 44 deletions server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,16 @@ TriggerEvent('es:addGroupCommand', 'unban', Config.permission, function (source,
end)

TriggerEvent('es:addGroupCommand', 'ban', Config.permission, function (source, args, user)
local target = tonumber(args[1])
local duree = tonumber(args[2])
local reason = table.concat(args, " ",3)
local permanent = 0
local identifier
local license
local liveid
local xblid
local discord
local playerip
local target = tonumber(args[1])
local duree = tonumber(args[2])
local reason = table.concat(args, " ",3)
local permanent = 0

if reason == "" then
reason = Text.noreason
Expand All @@ -137,16 +143,28 @@ TriggerEvent('es:addGroupCommand', 'ban', Config.permission, function (source, a
if duree ~= nil and duree < 365 then
local sourceplayername = GetPlayerName(source)
local targetplayername = GetPlayerName(target)
local identifier = GetPlayerIdentifiers(target)[1]
local license = GetPlayerIdentifiers(target)[2]
local playerip = GetPlayerIdentifiers(target)[3]
for k,v in ipairs(GetPlayerIdentifiers(target))do
if string.sub(v, 1, string.len("steam:")) == "steam:" then
identifier = v
elseif string.sub(v, 1, string.len("license:")) == "license:" then
license = v
elseif string.sub(v, 1, string.len("live:")) == "live:" then
liveid = v
elseif string.sub(v, 1, string.len("xbl:")) == "xbl:" then
xblid = v
elseif string.sub(v, 1, string.len("discord:")) == "discord:" then
discord = v
elseif string.sub(v, 1, string.len("ip:")) == "ip:" then
playerip = v
end
end

if duree > 0 then
ban(source,identifier,license,playerip,targetplayername,sourceplayername,duree,reason,permanent)
ban(source,identifier,license,liveid,xblid,discord,playerip,targetplayername,sourceplayername,duree,reason,permanent)
DropPlayer(target, Text.yourban .. reason)
else
local permanent = 1
ban(source,identifier,license,playerip,targetplayername,sourceplayername,duree,reason,permanent)
ban(source,identifier,license,liveid,xblid,discord,playerip,targetplayername,sourceplayername,duree,reason,permanent)
DropPlayer(target, Text.yourpermban .. reason)
end

Expand Down Expand Up @@ -187,6 +205,9 @@ TriggerEvent('es:addGroupCommand', 'reason', Config.permission, function (source
local reason = table.concat(args, " ",1)
local permanent = 0
local playerip = "0.0.0.0"
local liveid = "offlineban"
local xblid = "offlineban"
local discord = "offlineban"

if Config.esx then
MySQL.Async.fetchScalar('SELECT identifier FROM users WHERE name=@name',
Expand Down Expand Up @@ -216,12 +237,12 @@ TriggerEvent('es:addGroupCommand', 'reason', Config.permission, function (source
local sourceplayername = GetPlayerName(source)

if duree > 0 then
ban(source,steamID,fivemID,playerip,name,sourceplayername,duree,reason,permanent)
ban(source,steamID,fivemID,liveid,xblid,discord,playerip,name,sourceplayername,duree,reason,permanent)
lastduree = ""
lasttarget = ""
else
local permanent = 1
ban(source,steamID,fivemID,playerip,name,sourceplayername,duree,reason,permanent)
ban(source,steamID,fivemID,liveid,xblid,discord,playerip,name,sourceplayername,duree,reason,permanent)
lastduree = ""
lasttarget = ""
end
Expand Down Expand Up @@ -269,7 +290,7 @@ local embeds = {
PerformHttpRequest(DiscordWebHook, function(err, text, headers) end, 'POST', json.encode({ username = name,embeds = embeds}), { ['Content-Type'] = 'application/json' })
end

function ban(source,identifier,license,playerip,targetplayername,sourceplayername,duree,reason,permanent)
function ban(source,identifier,license,liveid,xblid,discord,playerip,targetplayername,sourceplayername,duree,reason,permanent)
--calcul total expiration (en secondes)
local expiration = duree * 86400
local timeat = os.time()
Expand All @@ -281,22 +302,28 @@ function ban(source,identifier,license,playerip,targetplayername,sourceplayernam
table.insert(BanList, {
identifier = identifier,
license = license,
liveid = liveid,
xblid = xblid,
discord = discord,
playerip = playerip,
reason = reason,
expiration = expiration,
permanent = permanent
})

if Config.EnableDiscordLink then
local message = (identifier .." ".. license .." ".. playerip .." ".. targetplayername .. Text.isban .." ".. duree .. Text.forr .. reason .." ".. Text.by .." ".. sourceplayername)
local message = (identifier .." ".. license .." ".. liveid .." ".. xblid .." ".. discord .." ".. playerip .." ".. targetplayername .. Text.isban .." ".. duree .. Text.forr .. reason .." ".. Text.by .." ".. sourceplayername)
sendToDiscord(Config.webhookban, "BanSql", message, Config.red)
end

MySQL.Async.execute(
'INSERT INTO banlist (identifier,license,playerip,targetplayername,sourceplayername,reason,expiration,timeat,permanent) VALUES (@identifier,@license,@playerip,@targetplayername,@sourceplayername,@reason,@expiration,@timeat,@permanent)',
'INSERT INTO banlist (identifier,license,liveid,xblid,discord,playerip,targetplayername,sourceplayername,reason,expiration,timeat,permanent) VALUES (@identifier,@license,@liveid,@xblid,@discord,@playerip,@targetplayername,@sourceplayername,@reason,@expiration,@timeat,@permanent)',
{
['@identifier'] = identifier,
['@license'] = license,
['@liveid'] = liveid,
['@xblid'] = xblid,
['@discord'] = discord,
['@playerip'] = playerip,
['@targetplayername'] = targetplayername,
['@sourceplayername'] = sourceplayername,
Expand All @@ -311,10 +338,13 @@ function ban(source,identifier,license,playerip,targetplayername,sourceplayernam
TriggerEvent('bansql:sendMessage', source, (Text.youban .. targetplayername .. Text.during .. duree .. Text.forr .. reason))

MySQL.Async.execute(
'INSERT INTO banlisthistory (identifier,license,playerip,targetplayername,sourceplayername,reason,expiration,timeat,permanent) VALUES (@identifier,@license,@playerip,@targetplayername,@sourceplayername,@reason,@expiration,@timeat,@permanent)',
'INSERT INTO banlisthistory (identifier,license,liveid,xblid,discord,playerip,targetplayername,sourceplayername,reason,expiration,timeat,permanent) VALUES (@identifier,@license,@liveid,@xblid,@discord,@playerip,@targetplayername,@sourceplayername,@reason,@expiration,@timeat,@permanent)',
{
['@identifier'] = identifier,
['@license'] = license,
['@liveid'] = liveid,
['@xblid'] = xblid,
['@discord'] = discord,
['@playerip'] = playerip,
['@targetplayername'] = targetplayername,
['@sourceplayername'] = sourceplayername,
Expand All @@ -333,17 +363,20 @@ function loadBanList()
MySQL.Async.fetchAll(
'SELECT * FROM banlist',
{},
function (identifiers)
function (data)
BanList = {}

for i=1, #identifiers, 1 do
for i=1, #data, 1 do
table.insert(BanList, {
identifier = identifiers[i].identifier,
license = identifiers[i].license,
playerip = identifiers[i].playerip,
reason = identifiers[i].reason,
expiration = identifiers[i].expiration,
permanent = identifiers[i].permanent
identifier = data[i].identifier,
license = data[i].license,
liveid = data[i].liveid,
xblid = data[i].xblid,
discord = data[i].discord,
playerip = data[i].playerip,
reason = data[i].reason,
expiration = data[i].expiration,
permanent = data[i].permanent
})
end
end
Expand All @@ -354,20 +387,23 @@ function loadBanListHistory()
MySQL.Async.fetchAll(
'SELECT * FROM banlisthistory',
{},
function (identifiers)
function (data)
BanListHistory = {}

for i=1, #identifiers, 1 do
for i=1, #data, 1 do
table.insert(BanListHistory, {
identifier = identifiers[i].identifier,
license = identifiers[i].license,
playerip = identifiers[i].playerip,
targetplayername = identifiers[i].targetplayername,
sourceplayername = identifiers[i].sourceplayername,
reason = identifiers[i].reason,
expiration = identifiers[i].expiration,
permanent = identifiers[i].permanent,
timeat = identifiers[i].timeat
identifier = data[i].identifier,
license = data[i].license,
liveid = data[i].liveid,
xblid = data[i].xblid,
discord = data[i].discord,
playerip = data[i].playerip,
targetplayername = data[i].targetplayername,
sourceplayername = data[i].sourceplayername,
reason = data[i].reason,
expiration = data[i].expiration,
permanent = data[i].permanent,
timeat = data[i].timeat
})
end
end
Expand All @@ -390,10 +426,28 @@ end


AddEventHandler('playerConnecting', function (playerName,setKickReason)
local steamID = GetPlayerIdentifiers(source)[1]
local license = GetPlayerIdentifiers(source)[2]
local playerip = GetPlayerIdentifiers(source)[3]

local steamID = "no info"
local license = "no info"
local liveid = "no info"
local xblid = "no info"
local discord = "no info"
local playerip = "no info"

for k,v in ipairs(GetPlayerIdentifiers(source))do
if string.sub(v, 1, string.len("steam:")) == "steam:" then
steamID = v
elseif string.sub(v, 1, string.len("license:")) == "license:" then
license = v
elseif string.sub(v, 1, string.len("live:")) == "live:" then
liveid = v
elseif string.sub(v, 1, string.len("xbl:")) == "xbl:" then
xblid = v
elseif string.sub(v, 1, string.len("discord:")) == "discord:" then
discord = v
elseif string.sub(v, 1, string.len("ip:")) == "ip:" then
playerip = v
end
end

--Si Banlist pas chargée
if (Banlist == {}) then
Expand All @@ -406,7 +460,15 @@ AddEventHandler('playerConnecting', function (playerName,setKickReason)
end

for i = 1, #BanList, 1 do
if ((tostring(BanList[i].identifier)) == tostring(steamID) or (tostring(BanList[i].license)) == tostring(license) or (tostring(BanList[i].playerip)) == tostring(playerip)) and (tonumber(BanList[i].expiration)) > os.time() and (tonumber(BanList[i].permanent)) == 0 then
if ((tostring(BanList[i].identifier)) == tostring(steamID)
or (tostring(BanList[i].license)) == tostring(license)
or (tostring(BanList[i].liveid)) == tostring(liveid)
or (tostring(BanList[i].xblid)) == tostring(xblid)
or (tostring(BanList[i].discord)) == tostring(discord)
or (tostring(BanList[i].playerip)) == tostring(playerip))
and (tonumber(BanList[i].expiration)) > os.time()
and (tonumber(BanList[i].permanent)) == 0 then

local tempsrestant = (((tonumber(BanList[i].expiration)) - os.time())/60)
if tempsrestant >= 1440 then
local day = (tempsrestant / 60) / 24
Expand Down Expand Up @@ -435,13 +497,26 @@ AddEventHandler('playerConnecting', function (playerName,setKickReason)
end
end

if ((tostring(BanList[i].identifier)) == tostring(steamID) or (tostring(BanList[i].license)) == tostring(license) or (tostring(BanList[i].playerip)) == tostring(playerip)) and (tonumber(BanList[i].permanent)) == 1 then
setKickReason(Text.yourpermban .. BanList[i].reason)
CancelEvent()
if ((tostring(BanList[i].identifier)) == tostring(steamID)
or (tostring(BanList[i].license)) == tostring(license)
or (tostring(BanList[i].liveid)) == tostring(liveid)
or (tostring(BanList[i].xblid)) == tostring(xblid)
or (tostring(BanList[i].discord)) == tostring(discord)
or (tostring(BanList[i].playerip)) == tostring(playerip))
and (tonumber(BanList[i].permanent)) == 1 then
setKickReason(Text.yourpermban .. BanList[i].reason)
CancelEvent()
end

if ((tostring(BanList[i].identifier)) == tostring(steamID) or (tostring(BanList[i].license)) == tostring(license) or (tostring(BanList[i].playerip)) == tostring(playerip)) and (tonumber(BanList[i].expiration)) < os.time() and (tonumber(BanList[i].permanent)) == 0 then
deletebanned(steamID)
if ((tostring(BanList[i].identifier)) == tostring(steamID)
or (tostring(BanList[i].license)) == tostring(license)
or (tostring(BanList[i].liveid)) == tostring(liveid)
or (tostring(BanList[i].xblid)) == tostring(xblid)
or (tostring(BanList[i].discord)) == tostring(discord)
or (tostring(BanList[i].playerip)) == tostring(playerip))
and (tonumber(BanList[i].expiration)) < os.time()
and (tonumber(BanList[i].permanent)) == 0 then
deletebanned(steamID)
end

end
Expand Down

0 comments on commit 8536246

Please sign in to comment.