Conversation
|
@dudantas please have a look 🤭 |
|
|
Using loadstring here introduces potential security and performance risks, especially if the input (split[2]) is user-provided or not sanitized. A safer and more efficient approach would be to directly attempt converting the value to a number or treating it as a string key if the conversion fails. This would eliminate the need for dynamically executed code and improve both the safety and clarity of the implementation. Example alternative: local storageKey = tonumber(split[2]) or split[2]
local storageValue = target:getStorageValue(storageKey)
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The storage with id: " .. split[1] .. " is: " .. storageValue .. ".")This ensures the same functionality without the risks associated with loadstring. |
kaleohanopahala
left a comment
There was a problem hiding this comment.
Nah...
This changes seems unsafe to me.
Could you test this?
function Player.getStorageValueTalkaction(self, param)
-- Sanity check for parameters
if not HasValidTalkActionParams(self, param, "Usage: /getstorage <playername>, <storage key or name>") then
return true
end
local split = param:split(",")
if not split[2] then
self:sendCancelMessage("Insufficient parameters.")
return true
end
local target = Player(split[1]:trim())
if not target then
self:sendCancelMessage("A player with that name is not online.")
return true
end
-- Storage key Validation
local storageKey = tonumber(split[2]) or split[2]:trim()
if not storageKey then
self:sendCancelMessage("Invalid storage key or name.")
return true
end
-- Get the storage key
local storageValue = target:getStorageValue(storageKey)
if storageValue == nil then
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The storage with id: " .. split[2] .. " does not exist or is not set for player " .. target:getName() .. ".")
else
self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The storage with id: " .. split[2] .. " from player " .. target:getName() .. " is: " .. storageValue .. ".")
end
return true
end
local storageGet = TalkAction("/getstorage")
function storageGet.onSay(player, words, param)
return player:getStorageValueTalkaction(param)
end
storageGet:separator(" ")
storageGet:groupType("gamemaster")
storageGet:register()



Description
Fix the getstorage talkaction used by server admins, which helps imensely with quest debugging.
Behaviour
Actual
Whenever the talkaction /getstorage Player, storagename is called, the server receives a string (storage name) or a number (storage key) as parameters, the key works fine, but the name should not be a string, it should be converted to the actual global storage variable type.
Expected
Given the admin prepares the /getstorage talkaction to be sent;
When the admin sends the storage parameter as a string e.g (/getstorage GOD, Storage.Quest.U8_0.TheIceIslands.Questline);
Then the /getstorage talkaction accepts the string parameter correctly.
Type of change
Please delete options that are not relevant.
How Has This Been Tested
Test Configuration:
Checklist