Skip to content

Commit

Permalink
Remove /kill command, add element data checker
Browse files Browse the repository at this point in the history
  • Loading branch information
jlillis committed Sep 1, 2024
1 parent 86882e4 commit 809e1b7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
40 changes: 38 additions & 2 deletions [gamemodes]/[deathmatch]/deathmatch/server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,41 @@ function calculatePlayerRanks()
end
end

-- TODO: remove this debug command
addCommandHandler("kill", function(p) killPed(p) end)
--
-- checkElementData(): secures element data against unauthorized changes
--
function checkElementData(key, oldValue, newValue)
-- if the change was server-side, ignore it
if not client then
return
end

local revert = true

-- if the change by the client was on resourceRoot, revert it
if source == resourceRoot then
revert = true
end

-- if the change by the client was a player's rank or score, revert it
if getElementType(source) == "player" and (key == "Rank" or key == "Score") then
revert = true
end

if not revert then
return
end

-- revert the change and output a warning
setElementData(source, key, oldValue)
local warning = string.format(
"Unauthorized element data change detected: client = %s, element = %s, key = %s, oldValue = %s, newValue = %s",
getPlayerName(client),
getElementType(source) == "player" and getPlayerName(source) or tostring(source),
tostring(key),
tostring(oldValue),
tostring(newValue)
)
outputDebugString(warning, 2)
end
addEventHandler("onElementDataChange", resourceRoot, checkElementData)
2 changes: 2 additions & 0 deletions [gamemodes]/[deathmatch]/deathmatch/server/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
--
local function processPlayerJoin()
_playerStates[source] = PLAYER_JOINED
-- begin protecting player element data
addEventHandler("onElementDataChange", source, checkElementData)
-- initialize player score data
setElementData(source, "Score", 0)
setElementData(source, "Rank", "-")
Expand Down

0 comments on commit 809e1b7

Please sign in to comment.