mirror of
https://github.com/edubart/otclient.git
synced 2025-10-20 06:23:26 +02:00
Refactor modules, closes #223
* All modules are sandboxed now * All images,sounds,fonts,translations and styles were moved to "data" folder * Reorganize image files folders * Remove unmaintained modules: client_particles, client_shaders * Implement new automatic way to load styles and fonts * Add hide/show offline option in VipList * Add invite/exclude to/from private channel in players menus * Many other minor changes
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
local opcodeCallbacks = {}
|
||||
local extendedCallbacks = {}
|
||||
|
||||
function ProtocolGame:onOpcode(opcode, msg)
|
||||
for i, callback in pairs(opcodeCallbacks) do
|
||||
if i == opcode then
|
||||
callback(msg)
|
||||
callback(self, msg)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function ProtocolGame:onExtendedOpcode(opcode, buffer)
|
||||
local callback = extendedCallbacks[opcode]
|
||||
if callback then
|
||||
callback(self, opcode, buffer)
|
||||
end
|
||||
end
|
||||
|
||||
function ProtocolGame.registerOpcode(opcode, callback)
|
||||
if opcodeCallbacks[opcode] then
|
||||
error('opcode ' .. opcode .. ' already registered will be overriden')
|
||||
@@ -21,3 +29,31 @@ end
|
||||
function ProtocolGame.unregisterOpcode(opcode)
|
||||
opcodeCallbacks[opcode] = nil
|
||||
end
|
||||
|
||||
function ProtocolGame.registerExtendedOpcode(opcode, callback)
|
||||
if not callback or type(callback) ~= 'function' then
|
||||
error('Invalid callback.')
|
||||
end
|
||||
|
||||
if opcode < 0 or opcode > 255 then
|
||||
error('Invalid opcode. Range: 0-255')
|
||||
end
|
||||
|
||||
if extendedCallbacks[opcode] then
|
||||
error('Opcode is already taken.')
|
||||
end
|
||||
|
||||
extendedCallbacks[opcode] = callback
|
||||
end
|
||||
|
||||
function ProtocolGame.unregisterExtendedOpcode(opcode)
|
||||
if opcode < 0 or opcode > 255 then
|
||||
error('Invalid opcode. Range: 0-255')
|
||||
end
|
||||
|
||||
if not extendedCallbacks[opcode] then
|
||||
error('Opcode is not registered.')
|
||||
end
|
||||
|
||||
extendedCallbacks[opcode] = nil
|
||||
end
|
||||
|
Reference in New Issue
Block a user