Skip to content

Commit

Permalink
Add limit to admin chat message length
Browse files Browse the repository at this point in the history
Limit is 225 characters: the max chatbox message length, minus 7 for "ADMIN> ", minus 22 (max length for a player name), minus 2 (for ": ").
  • Loading branch information
jlillis committed Jul 8, 2023
1 parent abbcb9c commit 17d7014
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions [admin]/admin/admin_definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ function enum ( args, prefix )
end
end

-- MISC DEFINITIONS
ADMIN_CHAT_MAXLENGTH = 225

-- EVENT CALLS

enum
Expand Down
1 change: 1 addition & 0 deletions [admin]/admin/client/gui/admin_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ y=y+B aTab1.VehicleHealth = guiCreateLabel ( 0.26, y, 0.25, 0.04, "Vehicle Heal
guiGridListAddColumn ( aTab5.AdminPlayers, "Admins", 0.90 )
aTab5.AdminChatSound = guiCreateCheckBox ( 0.79, 0.86, 0.18, 0.04, "Play Sound", true, true, aTab5.Tab )
aTab5.AdminText = guiCreateEdit ( 0.03, 0.92, 0.80, 0.06, "", true, aTab5.Tab )
guiEditSetMaxLength(aTab5.AdminText, ADMIN_CHAT_MAXLENGTH)
aTab5.AdminSay = guiCreateButton ( 0.85, 0.92, 0.08, 0.06, "Say", true, aTab5.Tab )
aTab5.AdminChatHelp = guiCreateButton ( 0.94, 0.92, 0.03, 0.06, "?", true, aTab5.Tab )

Expand Down
3 changes: 3 additions & 0 deletions [admin]/admin/server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1631,6 +1631,9 @@ end )

addEvent ( "aAdminChat", true )
addEventHandler ( "aAdminChat", root, function ( chat )
if #chat > ADMIN_CHAT_MAXLENGTH then
return
end
if checkClient( true, source, 'aAdminChat' ) then return end
for id, player in ipairs(getElementsByType("player")) do
if ( aPlayers[player]["chat"] ) then
Expand Down
3 changes: 3 additions & 0 deletions [admin]/admin2/admin_definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function enum(args, prefix)
end
end

-- MISC DEFINITIONS
ADMIN_CHAT_MAXLENGTH = 225

-- EVENT CALLS

enum(
Expand Down
1 change: 1 addition & 0 deletions [admin]/admin2/client/main/admin_chat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function aChatTab.Create(tab)
aChatTab.AdminChatSound = guiCreateCheckBox(0.81, 0.83, 0.18, 0.04, "Play Sound", aGetSetting("adminChatSound"), true, tab)
aChatTab.AdminChatOutput = guiCreateCheckBox(0.81, 0.87, 0.18, 0.04, "Output", aGetSetting("adminChatOutput"), true, tab)
aChatTab.AdminText = guiCreateEdit(0.01, 0.92, 0.78, 0.06, "", true, tab)
guiEditSetMaxLength(aChatTab.AdminText, ADMIN_CHAT_MAXLENGTH)
aChatTab.AdminSay = guiCreateButton(0.80, 0.92, 0.19, 0.06, "Say", true, tab)

addEventHandler("aClientAdminChat", root, aChatTab.onClientAdminChat)
Expand Down
3 changes: 3 additions & 0 deletions [admin]/admin2/server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,9 @@ addEventHandler(
"aAdminChat",
root,
function(chat)
if #chat >= ADMIN_CHAT_MAXLENGTH then
return
end
for id, player in ipairs(getElementsByType("player")) do
if (aPlayers[player]["chat"]) then
triggerClientEvent(player, "aClientAdminChat", source, chat)
Expand Down

0 comments on commit 17d7014

Please sign in to comment.