From 5429a4b7e9e5495dff80010b685f6f027739d400 Mon Sep 17 00:00:00 2001 From: Blue <13604413+Bluethefurry@users.noreply.github.com> Date: Fri, 19 Feb 2021 23:42:46 +0100 Subject: [PATCH] add warning system, cleanup bannedjoin string --- admin_server.lua | 38 ++++++++++++++++++++++++++++++++++++++ gui_c.lua | 41 +++++++++++++++++++++++++++++++++++++++++ language/en.json | 12 ++++++++++-- util_shared.lua | 1 + 4 files changed, 90 insertions(+), 2 deletions(-) diff --git a/admin_server.lua b/admin_server.lua index 3c0653b6..13ea40a2 100644 --- a/admin_server.lua +++ b/admin_server.lua @@ -1065,6 +1065,43 @@ Citizen.CreateThread(function() end end + + RegisterServerEvent("EasyAdmin:warnPlayer") + AddEventHandler('EasyAdmin:warnPlayer', function(id, reason) + local src = source + if DoesPlayerHavePermission(src,"easyadmin.warn") and not DoesPlayerHavePermission(id,"easyadmin.immune") then + local maxWarnings = GetConvarInt("ea_maxWarnings", 3) + if not WarnedPlayers[id] then + WarnedPlayers[id] = {name = getName(id), identifiers = getAllPlayerIdentifiers(id), warns = 1} + TriggerClientEvent("chat:addMessage", id, { args = { "EasyAdmin", string.format(GetLocalisedText("warned"), reason, WarnedPlayers[id].warns, maxWarnings) } }) + SendWebhookMessage(moderationNotification,string.format(GetLocalisedText("adminwarnedplayer"), getName(src), getName(id), reason, WarnedPlayers[id].warns, maxWarnings), "warn") + else + WarnedPlayers[id].warns = WarnedPlayers[id].warns+1 + TriggerClientEvent("chat:addMessage", id, { args = { "EasyAdmin", string.format(GetLocalisedText("warned"), reason, WarnedPlayers[id].warns, maxWarnings) } }) + SendWebhookMessage(moderationNotification,string.format(GetLocalisedText("adminwarnedplayer"), getName(src), getName(id), reason, WarnedPlayers[id].warns, maxWarnings), "warn") + end + if WarnedPlayers[id].warns >= maxWarnings then + if GetConvar("ea_warnAction", "kick") == "kick" then + SendWebhookMessage(moderationNotification,string.format(GetLocalisedText("adminkickedplayer"), getName(src), getName(id), reason), "kick") + DropPlayer(id, GetLocalisedText("warnkicked")) + WarnedPlayers[id] = nil + elseif GetConvar("ea_warnAction", "kick") == "ban" then + local bannedIdentifiers = CachedPlayers[id].identifiers or getAllPlayerIdentifiers(id) + local username = CachedPlayers[id].name or GetPlayerName(id) + local expires = GetConvarInt("ea_warningBanTime", 604800) + + reason = GetLocalisedText("warnbanned").. string.format(GetLocalisedText("reasonadd"), CachedPlayers[id].name, getName(source) ) + local ban = {banid = GetFreshBanId(), name = username,identifiers = bannedIdentifiers, banner = getName(source, true), reason = reason, expire = expires } + updateBlacklist( ban ) + PrintDebugMessage("Player "..getName(source,true).." warnbanned player "..CachedPlayers[id].name.." for "..reason) + SendWebhookMessage(moderationNotification,string.format(GetLocalisedText("adminbannedplayer"), getName(source), CachedPlayers[id].name, reason, os.date('%d/%m/%Y %H:%M:%S', expires ) ), "ban") + DropPlayer(id, string.format(GetLocalisedText("banned"), reason, os.date('%d/%m/%Y %H:%M:%S', expires ) ) ) + WarnedPlayers[id] = nil + end + end + end + end) + function performBanlistUpgrades() for i,ban in pairs(blacklist) do if type(i) == "string" then @@ -1271,6 +1308,7 @@ MutedPlayers = {} -- DO NOT TOUCH THIS CachedPlayers = {} -- DO NOT TOUCH THIS OnlineAdmins = {} -- DO NOT TOUCH THIS ChatReminders = {} -- DO NOT TOUCH THIS +WarnedPlayers = {} -- DO NOT TOUCH THESE -- DO NOT TOUCH THESE -- DO NOT TOUCH THESE diff --git a/gui_c.lua b/gui_c.lua index ea787937..50b72be9 100644 --- a/gui_c.lua +++ b/gui_c.lua @@ -402,6 +402,47 @@ function GenerateMenu() -- this is a big ass function TriggerServerEvent("EasyAdmin:TakeScreenshot", thePlayer.id) end end + + if permissions["warn"] then + local thisWarnMenu = _menuPool:AddSubMenu(thisPlayer,GetLocalisedText("warnplayer"),"",true) + thisWarnMenu:SetMenuWidthOffset(menuWidth) + + local thisItem = NativeUI.CreateItem(GetLocalisedText("reason"),GetLocalisedText("warnreasonguide")) + thisWarnMenu:AddItem(thisItem) + WarnReason = GetLocalisedText("noreason") + thisItem:RightLabel(WarnReason) + thisItem.Activated = function(ParentMenu,SelectedItem) + DisplayOnscreenKeyboard(1, "FMMC_KEY_TIP8", "", "", "", "", "", 128 + 1) + + while UpdateOnscreenKeyboard() ~= 1 and UpdateOnscreenKeyboard() ~= 2 do + Citizen.Wait( 0 ) + end + + local result = GetOnscreenKeyboardResult() + + if result and result ~= "" then + WarnReason = result + thisItem:RightLabel(result) -- this is broken for now + else + WarnReason = GetLocalisedText("noreason") + end + end + + local thisItem = NativeUI.CreateItem(GetLocalisedText("confirmwarn"),GetLocalisedText("confirmwarnguide")) + thisWarnMenu:AddItem(thisItem) + thisItem.Activated = function(ParentMenu,SelectedItem) + if WarnReason == "" then + WarnReason = GetLocalisedText("noreason") + end + TriggerServerEvent("EasyAdmin:warnPlayer", thePlayer.id, WarnReason) + BanTime = 1 + BanReason = "" + _menuPool:CloseAllMenus() + Citizen.Wait(800) + GenerateMenu() + playermanagement:Visible(true) + end + end _menuPool:ControlDisablingEnabled(false) _menuPool:MouseControlsEnabled(false) diff --git a/language/en.json b/language/en.json index 10b10d67..ebc248d3 100644 --- a/language/en.json +++ b/language/en.json @@ -76,7 +76,7 @@ "chatsuggestionslap": "slap a player", "chatsuggestionfreeze": "freeze a player", - "bannedjoin": "You have been banned from this Server, \nReason: %s, Ban Expires: %s", + "bannedjoin": "\nYou have been banned from this Server\n\nReason: %s\n\nBan Expires: %s", "kicked": "Kicked by %s, Reason: %s", "banned": "You have been banned from this Server, Reason: %s, Ban Expires: %s", "reasonadd": " ( Nickname: %s ), Banned by: %s", @@ -127,5 +127,13 @@ "teleportedtoplayer": "**%s** has Teleported to **%s**", "searchbans": "Search Bans", "searchbansfail": "No Ban with the Search Criteria was found.", - "identifier": "%s Identifier" + "identifier": "%s Identifier", + "warnplayer": "Warn Player", + "warnreasonguide": "Add a reason to the Warn.", + "confirmwarn": "Confirm Warn", + "confirmwarnguide": "~r~~h~NOTE:~h~~w~ Pressing Confirm will Warn this Player with the specified settings.", + "warned": "You have been warned, Reason: %s Warning %s/%s", + "warnkicked": "You have been kicked due to getting Warned too many times.", + "warnbanned": "Warned too many times.", + "adminwarnedplayer": "**%s** warned **%s**, Reason: %s, Warning %s/%s" }] \ No newline at end of file diff --git a/util_shared.lua b/util_shared.lua index d7ed89e3..6e2ee597 100644 --- a/util_shared.lua +++ b/util_shared.lua @@ -12,6 +12,7 @@ permissions = { ["anon"] = false, ["mute"] = false, ["teleport.everyone"] = false, + ["warn"] = false, }