local skynet = require "skynet" local sockethelper = require "http.sockethelper" local socket = require "skynet.socket" local runconfig = require "run_config" local tools = require "tools" local CMD = {} local agents = {} function traceback(err) skynet.error(tostring(err)) skynet.error(debug.traceback()) end local dispatch = function(session, address, cmd, ...) local fun = CMD[cmd] if not fun then skynet.ret() return end local ret = table.pack(xpcall(fun, traceback, address, ...)) local isok = ret[1] if not isok then skynet.ret() return end skynet.retpack(table.unpack(ret,2)) end function getOneAgent() -- for i = 1, #agents, 1 do -- local isActive = skynet.call(agents[i],"lua",nil,nil,"isActive") -- if isActive then -- local isRunTask = skynet.call(agents[i],"lua",nil,nil,"isRunStak") -- if(isRunTask==false) then -- return agents[i] -- end -- end -- end local isActive = skynet.call(agents[1],"lua",nil,nil,"isActive") if isActive then return agents[1] end return nil end --更新筛选配置 function CMD.updateFilterConfig(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updateFilterConfig",msg_body) else skynet.error("把任务放到队列") end end --更新主体配置 function CMD.updateMainConfig(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updateMainConfig",msg_body) else skynet.error("把任务放到队列") end end --更新App配置 function CMD.updateAppConfig(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updateAppConfig",msg_body) else skynet.error("把任务放到队列") end end --更新平台配置 function CMD.updatePlatformConfig(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updatePlatformConfig",msg_body) else skynet.error("把任务放到队列") end end --添加主体 function CMD.addMain(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"addMain",msg_body) else skynet.error("把任务放到队列") end end --更新番茄key列表 function CMD.updateFqKeyList(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updateFqKeyList",msg_body) else skynet.error("把任务放到队列") end end function CMD.updateFqMfKeyList(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updateFqMfKeyList",msg_body) else skynet.error("把任务放到队列") end end function CMD.updateYwKeyList(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updateYwKeyList",msg_body) else skynet.error("把任务放到队列") end end --更新黑名单的书 function CMD.updateBlackBooks(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updateBlackBooks",msg_body) else skynet.error("把任务放到队列") end end --更新拉取配置 function CMD.updatePullConig(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updatePullConig",msg_body) else skynet.error("把任务放到队列") end end --更新拉取配置 function CMD.updatePullConig2(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"updatePullConig2",msg_body) else skynet.error("把任务放到队列") end end --同步主体 function CMD.syncMain(_,msg_body) local agent = getOneAgent() if agent~=nil then skynet.call(agent,"lua",nil,nil,"syncMain",msg_body) else skynet.error("把任务放到队列") end end skynet.start(function() local protocol = "ws" -- for i= 1, 3 do --开启30个服务用来接收消息 -- agents[i] = skynet.newservice("agent", "agent", protocol) -- end agents[1] = skynet.newservice("agent", "agent", protocol) local balance = 1 local id = socket.listen("0.0.0.0",runconfig.wsProt ) socket.start(id , function(id, addr) skynet.send(agents[balance], "lua", id,addr,"connect") balance = balance + 1 if balance > #agents then balance = 1 end end) skynet.dispatch("lua", dispatch) end)