You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
510 B
24 lines
510 B
12 years ago
|
local opcodeCallbacks = {}
|
||
|
|
||
|
function ProtocolGame:onOpcode(opcode, msg)
|
||
|
for i, callback in pairs(opcodeCallbacks) do
|
||
|
if i == opcode then
|
||
|
callback(msg)
|
||
|
return true
|
||
|
end
|
||
|
end
|
||
|
return false
|
||
|
end
|
||
|
|
||
|
function ProtocolGame.registerOpcode(opcode, callback)
|
||
|
if opcodeCallbacks[opcode] then
|
||
|
error('opcode ' .. opcode .. ' already registered will be overriden')
|
||
|
end
|
||
|
|
||
|
opcodeCallbacks[opcode] = callback
|
||
|
end
|
||
|
|
||
|
function ProtocolGame.unregisterOpcode(opcode)
|
||
|
opcodeCallbacks[opcode] = nil
|
||
|
end
|