Skip to content

Commit

Permalink
add warning system, cleanup bannedjoin string
Browse files Browse the repository at this point in the history
  • Loading branch information
Blumlaut committed Feb 19, 2021
1 parent 6af8fe2 commit 5429a4b
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
38 changes: 38 additions & 0 deletions admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions gui_c.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}]
1 change: 1 addition & 0 deletions util_shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ permissions = {
["anon"] = false,
["mute"] = false,
["teleport.everyone"] = false,
["warn"] = false,
}


Expand Down

0 comments on commit 5429a4b

Please sign in to comment.