Skip to content

Commit

Permalink
Add ban details widget
Browse files Browse the repository at this point in the history
  • Loading branch information
jlillis committed Nov 1, 2023
1 parent 616fd04 commit c734fd5
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 6 deletions.
10 changes: 4 additions & 6 deletions [admin]/admin2/client/main/admin_bans.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down
107 changes: 107 additions & 0 deletions [admin]/admin2/client/widgets/admin_ban_details.lua
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions [admin]/admin2/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<script src="client/widgets/admin_interior.lua" type="client" />
<script src="client/widgets/admin_screenshot.lua" type="client" />
<script src="client/widgets/admin_ban.lua" type="client" />
<script src="client/widgets/admin_ban_details.lua" type="client" />
<script src="client/widgets/admin_warp.lua" type="client" />
<script src="client/widgets/admin_report.lua" type="client" />
<script src="client/widgets/admin_weapon.lua" type="client" />
Expand Down
24 changes: 24 additions & 0 deletions [admin]/admin2/shared/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,27 @@ function isAnonAdmin(aplayer)

return (getElementData(player, "AnonAdmin") == true)
end

-- Source: https://wiki.multitheftauto.com/wiki/FormatDate
-- Credit: NeonBlack
local weekDays = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }
function formatDate(format, escaper, timestamp)
--check("formatDate", "string", format, "format", {"nil","string"}, escaper, "escaper", {"nil","string"}, timestamp, "timestamp")

escaper = (escaper or "'"):sub(1, 1)
local time = getRealTime(timestamp)
local formattedDate = ""
local escaped = false

time.year = time.year + 1900
time.month = time.month + 1

local datetime = { d = ("%02d"):format(time.monthday), h = ("%02d"):format(time.hour), i = ("%02d"):format(time.minute), m = ("%02d"):format(time.month), s = ("%02d"):format(time.second), w = weekDays[time.weekday+1]:sub(1, 2), W = weekDays[time.weekday+1], y = tostring(time.year):sub(-2), Y = time.year }

for char in format:gmatch(".") do
if (char == escaper) then escaped = not escaped
else formattedDate = formattedDate..(not escaped and datetime[char] or char) end
end

return formattedDate
end

0 comments on commit c734fd5

Please sign in to comment.