Update main.lua

Added database spam prevention
This commit is contained in:
Andyyy7666
2021-12-25 00:55:11 +01:00
committed by GitHub
parent 2a54af2a52
commit d43dc7d750

View File

@@ -93,17 +93,21 @@ RegisterNetEvent("newCharacter")
AddEventHandler("newCharacter", function(newCharacter) AddEventHandler("newCharacter", function(newCharacter)
local player = source local player = source
local license = GetPlayerIdentifierFromType("license", player) local license = GetPlayerIdentifierFromType("license", player)
exports.oxmysql:execute("SELECT MAX(character_id) AS nextID FROM characters WHERE license = ?", {license}, function(result) exports.oxmysql:execute("SELECT character_id FROM characters WHERE license = ?", {GetPlayerIdentifierFromType("license", player)}, function(result)
if result then if (result) and (config.characterLimit > #result) then
character_id = result[1].nextID exports.oxmysql:execute("SELECT MAX(character_id) AS nextID FROM characters WHERE license = ?", {license}, function(result)
if not character_id then if result then
character_id = 1 character_id = result[1].nextID
else if not character_id then
character_id = character_id + 1 character_id = 1
end else
exports.oxmysql:execute("INSERT INTO characters (license, character_id, first_name, last_name, dob, gender, twt, department, cash, bank) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", {license, character_id, newCharacter.firstName, newCharacter.lastName, newCharacter.dateOfBirth, newCharacter.gender, newCharacter.twtName, newCharacter.department, newCharacter.startingCash, newCharacter.startingBank}, function(id) character_id = character_id + 1
if id then end
TriggerClientEvent("returnNewCharacter", player, id, newCharacter) exports.oxmysql:execute("INSERT INTO characters (license, character_id, first_name, last_name, dob, gender, twt, department, cash, bank) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", {license, character_id, newCharacter.firstName, newCharacter.lastName, newCharacter.dateOfBirth, newCharacter.gender, newCharacter.twtName, newCharacter.department, newCharacter.startingCash, newCharacter.startingBank}, function(id)
if id then
TriggerClientEvent("returnNewCharacter", player, id, newCharacter)
end
end)
end end
end) end)
end end