Skip to content

Commit

Permalink
Migrate nick change handling from 'admin' to 'joinquit' (and improve …
Browse files Browse the repository at this point in the history
…it to fix spam due to bypass)

Until now, you'd be able to change nick (using /nick or MTA settings) at unlimited frequency despite the "You can only change your name once every 5 seconds" message, due to resources working past eachother.

Example scenario (Chatbox):

You can only change your name once every 5 seconds
* dude is now known as spammer1

It says it won't go through, but it does. This enabled massive spam.
  • Loading branch information
Dutchman101 committed Jan 26, 2024
1 parent 95e4da3 commit d8834a8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 29 deletions.
7 changes: 0 additions & 7 deletions [admin]/admin/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,6 @@
desc="When enabled, admin will use the ip2c resource to determine players' countries by their IP."
/>

<setting name="*nickChangeDelay" value="5000"
friendlyname="Nick change delay"
group="Durations"
accept="500-60000"
desc="Time in miliseconds between a player being able to change their name to prevent nick change spam"
/>

<setting name="*maxchatmsgs" value="10"
friendlyname="Max chat log messages"
accept="1-1000"
Expand Down
13 changes: 0 additions & 13 deletions [admin]/admin/server/admin_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ aInteriors = {}
aStats = {}
aReports = {}
aWeathers = {}
aNickChangeTime = {}

local aUnmuteTimerList = {}
local chatHistory = {}
Expand Down Expand Up @@ -465,7 +464,6 @@ end

addEventHandler ( "onPlayerQuit", root, function ()
aPlayers[source] = nil
aNickChangeTime[source] = nil
chatHistory[source] = nil
end )

Expand Down Expand Up @@ -1673,17 +1671,6 @@ function checkClient(checkAccess,player,...)
return false
end

function checkNickOnChange(old, new)
if aNickChangeTime[source] and aNickChangeTime[source] + tonumber(get("*nickChangeDelay")) > getTickCount() then
cancelEvent()
outputChatBox("You can only change your name once every "..(tonumber(get("*nickChangeDelay"))/1000).." seconds", source, 255, 0, 0)
return false
else
aNickChangeTime[source] = getTickCount()
end
end
addEventHandler("onPlayerChangeNick", root, checkNickOnChange)

addEventHandler ("onUnban",root,function(theBan,responsibleElement)
if isElement(responsibleElement) and getElementType (responsibleElement)=="player" then
outputServerLog ("BAN: "..getPlayerName(responsibleElement).."["..getAccountName (getPlayerAccount(responsibleElement)).."] ["..getPlayerSerial (responsibleElement).."] ["..getPlayerIP (responsibleElement).."] unbanned player "..(getBanNick(theBan) or "unknown").." ["..(getBanIP (theBan) or getBanSerial(theBan)).."] ")
Expand Down
37 changes: 28 additions & 9 deletions [gameplay]/joinquit/joinquit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ local settingPrefix = string.format("*%s.", resourceName)
local showColorCodes = get("showColorCodes") == "true" -- Shows player"s names colorcoded if set to true, and if set to false it doesn"t
local defaultColor = get("defaultColor") -- Hex code for what color to output messages in (only used if showColorCodes is true)
local fallbackHexCode = "#4E5768" -- Fallback hex code for incorrectly input settings values
local defaultColor = get("defaultColor")
local nickChangeDelay = get("nickChangeDelay")

nickChangeTime = {}

function reloadSettings(settingName)
-- Setting change affects this resource
if (string.find(settingName, settingPrefix, 1, true)) then
showColorCodes = get("showColorCodes") == "true"
defaultColor = get("defaultColor")
nickChangeDelay = get("nickChangeDelay")
end
end
addEventHandler("onSettingChange", root, reloadSettings)
Expand Down Expand Up @@ -47,15 +52,24 @@ end
addEventHandler("onPlayerJoin", root, joinMessage)

function nickChangeMessage(oldNick, newNick)
if wasEventCancelled() then

if wasEventCancelled() then return end

if isPlayerMuted(source) then
cancelEvent()
outputChatBox("You cannot change your nickname whilst muted!", source, 255, 0, 0)
return
end

if isPlayerMuted(source) then
cancelEvent()
outputChatBox("You cannot change your nickname whilst muted!", source, 255, 0, 0)
return
end
if nickChangeTime[source] and nickChangeTime[source] + tonumber(nickChangeDelay) > getTickCount() then
cancelEvent()
outputChatBox("You can only change your name once every "..(tonumber(nickChangeDelay)/1000).." seconds", source, 255, 0, 0)
return false
else
nickChangeTime[source] = getTickCount()
end

if wasEventCancelled() then return end

if (showColorCodes) then
outputChatBox(getDefaultColor().."* "..getHexFriendlyNick(source, oldNick)..getDefaultColor().." is now known as "..getHexFriendlyNick(source, newNick), root, 255, 100, 100, true)
Expand All @@ -65,11 +79,16 @@ end
end
addEventHandler("onPlayerChangeNick", root, nickChangeMessage)

function leftMessage(reason)
function leftMessage(quitType, reason)

if nickChangeTime[source] then
nickChangeTime[source] = nil
end

if (showColorCodes) then
outputChatBox(getDefaultColor().."* "..getHexFriendlyNick(source, getPlayerName(source))..getDefaultColor().." has left the game ["..reason.."]", root, 255, 100, 100, true)
outputChatBox(getDefaultColor().."* "..getHexFriendlyNick(source, getPlayerName(source))..getDefaultColor().." has left the game ["..quitType.."]", root, 255, 100, 100, true)
else
outputChatBox("* "..getPlayerName(source).." has left the game ["..reason.."]", root, 255, 100, 100)
outputChatBox("* "..getPlayerName(source).." has left the game ["..quitType.."]", root, 255, 100, 100)
end
end
addEventHandler("onPlayerQuit", root, leftMessage)
7 changes: 7 additions & 0 deletions [gameplay]/joinquit/meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@
accept=""
desc="If show color codes is set to true, this controls what color to output messages in"
/>
<setting name="*nickChangeDelay"
friendlyname="Nick change delay"
value="5000"
accept="500-60000"
group="Durations"
desc="Time in miliseconds between a player being able to change their name to prevent nick change spam"
/>
</settings>
</meta>

0 comments on commit d8834a8

Please sign in to comment.