Commit 4dc77717a9204577c6fac5e4a32ce15ea0e47c0a
1 parent
8b65a363
压测
Showing
15 changed files
with
848 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,12 @@ |
1 | +root = "./" | |
2 | +thread = 8 | |
3 | +logger = nil | |
4 | +harbor = 0 | |
5 | +start = "start" -- main script | |
6 | +bootstrap = "snlua bootstrap" -- The service for bootstrap | |
7 | + | |
8 | +lua_path = root .."skynet/lualib/?.lua;"..root.."robot/?.lua;"..root.."src/?.lua" | |
9 | +luaservice = root.."skynet/service/?.lua;"..root.."robot/?.lua" | |
10 | +lualoader = "skynet/lualib/loader.lua" | |
11 | +cpath = root.."skynet/cservice/?.so" | |
12 | +lua_cpath = "skynet/luaclib/?.so" | ... | ... |
... | ... | @@ -0,0 +1,190 @@ |
1 | +require "ProtocolCode" | |
2 | +require "shared.init" | |
3 | +require "utils.init" | |
4 | +skynet = require "skynet" | |
5 | +local socketdriver = require "skynet.socketdriver" | |
6 | +local netpack = require "skynet.netpack" | |
7 | +local xxtea = require "xxtea" | |
8 | +local httpc = require("http.httpc") | |
9 | +local config = require "robot_config" | |
10 | + | |
11 | +local XXTEA_KEY = "699D448D6D24f7F941E9F6E99F823E18" | |
12 | + | |
13 | +local CMD = {} | |
14 | +local client = {} | |
15 | +local eventListener = {} | |
16 | + | |
17 | +local ignoreListener = { | |
18 | + ["Role.updateProperty"] = function(data) | |
19 | + local msg = MsgPack.unpack(data) | |
20 | + for _, one in pairs(msg) do | |
21 | + client.role[one.key] = one.newValue | |
22 | + end | |
23 | + end, | |
24 | + ["Role.updateProperties"] = function(data) | |
25 | + local msg = MsgPack.unpack(data) | |
26 | + for field, value in pairs(msg) do | |
27 | + client.role[field] = value | |
28 | + end | |
29 | + end, | |
30 | + ["Role.notifyNewEvent"] = true, | |
31 | + ["Role.chat"] = true, | |
32 | + ["Role.updateItems"] = true, | |
33 | + ["Gm.receiveResponse"] = true, | |
34 | + ["Role.changeUpdate"] = true, | |
35 | + ["Role.loadRunes"] = true, | |
36 | + ["Hero.loadInfos"] = true, | |
37 | + ["Sys.innerErrorMsg"] = function(data) | |
38 | + local msg = MsgPack.unpack(data) | |
39 | + log("innerErrorMsg: " .. msg.id) | |
40 | + end, | |
41 | +} | |
42 | + | |
43 | +function addListener(actionCode, callback, isKeep) | |
44 | + callback = callback or function() end | |
45 | + local handlerName = actionHandlers[actionCode] | |
46 | + if string.sub(handlerName, -3, -1) == "Rpc" then | |
47 | + actionCode = actionCode + rpcResponseBegin | |
48 | + end | |
49 | + if eventListener[actionHandlers[actionCode]] then | |
50 | + log(handlerName .. " had listener") | |
51 | + end | |
52 | + local trueCall = callback | |
53 | + if not isKeep then | |
54 | + trueCall = function(data) | |
55 | + removeListener(actionCode) | |
56 | + callback(data) | |
57 | + end | |
58 | + end | |
59 | + eventListener[actionHandlers[actionCode]] = trueCall | |
60 | +end | |
61 | + | |
62 | +function removeListener(actionCode) | |
63 | + local handlerName = actionHandlers[actionCode] | |
64 | + if string.sub(handlerName, -3, -1) == "Rpc" then | |
65 | + actionCode = actionCode + rpcResponseBegin | |
66 | + end | |
67 | + eventListener[actionHandlers[actionCode]] = nil | |
68 | +end | |
69 | + | |
70 | +function triggerListener(listener, data) | |
71 | + if eventListener[listener] then | |
72 | + if #data > 0 then data = xxtea.decrypt(data, XXTEA_KEY) end | |
73 | + eventListener[listener](data) | |
74 | + elseif ignoreListener[listener] then | |
75 | + if type(ignoreListener[listener]) == "function" then | |
76 | + if #data > 0 then data = xxtea.decrypt(data, XXTEA_KEY) end | |
77 | + ignoreListener[listener](data) | |
78 | + end | |
79 | + else | |
80 | + log(listener .. " no handle!!!") | |
81 | + end | |
82 | +end | |
83 | + | |
84 | +function sendServer(actionCode, bin) | |
85 | + local session = 0 | |
86 | + local handlerName = actionHandlers[actionCode] | |
87 | + if actionCode == actionCodes.Role_queryLoginRpc or string.sub(handlerName, -3, -1) ~= "Rpc" then | |
88 | + session = nil | |
89 | + end | |
90 | + | |
91 | + local data = string.pack("H", actionCode) | |
92 | + if session then | |
93 | + data = data .. string.pack("H", session) | |
94 | + end | |
95 | + | |
96 | + if #bin > 0 then bin = xxtea.encrypt(bin, XXTEA_KEY) end | |
97 | + data = data .. bin | |
98 | + | |
99 | + socketdriver.send(client.fd, netpack.pack(data)) | |
100 | +end | |
101 | + | |
102 | +function requestServer(actionCode, bin, callback, isKeep) | |
103 | + sendServer(actionCode, bin) | |
104 | + addListener(actionCode, callback, isKeep) | |
105 | +end | |
106 | + | |
107 | +local function heartBeat() | |
108 | + sendServer(actionCodes.Sys_heartBeat, "") | |
109 | + skynet.timeout(500, heartBeat) | |
110 | +end | |
111 | + | |
112 | +local function startUnit(unit) | |
113 | + if unit == "login" then | |
114 | + else | |
115 | + unit = math.randWeight(config.units, "weight") | |
116 | + end | |
117 | + | |
118 | + local ok, unitTest = pcall(require, "unitTest." .. unit) | |
119 | + if not ok then | |
120 | + print("unitTest load error : " .. unitTest) | |
121 | + end | |
122 | + | |
123 | + unitTest.new(client):startTest() | |
124 | +end | |
125 | + | |
126 | +local function handle_timeout10000() | |
127 | + rpcServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 1, pm2 = 500})) | |
128 | + rpcServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 2, pm2 = 500})) | |
129 | + skynet.timeout(10000, handle_timeout6000) | |
130 | +end | |
131 | + | |
132 | +-- 登录成功开始任务 | |
133 | +function CMD.task() | |
134 | + heartBeat() | |
135 | + startUnit() | |
136 | +end | |
137 | + | |
138 | +-- 开始登录 | |
139 | +function CMD.start(fd, id) | |
140 | + client.fd = fd | |
141 | + client.clientId = id | |
142 | + | |
143 | + local uname = config.uname_prefix .. id | |
144 | + client.uname = uname | |
145 | + local status, body = httpc.get(config.http, "/login?" .. httpGetFormatData({token = uname, device = "test", channel = "develop"})) | |
146 | + if tonumber(status) ~= 200 then | |
147 | + print("http get error", uname, body) | |
148 | + return | |
149 | + end | |
150 | + local servInfo = json.decode(body) | |
151 | + client.uid = servInfo.userid | |
152 | + | |
153 | + startUnit("login") | |
154 | +end | |
155 | + | |
156 | +-- 退出 | |
157 | +function CMD.exit() | |
158 | + skynet.exit() | |
159 | +end | |
160 | + | |
161 | +skynet.register_protocol { | |
162 | + name = "client", | |
163 | + id = skynet.PTYPE_CLIENT, | |
164 | + unpack = function (msg, sz) | |
165 | + local data = skynet.tostring(msg, sz) | |
166 | + local cmd = string.unpack("H", string.sub(data, 1, 2)) | |
167 | + return cmd, string.sub(data, 3) | |
168 | + end, | |
169 | + dispatch = function(session, address, cmd, data) | |
170 | + local actionName = actionHandlers[cmd] | |
171 | + if not actionName then | |
172 | + print("actionName not exist", actionName) | |
173 | + return | |
174 | + end | |
175 | + | |
176 | + if cmd > rpcResponseBegin and actionName ~= "Role.queryLoginRpcResponse" then | |
177 | + -- 回复 有session | |
178 | + session = string.unpack("H", string.sub(data, 1, 2)) | |
179 | + data = string.sub(data, 3) | |
180 | + end | |
181 | + | |
182 | + triggerListener(actionName, data) | |
183 | + end, | |
184 | +} | |
185 | + | |
186 | +skynet.start(function () | |
187 | + skynet.dispatch("lua", function (_,_,cmd,...) | |
188 | + skynet.ret(skynet.pack(CMD[cmd](...))) | |
189 | + end) | |
190 | +end) | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +local skynet = require "skynet" | |
2 | +local string_format = string.format | |
3 | +local math_floor = math.floor | |
4 | + | |
5 | + | |
6 | +function log( msg ) | |
7 | + print(string_format("[%s]: %s", os.date("%m%d %H:%M:%S", math_floor(skynet.time())), msg)) | |
8 | +end | |
9 | + | |
10 | + | |
11 | + | |
12 | +return { | |
13 | + http = "http://106.13.60.20:9090", -- 登录服 | |
14 | + host = "127.0.0.1", --服务器地址 | |
15 | + port = 12001, -- 服务器端口 | |
16 | + | |
17 | + | |
18 | + online = 100, -- 稳定状态在线人数 | |
19 | + inpre = 10, -- 稳定前每秒进入人数 -- 必须小于online数 | |
20 | + max = 200, -- 最大玩家数 必须大于 online 数 | |
21 | + online_time = {10 * 60, 20 * 60}, -- 在线时间控制 秒 | |
22 | + | |
23 | + uname_prefix = "robot", --机器名称前缀 | |
24 | + | |
25 | + | |
26 | + -- 机器上线后的行为 | |
27 | + units = { | |
28 | + chat = {weight = 100}, -- 聊天 | |
29 | + item = {weight = 100}, -- 物品操作 | |
30 | + hero = {weight = 500}, -- 英雄 | |
31 | + hang = {weight = 1000}, -- 挂机战斗 | |
32 | + tower = {weight = 500}, -- 爬塔 | |
33 | + car = {weight = 100}, -- 爬塔 | |
34 | + pvp = {weight = 500}, -- pvp | |
35 | + email = {weight = 100}, -- 邮件 | |
36 | + adv = {weight = 200}, -- 冒险 | |
37 | + } | |
38 | +} | ... | ... |
... | ... | @@ -0,0 +1,135 @@ |
1 | +require("utils.StringUtil") | |
2 | +require("utils.TableUtil") | |
3 | +require "utils.MathUtil" | |
4 | +local config = require "robot_config" | |
5 | +local skynet = require "skynet" | |
6 | +local netpack = require "skynet.netpack" | |
7 | +local socketdriver = require "skynet.socketdriver" | |
8 | +local string_format = string.format | |
9 | + | |
10 | +local queue = {} | |
11 | +local fd2serv = {} | |
12 | +local id2fd = {} | |
13 | +local MSG = {} | |
14 | +local id_max = 0 -- robot id | |
15 | + | |
16 | + | |
17 | +function MSG.open( ... ) | |
18 | + print("open", ...) | |
19 | +end | |
20 | + | |
21 | +function MSG.close(fd) | |
22 | + if fd2serv[fd] then | |
23 | + skynet.send(fd2serv[fd].agent, "lua", "exit") | |
24 | + | |
25 | + log(string_format("logout %s", fd2serv[fd].id)) | |
26 | + | |
27 | + id2fd[fd2serv[fd].id] = nil | |
28 | + fd2serv[fd] = nil | |
29 | + end | |
30 | +end | |
31 | + | |
32 | +function MSG.error(fd, msg) | |
33 | + print("MSG.error", fd, msg) | |
34 | + MSG.close(fd) | |
35 | +end | |
36 | + | |
37 | +function MSG.data(fd, msg, sz) | |
38 | + if fd2serv[fd] then | |
39 | + skynet.redirect(fd2serv[fd].agent, 0, "client", 0, msg, sz) | |
40 | + end | |
41 | +end | |
42 | + | |
43 | +local function dispatch_queue() | |
44 | + local fd, msg, sz = netpack.pop(queue) | |
45 | + if fd then | |
46 | + skynet.fork(dispatch_queue) | |
47 | + MSG.data(fd, msg, sz) | |
48 | + for fd, msg, sz in netpack.pop, queue do | |
49 | + MSG.data(fd, msg, sz) | |
50 | + end | |
51 | + end | |
52 | +end | |
53 | +MSG.more = dispatch_queue | |
54 | + | |
55 | +skynet.register_protocol { | |
56 | + name = "socket", | |
57 | + id = skynet.PTYPE_SOCKET, | |
58 | + unpack = function (msg, sz) | |
59 | + return netpack.filter(queue, msg, sz) | |
60 | + end, | |
61 | + dispatch = function (_, _, q, type, ...) | |
62 | + queue = q | |
63 | + if type then | |
64 | + MSG[type](...) | |
65 | + end | |
66 | + end | |
67 | +} | |
68 | + | |
69 | +skynet.register_protocol { | |
70 | + name = "client", | |
71 | + id = skynet.PTYPE_CLIENT, | |
72 | +} | |
73 | + | |
74 | +local function add_robot() | |
75 | + local robot = skynet.newservice("robot") | |
76 | + local fd = socketdriver.connect(config.host, config.port) | |
77 | + socketdriver.start(fd) | |
78 | + local id | |
79 | + if id_max >= config.max then | |
80 | + while true do | |
81 | + id = math.randomInt(1, config.max) | |
82 | + if not id2fd[id] then | |
83 | + break | |
84 | + end | |
85 | + end | |
86 | + else | |
87 | + id_max = id_max + 1 | |
88 | + id = id_max | |
89 | + end | |
90 | + fd2serv[fd] = {agent = robot, id = id} | |
91 | + id2fd[id] = fd | |
92 | + pcall(skynet.call, robot, "lua", "start", fd, id) | |
93 | + log(string_format("login %s", fd2serv[fd].id)) | |
94 | + | |
95 | + -- 定时下线 | |
96 | + skynet.timeout(math.randomInt(config.online_time[1], config.online_time[2]) * 100, function() | |
97 | + socketdriver.close(fd) | |
98 | + MSG.close(fd) | |
99 | + end) | |
100 | +end | |
101 | + | |
102 | +local function online() | |
103 | + local curCount = 0 | |
104 | + for _, _ in pairs(fd2serv) do | |
105 | + curCount = curCount + 1 | |
106 | + end | |
107 | + | |
108 | + -- 及时补充人数 | |
109 | + if curCount < config.online then | |
110 | + for i = curCount + 1, config.online do | |
111 | + add_robot() | |
112 | + end | |
113 | + end | |
114 | + | |
115 | + -- log(string_format("online %s", curCount)) | |
116 | + skynet.timeout(100, online) | |
117 | +end | |
118 | + | |
119 | +local function start() | |
120 | + log("start testing ...") | |
121 | + | |
122 | + for i = 1, config.online, config.inpre do | |
123 | + for j = 1, config.inpre do | |
124 | + add_robot() | |
125 | + end | |
126 | + skynet.sleep(100) | |
127 | + end | |
128 | + | |
129 | + -- 每秒检查补充在线人数 | |
130 | + online() | |
131 | +end | |
132 | + | |
133 | +skynet.start(function() | |
134 | + skynet.fork(start) | |
135 | +end) | |
0 | 136 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,38 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("hang", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "fb", pm1 = 10606})) | |
11 | + self:task() | |
12 | +end | |
13 | + | |
14 | + | |
15 | +local taskMap = { | |
16 | + startAdv = {100}, | |
17 | + rank = {10}, | |
18 | +} | |
19 | + | |
20 | +function _M:task() | |
21 | + local curTask = math.randWeight(taskMap, 1) | |
22 | + self[curTask](self) | |
23 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
24 | +end | |
25 | + | |
26 | +function _M:startAdv() | |
27 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "advf", pm1 = 10606})) | |
28 | + requestServer(actionCodes.Adv_startAdvRpc, MsgPack.pack({chapterId = 101, format = {leader = 1, leader2 = 2, heros = {[1] = 1, [2] = 2}}})) | |
29 | + requestServer(actionCodes.Adv_exitAdvRpc, '') | |
30 | +end | |
31 | + | |
32 | + | |
33 | +function _M:rank() | |
34 | + requestServer(actionCodes.Adv_rankRpc, '') | |
35 | +end | |
36 | + | |
37 | + | |
38 | +return _M | |
0 | 39 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,34 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("hang", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "fb", pm1 = 10606})) | |
11 | + self:task() | |
12 | +end | |
13 | + | |
14 | + | |
15 | +local taskMap = { | |
16 | + equip = {100}, | |
17 | +} | |
18 | + | |
19 | +function _M:task() | |
20 | + local curTask = math.randWeight(taskMap, 1) | |
21 | + self[curTask](self) | |
22 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
23 | +end | |
24 | + | |
25 | +function _M:equip() | |
26 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 7103})) | |
27 | + requestServer(actionCodes.Car_saleEquipRpc, MsgPack.pack({backs = {[7103] = 1}})) | |
28 | +end | |
29 | + | |
30 | + | |
31 | + | |
32 | + | |
33 | + | |
34 | +return _M | |
0 | 35 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,43 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("chat", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + self:task() | |
11 | +end | |
12 | + | |
13 | +local taskMap = { | |
14 | + chat = {100}, | |
15 | + searchFriend = {100}, | |
16 | + friendList = {100}, | |
17 | + friendRandom = {100}, | |
18 | +} | |
19 | + | |
20 | +function _M:task() | |
21 | + local curTask = math.randWeight(taskMap, 1) | |
22 | + self[curTask](self) | |
23 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
24 | +end | |
25 | + | |
26 | + | |
27 | +function _M:chat() | |
28 | + requestServer(actionCodes.Role_chatRpc, MsgPack.pack({ cmd = 1, content = "我就是个机器人, 我来测试测试没问题吧。"})) | |
29 | +end | |
30 | + | |
31 | +function _M:searchFriend() | |
32 | + requestServer(actionCodes.Friend_searchRpc, MsgPack.pack({ key = "hehehe"})) | |
33 | +end | |
34 | + | |
35 | +function _M:friendList() | |
36 | + requestServer(actionCodes.Friend_listRpc, '') | |
37 | +end | |
38 | + | |
39 | +function _M:friendRandom() | |
40 | + requestServer(actionCodes.Friend_randomRpc, '') | |
41 | +end | |
42 | + | |
43 | +return _M | |
0 | 44 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,39 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("hero", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + self:task() | |
11 | +end | |
12 | + | |
13 | + | |
14 | +local taskMap = { | |
15 | + list = {100}, | |
16 | + drawAllAttach = {100}, | |
17 | + delete = {100}, | |
18 | +} | |
19 | + | |
20 | +function _M:task() | |
21 | + local curTask = math.randWeight(taskMap, 1) | |
22 | + self[curTask](self) | |
23 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
24 | +end | |
25 | + | |
26 | +function _M:list() | |
27 | + requestServer(actionCodes.Email_listRpc, '') | |
28 | +end | |
29 | + | |
30 | +function _M:drawAllAttach() | |
31 | + requestServer(actionCodes.Email_drawAllAttachRpc, '') | |
32 | +end | |
33 | + | |
34 | +function _M:delete() | |
35 | + requestServer(actionCodes.Email_delRpc, '') | |
36 | +end | |
37 | + | |
38 | + | |
39 | +return _M | |
0 | 40 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,37 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("hang", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + self:task() | |
11 | +end | |
12 | + | |
13 | + | |
14 | +local taskMap = { | |
15 | + hangBattle = {100}, | |
16 | +} | |
17 | + | |
18 | +function _M:task() | |
19 | + local curTask = math.randWeight(taskMap, 1) | |
20 | + self[curTask](self) | |
21 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
22 | +end | |
23 | + | |
24 | +function _M:hangBattle() | |
25 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "fbc", pm1 = 10101})) | |
26 | + requestServer(actionCodes.Hang_startRpc, MsgPack.pack({carbonId = 10101}), function() | |
27 | + requestServer(actionCodes.Hang_startBattleRpc, MsgPack.pack({carbonId = 10101}), function(data) | |
28 | + local msg = MsgPack.unpack(data) | |
29 | + requestServer(actionCodes.Hang_endBattleRpc, MsgPack.pack({key = msg.key, carbonId = 10101, starNum = 1})) | |
30 | + end) | |
31 | + end) | |
32 | +end | |
33 | + | |
34 | + | |
35 | + | |
36 | + | |
37 | +return _M | |
0 | 38 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,43 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("hero", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "fb", pm1 = 10606})) | |
11 | + self:task() | |
12 | +end | |
13 | + | |
14 | + | |
15 | +local taskMap = { | |
16 | + drawHero = {100}, | |
17 | + drawHero10 = {10}, | |
18 | + createHeroRandom = {10000}, | |
19 | +} | |
20 | + | |
21 | +function _M:task() | |
22 | + local curTask = math.randWeight(taskMap, 1) | |
23 | + self[curTask](self) | |
24 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
25 | +end | |
26 | + | |
27 | +function _M:drawHero() | |
28 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 3, pm2 = 400})) | |
29 | + requestServer(actionCodes.Hero_drawHeroRpc, MsgPack.pack({pool = 1, type = 1})) | |
30 | +end | |
31 | + | |
32 | +function _M:drawHero10() | |
33 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 3, pm2 = 4000})) | |
34 | + requestServer(actionCodes.Hero_drawHeroRpc, MsgPack.pack({pool = 2, type = 2})) | |
35 | +end | |
36 | + | |
37 | +function _M:createHeroRandom() | |
38 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 703, pm2 = 20})) | |
39 | + requestServer(actionCodes.Hero_createHeroRandomRpc, MsgPack.pack({itemId = 703})) | |
40 | +end | |
41 | + | |
42 | + | |
43 | +return _M | |
0 | 44 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,46 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("item", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + self:task() | |
11 | +end | |
12 | + | |
13 | + | |
14 | +local taskMap = { | |
15 | + saleItem = {100}, | |
16 | + openItem = {100}, | |
17 | + openTimeBox = {100}, | |
18 | +} | |
19 | + | |
20 | +function _M:task() | |
21 | + local curTask = math.randWeight(taskMap, 1) | |
22 | + self[curTask](self) | |
23 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
24 | +end | |
25 | + | |
26 | + | |
27 | +function _M:saleItem() | |
28 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 105, pm2 = 500})) | |
29 | + requestServer(actionCodes.Role_saleItemRpc, MsgPack.pack({backs = {[105] = 500}})) | |
30 | +end | |
31 | + | |
32 | + | |
33 | +function _M:openItem() | |
34 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 701, pm2 = 20})) | |
35 | + requestServer(actionCodes.Role_openItemRpc, MsgPack.pack({itemId = 701, count = 1})) | |
36 | +end | |
37 | + | |
38 | +function _M:openTimeBox() | |
39 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 6001, pm2 = 1})) | |
40 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "get", pm1 = 60, pm2 = 100})) | |
41 | + requestServer(actionCodes.Role_openTimeBoxRpc, MsgPack.pack({oper = 1, slot = 1, itemId = 6001}), function() | |
42 | + requestServer(actionCodes.Role_openTimeBoxRpc, MsgPack.pack({oper = 2, slot = 1, quick = 1})) | |
43 | + end) | |
44 | +end | |
45 | + | |
46 | +return _M | |
0 | 47 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,90 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | +local _M = class("login", require("unitTest.unitTest")) | |
5 | + | |
6 | +function _M:start() | |
7 | + requestServer(actionCodes.Role_queryLoginRpc, MsgPack.pack({uid = self.client.uid}), handler(self, self.onQueryLogin)) | |
8 | +end | |
9 | + | |
10 | +function _M:onQueryLogin(data) | |
11 | + local msg = MsgPack.unpack(data) | |
12 | + | |
13 | + if msg.ret == "RET_NOT_EXIST" then | |
14 | + requestServer(actionCodes.Role_createRpc, MsgPack.pack({ uid = self.client.uid }), function(data2) | |
15 | + local msg2 = MsgPack.unpack(data2) | |
16 | + self:sendLogin(msg2.roleName) | |
17 | + end) | |
18 | + elseif msg.ret == "RET_HAS_EXISTED" then | |
19 | + self:sendLogin(msg.name) | |
20 | + elseif msg.ret == "INNER_ERROR" then | |
21 | + -- 过几秒中尝试登录 | |
22 | + -- local time = math.random(5)*100 | |
23 | + -- skynet.timeout(time, function () | |
24 | + -- rpcServer(actionCodes.Role_queryLoginRpc, MsgPack.pack({uid = self.client.uid})) | |
25 | + -- end) | |
26 | + print("INNER_ERROR") | |
27 | + end | |
28 | +end | |
29 | + | |
30 | + | |
31 | +function _M:sendLogin(name) | |
32 | + self.client.name = name | |
33 | + | |
34 | + local totalWave = 0 | |
35 | + local roleData = {} | |
36 | + local waveTag = {} | |
37 | + | |
38 | + requestServer(actionCodes.Role_loginRpc, MsgPack.pack({name = self.client.name, codeVersion = 1}), function(data) | |
39 | + local msg = MsgPack.unpack(data) | |
40 | + if msg.wave then | |
41 | + totalWave = msg.wave | |
42 | + for key, value in pairs(msg) do | |
43 | + roleData[key] = value | |
44 | + end | |
45 | + waveTag[1] = true | |
46 | + end | |
47 | + | |
48 | + if msg.runeWave then | |
49 | + if not roleData.runeBag then | |
50 | + roleData.runeBag = {} | |
51 | + end | |
52 | + for _, rune in pairs(msg.runeBag) do | |
53 | + table.insert(roleData.runeBag, rune) | |
54 | + end | |
55 | + waveTag[msg.runeWave] = true | |
56 | + end | |
57 | + | |
58 | + if msg.heroWave then | |
59 | + if not roleData.heros then | |
60 | + roleData.heros = {} | |
61 | + end | |
62 | + for _, hero in pairs(msg.heros) do | |
63 | + table.insert(roleData.heros, hero) | |
64 | + end | |
65 | + waveTag[msg.heroWave] = true | |
66 | + end | |
67 | + | |
68 | + if msg.chatWave then | |
69 | + waveTag[msg.chatWave] = true | |
70 | + end | |
71 | + | |
72 | + -- 检查是否全部接收完 | |
73 | + if totalWave > 0 then | |
74 | + local finish = true | |
75 | + for _wave = 1, totalWave do | |
76 | + if not waveTag[_wave] then | |
77 | + finish = false | |
78 | + break | |
79 | + end | |
80 | + end | |
81 | + if finish then | |
82 | + self.client.role = roleData | |
83 | + removeListener(actionCodes.Role_loginRpc) | |
84 | + pcall(skynet.call, skynet.self(), "lua", "task") -- 开始任务 | |
85 | + end | |
86 | + end | |
87 | + end, true) | |
88 | +end | |
89 | + | |
90 | +return _M | |
0 | 91 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,47 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("pvp", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "fb", pm1 = 10606})) | |
11 | + self:task() | |
12 | +end | |
13 | + | |
14 | + | |
15 | +local taskMap = { | |
16 | + info = {1000}, | |
17 | + refresh = {100}, | |
18 | + rank = {100}, | |
19 | + record = {100}, | |
20 | +} | |
21 | + | |
22 | +function _M:task() | |
23 | + local curTask = math.randWeight(taskMap, 1) | |
24 | + self[curTask](self) | |
25 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
26 | +end | |
27 | + | |
28 | +function _M:info() | |
29 | + requestServer(actionCodes.Pvp_infoRpc, MsgPack.pack({ptype = 1})) | |
30 | +end | |
31 | + | |
32 | +function _M:refresh() | |
33 | + requestServer(actionCodes.Pvp_refreshMatchCRpc, '') | |
34 | +end | |
35 | + | |
36 | + | |
37 | +function _M:rank() | |
38 | + requestServer(actionCodes.Pvp_rankListRpc, MsgPack.pack({ptype = 1})) | |
39 | +end | |
40 | + | |
41 | +function _M:record() | |
42 | + requestServer(actionCodes.Pvp_recordListRpc, MsgPack.pack({ptype = 1})) | |
43 | +end | |
44 | + | |
45 | + | |
46 | + | |
47 | +return _M | |
0 | 48 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,40 @@ |
1 | +local MsgPack = MsgPack | |
2 | +local skynet = require "skynet" | |
3 | + | |
4 | + | |
5 | +local TIME_WAIT = 10 | |
6 | + | |
7 | +local _M = class("hang", require("unitTest.unitTest")) | |
8 | + | |
9 | +function _M:start() | |
10 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "fb", pm1 = 10606})) | |
11 | + self:task() | |
12 | +end | |
13 | + | |
14 | + | |
15 | +local taskMap = { | |
16 | + towerBattle = {100}, | |
17 | + towerRank = {3}, | |
18 | +} | |
19 | + | |
20 | +function _M:task() | |
21 | + local curTask = math.randWeight(taskMap, 1) | |
22 | + self[curTask](self) | |
23 | + skynet.timeout(TIME_WAIT * 100, handler(self, self.task)) | |
24 | +end | |
25 | + | |
26 | +function _M:towerBattle() | |
27 | + sendServer(actionCodes.Gm_clientRequest, MsgPack.pack({cmd = "tower", pm1 = 1})) | |
28 | + requestServer(actionCodes.Tower_startBattleRpc, MsgPack.pack({id = 1}), function(data) | |
29 | + requestServer(actionCodes.Tower_endBattleRpc, MsgPack.pack({key = self.client.role.towerInfo.k, id = 1, passTime = 100, starNum = 1})) | |
30 | + end) | |
31 | +end | |
32 | + | |
33 | +function _M:towerRank() | |
34 | + requestServer(actionCodes.Tower_rankRpc, MsgPack.pack({id = 1})) | |
35 | +end | |
36 | + | |
37 | + | |
38 | + | |
39 | + | |
40 | +return _M | |
0 | 41 | \ No newline at end of file | ... | ... |
... | ... | @@ -0,0 +1,16 @@ |
1 | +local unitTest = class("unitTest") | |
2 | + | |
3 | + | |
4 | +function unitTest:ctor(client) | |
5 | + self.client = client | |
6 | +end | |
7 | + | |
8 | +function unitTest:startTest() | |
9 | + self:start() | |
10 | +end | |
11 | + | |
12 | +function unitTest:start() | |
13 | + print("no start") | |
14 | +end | |
15 | + | |
16 | +return unitTest | |
0 | 17 | \ No newline at end of file | ... | ... |