From 27c7f48d8e0bf49ba1ba10b58e3c96a54f4e3f30 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 4 Jul 2023 04:50:01 -0400 Subject: [PATCH 01/19] Rewrite UI, enable basic player ban functionality --- [admin]/admin2/client/main/admin_players.lua | 5 +- [admin]/admin2/client/widgets/admin_ban.lua | 270 ++++++++++++++----- [admin]/admin2/server/admin_server.lua | 9 + 3 files changed, 207 insertions(+), 77 deletions(-) diff --git a/[admin]/admin2/client/main/admin_players.lua b/[admin]/admin2/client/main/admin_players.lua index 150c166d6..4e5e50d1e 100644 --- a/[admin]/admin2/client/main/admin_players.lua +++ b/[admin]/admin2/client/main/admin_players.lua @@ -168,10 +168,7 @@ function aPlayersTab.onClientClick(button) triggerServerEvent("aPlayer", localPlayer, player, "kick", reason) end elseif (source == aPlayersTab.Ban) then - local reason = inputBox("Ban player " .. name, "Enter the ban reason") - if (reason) then - triggerServerEvent("aPlayer", localPlayer, player, "ban", reason) - end + aBan.Show(player) elseif (source == aPlayersTab.Slap) then triggerServerEvent("aPlayer", localPlayer, player, "slap", guiComboBoxGetItemText(aPlayersTab.SlapOptions, guiComboBoxGetSelected(aPlayersTab.SlapOptions)) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 4e726c6ba..348f297fa 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -7,90 +7,214 @@ * Original File by lil_Toady * **************************************]] -aBanForm = nil +aBan = { + Form = nil, + defaultDurations = { + {"1 second", 1}, + {"1 hour", 60 * 60}, + {"1 day", 60 * 60 * 24}, + {"1 week", 60 * 60 * 24 * 7}, + {"Permanent", 0} + }, + playerName = nil +} -function aBanDetails(ip) - if (aBanForm == nil) then - local x, y = guiGetScreenSize() - aBanForm = guiCreateWindow(x / 2 - 130, y / 2 - 150, 260, 300, "Ban Details", false) - aBanIP = guiCreateLabel(0.03, 0.10, 0.80, 0.09, "", true, aBanForm) - aBanNick = guiCreateLabel(0.03, 0.20, 0.80, 0.09, "", true, aBanForm) - aBanDate = guiCreateLabel(0.03, 0.30, 0.80, 0.09, "", true, aBanForm) - aBanTime = guiCreateLabel(0.03, 0.40, 0.80, 0.09, "", true, aBanForm) - aBanBanner = guiCreateLabel(0.03, 0.50, 0.80, 0.09, "", true, aBanForm) - aBanClose = guiCreateButton(0.80, 0.88, 0.17, 0.08, "Close", true, aBanForm) +function aBan.Show(player) + if not aBan.Form then + aBan.Create() + end + + -- If a player was selected, auto-fill the form with the player's info + if player then + aBan.playerName = getPlayerName(player) + guiSetText(aBan.Form, "Ban player "..aBan.playerName) + guiSetText(aBan.SerialEditBox, aPlayers[player].serial) + guiSetEnabled(aBan.SerialEditBox, false) + guiSetText(aBan.IPEditBox, aPlayers[player].ip) + guiSetEnabled(aBan.IPEditBox, false) + end + + addEventHandler("onClientGUIClick", aBan.Form, aBan.onClick) + addEventHandler("onClientGUIFocus", aBan.Form, aBan.onFocus) + addEventHandler("onClientGUIBlur", aBan.Form, aBan.onBlur) + guiSetVisible(aBan.Form, true) + guiBringToFront(aBan.Form) +end + +function aBan.Close(destroy) + if destroy then + destroyElement(aBan.Form) + aBan.Form = nil + else + removeEventHandler("onClientGUIClick", aBan.Form, aBan.onClick) + guiSetVisible(aBan.Form, false) + aBan.Reset() + end + aBan.playerName = nil +end + +function aBan.Create() + local sx, sy = guiGetScreenSize() + aBan.Form = guiCreateWindow(sx / 2 - 200, sy / 2 - 170, 400, 340, "Add ban", false) + aBan.ReasonLabel = guiCreateLabel(50, 40, 300, 20, "Ban reason (required):", false, aBan.Form) + aBan.ReasonEditBox = guiCreateEdit(50, 70, 300, 30, "Enter ban reason...", false, aBan.Form) + aBan.ReasonEditBoxRecievedInput = false + aBan.DurationLabel = guiCreateLabel(50, 110, 300, 20, "Ban duration (required):", false, aBan.Form) + aBan.DurationComboBox = guiCreateComboBox(50, 140, 300, 100, "Select ban duration...", false, aBan.Form) + for i=1, #aBan.defaultDurations do + guiComboBoxAddItem(aBan.DurationComboBox, aBan.defaultDurations[i][1]) + end + aBan.IdentifiersLabel = guiCreateLabel(50, 180, 300, 20, "Select identifiers to use (select at least 1):", false, aBan.Form) + aBan.IPCheckBox = guiCreateCheckBox(70, 210, 125, 30, "Use IP address", true, false, aBan.Form) + aBan.IPEditBox = guiCreateEdit(200, 210, 150, 30, "Enter IP address...", false, aBan.Form) + aBan.IPEditBoxRecievedInput = false + aBan.SerialCheckBox = guiCreateCheckBox(70, 250, 125, 30, "Use MTA serial", true, false, aBan.Form) + aBan.SerialEditBox = guiCreateEdit(200, 250, 150, 30, "Enter MTA serial...", false, aBan.Form) + guiEditSetMaxLength(aBan.SerialEditBox, 32) + aBan.SerialEditBoxRecievedInput = false + aBan.SubmitButton = guiCreateButton(130, 290, 60, 40, "Submit", false, aBan.Form) + aBan.CancelButton = guiCreateButton(210, 290, 60, 40, "Cancel", false, aBan.Form) + aRegister("Ban", aBan.Form, aBan.Show, aBan.Close) + guiSetVisible(aBan.Form, false) +end + +function aBan.Reset() + guiSetText(aBan.Form, "Add ban") + guiSetText(aBan.ReasonEditBox, "Enter ban reason...") + aBan.ReasonEditBoxRecievedInput = false + guiCheckBoxSetSelected(aBan.IPCheckBox, true) + guiSetText(aBan.IPEditBox, "Enter IP address") + guiSetEnabled(aBan.IPEditBox, true) + aBan.IPEditBoxRecievedInput = false + guiCheckBoxSetSelected(aBan.SerialCheckBox, true) + guiSetText(aBan.SerialEditBox, "Enter MTA serial...") + guiSetEnabled(aBan.SerialEditBox, true) + aBan.SerialEditBoxRecievedInput = false +end + +function aBan.onClick(button, state) + if not (button == "left" and state == "up") then + return + end + + -- Handle cancel button first + if source == aBan.CancelButton then + aBan.Close() + return + end + + -- Toggle IP/serial fields based on corresponding checkboxes + if source == aBan.IPCheckBox and (not aBan.playerName) then + guiSetEnabled(aBan.IPEditBox, guiCheckBoxGetSelected(source)) + return + elseif source == aBan.SerialCheckBox and (not aBan.playerName) then + guiSetEnabled(aBan.SerialEditBox, guiCheckBoxGetSelected(source)) + return + end - guiSetVisible(aBanForm, false) - addEventHandler("onClientGUIClick", aBanForm, aClientBanClick) - --Register With Admin Form - aRegister("BanDetails", aBanForm, aBanDetails, aBanDetailsClose) - end - if (aBans["IP"][ip]) then - guiSetText(aBanIP, "IP: " .. ip) - guiSetText(aBanNick, "Nickname: " .. iif(aBans["IP"][ip]["nick"], aBans["IP"][ip]["nick"], "Unknown")) - guiSetText(aBanDate, "Date: " .. iif(aBans["IP"][ip]["date"], aBans["IP"][ip]["date"], "Unknown")) - guiSetText(aBanTime, "Time: " .. iif(aBans["IP"][ip]["time"], aBans["IP"][ip]["time"], "Unknown")) - guiSetText(aBanBanner, "Bant by: " .. iif(aBans["IP"][ip]["banner"], aBans["IP"][ip]["banner"], "Unknown")) - if (aBanReason) then - destroyElement(aBanReason) + -- Handle submit button + if source == aBan.SubmitButton then + aBan.verifyForm() + return + end +end + +function aBan.onFocus() + -- Clear reason/IP/serial edit boxes on first click + if source == aBan.ReasonEditBox then + if not aBan.ReasonEditBoxRecievedInput then + guiSetText(aBan.ReasonEditBox, "") + aBan.ReasonEditBoxRecievedInput = true + end + elseif source == aBan.IPEditBox then + if not aBan.IPEditBoxRecievedInput then + guiSetText(aBan.IPEditBox, "") + aBan.IPEditBoxRecievedInput = true end - aBanReason = - guiCreateLabel( - 0.03, - 0.60, - 0.80, - 0.30, - "Reason: " .. iif(aBans["IP"][ip]["reason"], aBans["IP"][ip]["reason"], "Unknown"), - true, - aBanForm - ) - guiLabelSetHorizontalAlign(aBanReason, 4) - guiSetVisible(aBanForm, true) - guiBringToFront(aBanForm) - elseif (aBans["Serial"][ip]) then - guiSetText(aBanIP, "Serial: " .. ip) - guiSetText(aBanNick, "Nickname: " .. iif(aBans["Serial"][ip]["nick"], aBans["Serial"][ip]["nick"], "Unknown")) - guiSetText(aBanDate, "Date: " .. iif(aBans["Serial"][ip]["date"], aBans["Serial"][ip]["date"], "Unknown")) - guiSetText(aBanTime, "Time: " .. iif(aBans["Serial"][ip]["time"], aBans["Serial"][ip]["time"], "Unknown")) - guiSetText( - aBanBanner, - "Bant by: " .. iif(aBans["Serial"][ip]["banner"], aBans["Serial"][ip]["banner"], "Unknown") - ) - if (aBanReason) then - destroyElement(aBanReason) + elseif source == aBan.SerialEditBox then + if not aBan.SerialEditBoxRecievedInput then + guiSetText(aBan.SerialEditBox, "") + aBan.SerialEditBoxRecievedInput = true end - aBanReason = - guiCreateLabel( - 0.03, - 0.60, - 0.80, - 0.30, - "Reason: " .. iif(aBans["Serial"][ip]["reason"], aBans["Serial"][ip]["reason"], "Unknown"), - true, - aBanForm - ) - guiLabelSetHorizontalAlign(aBanReason, 4) - guiSetVisible(aBanForm, true) - guiBringToFront(aBanForm) end end -function aBanDetailsClose(destroy) - if ((destroy) or (guiCheckBoxGetSelected(aPerformanceBan))) then - if (aBanForm) then - removeEventHandler("onClientGUIClick", aBanForm, aClientBanClick) - destroyElement(aBanForm) - aBanForm = nil +function aBan.onBlur() + -- Reset default text of reason/IP/serial edit boxes if they lose focus with no input + if source == aBan.ReasonEditBox then + if guiGetText(source) == "" then + guiSetText(aBan.ReasonEditBox, "Enter ban reason...") + aBan.ReasonEditBoxRecievedInput = false + end + elseif source == aBan.IPEditBox then + if guiGetText(source) == "" then + guiSetText(aBan.IPEditBox, "Enter IP address...") + aBan.IPEditBoxRecievedInput = false + end + elseif source == aBan.SerialEditBox then + if guiGetText(source) == "" then + guiSetText(aBan.SerialEditBox, "Enter MTA serial...") + aBan.SerialEditBoxRecievedInput = false end - else - guiSetVisible(aBanForm, false) end end -function aClientBanClick(button) - if (button == "left") then - if (source == aBanClose) then - aBanDetailsClose(false) +function aBan.verifyForm() + -- Verify ban reason + local banReason = guiGetText(aBan.ReasonEditBox) + if guiGetText == "" or (not aBan.ReasonEditBoxRecievedInput) then + messageBox("No ban reason provided.", MB_ERROR, MB_OK) + return + end + + -- Verify ban duration + local banDurationSelection = guiComboBoxGetSelected(aBan.DurationComboBox) + if banDurationSelection == -1 then + messageBox("No ban duration provided.", MB_ERROR, MB_OK) + return + end + banDurationSelection = banDurationSelection + 1 -- ComboBox item indices starts at 0 instead of one + -- Verify ban IP + local banIP = "" + if guiCheckBoxGetSelected(aBan.IPCheckBox) then + banIP = guiGetText(aBan.IPEditBox) + if banIP == "" or (not aBan.IPEditBoxRecievedInput) then + if not aBan.playerName then + messageBox("No IP address provided.", MB_ERROR, MB_OK) + end + end + end + + -- Verify ban serial + local banSerial = "" + if guiCheckBoxGetSelected(aBan.SerialCheckBox) then + banSerial = guiGetText(aBan.SerialEditBox) + if banSerial== "" or (not aBan.IPEditBoxRecievedInput) or #banSerial ~= 32 then + if not aBan.playerName then + messageBox("Invalid MTA serial provided.", MB_ERROR, MB_OK) + end end end + + -- Show confirmation dialog + local confirmationMessage + if aBan.playerName then + confirmationMessage = "Are you sure you want to ban "..aBan.playerName.."?" + else + confirmationMessage = "Are you sure you want to add this ban?\nIP = "..(banIP ~= "" and banIP or "None").."\nSerial = "..(banSerial ~= "" and banSerial or "None") + end + iprint(banDurationSelection) + iprint(banDurationSelection, aBan.defaultDurations[banDurationSelection][2]) + if messageBox(confirmationMessage, MB_QUESTION, MB_YESNO) then + -- Build ban request "packet" and send to server + local data = { + player = getPlayerFromName(aBan.playerName), + playerName = aBan.playerName, + ip = banIP, + serial = banSerial, + reason = banReason, + duration = aBan.defaultDurations[banDurationSelection][2] + } + triggerServerEvent('aBans', localPlayer, "ban", data) + end end diff --git a/[admin]/admin2/server/admin_server.lua b/[admin]/admin2/server/admin_server.lua index ac88395ad..8c5839fc7 100644 --- a/[admin]/admin2/server/admin_server.lua +++ b/[admin]/admin2/server/admin_server.lua @@ -420,6 +420,15 @@ addEventHandler( outputChatBox("Error - Invalid serial", source, 255, 0, 0) action = nil end + elseif (action == "ban") then + if isElement(data.player) then + banPlayer(data.player, data.ip ~= "" and true, false, data.serial ~= "" and true, source, data.reason, data.duration) + else + local ban = addBan(data.ip ~= "" and data.ip or nil, nil, data.serial ~= "" and data.serial or nil, source, data.reason, data.duration) + if data.playerName then + setBanNick(ban, data.playerName) + end + end elseif (action == "unbanip") then mdata = data if (not UnbanIP(data, source)) then From 67c484f3088f45c7b9069a8eb5c5f51eca332597 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 4 Jul 2023 05:07:48 -0400 Subject: [PATCH 02/19] Hacky fix for server error Requires further investigation & future refactoring --- [admin]/admin2/server/admin_bans.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/[admin]/admin2/server/admin_bans.lua b/[admin]/admin2/server/admin_bans.lua index 707b3b89b..9e64170f2 100644 --- a/[admin]/admin2/server/admin_bans.lua +++ b/[admin]/admin2/server/admin_bans.lua @@ -11,6 +11,17 @@ local aBans = { List = {} } +-- TODO: replace this hacky fix with a proper refactor +local function aSyncData(unk1, unkStr, data, command) + local players = getElementsByType("player") + iprint(players) + for i=1, #players do + if hasObjectPermissionTo(players[i], "general.tab_bans") then + triggerClientEvent(players[i], EVENT_SYNC, resourceRoot, SYNC_BAN, data) + end + end +end + addEventHandler( "onResourceStart", resourceRoot, From 1d3da16a01adc16991a500a8f71454112d2696ae Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 4 Jul 2023 05:08:02 -0400 Subject: [PATCH 03/19] Addendum to previous commit --- [admin]/admin2/server/admin_server.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/[admin]/admin2/server/admin_server.lua b/[admin]/admin2/server/admin_server.lua index 8c5839fc7..50df8f0de 100644 --- a/[admin]/admin2/server/admin_server.lua +++ b/[admin]/admin2/server/admin_server.lua @@ -421,6 +421,7 @@ addEventHandler( action = nil end elseif (action == "ban") then + mdata = data if isElement(data.player) then banPlayer(data.player, data.ip ~= "" and true, false, data.serial ~= "" and true, source, data.reason, data.duration) else From 4f5039e151fdef31ab89857d5bfadedf50114b77 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 4 Jul 2023 05:12:50 -0400 Subject: [PATCH 04/19] Add button to create new ban from bans tab --- [admin]/admin2/client/main/admin_bans.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/[admin]/admin2/client/main/admin_bans.lua b/[admin]/admin2/client/main/admin_bans.lua index b4417eb4b..e0006ab1d 100644 --- a/[admin]/admin2/client/main/admin_bans.lua +++ b/[admin]/admin2/client/main/admin_bans.lua @@ -26,7 +26,8 @@ function aBansTab.Create(tab) guiGridListAddColumn(aBansTab.BansList, "Banned by", 0.22) guiGridListAddColumn(aBansTab.BansList, "Temporary", 0.22) aBansTab.Details = guiCreateButton(0.82, 0.07, 0.17, 0.04, "Details", true, aBansTab.Tab) - aBansTab.Unban = guiCreateButton(0.82, 0.12, 0.17, 0.04, "Unban", true, aBansTab.Tab, "unban") + aBansTab.Ban = guiCreateButton(0.82, 0.12, 0.17, 0.04, "Add ban", true, aBansTab.Tab, "ban") + aBansTab.Unban = guiCreateButton(0.82, 0.17, 0.17, 0.04, "Unban", true, aBansTab.Tab, "unban") aBansTab.BansRefresh = guiCreateButton(0.82, 0.94, 0.17, 0.04, "Refresh", true, aBansTab.Tab, "listbans") addEventHandler("onClientGUIChanged", aBansTab.BansListSearch, aBansTab.onBansListSearch) @@ -46,6 +47,8 @@ function aBansTab.onClientClick(button) local ip = guiGridListGetItemText(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 2) aBanDetails(ip) end + elseif source == aBansTab.Ban then + aBan.Show() elseif (source == aBansTab.Unban) then if (guiGridListGetSelectedItem(aBansTab.BansList) == -1) then messageBox("No ban row selected!", MB_ERROR, MB_OK) From c0c73cec3d18be300c94d1317932d6692abb2c28 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Wed, 5 Jul 2023 21:33:16 -0400 Subject: [PATCH 05/19] Fix sync of new bans --- [admin]/admin2/admin_definitions.lua | 1 + [admin]/admin2/server/admin_bans.lua | 17 +++-------------- [admin]/admin2/server/admin_sync.lua | 2 ++ 3 files changed, 6 insertions(+), 14 deletions(-) diff --git a/[admin]/admin2/admin_definitions.lua b/[admin]/admin2/admin_definitions.lua index 641af358d..6ea18f964 100644 --- a/[admin]/admin2/admin_definitions.lua +++ b/[admin]/admin2/admin_definitions.lua @@ -60,6 +60,7 @@ enum( "SYNC_RESOURCE", "SYNC_ADMINS", "SYNC_SERVER", + "SYNC_BAN", "SYNC_BANS", "SYNC_MESSAGES" }, diff --git a/[admin]/admin2/server/admin_bans.lua b/[admin]/admin2/server/admin_bans.lua index 9e64170f2..51f8b330f 100644 --- a/[admin]/admin2/server/admin_bans.lua +++ b/[admin]/admin2/server/admin_bans.lua @@ -11,17 +11,6 @@ local aBans = { List = {} } --- TODO: replace this hacky fix with a proper refactor -local function aSyncData(unk1, unkStr, data, command) - local players = getElementsByType("player") - iprint(players) - for i=1, #players do - if hasObjectPermissionTo(players[i], "general.tab_bans") then - triggerClientEvent(players[i], EVENT_SYNC, resourceRoot, SYNC_BAN, data) - end - end -end - addEventHandler( "onResourceStart", resourceRoot, @@ -45,7 +34,7 @@ addEventHandler( ban = getBanData(ban) } - aSyncData(nil, "ban", root, data, "command.listbans") + requestSync(root, SYNC_BAN, data) end ) @@ -62,7 +51,7 @@ addEventHandler( ban = getBanData(ban) } - aSyncData(nil, "ban", root, data, "command.listbans") + requestSync(root, SYNC_BAN, data) end ) @@ -77,7 +66,7 @@ addEventHandler( id = id } - aSyncData(nil, "ban", root, data, "command.listbans") + requestSync(root, SYNC_BAN, data) aBans.List[id] = nil end diff --git a/[admin]/admin2/server/admin_sync.lua b/[admin]/admin2/server/admin_sync.lua index 0f1deba6d..03fbee915 100644 --- a/[admin]/admin2/server/admin_sync.lua +++ b/[admin]/admin2/server/admin_sync.lua @@ -107,6 +107,8 @@ addEventHandler( tableOut["game"] = getGameType() tableOut["map"] = getMapName() tableOut["password"] = getServerPassword() + elseif (type == SYNC_BAN) then + tableOut = data elseif (type == SYNC_BANS) then for id, ban in pairs(getBansList()) do tableOut[id] = getBanData(ban) From 7526f21c1417bd880eafc3beedeae9619cdda2ae Mon Sep 17 00:00:00 2001 From: John Lillis Date: Wed, 5 Jul 2023 21:33:45 -0400 Subject: [PATCH 06/19] Fix client error when banning offline player --- [admin]/admin2/client/widgets/admin_ban.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 348f297fa..6da8732b7 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -207,8 +207,12 @@ function aBan.verifyForm() iprint(banDurationSelection, aBan.defaultDurations[banDurationSelection][2]) if messageBox(confirmationMessage, MB_QUESTION, MB_YESNO) then -- Build ban request "packet" and send to server + local actualPlayer -- Actual player may be offline + if aBan.playerName then + actualPlayer = getPlayerFromName(aBan.playerName) + end local data = { - player = getPlayerFromName(aBan.playerName), + player = actualPlayer, playerName = aBan.playerName, ip = banIP, serial = banSerial, From ec9282ef7a3a6d6bb6a0e7bd7e8428d8b2f281e8 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Wed, 5 Jul 2023 21:37:44 -0400 Subject: [PATCH 07/19] Fix UI bugs --- [admin]/admin2/client/widgets/admin_ban.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 6da8732b7..643ddd8b1 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -174,6 +174,7 @@ function aBan.verifyForm() return end banDurationSelection = banDurationSelection + 1 -- ComboBox item indices starts at 0 instead of one + -- Verify ban IP local banIP = "" if guiCheckBoxGetSelected(aBan.IPCheckBox) then @@ -181,6 +182,7 @@ function aBan.verifyForm() if banIP == "" or (not aBan.IPEditBoxRecievedInput) then if not aBan.playerName then messageBox("No IP address provided.", MB_ERROR, MB_OK) + return end end end @@ -192,6 +194,7 @@ function aBan.verifyForm() if banSerial== "" or (not aBan.IPEditBoxRecievedInput) or #banSerial ~= 32 then if not aBan.playerName then messageBox("Invalid MTA serial provided.", MB_ERROR, MB_OK) + return end end end From 2caa7b79c9943e9cc81618bfc186e36096543ae1 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Thu, 6 Jul 2023 00:21:40 -0400 Subject: [PATCH 08/19] Reset duration combobox on ban form reset --- [admin]/admin2/client/widgets/admin_ban.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 643ddd8b1..43293e38b 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -82,6 +82,7 @@ function aBan.Reset() guiSetText(aBan.Form, "Add ban") guiSetText(aBan.ReasonEditBox, "Enter ban reason...") aBan.ReasonEditBoxRecievedInput = false + guiComboBoxSetSelected(aBan.DurationComboBox, -1) guiCheckBoxSetSelected(aBan.IPCheckBox, true) guiSetText(aBan.IPEditBox, "Enter IP address") guiSetEnabled(aBan.IPEditBox, true) From 8d00e1268e79c01c589275b60446c68d624d08af Mon Sep 17 00:00:00 2001 From: John Lillis Date: Sat, 8 Jul 2023 00:51:22 -0400 Subject: [PATCH 09/19] Fix ban serial validation --- [admin]/admin2/client/widgets/admin_ban.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 43293e38b..b44e6e7ea 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -192,7 +192,8 @@ function aBan.verifyForm() local banSerial = "" if guiCheckBoxGetSelected(aBan.SerialCheckBox) then banSerial = guiGetText(aBan.SerialEditBox) - if banSerial== "" or (not aBan.IPEditBoxRecievedInput) or #banSerial ~= 32 then + if banSerial == "" or (not aBan.SerialEditBoxRecievedInput) or #banSerial ~= 32 then + outputDebugString("len = "..#banSerial) if not aBan.playerName then messageBox("Invalid MTA serial provided.", MB_ERROR, MB_OK) return From fb5ceb2f45cbb48a246632b43f2f9e8fb169d6b0 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Sat, 8 Jul 2023 00:59:23 -0400 Subject: [PATCH 10/19] Reduce ban widget padding by 50% --- [admin]/admin2/client/widgets/admin_ban.lua | 24 ++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index b44e6e7ea..2bea2f133 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -55,25 +55,25 @@ end function aBan.Create() local sx, sy = guiGetScreenSize() - aBan.Form = guiCreateWindow(sx / 2 - 200, sy / 2 - 170, 400, 340, "Add ban", false) - aBan.ReasonLabel = guiCreateLabel(50, 40, 300, 20, "Ban reason (required):", false, aBan.Form) - aBan.ReasonEditBox = guiCreateEdit(50, 70, 300, 30, "Enter ban reason...", false, aBan.Form) + aBan.Form = guiCreateWindow(sx / 2 - 175, sy / 2 - 170, 350, 340, "Add ban", false) + aBan.ReasonLabel = guiCreateLabel(25, 40, 300, 20, "Ban reason (required):", false, aBan.Form) + aBan.ReasonEditBox = guiCreateEdit(25, 70, 300, 30, "Enter ban reason...", false, aBan.Form) aBan.ReasonEditBoxRecievedInput = false - aBan.DurationLabel = guiCreateLabel(50, 110, 300, 20, "Ban duration (required):", false, aBan.Form) - aBan.DurationComboBox = guiCreateComboBox(50, 140, 300, 100, "Select ban duration...", false, aBan.Form) + aBan.DurationLabel = guiCreateLabel(25, 110, 300, 20, "Ban duration (required):", false, aBan.Form) + aBan.DurationComboBox = guiCreateComboBox(25, 140, 300, 100, "Select ban duration...", false, aBan.Form) for i=1, #aBan.defaultDurations do guiComboBoxAddItem(aBan.DurationComboBox, aBan.defaultDurations[i][1]) end - aBan.IdentifiersLabel = guiCreateLabel(50, 180, 300, 20, "Select identifiers to use (select at least 1):", false, aBan.Form) - aBan.IPCheckBox = guiCreateCheckBox(70, 210, 125, 30, "Use IP address", true, false, aBan.Form) - aBan.IPEditBox = guiCreateEdit(200, 210, 150, 30, "Enter IP address...", false, aBan.Form) + aBan.IdentifiersLabel = guiCreateLabel(25, 180, 300, 20, "Select identifiers to use (select at least 1):", false, aBan.Form) + aBan.IPCheckBox = guiCreateCheckBox(45, 210, 125, 30, "Use IP address", true, false, aBan.Form) + aBan.IPEditBox = guiCreateEdit(175, 210, 150, 30, "Enter IP address...", false, aBan.Form) aBan.IPEditBoxRecievedInput = false - aBan.SerialCheckBox = guiCreateCheckBox(70, 250, 125, 30, "Use MTA serial", true, false, aBan.Form) - aBan.SerialEditBox = guiCreateEdit(200, 250, 150, 30, "Enter MTA serial...", false, aBan.Form) + aBan.SerialCheckBox = guiCreateCheckBox(45, 250, 125, 30, "Use MTA serial", true, false, aBan.Form) + aBan.SerialEditBox = guiCreateEdit(175, 250, 150, 30, "Enter MTA serial...", false, aBan.Form) guiEditSetMaxLength(aBan.SerialEditBox, 32) aBan.SerialEditBoxRecievedInput = false - aBan.SubmitButton = guiCreateButton(130, 290, 60, 40, "Submit", false, aBan.Form) - aBan.CancelButton = guiCreateButton(210, 290, 60, 40, "Cancel", false, aBan.Form) + aBan.SubmitButton = guiCreateButton(105, 290, 60, 40, "Submit", false, aBan.Form) + aBan.CancelButton = guiCreateButton(185, 290, 60, 40, "Cancel", false, aBan.Form) aRegister("Ban", aBan.Form, aBan.Show, aBan.Close) guiSetVisible(aBan.Form, false) end From c5ce014421030d9501ac0b597b91505244a80e08 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Sat, 8 Jul 2023 03:11:19 -0400 Subject: [PATCH 11/19] Add ability to define custom ban duration --- [admin]/admin2/client/widgets/admin_ban.lua | 71 +++++++++++++++++---- 1 file changed, 60 insertions(+), 11 deletions(-) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 2bea2f133..47c390a2e 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -14,7 +14,8 @@ aBan = { {"1 hour", 60 * 60}, {"1 day", 60 * 60 * 24}, {"1 week", 60 * 60 * 24 * 7}, - {"Permanent", 0} + {"Permanent", 0}, -- HARDCODED AS SECOND LAST IN THIS TABLE, DO NOT MOVE + {"Custom", 0} -- HARDCODED AS LAST IN THIS TABLE, DO NOT MOVE }, playerName = nil } @@ -60,10 +61,13 @@ function aBan.Create() aBan.ReasonEditBox = guiCreateEdit(25, 70, 300, 30, "Enter ban reason...", false, aBan.Form) aBan.ReasonEditBoxRecievedInput = false aBan.DurationLabel = guiCreateLabel(25, 110, 300, 20, "Ban duration (required):", false, aBan.Form) - aBan.DurationComboBox = guiCreateComboBox(25, 140, 300, 100, "Select ban duration...", false, aBan.Form) + aBan.DurationComboBox = guiCreateComboBox(25, 145, 150, 100, "Select ban duration...", false, aBan.Form) for i=1, #aBan.defaultDurations do guiComboBoxAddItem(aBan.DurationComboBox, aBan.defaultDurations[i][1]) end + aBan.DurationEditBox = guiCreateEdit(175, 140, 150, 30, "Duration (seconds)...", false, aBan.Form) + guiSetEnabled(aBan.DurationEditBox, false) + aBan.DurationEditBoxRecievedInput = false aBan.IdentifiersLabel = guiCreateLabel(25, 180, 300, 20, "Select identifiers to use (select at least 1):", false, aBan.Form) aBan.IPCheckBox = guiCreateCheckBox(45, 210, 125, 30, "Use IP address", true, false, aBan.Form) aBan.IPEditBox = guiCreateEdit(175, 210, 150, 30, "Enter IP address...", false, aBan.Form) @@ -83,6 +87,9 @@ function aBan.Reset() guiSetText(aBan.ReasonEditBox, "Enter ban reason...") aBan.ReasonEditBoxRecievedInput = false guiComboBoxSetSelected(aBan.DurationComboBox, -1) + guiSetText(aBan.DurationEditBox, "Duration (seconds)...") + guiSetEnabled(aBan.DurationEditBox, false) + aBan.DurationEditBoxRecievedInput = false guiCheckBoxSetSelected(aBan.IPCheckBox, true) guiSetText(aBan.IPEditBox, "Enter IP address") guiSetEnabled(aBan.IPEditBox, true) @@ -104,6 +111,27 @@ function aBan.onClick(button, state) return end + -- Autofill and enable/disable duration editbox based on choice + if source == aBan.DurationComboBox then + local selected = guiComboBoxGetSelected(aBan.DurationComboBox) + if selected == -1 then + return + elseif selected == #aBan.defaultDurations - 2 then + -- Second-last option is permanent duration - clear and disable edit box + guiSetText(aBan.DurationEditBox, "") + guiSetEnabled(aBan.DurationEditBox, false) + elseif selected == #aBan.defaultDurations - 1 then + -- Last option (should) be custom duration - enable duration edit box + guiSetText(aBan.DurationEditBox, "Duration (seconds)...") + guiSetEnabled(aBan.DurationEditBox, true) + aBan.DurationEditBoxRecievedInput = false + else + guiSetText(aBan.DurationEditBox, aBan.defaultDurations[selected + 1][2]) + guiSetEnabled(aBan.DurationEditBox, false) + end + return + end + -- Toggle IP/serial fields based on corresponding checkboxes if source == aBan.IPCheckBox and (not aBan.playerName) then guiSetEnabled(aBan.IPEditBox, guiCheckBoxGetSelected(source)) @@ -121,12 +149,17 @@ function aBan.onClick(button, state) end function aBan.onFocus() - -- Clear reason/IP/serial edit boxes on first click + -- Clear reason/duration/IP/serial edit boxes on first click if source == aBan.ReasonEditBox then if not aBan.ReasonEditBoxRecievedInput then guiSetText(aBan.ReasonEditBox, "") aBan.ReasonEditBoxRecievedInput = true end + elseif source == aBan.DurationEditBox then + if not aBan.DurationEditBoxRecievedInput then + guiSetText(aBan.DurationEditBox, "") + aBan.DurationEditBoxRecievedInput = true + end elseif source == aBan.IPEditBox then if not aBan.IPEditBoxRecievedInput then guiSetText(aBan.IPEditBox, "") @@ -141,12 +174,17 @@ function aBan.onFocus() end function aBan.onBlur() - -- Reset default text of reason/IP/serial edit boxes if they lose focus with no input + -- Reset default text of reason/duration/IP/serial edit boxes if they lose focus with no input if source == aBan.ReasonEditBox then if guiGetText(source) == "" then guiSetText(aBan.ReasonEditBox, "Enter ban reason...") aBan.ReasonEditBoxRecievedInput = false end + elseif source == aBan.DurationEditBox then + if guiGetText(source) == "" and (guiComboBoxGetSelected(aBan.DurationComboBox) == #aBan.defaultDurations - 1) then + guiSetText(aBan.DurationEditBox, "Duration (seconds)...") + aBan.DurationEditBoxRecievedInput = false + end elseif source == aBan.IPEditBox then if guiGetText(source) == "" then guiSetText(aBan.IPEditBox, "Enter IP address...") @@ -163,18 +201,29 @@ end function aBan.verifyForm() -- Verify ban reason local banReason = guiGetText(aBan.ReasonEditBox) - if guiGetText == "" or (not aBan.ReasonEditBoxRecievedInput) then + if banReason == "" or (not aBan.ReasonEditBoxRecievedInput) then messageBox("No ban reason provided.", MB_ERROR, MB_OK) return end -- Verify ban duration - local banDurationSelection = guiComboBoxGetSelected(aBan.DurationComboBox) - if banDurationSelection == -1 then + local banDuration + local durationSelection = guiComboBoxGetSelected(aBan.DurationComboBox) + if durationSelection == -1 then messageBox("No ban duration provided.", MB_ERROR, MB_OK) return end - banDurationSelection = banDurationSelection + 1 -- ComboBox item indices starts at 0 instead of one + durationSelection = durationSelection + 1 -- ComboBox item indices starts at 0 instead of one + if durationSelection == #aBan.defaultDurations then + banDuration = guiGetText(aBan.DurationEditBox) + banDuration = tonumber(banDuration) + if not banDuration or banDuration <= 0 then + messageBox("Invalid ban duration provided.", MB_ERROR, MB_OK) + return + end + else + banDuration = aBan.defaultDurations[durationSelection][2] + end -- Verify ban IP local banIP = "" @@ -201,6 +250,7 @@ function aBan.verifyForm() end end + outputDebugString(banDuration) -- Show confirmation dialog local confirmationMessage if aBan.playerName then @@ -208,8 +258,7 @@ function aBan.verifyForm() else confirmationMessage = "Are you sure you want to add this ban?\nIP = "..(banIP ~= "" and banIP or "None").."\nSerial = "..(banSerial ~= "" and banSerial or "None") end - iprint(banDurationSelection) - iprint(banDurationSelection, aBan.defaultDurations[banDurationSelection][2]) + if messageBox(confirmationMessage, MB_QUESTION, MB_YESNO) then -- Build ban request "packet" and send to server local actualPlayer -- Actual player may be offline @@ -222,7 +271,7 @@ function aBan.verifyForm() ip = banIP, serial = banSerial, reason = banReason, - duration = aBan.defaultDurations[banDurationSelection][2] + duration = banDuration } triggerServerEvent('aBans', localPlayer, "ban", data) end From 7171fe3f3e12af611c724ddbc9c1cad4d40ae1ea Mon Sep 17 00:00:00 2001 From: John Lillis Date: Sat, 8 Jul 2023 03:13:28 -0400 Subject: [PATCH 12/19] Remove extra debug output --- [admin]/admin2/client/widgets/admin_ban.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 47c390a2e..207f19e93 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -250,7 +250,6 @@ function aBan.verifyForm() end end - outputDebugString(banDuration) -- Show confirmation dialog local confirmationMessage if aBan.playerName then From 7a37592cf598e9c28193b293813320f2413e0656 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Sat, 8 Jul 2023 03:23:01 -0400 Subject: [PATCH 13/19] Mask player identifiers in "streamer mode" --- [admin]/admin2/client/widgets/admin_ban.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index 207f19e93..a7eeb37c1 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -29,9 +29,9 @@ function aBan.Show(player) if player then aBan.playerName = getPlayerName(player) guiSetText(aBan.Form, "Ban player "..aBan.playerName) - guiSetText(aBan.SerialEditBox, aPlayers[player].serial) + guiSetText(aBan.SerialEditBox, getSensitiveText(aPlayers[player].serial)) guiSetEnabled(aBan.SerialEditBox, false) - guiSetText(aBan.IPEditBox, aPlayers[player].ip) + guiSetText(aBan.IPEditBox, getSensitiveText(aPlayers[player].ip)) guiSetEnabled(aBan.IPEditBox, false) end From 49dc5d095df53091d799b2e7c61985013d1c23ec Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 31 Oct 2023 18:52:14 -0400 Subject: [PATCH 14/19] Refactor server code & fix unbans --- [admin]/admin2/admin_definitions.lua | 2 +- [admin]/admin2/client/main/admin_bans.lua | 22 ++++---- [admin]/admin2/client/widgets/admin_ban.lua | 2 +- [admin]/admin2/conf/messages.xml | 23 +++----- [admin]/admin2/server/admin_bans.lua | 56 ++++++++++++++++++++ [admin]/admin2/server/admin_server.lua | 58 --------------------- 6 files changed, 74 insertions(+), 89 deletions(-) diff --git a/[admin]/admin2/admin_definitions.lua b/[admin]/admin2/admin_definitions.lua index 6ea18f964..233212d5f 100644 --- a/[admin]/admin2/admin_definitions.lua +++ b/[admin]/admin2/admin_definitions.lua @@ -34,7 +34,7 @@ enum( "EVENT_RESOURCE", "EVENT_SERVER", "EVENT_MESSAGE", - "EVENT_BANS", + "EVENT_BAN", "EVENT_NETWORK", "EVENT_EXECUTE", "EVENT_PROXY", diff --git a/[admin]/admin2/client/main/admin_bans.lua b/[admin]/admin2/client/main/admin_bans.lua index e0006ab1d..5ae4089c8 100644 --- a/[admin]/admin2/client/main/admin_bans.lua +++ b/[admin]/admin2/client/main/admin_bans.lua @@ -42,7 +42,7 @@ function aBansTab.onClientClick(button) if (button == "left") then if (source == aBansTab.Details) then if (guiGridListGetSelectedItem(aBansTab.BansList) == -1) then - messageBox("No ban row selected!", MB_ERROR, MB_OK) + messageBox("No ban selected!", MB_ERROR, MB_OK) else local ip = guiGridListGetItemText(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 2) aBanDetails(ip) @@ -51,18 +51,13 @@ function aBansTab.onClientClick(button) aBan.Show() elseif (source == aBansTab.Unban) then if (guiGridListGetSelectedItem(aBansTab.BansList) == -1) then - messageBox("No ban row selected!", MB_ERROR, MB_OK) + messageBox("No ban selected!", MB_ERROR, MB_OK) else - local selected = - guiGridListGetItemText(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 2) - if (aBans["Serial"][selected]) then - if (messageBox("Unban Serial " .. selected .. "?", MB_QUESTION, MB_YESNO ) == true) then - triggerServerEvent ( "aBans", localPlayer, "unbanserial", selected ) - end - else - if (messageBox("Unban IP " .. selected .. "?", MB_QUESTION, MB_YESNO) == true) then - triggerServerEvent ( "aBans", localPlayer, "unbanip", selected ) - end + local banID = + guiGridListGetItemData(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 1) + -- TODO: use aBanDetails widget (also TODO) to display more information + if (messageBox("Are you sure you want to remove this ban?", MB_QUESTION, MB_YESNO ) == true) then + triggerServerEvent(EVENT_BAN, localPlayer, "unban", banID) end end elseif (source == aBansTab.BansRefresh) then @@ -142,7 +137,8 @@ end function aBansTab.DeleteRow(id) local list = aBansTab.BansList - for i = 1, guiGridListGetRowCount(list) do + -- GridList row ids start at zero, not one + for i = 0, guiGridListGetRowCount(list) do local data = guiGridListGetItemData(list, i, 1) if (data == id) then guiGridListRemoveRow(list, i) diff --git a/[admin]/admin2/client/widgets/admin_ban.lua b/[admin]/admin2/client/widgets/admin_ban.lua index a7eeb37c1..cfee8674b 100644 --- a/[admin]/admin2/client/widgets/admin_ban.lua +++ b/[admin]/admin2/client/widgets/admin_ban.lua @@ -272,6 +272,6 @@ function aBan.verifyForm() reason = banReason, duration = banDuration } - triggerServerEvent('aBans', localPlayer, "ban", data) + triggerServerEvent(EVENT_BAN, localPlayer, "ban", data) end end diff --git a/[admin]/admin2/conf/messages.xml b/[admin]/admin2/conf/messages.xml index a20321d39..062dd7be5 100644 --- a/[admin]/admin2/conf/messages.xml +++ b/[admin]/admin2/conf/messages.xml @@ -11,9 +11,6 @@ $data2 - Additional information, not all the nodes use it. --> - - ADMIN: $admin has banned $player ($data) - ADMIN: $admin has kicked $player ($data) @@ -248,21 +245,15 @@ - - IP: $data successfully removed from bans list - ADMIN: $admin has unbanned IP $data - - - SERIAL: $data successfully removed from bans list - ADMIN: $admin has unbanned Serial $data + + ADMIN: $admin has banned $player ($data) + ADMIN: $admin has banned $player ($data) - - IP: $data successfully added to bans list - ADMIN: $admin has banned IP $data + + ADMIN: $admin has added a manual ban (IP = $data, Serial = $data2) - - SERIAL: $data successfully added to bans list - ADMIN: $admin has banned Serial $data + + ADMIN: $admin has removed a ban (IP = $data, Serial = $data2) diff --git a/[admin]/admin2/server/admin_bans.lua b/[admin]/admin2/server/admin_bans.lua index 51f8b330f..39ff755c3 100644 --- a/[admin]/admin2/server/admin_bans.lua +++ b/[admin]/admin2/server/admin_bans.lua @@ -106,3 +106,59 @@ function getBanData(ban) return t end + +local function handleBanRequest(action, data) + -- TODO: add commands 'ban' and 'unban' + -- Basic security check + if client and source ~= client then + return + end + + -- Permissions check + if not hasObjectPermissionTo(source, "command."..action) then + outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0) + return + end + + -- Add ban + if action == "ban" then + local ban + if isElement(data.player) then + ban = banPlayer(data.player, data.ip ~= "" and true, false, data.serial ~= "" and true, source, data.reason, data.duration) + else + ban = addBan(data.ip ~= "" and data.ip or nil, nil, data.serial ~= "" and data.serial or nil, source, data.reason, data.duration) + if data.playerName then + setBanNick(ban, data.playerName) + end + end + -- Unlikely to occur, but advise admin if ban failed for some reason + if not ban then + outputChatBox("Ban action failed - check ban details.", source, 255, 0, 0) + return + end + -- Log this action + if isElement(data.player) then + aAction("bans", "banplayer", source, data.player, data.reason or "None") + else + aAction("bans", "addban", source, nil, data.ip or "None", data.serial or "None") + end + -- Remove ban + elseif action == "unban" then + local ban = aBans.List[data] + + -- Unlikely to occur, but advise admin if ban failed for some reason + if not ban then + outputChatBox("Ban action failed - check ban details.", source, 255, 0, 0) + return + end + + if ban then + local banData = getBanData(ban) + removeBan(ban, source) + aAction("bans", "unban", source, nil, banData.ip or "None", banData.serial or "None") + end + end +end + +addEvent(EVENT_BAN, true) +addEventHandler(EVENT_BAN, root, handleBanRequest) \ No newline at end of file diff --git a/[admin]/admin2/server/admin_server.lua b/[admin]/admin2/server/admin_server.lua index 50df8f0de..8f335ba92 100644 --- a/[admin]/admin2/server/admin_server.lua +++ b/[admin]/admin2/server/admin_server.lua @@ -397,64 +397,6 @@ addEventHandler( end ) -addEvent("aBans", true) -addEventHandler( - "aBans", - root, - function(action, data) - if (hasObjectPermissionTo(source, "command." .. action)) then - local mdata = "" - local more = "" - if (action == "banip") then - mdata = data - if (not BanIP(data, source)) then - action = nil - end - elseif (action == "banserial") then - mdata = data - if (isValidSerial(data)) then - if (not BanSerial(string.upper(data), source)) then - action = nil - end - else - outputChatBox("Error - Invalid serial", source, 255, 0, 0) - action = nil - end - elseif (action == "ban") then - mdata = data - if isElement(data.player) then - banPlayer(data.player, data.ip ~= "" and true, false, data.serial ~= "" and true, source, data.reason, data.duration) - else - local ban = addBan(data.ip ~= "" and data.ip or nil, nil, data.serial ~= "" and data.serial or nil, source, data.reason, data.duration) - if data.playerName then - setBanNick(ban, data.playerName) - end - end - elseif (action == "unbanip") then - mdata = data - if (not UnbanIP(data, source)) then - action = nil - end - elseif (action == "unbanserial") then - mdata = data - if (not UnbanSerial(data, source)) then - action = nil - end - else - action = nil - end - - if (action ~= nil) then - aAction("bans", action, source, false, mdata, more) - triggerEvent("aSync", source, "sync", "bans") - end - return true - end - outputChatBox("Access denied for '" .. tostring(action) .. "'", source, 255, 168, 0) - return false - end -) - addEvent("aExecute", true) addEventHandler( "aExecute", From 616fd04f3fe597c065d9719813119258aed357b1 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 31 Oct 2023 18:52:32 -0400 Subject: [PATCH 15/19] Remove unimplemented commands --- [admin]/admin2/conf/commands.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/[admin]/admin2/conf/commands.xml b/[admin]/admin2/conf/commands.xml index e2079d23f..f82266625 100644 --- a/[admin]/admin2/conf/commands.xml +++ b/[admin]/admin2/conf/commands.xml @@ -55,10 +55,10 @@ - + From c734fd5e3cb70e3b21d9ef860e0dad300c4f19a8 Mon Sep 17 00:00:00 2001 From: John Lillis Date: Tue, 31 Oct 2023 20:42:46 -0400 Subject: [PATCH 16/19] Add ban details widget --- [admin]/admin2/client/main/admin_bans.lua | 10 +- .../client/widgets/admin_ban_details.lua | 107 ++++++++++++++++++ [admin]/admin2/meta.xml | 1 + [admin]/admin2/shared/utils.lua | 24 ++++ 4 files changed, 136 insertions(+), 6 deletions(-) create mode 100644 [admin]/admin2/client/widgets/admin_ban_details.lua diff --git a/[admin]/admin2/client/main/admin_bans.lua b/[admin]/admin2/client/main/admin_bans.lua index 5ae4089c8..21865af2d 100644 --- a/[admin]/admin2/client/main/admin_bans.lua +++ b/[admin]/admin2/client/main/admin_bans.lua @@ -44,8 +44,9 @@ function aBansTab.onClientClick(button) if (guiGridListGetSelectedItem(aBansTab.BansList) == -1) then messageBox("No ban selected!", MB_ERROR, MB_OK) else - local ip = guiGridListGetItemText(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 2) - aBanDetails(ip) + local banID = + guiGridListGetItemData(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 1) + aBanDetails.Show(banID, false) end elseif source == aBansTab.Ban then aBan.Show() @@ -55,10 +56,7 @@ function aBansTab.onClientClick(button) else local banID = guiGridListGetItemData(aBansTab.BansList, guiGridListGetSelectedItem(aBansTab.BansList), 1) - -- TODO: use aBanDetails widget (also TODO) to display more information - if (messageBox("Are you sure you want to remove this ban?", MB_QUESTION, MB_YESNO ) == true) then - triggerServerEvent(EVENT_BAN, localPlayer, "unban", banID) - end + aBanDetails.Show(banID, true) end elseif (source == aBansTab.BansRefresh) then guiGridListClear(aBansTab.BansList) diff --git a/[admin]/admin2/client/widgets/admin_ban_details.lua b/[admin]/admin2/client/widgets/admin_ban_details.lua new file mode 100644 index 000000000..a2f733c75 --- /dev/null +++ b/[admin]/admin2/client/widgets/admin_ban_details.lua @@ -0,0 +1,107 @@ +--[[********************************** +* +* Multi Theft Auto - Admin Panel +* +* client\widgets\admin_ban_details.lua +* +**************************************]] +aBanDetails = { + Form = nil, + banID = nil +} + +function aBanDetails.Show(banID, showUnban) + if not aBanDetails.Form then + aBanDetails.Create() + end + + aBanDetails.banID = banID + local data = aBansTab.List[banID] + guiSetText(aBanDetails.NickText, "Player name: "..(data.nick or "Unknown")) + guiSetText(aBanDetails.IPText, "IP: "..(data.ip or "None")) + guiSetText(aBanDetails.SerialText, "Serial: "..(data.serial or "None")) + guiSetText(aBanDetails.ReasonText, "Reason: "..(data.reason or "None")) + guiSetText(aBanDetails.AdminText, "Responsible admin: "..(data.banner or "Unknown")) + if data.unban then + guiSetText(aBanDetails.ExpireText, "Expire time: "..formatDate("m/d/y h:m", nil, data.unban)) + else + guiSetText(aBanDetails.ExpireText, "Expire time: Never") + end + + addEventHandler("onClientGUIClick", aBanDetails.Form, aBanDetails.onClick) + guiSetVisible(aBanDetails.Form, true) + + -- Toggle visibilty of certain elements if this is being opened as a confimration dialog for unban action + if showUnban then + guiSetText(aBanDetails.ConfirmationText, "Are you sure you want to remove this ban?") + guiSetVisible(aBanDetails.CloseButton, false) + guiSetVisible(aBanDetails.SubmitButton, true) + guiSetVisible(aBanDetails.CancelButton, true) + end + guiBringToFront(aBanDetails.Form) +end + +function aBanDetails.Close(destroy) + if destroy then + destroyElement(aBanDetails.Form) + aBanDetails.Form = nil + else + removeEventHandler("onClientGUIClick", aBanDetails.Form, aBanDetails.onClick) + guiSetVisible(aBanDetails.Form, false) + aBanDetails.Reset() + end + aBanDetails.banID = nil +end + +function aBanDetails.Create() + local sx, sy = guiGetScreenSize() + aBanDetails.Form = guiCreateWindow(sx / 2 - 175, sy / 2 - 135, 350, 250, "Ban Details", false) + aBanDetails.ConfirmationText = guiCreateLabel(25, 40, 300, 20, "Ban details:", false, aBanDetails.Form) + aBanDetails.NickText = guiCreateLabel(50, 70, 300, 20, "Player name: Unknown", false, aBanDetails.Form) + aBanDetails.IPText = guiCreateLabel(50, 90, 300, 20, "IP: None", false, aBanDetails.Form) + aBanDetails.SerialText = guiCreateLabel(50, 110, 300, 20, "Serial: None", false, aBanDetails.Form) + aBanDetails.ReasonText = guiCreateLabel(50, 130, 300, 20, "Reason: None", false, aBanDetails.Form) + aBanDetails.AdminText = guiCreateLabel(50, 150, 300, 20, "Responsible admin: Unknown", false, aBanDetails.Form) + aBanDetails.ExpireText = guiCreateLabel(50, 170, 300, 20, "Expire time: Never", false, aBanDetails.Form) + + aBanDetails.SubmitButton = guiCreateButton(105, 200, 60, 40, "Submit", false, aBanDetails.Form) + aBanDetails.CancelButton = guiCreateButton(185, 200, 60, 40, "Cancel", false, aBanDetails.Form) + aBanDetails.CloseButton = guiCreateButton(145, 200, 60, 40, "Close", false, aBanDetails.Form) + guiSetVisible(aBanDetails.CloseButton, true) + guiSetVisible(aBanDetails.SubmitButton, false) + guiSetVisible(aBanDetails.CancelButton, false) + aRegister("Ban Details", aBanDetails.Form, aBanDetails.Show, aBanDetails.Close) + guiSetVisible(aBanDetails.Form, false) +end + +function aBanDetails.Reset() + outputDebugString("reset") + guiSetText(aBanDetails.Form, "Ban Details") + guiSetText(aBanDetails.ConfirmationText, "Ban details:") + guiSetText(aBanDetails.NickText, "Player name: Unknown") + guiSetText(aBanDetails.IPText, "IP: None") + guiSetText(aBanDetails.SerialText, "Serial: None") + guiSetText(aBanDetails.ReasonText, "Reason: None") + guiSetText(aBanDetails.AdminText, "Responsible admin: Unknown") + guiSetText(aBanDetails.ExpireText, "Expire time: Never") + guiSetVisible(aBanDetails.CloseButton, true) + guiSetVisible(aBanDetails.SubmitButton, false) + guiSetVisible(aBanDetails.CancelButton, false) +end + +function aBanDetails.onClick(button, state) + if not (button == "left" and state == "up") then + return + end + + -- Handle cancel button first + if source == aBanDetails.CancelButton or source == aBanDetails.CloseButton then + aBanDetails.Close() + return + end + + if source == aBanDetails.SubmitButton then + triggerServerEvent(EVENT_BAN, localPlayer, "unban", aBanDetails.banID) + return + end +end \ No newline at end of file diff --git a/[admin]/admin2/meta.xml b/[admin]/admin2/meta.xml index 20d65581a..29cfcc24d 100644 --- a/[admin]/admin2/meta.xml +++ b/[admin]/admin2/meta.xml @@ -66,6 +66,7 @@