From d8834a86c60490d7919f8e4b05ac70946f420279 Mon Sep 17 00:00:00 2001 From: Dutchman101 Date: Fri, 26 Jan 2024 03:22:50 +0100 Subject: [PATCH] Migrate nick change handling from 'admin' to 'joinquit' (and improve 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. --- [admin]/admin/meta.xml | 7 ----- [admin]/admin/server/admin_server.lua | 13 ---------- [gameplay]/joinquit/joinquit.lua | 37 ++++++++++++++++++++------- [gameplay]/joinquit/meta.xml | 7 +++++ 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/[admin]/admin/meta.xml b/[admin]/admin/meta.xml index f88ba1420..0c3b65995 100644 --- a/[admin]/admin/meta.xml +++ b/[admin]/admin/meta.xml @@ -156,13 +156,6 @@ desc="When enabled, admin will use the ip2c resource to determine players' countries by their IP." /> - - 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)).."] ") diff --git a/[gameplay]/joinquit/joinquit.lua b/[gameplay]/joinquit/joinquit.lua index 11b7605f3..33f157cea 100644 --- a/[gameplay]/joinquit/joinquit.lua +++ b/[gameplay]/joinquit/joinquit.lua @@ -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) @@ -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) @@ -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) \ No newline at end of file diff --git a/[gameplay]/joinquit/meta.xml b/[gameplay]/joinquit/meta.xml index e40f72880..cc058e203 100644 --- a/[gameplay]/joinquit/meta.xml +++ b/[gameplay]/joinquit/meta.xml @@ -14,5 +14,12 @@ accept="" desc="If show color codes is set to true, this controls what color to output messages in" /> +