From ca7e96bcbcaf4d084bfaaa8cd00dd66b381ace08 Mon Sep 17 00:00:00 2001 From: bitpredator <67551273+bitpredator@users.noreply.github.com> Date: Thu, 28 Nov 2024 17:46:40 +0100 Subject: [PATCH] chore: set the ping limit to 600ms --- .../esx_scoreboard/client/main.lua | 2 - .../esx_scoreboard/server/main.lua | 190 +++++++++--------- 2 files changed, 93 insertions(+), 99 deletions(-) diff --git a/server-data/resources/[esx_addons]/esx_scoreboard/client/main.lua b/server-data/resources/[esx_addons]/esx_scoreboard/client/main.lua index 922a1ec6e..98f655c3a 100644 --- a/server-data/resources/[esx_addons]/esx_scoreboard/client/main.lua +++ b/server-data/resources/[esx_addons]/esx_scoreboard/client/main.lua @@ -155,8 +155,6 @@ Citizen.CreateThread(function() if IsControlJustReleased(0, Keys["F10"]) and IsInputDisabled(0) then ToggleScoreBoard() Citizen.Wait(200) - - -- D-pad up on controllers works, too! elseif IsControlJustReleased(0, 172) and not IsInputDisabled(0) then ToggleScoreBoard() Citizen.Wait(200) diff --git a/server-data/resources/[esx_addons]/esx_scoreboard/server/main.lua b/server-data/resources/[esx_addons]/esx_scoreboard/server/main.lua index 8020c41a8..4e2ee8a68 100644 --- a/server-data/resources/[esx_addons]/esx_scoreboard/server/main.lua +++ b/server-data/resources/[esx_addons]/esx_scoreboard/server/main.lua @@ -3,150 +3,146 @@ local connectedPlayers = {} ESX = exports["es_extended"]:getSharedObject() ESX.RegisterServerCallback("esx_scoreboard:getConnectedPlayers", function(_, cb) - cb(connectedPlayers) + cb(connectedPlayers) end) AddEventHandler("esx:playerLoaded", function(_, xPlayer) - AddPlayerToScoreboard(xPlayer, true) + AddPlayerToScoreboard(xPlayer, true) end) AddEventHandler("esx:playerDropped", function(playerId) - connectedPlayers[playerId] = nil + connectedPlayers[playerId] = nil - TriggerClientEvent("esx_scoreboard:updateConnectedPlayers", -1, connectedPlayers) + TriggerClientEvent("esx_scoreboard:updateConnectedPlayers", -1, connectedPlayers) end) Citizen.CreateThread(function() - while true do - Citizen.Wait(5000) - UpdatePing() - end + while true do + Citizen.Wait(5000) + UpdatePing() + end end) AddEventHandler("onResourceStart", function(resource) - if resource == GetCurrentResourceName() then - Citizen.CreateThread(function() - Citizen.Wait(1000) - AddPlayersToScoreboard() - end) - end + if resource == GetCurrentResourceName() then + Citizen.CreateThread(function() + Citizen.Wait(1000) + AddPlayersToScoreboard() + end) + end end) function AddPlayerToScoreboard(xPlayer, update) - local playerId = xPlayer.source - - connectedPlayers[playerId] = {} - connectedPlayers[playerId].ping = GetPlayerPing(playerId) - connectedPlayers[playerId].id = playerId - connectedPlayers[playerId].name = GetPlayerName(playerId) - - if update then - TriggerClientEvent("esx_scoreboard:updateConnectedPlayers", -1, connectedPlayers) - end - - if xPlayer.permission_level == 0 then - Citizen.CreateThread(function() - Citizen.Wait(3000) - TriggerClientEvent("esx_scoreboard:toggleID", playerId, false) - end) - end + local playerId = xPlayer.source + + connectedPlayers[playerId] = {} + connectedPlayers[playerId].ping = GetPlayerPing(playerId) + connectedPlayers[playerId].id = playerId + connectedPlayers[playerId].name = GetPlayerName(playerId) + + if update then + TriggerClientEvent("esx_scoreboard:updateConnectedPlayers", -1, connectedPlayers) + end + + if xPlayer.permission_level == 0 then + Citizen.CreateThread(function() + Citizen.Wait(3000) + TriggerClientEvent("esx_scoreboard:toggleID", playerId, false) + end) + end end function AddPlayersToScoreboard() - local players = ESX.GetPlayers() + local players = ESX.GetPlayers() - for i = 1, #players, 1 do - local xPlayer = ESX.GetPlayerFromId(players[i]) - AddPlayerToScoreboard(xPlayer, false) - end + for i = 1, #players, 1 do + local xPlayer = ESX.GetPlayerFromId(players[i]) + AddPlayerToScoreboard(xPlayer, false) + end - TriggerClientEvent("esx_scoreboard:updateConnectedPlayers", -1, connectedPlayers) + TriggerClientEvent("esx_scoreboard:updateConnectedPlayers", -1, connectedPlayers) end function UpdatePing() - for k, v in pairs(connectedPlayers) do - v.ping = GetPlayerPing(k) - TriggerClientEvent("status:updatePing", k, v.ping) - end - TriggerClientEvent("esx_scoreboard:updatePing", -1, connectedPlayers) + for k, v in pairs(connectedPlayers) do + v.ping = GetPlayerPing(k) + TriggerClientEvent("status:updatePing", k, v.ping) + end + TriggerClientEvent("esx_scoreboard:updatePing", -1, connectedPlayers) end RegisterCommand("screfresh", function(source) - local xPlayer = ESX.GetPlayerFromId(source) + local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer.getGroup() == "admin" or xPlayer.getGroup() == "admin" then - AddPlayersToScoreboard() - else - TriggerClientEvent("chatMessage", source, "[CONSOLE]", { 255, 0, 0 }, " ^0Shoma ^1Admin ^0nistid!") - end + if xPlayer.getGroup() == "admin" or xPlayer.getGroup() == "admin" then + AddPlayersToScoreboard() + else + TriggerClientEvent("chatMessage", source, "[CONSOLE]", { 255, 0, 0 }, " ^0Shoma ^1Admin ^0nistid!") + end end, false) RegisterCommand("sctoggle", function(source) - local xPlayer = ESX.GetPlayerFromId(source) + local xPlayer = ESX.GetPlayerFromId(source) - if xPlayer.getGroup() == "admin" or xPlayer.getGroup() == "admin" then - TriggerClientEvent("esx_scoreboard:toggleID", source) - else - TriggerClientEvent("chatMessage", source, "[CONSOLE]", { 255, 0, 0 }, " ^0Shoma ^1Admin ^0nistid!") - end + if xPlayer.getGroup() == "admin" or xPlayer.getGroup() == "admin" then + TriggerClientEvent("esx_scoreboard:toggleID", source) + else + TriggerClientEvent("chatMessage", source, "[CONSOLE]", { 255, 0, 0 }, " ^0Shoma ^1Admin ^0nistid!") + end end, false) -- Ping Kick -local limit = GetConvarInt("pingkick", 200) +local limit = GetConvarInt("pingkick", 600) local checkInterval = GetConvarInt("pingkick_interval", 5000) -local warningStr = GetConvar("pingkick_warning", "Your ping is too high. Fix it. (%dms, Warning: %d/3)") -local reasonStr = GetConvar("pingkick_reason", "You were kicked for having a high ping. (%dms)") +local warningStr = GetConvar("pingkick_warning", "Il tuo ping è troppo alto. (%dms, Warning: %d/3)") +local reasonStr = GetConvar("pingkick_reason", "Sei stato espulso perché avevi un ping alto. (%dms)") local pingHits = {} print("Limit set to " .. limit) local function CheckPing(player) - CreateThread(function() - if GetPlayerPed(player) == 0 then - return - end -- Don't do anything if player doesn't have a ped yet - - local name = GetPlayerName(player) - local ping = GetPlayerPing(player) - - if pingHits[player] == nil then - pingHits[player] = 0 - end - - if ping >= limit then - pingHits[player] = pingHits[player] + 1 - - print(name .. " was warned. (Ping: " .. ping .. "ms, Warning: " .. pingHits[player] .. "/3)") - TriggerClientEvent( - "chat:addMessage", - player, - { args = { "Ping", warningStr:format(ping, pingHits[player]) } } - ) - elseif pingHits[player] > 0 then - pingHits[player] = pingHits[player] - 1 - end - - if pingHits[player] == 3 then - pingHits[player] = 0 - - print(name .. " was kicked. (Ping: " .. ping .. "ms)") - - DropPlayer(player, reasonStr:format(ping)) - end - end) + CreateThread(function() + if GetPlayerPed(player) == 0 then + return + end -- Don't do anything if player doesn't have a ped yet + + local name = GetPlayerName(player) + local ping = GetPlayerPing(player) + + if pingHits[player] == nil then + pingHits[player] = 0 + end + + if ping >= limit then + pingHits[player] = pingHits[player] + 1 + + print(name .. " was warned. (Ping: " .. ping .. "ms, Warning: " .. pingHits[player] .. "/3)") + TriggerClientEvent("chat:addMessage", player, { args = { "Ping", warningStr:format(ping, pingHits[player]) } }) + elseif pingHits[player] > 0 then + pingHits[player] = pingHits[player] - 1 + end + + if pingHits[player] == 3 then + pingHits[player] = 0 + + print(name .. " was kicked. (Ping: " .. ping .. "ms)") + + DropPlayer(player, reasonStr:format(ping)) + end + end) end CreateThread(function() -- Loop trough all players and check their pings - while true do - for _, player in ipairs(GetPlayers()) do - CheckPing(player) - end + while true do + for _, player in ipairs(GetPlayers()) do + CheckPing(player) + end - Wait(checkInterval) - end + Wait(checkInterval) + end end) AddEventHandler("playerDropped", function() - pingHits[source] = 0 + pingHits[source] = 0 end)