diff --git a/lualib/mcgroup.lua b/lualib/mcgroup.lua index a6d74d55..be566544 100644 --- a/lualib/mcgroup.lua +++ b/lualib/mcgroup.lua @@ -24,12 +24,12 @@ function group.leave(id, handle) end function group.release(id) - skynet.send(SERVICE, "lua" , "CLEAR", skynet.self(), id) + skynet.send(SERVICE, "lua" , "DELETE", skynet.self(), id) end skynet.init(function() SERVICE = skynet.call("SERVICE", "lua", "group_mgr") - skynet.call(".service","lua","group_agent") -end, "group") + skynet.call(".service","lua","group_agent", SERVICE) +end, "mcgroup") -return group \ No newline at end of file +return group diff --git a/service/group_agent.lua b/service/group_agent.lua index 386a7785..84d11764 100644 --- a/service/group_agent.lua +++ b/service/group_agent.lua @@ -1,5 +1,9 @@ local skynet = require "skynet" +local group_mgr = ... + +group_mgr = tonumber(group_mgr) + local command = {} local group = {} @@ -52,5 +56,5 @@ skynet.start(function() assert(f, cmd) f(id,handle) end) - skynet.send("GROUPMGR" , "lua", "MASTER", skynet.self()) + skynet.send(group_mgr , "lua", "MASTER", skynet.self()) end) diff --git a/service/group_mgr.lua b/service/group_mgr.lua index ba6b9bd1..edb5a906 100644 --- a/service/group_mgr.lua +++ b/service/group_mgr.lua @@ -12,9 +12,12 @@ end local function create_group_in(harbor, id) local local_ctrl = assert(harbor_ctrl[harbor]) local g = multicast[id] + g[harbor] = false local local_mc = skynet.call(local_ctrl, "lua", "CREATE", id) for _,mc in pairs(g) do - skynet.send(local_ctrl, "lua", "AGENT", id, mc) + if mc then + skynet.send(local_ctrl, "lua", "AGENT", id, mc) + end end for harbor_id,ctrl in pairs(harbor_ctrl) do if harbor_id ~= harbor then @@ -42,15 +45,13 @@ function command.ENTER(address, harbor, id) end function command.LEAVE(address, harbor, id) - local g = multicast[id] - assert(g,id) + assert(multicast[id], id) local local_ctrl = assert(harbor_ctrl[harbor]) skynet.send(local_ctrl, "lua", "LEAVE", id, address) end function command.DELETE(_,_, id) - local g = multicast[id] - assert(g,id) + assert(multicast[id], id) multicast[id] = nil for harbor_id,_ in pairs(g) do @@ -59,12 +60,11 @@ function command.DELETE(_,_, id) end skynet.start(function() - skynet.dispatch("lua", function(_, _, cmd , address, param) + 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)