From c763e563a0e22fa91642841ed6619a8804e1f1fe Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Mon, 23 Mar 2020 19:34:30 +0800 Subject: [PATCH] 删除NGX --- restart.sh | 17 ----------------- src/actions/HttpAction.lua | 20 ++++++++++++++++++-- src/actions/NgxAction.lua | 65 ----------------------------------------------------------------- src/main.lua | 2 -- src/services/ngxd.lua | 106 ---------------------------------------------------------------------------------------------------------- src/services/watchdog.lua | 3 +-- 6 files changed, 19 insertions(+), 194 deletions(-) delete mode 100755 restart.sh delete mode 100644 src/actions/NgxAction.lua delete mode 100644 src/services/ngxd.lua diff --git a/restart.sh b/restart.sh deleted file mode 100755 index 2ef15cf..0000000 --- a/restart.sh +++ /dev/null @@ -1,17 +0,0 @@ -#! /bin/bash -e -echo "server git pull" -git pull -echo "src/csvdata git pull" -cd src/csvdata -pwd -git pull -cd ../../ -echo "check status" -port=`cat src/main.lua | grep 'services/ngxd' | sed 's/)//g' | awk '{printf $5}'` -echo 'prot '$port -pid=$(lsof -i:$port | grep skynet | awk '{print $2}') -if [ -n "$pid" ]; then - echo 'kill old server pid '$pid - kill -9 $pid -fi -skynet/skynet src/config \ No newline at end of file diff --git a/src/actions/HttpAction.lua b/src/actions/HttpAction.lua index ba92ea4..2a33f4a 100644 --- a/src/actions/HttpAction.lua +++ b/src/actions/HttpAction.lua @@ -172,8 +172,6 @@ function _M.gm_action(query) if isOn ~= "not_online" then return isOn end - -- 如果_M有直接操作,跳过load角色 - if _M[query.cmd] then return _M[query.cmd](query) end -- 离线操作 local role = require("models.Role").new({key = string.format("role:%d", query.id)}) local ret = role:load() @@ -184,6 +182,24 @@ function _M.gm_action(query) return gmFuncs[query.cmd](role, query) end +function _M.broadcast(query) + local bin = MsgPack.pack({body = query.content}) + local codes = { + ["common"] = actionCodes.Sys_commonNotice, + ["maintain"] = actionCodes.Sys_maintainNotice, + } + if not codes[query.cmd] then return "错误" end + + mcast_util.pub_world(codes[query.cmd], bin) + return "广播成功" +end + +function _M.online(query) + local count = datacenter.get("onlineCount") or 0 + return count +end + + function _M.account_init(query, body) if not query.id or not body or body == "" then return "指令不存在" end diff --git a/src/actions/NgxAction.lua b/src/actions/NgxAction.lua deleted file mode 100644 index 9bd11aa..0000000 --- a/src/actions/NgxAction.lua +++ /dev/null @@ -1,65 +0,0 @@ -local string_format = string.format -local mcast_util = mcast_util -local gmFuncs = require "actions.GmAction" - -local function proc_online(cmd, roleId, pms) - local agent = datacenter.get("agent", roleId) - if agent then - local ok, result = pcall(skynet.call, agent.serv, "lua", cmd, pms) - return ok and result or "指令在线失败" - end - return "not_online" -end - -local _M = {} -local __const = {["id"]=1,["pm1"]=1,["pm2"]=1,["pm3"]=1} - -local _T = setmetatable({}, {__index = function(_, k) - return function (pms) - for k, v in pairs(pms) do - -- tonum(v, v) 能tonumber 则 转换,不能则返回原来的值 - pms[k] = __const[k] and tonum(v, v) or v - end - -- 群体操作 - if not pms.id or pms.id == 0 then - return _M[k] and _M[k](pms) or "指令不存在" - end - -- 个体操作 - if not gmFuncs[k] then return "指令不存在" end - -- 在线操作 - local isOn = proc_online(k, pms.id, pms) - if isOn ~= "not_online" then - return isOn - end - -- 如果_M有直接操作,跳过load角色 - if _M[k] then return _M[k](pms) end - -- 离线操作 - local role = require("models.Role").new({key = string_format("role:%d", pms.id)}) - local ret = role:load() - if not ret then - return "角色不存在" - end - role:loadAll() - return gmFuncs[k](role, pms) - end -end}) - --- 在线广播 -function _M.broadcast(pms) - local bin = MsgPack.pack({body = pms.pm2}) - local codes = { - ["common"] = actionCodes.Sys_commonNotice, - ["maintain"] = actionCodes.Sys_maintainNotice, - } - if not codes[pms.pm1] then return "错误" end - - mcast_util.pub_world(codes[pms.pm1], bin) - return "广播成功" -end - -function _M.online(pms) - local count = datacenter.get("onlineCount") or 0 - return count -end - -return _T \ No newline at end of file diff --git a/src/main.lua b/src/main.lua index cffa0ff..bb1173a 100644 --- a/src/main.lua +++ b/src/main.lua @@ -7,14 +7,12 @@ skynet.start(function() skynet.newservice("console") skynet.newservice("debug_console", 10001) - local ngxd = skynet.newservice("services/ngxd", 11001) local httpd = skynet.newservice("services/httpweb", 8001) local watchdog = skynet.newservice("services/watchdog", max_client) skynet.call(watchdog, "lua", "start", { port = 12001, maxclient = max_client, - ngxd = ngxd, httpd = httpd, redishost = "127.0.0.1", diff --git a/src/services/ngxd.lua b/src/services/ngxd.lua deleted file mode 100644 index dd60015..0000000 --- a/src/services/ngxd.lua +++ /dev/null @@ -1,106 +0,0 @@ -skynet = require "skynet" -redisproxy = require "shared.redisproxy" -netpack = require "skynet.netpack" -datacenter = require "skynet.datacenter" -sharedata = require "skynet.sharedata" -mcast_util = require "services/mcast_util" -globalCsv = require "csvdata/GlobalDefine" - -local socket = require "skynet.socket" -local harbor = require "skynet.harbor" - -require "shared.init" -require "utils.init" -require "ProtocolCode" -require "skynet.manager" -require "RedisKeys" -require "GlobalVar" - -local port = tonumber(...) -local SEP = "$end$" -local actions = {} - -SendPacket = function(...) end -rpcAgent = function(...) end -rpcParter = function(...) end -rpcRole = function(...) end -rpcUnion = function(...) end -rpcOtherUnion = function(...) end - -skynet.register_protocol { - name = "role", - id = 13, - pack = skynet.pack, - unpack = skynet.unpack, -} - -local function process(request) - local req = json.decode(request) - if req["handle"] == "checkStatus" then - return "success" - end - - local modName, funcName = req["handle"]:match("([%w_]+)%.([%w_]+)") - if not modName or not funcName then - return table.concat({"handle格式错误", modName, funcName}, "\t") - end - local action = require("actions." .. modName .. "Action") - return action[funcName](req) -end - -local function main_loop(stdin, send) - socket.lock(stdin) - while true do - local request = socket.readline(stdin, SEP) - if not request then - break - end - - local response = process(request) - if response then send(response) end - end - socket.unlock(stdin) -end - -local function start() - local listen_socket = socket.listen("0.0.0.0", port) - print("Start nginx proxy at port: ", port) - - redisd = harbor.queryname("REDIS") - - csvdb = sharedata.query("csvdata") - - socket.start(listen_socket, function(id, addr) - local function send(...) - local t = { ... } - socket.write(id, table.concat(t, "\t")) - socket.write(id, SEP) - end - socket.start(id) - skynet.fork(main_loop, id, send) - end) - - -- 注册全服广播 - local channels = {} - for i = 1, 10 do - local channel = datacenter.get("MC_W_CHANNEL" .. i) - if channel then - table.insert(channels, channel) - end - end - if #channels > 0 then - mcast_util.sub_worlds(channels) - end -end - -local function __init__() - skynet.dispatch("lua", function(_,_, command, ...) - if command == "start" then - skynet.ret(skynet.pack(start(...))) - end - end) - - skynet.register "NGXD" -end - -skynet.start(__init__) diff --git a/src/services/watchdog.lua b/src/services/watchdog.lua index 067f1f0..0410326 100644 --- a/src/services/watchdog.lua +++ b/src/services/watchdog.lua @@ -65,14 +65,13 @@ function CMD.start(conf) skynet.call(redisd, "lua", "open", conf) if use_logd == 1 then - skynet.call(logd, "lua", "open", conf) + skynet.call(logd, "lua", "open") end -- 开启agent状态检测定时器 check_agent_status() -- 创建广播服务 create_mutilcast() - skynet.call(conf.ngxd, "lua", "start") skynet.call(conf.httpd, "lua", "start") -- roomServer = skynet.newservice("services/roomServer") -- libgit2 0.21.2