3fe4471e
zhouhaihai
热更新 demo
|
1
2
|
local codecache = require "skynet.codecache" -- 清空缓存用
|
222a7d5f
zhouhaihai
httpGm
|
3
|
|
3fe4471e
zhouhaihai
热更新 demo
|
4
5
|
local _M = {}
|
2d392ede
zhouhaihai
热更新 最终版
|
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
--[=[使用python 调用的话eg:
import requests
@params 指处理方法中的 query
@data 指处理方法中的 body
@return 'success' 成功
status = requests.post("http://127.0.0.1:8001/clearcache", params = {"key": "zhaolu1234dangge"}, data = "", timeout = 300).text
if status != 'success' :
print("错误")
]=]
|
5e5d7680
zhouhaihai
热更新 优化
|
22
|
-- 清空缓存
|
3fe4471e
zhouhaihai
热更新 demo
|
23
24
25
26
27
28
|
function _M.clearcache(query, body)
skynet.error(string.format("clearcache time: %s", skynet.timex()))
codecache.clear()
return 'success'
end
|
2d392ede
zhouhaihai
热更新 最终版
|
29
|
--重新加载 需要修改的csvdb -- 单字段修改 优先使用hotfix_csvdata
|
5e5d7680
zhouhaihai
热更新 优化
|
30
31
32
33
34
35
|
--[=[ eg:
body = """
csvdb["itemCsv"][1]["name"] = "测试一下"
"""
]=]
|
3fe4471e
zhouhaihai
热更新 demo
|
36
|
function _M.reload_csvdata(query, body)
|
5e5d7680
zhouhaihai
热更新 优化
|
37
|
if not body or body == "" then
|
2d392ede
zhouhaihai
热更新 最终版
|
38
|
return 'no body'
|
3fe4471e
zhouhaihai
热更新 demo
|
39
|
end
|
3fe4471e
zhouhaihai
热更新 demo
|
40
|
|
5e5d7680
zhouhaihai
热更新 优化
|
41
|
local ok = pcall(load, body)
|
2d392ede
zhouhaihai
热更新 最终版
|
42
43
44
|
if not ok then
return "code error"
end
|
5e5d7680
zhouhaihai
热更新 优化
|
45
|
|
da898074
zhouhaihai
pvp 高级领奖
|
46
|
local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "reload", body)
|
5e5d7680
zhouhaihai
热更新 优化
|
47
|
if status == "ok" then
|
2d392ede
zhouhaihai
热更新 最终版
|
48
|
skynet.error(string.format("reload_csvdata time: %s, code: %s", skynet.timex(), body))
|
5e5d7680
zhouhaihai
热更新 优化
|
49
|
return 'success'
|
2d392ede
zhouhaihai
热更新 最终版
|
50
51
|
else
return 'error update'
|
5e5d7680
zhouhaihai
热更新 优化
|
52
|
end
|
3fe4471e
zhouhaihai
热更新 demo
|
53
54
|
end
|
2d392ede
zhouhaihai
热更新 最终版
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
--指定更新某个字段值
--[=[
解码后
body = {
{"itemCsv", 1, "name", "测试一下"},
{"itemCsv", 2, "name", "测试一下"}
}
]=]
function _M.hotfix_csvdata(query, body)
if not body or body == "" then
return 'no body'
end
local ok, result = pcall(json.decode, body)
if not ok or type(result) ~= 'table' then
return "decode error"
end
|
da898074
zhouhaihai
pvp 高级领奖
|
72
|
local ok, status = pcall(skynet.call, '.CSVDATA', "lua", "hotfix", result)
|
2d392ede
zhouhaihai
热更新 最终版
|
73
74
75
76
77
78
79
80
|
if status == "ok" then
skynet.error(string.format("hotfix_csvdata time: %s, code: %s", skynet.timex(), body))
return 'success'
else
return 'error update'
end
end
|
3fe4471e
zhouhaihai
热更新 demo
|
81
82
83
84
|
-- 热更新代码 -- 针对 agent 执行发送过来的代码 -- 代码要规范~
--[=[ eg:
|
5e5d7680
zhouhaihai
热更新 优化
|
85
86
87
88
89
90
91
92
|
1. *Action
body = """
_hotfixActions = _hotfixActions or {}
_hotfixActions["Gm.clientRequest"] = function(agent, data)
bin = MsgPack.pack({ cmd = "testtest" })
SendPacket(actionCodes.Gm_receiveResponse, bin)
end
"""
|
3fe4471e
zhouhaihai
热更新 demo
|
93
94
95
96
97
98
|
2. 修改 global 方法 和 变量 直接覆盖
body = """
function a()
print(123)
end
|
5e5d7680
zhouhaihai
热更新 优化
|
99
100
101
102
|
globalCsv["asdasd"] = 12
HEHE = 123
|
3fe4471e
zhouhaihai
热更新 demo
|
103
104
|
"""
|
2d392ede
zhouhaihai
热更新 最终版
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
|
3. 修改 class 类 方法
1. 修改role的方法
body = """
local role = ...
_hotfixClass = _hotfixClass or {}
_hotfixClass["Role"] = _hotfixClass["Role"] or {}
local hotfixFunc = function(hotfixclass)
function hotfixclass:getItemCount(itemId)
return self:getProperty("id") .. "__" .. self:getProperty("uid") .. "__" .. itemId
end
end
table.insert(_hotfixClass["Role"], hotfixFunc)
if role then
hotfixFunc(role)
end
"""
2. 修改hero的方法
|
3fe4471e
zhouhaihai
热更新 demo
|
122
|
body = """
|
2d392ede
zhouhaihai
热更新 最终版
|
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
local role = ...
_hotfixClass = _hotfixClass or {}
_hotfixClass["Hero"] = _hotfixClass["Hero"] or {}
local hotfixFunc = function(hotfixclass)
function hotfixclass:getBattleValue()
return self:getProperty("id") + "98700000000"
end
end
table.insert(_hotfixClass["Hero"], hotfixFunc)
if role and role.heros then
for _, hero in pairs(role.heros) do
hotfixFunc(hero)
end
end
|
3fe4471e
zhouhaihai
热更新 demo
|
137
|
"""
|
2d392ede
zhouhaihai
热更新 最终版
|
138
139
|
3. 其他的类仿照上面的写法
|
3fe4471e
zhouhaihai
热更新 demo
|
140
141
|
]=]
|
2d392ede
zhouhaihai
热更新 最终版
|
142
|
function _M.hotfix_code(query, body)
|
3fe4471e
zhouhaihai
热更新 demo
|
143
|
if not body or body == "" then
|
2d392ede
zhouhaihai
热更新 最终版
|
144
|
return "no body"
|
3fe4471e
zhouhaihai
热更新 demo
|
145
|
end
|
3fe4471e
zhouhaihai
热更新 demo
|
146
|
local ok = pcall(load, body)
|
2d392ede
zhouhaihai
热更新 最终版
|
147
148
149
|
if not ok then
return "code error"
end
|
5e5d7680
zhouhaihai
热更新 优化
|
150
|
|
2d392ede
zhouhaihai
热更新 最终版
|
151
|
skynet.error(string.format("hotfix_code time: %s, code: %s", skynet.timex(), body))
|
5e5d7680
zhouhaihai
热更新 优化
|
152
|
|
da898074
zhouhaihai
pvp 高级领奖
|
153
|
pcall(skynet.call, '.WATCHDOG', "lua", "hotfix", body)
|
3fe4471e
zhouhaihai
热更新 demo
|
154
155
156
|
return 'success'
end
|
222a7d5f
zhouhaihai
httpGm
|
157
158
159
160
161
162
163
164
|
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
|
3fe4471e
zhouhaihai
热更新 demo
|
165
|
|
222a7d5f
zhouhaihai
httpGm
|
166
167
168
169
170
171
172
173
174
|
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
|
222a7d5f
zhouhaihai
httpGm
|
175
176
177
178
179
180
181
182
183
|
-- 离线操作
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
|
3fe4471e
zhouhaihai
热更新 demo
|
184
|
|
c763e563
zhouhaihai
删除NGX
|
185
186
187
188
189
190
191
|
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
|
c763e563
zhouhaihai
删除NGX
|
192
193
194
195
196
197
198
199
200
201
|
mcast_util.pub_world(codes[query.cmd], bin)
return "广播成功"
end
function _M.online(query)
local count = datacenter.get("onlineCount") or 0
return count
end
|
c7ecb87f
zhouhaihai
添加 测试账号 方法
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
function _M.account_init(query, body)
if not query.id or not body or body == "" then return "指令不存在" end
local ok, result = pcall(json.decode, body)
if not ok or type(result) ~= 'table' then
return "decode body error"
end
query.id = tonumber(query.id)
local agent = datacenter.get("agent", query.id)
if agent and agent.serv then
-- local ok, result = pcall(skynet.call, agent.serv, "role", "accountInit", result)
-- return ok and result or "指令在线失败"
skynet.call(agent.serv, "role", "accountInit", result)
return "成功"
else
return "角色不在线"
end
end
|
3fe4471e
zhouhaihai
热更新 demo
|
220
221
|
return _M
|