support multi protocol

This commit is contained in:
云风
2012-08-31 21:18:19 +08:00
parent 1ee802c5c5
commit 0a886cd57c
47 changed files with 542 additions and 520 deletions

View File

@@ -12,13 +12,13 @@ end
local function create_group_in(harbor, id)
local local_ctrl = assert(harbor_ctrl[harbor])
local g = multicast[id]
local local_mc = skynet.call(local_ctrl, skynet.unpack, skynet.pack("CREATE", id))
local local_mc = skynet.call(local_ctrl, "lua", "CREATE", id)
for _,mc in pairs(g) do
skynet.send(local_ctrl, 0, skynet.pack("AGENT", id, mc))
skynet.send(local_ctrl, "lua", "AGENT", id, mc)
end
for harbor_id,ctrl in pairs(harbor_ctrl) do
if harbor_id ~= harbor then
skynet.send(ctrl,0, skynet.pack("AGENT", id, local_mc))
skynet.send(ctrl, "lua", "AGENT", id, local_mc)
end
end
g[harbor] = local_mc
@@ -38,14 +38,14 @@ function command.ENTER(address, harbor, id)
end
local local_ctrl = assert(harbor_ctrl[harbor])
skynet.send(local_ctrl, 0, skynet.pack("ENTER", id, address))
skynet.send(local_ctrl, "lua", "ENTER", id, address)
end
function command.LEAVE(address, harbor, id)
local g = multicast[id]
assert(g,id)
local local_ctrl = assert(harbor_ctrl[harbor])
skynet.send(local_ctrl, 0, skynet.pack("LEAVE", id, address))
skynet.send(local_ctrl, "lua", "LEAVE", id, address)
end
function command.DELETE(_,_, id)
@@ -54,16 +54,17 @@ function command.DELETE(_,_, id)
multicast[id] = nil
for harbor_id,_ in pairs(g) do
skynet.send(harbor_ctrl[harbor_id],0, skynet.pack("CLEAR", id))
skynet.send(harbor_ctrl[harbor_id], "lua", "CLEAR", id)
end
end
skynet.dispatch(function (msg,sz)
local cmd , address , param = skynet.unpack(msg,sz)
local f = command[cmd]
assert(f, cmd, param)
local harbor = skynet.harbor(address)
f(address, harbor, param)
skynet.start(function()
skynet.dispatch("lua", function(_, _, cmd , address, param)
local f = command[cmd]
assert(f, cmd, param)
local harbor = skynet.harbor(address)
f(address, harbor, param)
end)
skynet.register("GROUPMGR")
end)
skynet.register("GROUPMGR")