diff --git a/src/actions/HttpAction.lua b/src/actions/HttpAction.lua index 66affe5..daed31a 100644 --- a/src/actions/HttpAction.lua +++ b/src/actions/HttpAction.lua @@ -1,8 +1,6 @@ - -local skynet = require "skynet" -local sharedata = require "skynet.sharedata" local codecache = require "skynet.codecache" -- 清空缓存用 + local _M = {} @@ -156,7 +154,35 @@ function _M.hotfix_code(query, body) return 'success' end +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 +function _M.gm_action(query) + local gmFuncs = require "actions.GmAction" + if not query.cmd or not query.id or not gmFuncs[query.cmd] then return "指令不存在" end + -- 在线操作 + query.id = tonumber(query.id) + local isOn = proc_online(query.cmd, query.id, 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() + if not ret then + return "角色不存在" + end + role:loadAll() + return gmFuncs[query.cmd](role, query) +end return _M \ No newline at end of file diff --git a/src/services/httpweb.lua b/src/services/httpweb.lua index 5bdb29f..bdd37d9 100644 --- a/src/services/httpweb.lua +++ b/src/services/httpweb.lua @@ -1,10 +1,33 @@ -local skynet = require "skynet" -local socket = require "skynet.socket" -local httpd = require "http.httpd" -local sockethelper = require "http.sockethelper" + local urllib = require "http.url" require "shared.init" require "utils.init" +local sockethelper = require "http.sockethelper" +local httpd = require "http.httpd" +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" + +SendPacket = function(...) end +rpcAgent = function(...) end +rpcParter = function(...) end +rpcRole = function(...) end +rpcUnion = function(...) end +rpcOtherUnion = function(...) end local table = table local string = string @@ -25,6 +48,9 @@ end local CMD = require "actions.HttpAction" local function start() + redisd = harbor.queryname("REDIS") + csvdb = sharedata.query("csvdata") + local listen_socket = socket.listen("0.0.0.0", port) print("Listen web port " .. port) socket.start(listen_socket , function(id, addr) diff --git a/src/utils/TableUtil.lua b/src/utils/TableUtil.lua index 9cb7bb4..d6f8faf 100644 --- a/src/utils/TableUtil.lua +++ b/src/utils/TableUtil.lua @@ -1,4 +1,5 @@ function table.arrayToMap(tab) + tab = tab or {} local len = #tab local result = {} for i = 1, len, 2 do -- libgit2 0.21.2