Commit 222a7d5ff60dd6e33e4d9a3ae9fb0c5daeae65bb
1 parent
318c573a
httpGm
Showing
3 changed files
with
60 additions
and
7 deletions
Show diff stats
src/actions/HttpAction.lua
1 | - | ||
2 | -local skynet = require "skynet" | ||
3 | -local sharedata = require "skynet.sharedata" | ||
4 | local codecache = require "skynet.codecache" -- 清空缓存用 | 1 | local codecache = require "skynet.codecache" -- 清空缓存用 |
5 | 2 | ||
3 | + | ||
6 | local _M = {} | 4 | local _M = {} |
7 | 5 | ||
8 | 6 | ||
@@ -156,7 +154,35 @@ function _M.hotfix_code(query, body) | @@ -156,7 +154,35 @@ function _M.hotfix_code(query, body) | ||
156 | return 'success' | 154 | return 'success' |
157 | end | 155 | end |
158 | 156 | ||
157 | +local function proc_online(cmd, roleId, pms) | ||
158 | + local agent = datacenter.get("agent", roleId) | ||
159 | + if agent then | ||
160 | + local ok, result = pcall(skynet.call, agent.serv, "lua", cmd, pms) | ||
161 | + return ok and result or "指令在线失败" | ||
162 | + end | ||
163 | + return "not_online" | ||
164 | +end | ||
159 | 165 | ||
166 | +function _M.gm_action(query) | ||
167 | + local gmFuncs = require "actions.GmAction" | ||
168 | + if not query.cmd or not query.id or not gmFuncs[query.cmd] then return "指令不存在" end | ||
169 | + -- 在线操作 | ||
170 | + query.id = tonumber(query.id) | ||
171 | + local isOn = proc_online(query.cmd, query.id, query) | ||
172 | + if isOn ~= "not_online" then | ||
173 | + return isOn | ||
174 | + end | ||
175 | + -- 如果_M有直接操作,跳过load角色 | ||
176 | + if _M[query.cmd] then return _M[query.cmd](query) end | ||
177 | + -- 离线操作 | ||
178 | + local role = require("models.Role").new({key = string.format("role:%d", query.id)}) | ||
179 | + local ret = role:load() | ||
180 | + if not ret then | ||
181 | + return "角色不存在" | ||
182 | + end | ||
183 | + role:loadAll() | ||
184 | + return gmFuncs[query.cmd](role, query) | ||
185 | +end | ||
160 | 186 | ||
161 | 187 | ||
162 | return _M | 188 | return _M |
163 | \ No newline at end of file | 189 | \ No newline at end of file |
src/services/httpweb.lua
1 | -local skynet = require "skynet" | ||
2 | -local socket = require "skynet.socket" | ||
3 | -local httpd = require "http.httpd" | ||
4 | -local sockethelper = require "http.sockethelper" | 1 | + |
5 | local urllib = require "http.url" | 2 | local urllib = require "http.url" |
6 | require "shared.init" | 3 | require "shared.init" |
7 | require "utils.init" | 4 | require "utils.init" |
5 | +local sockethelper = require "http.sockethelper" | ||
6 | +local httpd = require "http.httpd" | ||
7 | +skynet = require "skynet" | ||
8 | +redisproxy = require "shared.redisproxy" | ||
9 | +netpack = require "skynet.netpack" | ||
10 | +datacenter = require "skynet.datacenter" | ||
11 | +sharedata = require "skynet.sharedata" | ||
12 | +mcast_util = require "services/mcast_util" | ||
13 | +globalCsv = require "csvdata/GlobalDefine" | ||
14 | + | ||
15 | +local socket = require "skynet.socket" | ||
16 | +local harbor = require "skynet.harbor" | ||
17 | + | ||
18 | +require "shared.init" | ||
19 | +require "utils.init" | ||
20 | +require "ProtocolCode" | ||
21 | +require "skynet.manager" | ||
22 | +require "RedisKeys" | ||
23 | +require "GlobalVar" | ||
24 | + | ||
25 | +SendPacket = function(...) end | ||
26 | +rpcAgent = function(...) end | ||
27 | +rpcParter = function(...) end | ||
28 | +rpcRole = function(...) end | ||
29 | +rpcUnion = function(...) end | ||
30 | +rpcOtherUnion = function(...) end | ||
8 | 31 | ||
9 | local table = table | 32 | local table = table |
10 | local string = string | 33 | local string = string |
@@ -25,6 +48,9 @@ end | @@ -25,6 +48,9 @@ end | ||
25 | local CMD = require "actions.HttpAction" | 48 | local CMD = require "actions.HttpAction" |
26 | 49 | ||
27 | local function start() | 50 | local function start() |
51 | + redisd = harbor.queryname("REDIS") | ||
52 | + csvdb = sharedata.query("csvdata") | ||
53 | + | ||
28 | local listen_socket = socket.listen("0.0.0.0", port) | 54 | local listen_socket = socket.listen("0.0.0.0", port) |
29 | print("Listen web port " .. port) | 55 | print("Listen web port " .. port) |
30 | socket.start(listen_socket , function(id, addr) | 56 | socket.start(listen_socket , function(id, addr) |