123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- 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)
|