mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 19:44:54 +02:00
Module sandboxing system
Sandboxing makes module scripts run inside an isolated lua environments, making more easier and secure to script Move and rework TextMessage using the new sandbox system
This commit is contained in:
@@ -16,6 +16,5 @@ Module
|
||||
dofile 'settings'
|
||||
dofile 'keyboard'
|
||||
dofile 'mouse'
|
||||
dofile 'protocol'
|
||||
|
||||
dofiles 'ui'
|
||||
|
@@ -1,188 +0,0 @@
|
||||
GameServerOpcodes = {
|
||||
GameServerInitGame = 10,
|
||||
GameServerGMActions = 11,
|
||||
GameServerLoginError = 20,
|
||||
GameServerLoginAdvice = 21,
|
||||
GameServerLoginWait = 22,
|
||||
GameServerPingBack = 29,
|
||||
GameServerPing = 30,
|
||||
GameServerChallange = 31,
|
||||
GameServerDeath = 40,
|
||||
|
||||
-- all in game opcodes must be greater than 50
|
||||
GameServerFirstGameOpcode = 50,
|
||||
|
||||
-- otclient ONLY
|
||||
GameServerExtendedOpcode = 50,
|
||||
|
||||
-- NOTE: add any custom opcodes in this range
|
||||
-- 51 - 99
|
||||
|
||||
-- original tibia ONLY
|
||||
GameServerFullMap = 100,
|
||||
GameServerMapTopRow = 101,
|
||||
GameServerMapRightRow = 102,
|
||||
GameServerMapBottomRow = 103,
|
||||
GameServerMapLeftRow = 104,
|
||||
GameServerUpdateTile = 105,
|
||||
GameServerCreateOnMap = 106,
|
||||
GameServerChangeOnMap = 107,
|
||||
GameServerDeleteOnMap = 108,
|
||||
GameServerMoveCreature = 109,
|
||||
GameServerOpenContainer = 110,
|
||||
GameServerCloseContainer = 111,
|
||||
GameServerCreateContainer = 112,
|
||||
GameServerChangeInContainer = 113,
|
||||
GameServerDeleteInContainer = 114,
|
||||
GameServerSetInventory = 120,
|
||||
GameServerDeleteInventory = 121,
|
||||
GameServerOpenNpcTrade = 122,
|
||||
GameServerPlayerGoods = 123,
|
||||
GameServerCloseNpcTrade = 124,
|
||||
GameServerOwnTrade = 125,
|
||||
GameServerCounterTrade = 126,
|
||||
GameServerCloseTrade = 127,
|
||||
GameServerAmbient = 130,
|
||||
GameServerGraphicalEffect = 131,
|
||||
GameServerTextEffect = 132,
|
||||
GameServerMissleEffect = 133,
|
||||
GameServerMarkCreature = 134,
|
||||
GameServerTrappers = 135,
|
||||
GameServerCreatureHealth = 140,
|
||||
GameServerCreatureLight = 141,
|
||||
GameServerCreatureOutfit = 142,
|
||||
GameServerCreatureSpeed = 143,
|
||||
GameServerCreatureSkull = 144,
|
||||
GameServerCreatureParty = 145,
|
||||
GameServerCreatureUnpass = 146,
|
||||
GameServerEditText = 150,
|
||||
GameServerEditList = 151,
|
||||
GameServerPlayerDataBasic = 159, -- 910
|
||||
GameServerPlayerData = 160,
|
||||
GameServerPlayerSkills = 161,
|
||||
GameServerPlayerState = 162,
|
||||
GameServerClearTarget = 163,
|
||||
GameServerSpellDelay = 164, --870
|
||||
GameServerSpellGroupDelay = 165, -- 870
|
||||
GameServerMultiUseDelay = 166, -- 870
|
||||
GameServerTalk = 170,
|
||||
GameServerChannels = 171,
|
||||
GameServerOpenChannel = 172,
|
||||
GameServerOpenPrivateChannel = 173,
|
||||
GameServerRuleViolationChannel = 174,
|
||||
GameServerRuleViolationRemove = 175,
|
||||
GameServerRuleViolationCancel = 176,
|
||||
GameServerRuleViolationLock = 177,
|
||||
GameServerOpenOwnChannel = 178,
|
||||
GameServerCloseChannel = 179,
|
||||
GameServerTextMessage = 180,
|
||||
GameServerCancelWalk = 181,
|
||||
GameServerWalkWait = 182,
|
||||
GameServerFloorChangeUp = 190,
|
||||
GameServerFloorChangeDown = 191,
|
||||
GameServerChooseOutfit = 200,
|
||||
GameServerVipAdd = 210,
|
||||
GameServerVipLogin = 211,
|
||||
GameServerVipLogout = 212,
|
||||
GameServerTutorialHint = 220,
|
||||
GameServerAutomapFlag = 221,
|
||||
GameServerQuestLog = 240,
|
||||
GameServerQuestLine = 241,
|
||||
GameServerChannelEvent = 243, -- 910
|
||||
GameServerItemInfo = 244, -- 910
|
||||
GameServerPlayerInventory = 245, -- 910
|
||||
GameServerMarketEnter = 246, -- 944
|
||||
GameServerMarketLeave = 247, -- 944
|
||||
GameServerMarketDetail = 248, -- 944
|
||||
GameServerMarketBrowse = 249 -- 944
|
||||
}
|
||||
|
||||
ClientOpcodes = {
|
||||
ClientEnterAccount = 1,
|
||||
ClientEnterGame = 10,
|
||||
ClientLeaveGame = 20,
|
||||
ClientPing = 29,
|
||||
ClientPingBack = 30,
|
||||
|
||||
-- all in game opcodes must be equal or greater than 50
|
||||
ClientFirstGameOpcode = 50,
|
||||
|
||||
-- otclient ONLY
|
||||
ClientExtendedOpcode = 50,
|
||||
|
||||
-- NOTE: add any custom opcodes in this range
|
||||
-- 51 - 99
|
||||
|
||||
-- original tibia ONLY
|
||||
ClientAutoWalk = 100,
|
||||
ClientWalkNorth = 101,
|
||||
ClientWalkEast = 102,
|
||||
ClientWalkSouth = 103,
|
||||
ClientWalkWest = 104,
|
||||
ClientStop = 105,
|
||||
ClientWalkNorthEast = 106,
|
||||
ClientWalkSouthEast = 107,
|
||||
ClientWalkSouthWest = 108,
|
||||
ClientWalkNorthWest = 109,
|
||||
ClientTurnNorth = 111,
|
||||
ClientTurnEast = 112,
|
||||
ClientTurnSouth = 113,
|
||||
ClientTurnWest = 114,
|
||||
ClientEquipItem = 119, -- 910
|
||||
ClientMove = 120,
|
||||
ClientInspectNpcTrade = 121,
|
||||
ClientBuyItem = 122,
|
||||
ClientSellItem = 123,
|
||||
ClientCloseNpcTrade = 124,
|
||||
ClientRequestTrade = 125,
|
||||
ClientInspectTrade = 126,
|
||||
ClientAcceptTrade = 127,
|
||||
ClientRejectTrade = 128,
|
||||
ClientUseItem = 130,
|
||||
ClientUseItemWith = 131,
|
||||
ClientUseOnCreature = 132,
|
||||
ClientRotateItem = 133,
|
||||
ClientCloseContainer = 135,
|
||||
ClientUpContainer = 136,
|
||||
ClientEditText = 137,
|
||||
ClientEditList = 138,
|
||||
ClientLook = 140,
|
||||
ClientTalk = 150,
|
||||
ClientRequestChannels = 151,
|
||||
ClientJoinChannel = 152,
|
||||
ClientLeaveChannel = 153,
|
||||
ClientOpenPrivateChannel = 154,
|
||||
ClientCloseNpcChannel = 158,
|
||||
ClientChangeFightModes = 160,
|
||||
ClientAttack = 161,
|
||||
ClientFollow = 162,
|
||||
ClientInviteToParty = 163,
|
||||
ClientJoinParty = 164,
|
||||
ClientRevokeInvitation = 165,
|
||||
ClientPassLeadership = 166,
|
||||
ClientLeaveParty = 167,
|
||||
ClientShareExperience = 168,
|
||||
ClientDisbandParty = 169,
|
||||
ClientOpenOwnChannel = 170,
|
||||
ClientInviteToOwnChannel = 171,
|
||||
ClientExcludeFromOwnChannel = 172,
|
||||
ClientCancelAttackAndFollow = 190,
|
||||
ClientRefreshContainer = 202,
|
||||
ClientRequestOutfit = 210,
|
||||
ClientChangeOutfit = 211,
|
||||
ClientMount = 212, -- 870
|
||||
ClientAddVip = 220,
|
||||
ClientRemoveVip = 221,
|
||||
ClientBugReport = 230,
|
||||
ClientRuleViolation = 231,
|
||||
ClientDebugReport = 232,
|
||||
ClientRequestQuestLog = 240,
|
||||
ClientRequestQuestLine = 241,
|
||||
ClientNewRuleViolation = 242, -- 910
|
||||
ClientRequestItemInfo = 243, -- 910
|
||||
ClientMarketLeave = 244, -- 944
|
||||
ClientMarketBrowse = 245, -- 944
|
||||
ClientMarketCreate = 246, -- 944
|
||||
ClientMarketCancel = 247, -- 944
|
||||
ClientMarketAccept = 248 -- 944
|
||||
}
|
@@ -51,11 +51,13 @@ function g_settings.getString(key, default)
|
||||
end
|
||||
|
||||
function g_settings.getInteger(key, default)
|
||||
return tonumber(g_settings.get(key, default))
|
||||
local v = tonumber(g_settings.get(key, default)) or 1
|
||||
return v
|
||||
end
|
||||
|
||||
function g_settings.getNumber(key, default)
|
||||
return tonumber(g_settings.get(key, default))
|
||||
local v = tonumber(g_settings.get(key, default)) or 1
|
||||
return v
|
||||
end
|
||||
|
||||
function g_settings.getBoolean(key, default)
|
||||
|
@@ -110,9 +110,34 @@ function extends(base)
|
||||
return derived
|
||||
end
|
||||
|
||||
function export(what, key)
|
||||
if key ~= nil then
|
||||
_G[key] = what
|
||||
else
|
||||
for k,v in pairs(what) do
|
||||
_G[k] = v
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function unexport(key)
|
||||
if type(key) == 'table' then
|
||||
for _k,v in pairs(key) do
|
||||
_G[v] = nil
|
||||
end
|
||||
else
|
||||
_G[key] = nil
|
||||
end
|
||||
end
|
||||
|
||||
function sandbox(what)
|
||||
what = what or 2
|
||||
setfenv(what, newenv())
|
||||
end
|
||||
|
||||
function newenv()
|
||||
local env = { }
|
||||
setmetatable(env, { __index = _G} )
|
||||
setmetatable(env, { __index = getfenv() } )
|
||||
return env
|
||||
end
|
||||
|
||||
@@ -157,13 +182,6 @@ function toboolean(str)
|
||||
return false
|
||||
end
|
||||
|
||||
local oldtonumber = tonumber
|
||||
|
||||
function tonumber(v)
|
||||
if v == nil then return 0 end
|
||||
return oldtonumber(v)
|
||||
end
|
||||
|
||||
function signalcall(param, ...)
|
||||
if type(param) == 'function' then
|
||||
return param(...)
|
||||
|
Reference in New Issue
Block a user