Skip to content

Commit

Permalink
Allow disabling/enabling default reporting system (#501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Viude authored Jun 19, 2024
1 parent fa5beb9 commit 0dbb83d
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions [admin]/admin/client/admin_client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ addEvent ( "aClientAdminChat", true )
addEvent ( "aClientResourceStart", true )
addEvent ( "aClientResourceStop", true )
addEvent ( "aClientAdminMenu", true )
addEvent ( "aClientReports", true )
function aAdminResourceStart ()
addEventHandler ( "aClientAdminMenu", root, aClientAdminMenu )
local node = xmlLoadFile ( "conf\\weathers.xml" )
Expand Down
4 changes: 3 additions & 1 deletion [admin]/admin/client/gui/admin_messages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ function aViewMessagesClose ( destroy )
end
end

function aMessagesSync ( action, data )
function aMessagesSync ( action, data, isReportDisabled )
if ( action == "get" ) then
_messages = data
guiGridListClear ( aMessagesList )

for id=#data,1,-1 do
local message = data[id]
local row = guiGridListAddRow ( aMessagesList )
Expand All @@ -68,6 +69,7 @@ function aMessagesSync ( action, data )
guiGridListSetItemText ( aMessagesList, row, 3, message.time, false, false )
guiGridListSetItemText ( aMessagesList, row, 4, removeColorCoding(message.author), false, false )
end
guiSetText(aMessagesForm, (isReportDisabled ~= "true" and "View Messages (reports are disabled)" or "View Messages"))
end
end

Expand Down
4 changes: 2 additions & 2 deletions [admin]/admin/client/gui/admin_report.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ local reportCategories
local aSelectPlayer = nil

function aReport ( )

if ( aReportForm == nil ) then
reportCategories = {}
for i,cat in ipairs( split( g_Prefs.reportCategories, string.byte(',') ) ) do
Expand Down Expand Up @@ -58,8 +59,7 @@ function aReport ( )
guiBringToFront ( aReportForm )
showCursor ( true )
end
addCommandHandler ( "report", aReport )

addEventHandler( "aClientReports", root, aReport )

function aReportClose ( )
if ( aReportForm ) then
Expand Down
9 changes: 8 additions & 1 deletion [admin]/admin/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<script src="server/admin_ACL.lua" />
<script src="server/admin_settings.lua" />
<script src="server/admin_screenshot.lua" />
<script src="server/admin_report.lua" />
<script src="server/http/admin_http.lua" />
<script src="client/admin_clientprefs.lua" type="client" cache="false" />
<script src="client/admin_client.lua" type="client" cache="false" />
Expand Down Expand Up @@ -115,7 +116,13 @@
4. double click on the resource name
***************************************************** -->

<setting name="*maxmsgs" value="55"
<setting name="*reportsEnabled" value="true"
friendlyname="Enable default reporting system"
accept="true,false"
desc="When enabled, players will be able to submit reports to admins via the /report command."
/>

<setting name="*maxmsgs" value="55"
friendlyname="Max messages"
accept="1-1000"
desc="Maximum admin messages to keep."
Expand Down
7 changes: 7 additions & 0 deletions [admin]/admin/server/admin_report.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
addCommandHandler("report", function( playerSource )
if ( get("reportsEnabled") ~= "false" ) then
triggerClientEvent( playerSource, "aClientReports", playerSource )
else
outputChatBox ( "Reports are not accepted currently.", playerSource, 255, 0, 0 )
end
end, false, false)
4 changes: 3 additions & 1 deletion [admin]/admin/server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1510,6 +1510,8 @@ function ( action, data )
return
end
if ( action == "new" ) then
--dont allow creating reports when reports are disabled
if ( get("reportsEnabled") ~= "true" ) then return end
local time = getRealTime()
local id = #aReports + 1
aReports[id] = {}
Expand Down Expand Up @@ -1545,7 +1547,7 @@ function ( action, data )
end
if ( hasObjectPermissionTo ( client or source, "general.adminpanel" ) ) then
if ( action == "get" ) then
triggerClientEvent ( source, "aMessage", source, "get", aReports )
triggerClientEvent ( source, "aMessage", source, "get", aReports, get("reportsEnabled") )
elseif ( action == "read" ) then
if ( aReports[data] ) then
aReports[data].read = true
Expand Down

0 comments on commit 0dbb83d

Please sign in to comment.