Skip to content

Commit 8a717a2

Browse files
authored
admin/admin2: Refactor use tables instead of element data (#699)
* Refactor: use tables instead of element data * admin2: Refactor use tables instead of element data
1 parent defb2e5 commit 8a717a2

File tree

6 files changed

+28
-8
lines changed

6 files changed

+28
-8
lines changed

[admin]/admin/client/gui/admin_main.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1408,7 +1408,7 @@ end
14081408

14091409
function setAnonAdmin( bOn )
14101410
guiCheckBoxSetSelected ( aTab1.AnonAdmin, bOn )
1411-
setElementData( localPlayer, "AnonAdmin", bOn )
1411+
triggerServerEvent("aAdmin", localPlayer, "adminpanel", "updateAnonymous", bOn)
14121412
aSetSetting ( "currentAnonState", bOn )
14131413
end
14141414

[admin]/admin/server/admin_server.lua

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ end
618618

619619
-- Should admin name be hidden from public chatbox message?
620620
function isAnonAdmin4All ( admin )
621-
return getElementData( admin, "AnonAdmin" ) == true
621+
return aPlayers[admin] and aPlayers[admin]["AnonymousAdmin"] or false
622622
end
623623

624624
-- Should admin name be hidden from private chatbox message?
@@ -666,6 +666,7 @@ end )
666666
local aAdminRights = {
667667
["settings"] = "general.tab_resources",
668668
["resourcelist"] = "general.tab_resources",
669+
["adminpanel"] = "general.adminpanel",
669670

670671
["sync"] = "command.aclmanager",
671672
["aclcreate"] = "command.aclcreate",
@@ -907,6 +908,13 @@ addEventHandler ( "aAdmin", root, function ( action, ... )
907908
end
908909
end
909910
end
911+
elseif ( action == "adminpanel" ) then
912+
local cmd = arg[1]
913+
914+
if cmd == "updateAnonymous" then
915+
local state = arg[2]
916+
aPlayers[client]["AnonymousAdmin"] = state
917+
end
910918
end
911919
end )
912920

@@ -961,7 +969,7 @@ addEventHandler ( "aPlayer", root, function ( player, action, data, additional,
961969
if ( action == "kick" ) then
962970
local reason = data or ""
963971
mdata = reason~="" and ( "(" .. reason .. ")" ) or ""
964-
local isAnonAdmin = getElementData(source, "AnonAdmin")
972+
local isAnonAdmin = isAnonAdmin4All(source)
965973
if isAnonAdmin then
966974
setTimer ( kickPlayer, 100, 1, player, "Anonymous admin", reason )
967975
else
@@ -971,7 +979,7 @@ addEventHandler ( "aPlayer", root, function ( player, action, data, additional,
971979
local reason = data or ""
972980
local seconds = tonumber(additional) and tonumber(additional) > 0 and tonumber(additional)
973981
local bUseSerial = additional2
974-
local isAnonAdmin = getElementData(source, "AnonAdmin")
982+
local isAnonAdmin = isAnonAdmin4All(source)
975983
mdata = reason~="" and ( "(" .. reason .. ")" ) or ""
976984
more = seconds and ( "(" .. secondsToTimeDesc(seconds) .. ")" ) or ""
977985
if bUseSerial and getPlayerName ( player ) and not isAnonAdmin then
@@ -1034,7 +1042,7 @@ addEventHandler ( "aPlayer", root, function ( player, action, data, additional,
10341042
elseif ( action == "shout" ) then
10351043
local textDisplay = textCreateDisplay ()
10361044
local textItem
1037-
local anon = getElementData( admin, "AnonAdmin" )
1045+
local anon = isAnonAdmin4All( admin )
10381046
if (anon) then
10391047
textItem = textCreateTextItem ( "ADMIN:\n\n"..data, 0.5, 0.5, 2, 255, 100, 50, 255, 4, "center", "center" )
10401048
else

[admin]/admin2/admin_definitions.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ enum(
4646
"EVENT_SCREEN_SHOT",
4747
"EVENT_RESOURCE_START",
4848
"EVENT_RESOURCE_STOP",
49-
"EVENT_PLAYER_JOIN"
49+
"EVENT_PLAYER_JOIN",
50+
"EVENT_ANONYMOUS_UPDATE"
5051
},
5152
"ae"
5253
)

[admin]/admin2/client/main/admin_players.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ function aPlayersTab.onClientClick(button)
263263
end
264264
end
265265
elseif (source == aPlayersTab.AnonAdmin) then
266-
setElementData(localPlayer, "AnonAdmin", guiCheckBoxGetSelected(aPlayersTab.AnonAdmin))
266+
triggerServerEvent(EVENT_ANONYMOUS_UPDATE, localPlayer, guiCheckBoxGetSelected(aPlayersTab.AnonAdmin))
267267
elseif (source == aPlayersTab.ColorCodes) then
268268
aPlayersTab.Refresh()
269269
aSetSetting('hideColorCodes', guiCheckBoxGetSelected(source))

[admin]/admin2/server/admin_server.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,17 @@ addEventHandler(
418418
end
419419
)
420420

421+
addEvent(EVENT_ANONYMOUS_UPDATE, true)
422+
addEventHandler(
423+
EVENT_ANONYMOUS_UPDATE,
424+
root,
425+
function(state)
426+
if (hasObjectPermissionTo(client, "general.adminpanel", false)) then
427+
aPlayers[client]["AnonymousAdmin"] = state
428+
end
429+
end
430+
)
431+
421432
addCommandHandler(get("adminChatCommandName"),
422433
function(thePlayer, cmd, ...)
423434
if (hasObjectPermissionTo(thePlayer, "general.tab_adminchat", false) and #arg > 0) then

[admin]/admin2/shared/utils.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function isAnonAdmin(aplayer)
3838
return false
3939
end
4040

41-
return (getElementData(player, "AnonAdmin") == true)
41+
return aPlayers[aplayer] and aPlayers[aplayer]["AnonymousAdmin"] or false
4242
end
4343

4444
-- Source: https://wiki.multitheftauto.com/wiki/FormatDate

0 commit comments

Comments
 (0)