Commit c7c5571b41739c007bc042a119c05fb44348efab

Authored by zhouhaihai
2 parents 632c507c bc36785e

Merge branch 'develop' into qa

Showing 2 changed files with 28 additions and 5 deletions   Show diff stats
src/adv/AdvBattle.lua
@@ -61,7 +61,7 @@ end @@ -61,7 +61,7 @@ end
61 61
62 function Battle:initPlayer() 62 function Battle:initPlayer()
63 local advTeam = self.adv.owner:getProperty("advTeam") 63 local advTeam = self.adv.owner:getProperty("advTeam")
64 - if not next(advTeam.heros) then return end 64 + if not advTeam.heros or not next(advTeam.heros) then return end
65 local leaderPassive = {} 65 local leaderPassive = {}
66 local player = advTeam.player 66 local player = advTeam.player
67 if not player then 67 if not player then
@@ -24,6 +24,8 @@ local agent_util, cs @@ -24,6 +24,8 @@ local agent_util, cs
24 _hotfixActions = _hotfixActions or {} 24 _hotfixActions = _hotfixActions or {}
25 _hotfixClass = _hotfixClass or {} 25 _hotfixClass = _hotfixClass or {}
26 26
  27 +_codeSession = {}
  28 +
27 --- {{{ 定时器相关 29 --- {{{ 定时器相关
28 local function handle_timeout() 30 local function handle_timeout()
29 if not agentInfo.open_timer then return end 31 if not agentInfo.open_timer then return end
@@ -48,6 +50,7 @@ function cancel_agent_timer() @@ -48,6 +50,7 @@ function cancel_agent_timer()
48 end 50 end
49 ---- 定时器相关 }}} 51 ---- 定时器相关 }}}
50 52
  53 +
51 local _pipelinings = {} --可同时多个序列 栈的形式保证嵌套不出错 54 local _pipelinings = {} --可同时多个序列 栈的形式保证嵌套不出错
52 function SendPacket(actionCode, bin, client_fd) 55 function SendPacket(actionCode, bin, client_fd)
53 -- 内部消息不扩散出去 56 -- 内部消息不扩散出去
@@ -57,22 +60,31 @@ function SendPacket(actionCode, bin, client_fd) @@ -57,22 +60,31 @@ function SendPacket(actionCode, bin, client_fd)
57 end 60 end
58 return 61 return
59 end 62 end
60 -  
61 - 63 +
62 client_fd = client_fd or agentInfo.client_fd 64 client_fd = client_fd or agentInfo.client_fd
63 65
64 local handlerName = actionHandlers[actionCode] 66 local handlerName = actionHandlers[actionCode]
65 - if string.sub(handlerName, -3, -1) == "Rpc" then 67 + local isRpc = string.sub(handlerName, -3, -1) == "Rpc"
  68 + local session = _codeSession[actionCode] or 0
  69 + if isRpc then
66 actionCode = actionCode + rpcResponseBegin 70 actionCode = actionCode + rpcResponseBegin
67 end 71 end
  72 +
68 -- 查看是否是在 流水线操作中 73 -- 查看是否是在 流水线操作中
69 if #_pipelinings > 0 then 74 if #_pipelinings > 0 then
70 local _curPipelining = _pipelinings[#_pipelinings] 75 local _curPipelining = _pipelinings[#_pipelinings]
71 _curPipelining[client_fd] = _curPipelining[client_fd] or {} --区分不同客户端 76 _curPipelining[client_fd] = _curPipelining[client_fd] or {} --区分不同客户端
72 - table.insert(_curPipelining[client_fd], {actionCode, bin}) 77 + if not isRpc then
  78 + session = nil
  79 + end
  80 + table.insert(_curPipelining[client_fd], {actionCode, bin, session})
73 else 81 else
74 if #bin > 0 then bin = xxtea.encrypt(bin, XXTEA_KEY) end 82 if #bin > 0 then bin = xxtea.encrypt(bin, XXTEA_KEY) end
75 local head = string.pack("H", actionCode) 83 local head = string.pack("H", actionCode)
  84 + if isRpc then
  85 + -- 是回复 -- 有session号
  86 + head = head .. string.pack("H", session)
  87 + end
76 return socket.write(client_fd, netpack.pack(head .. bin)) 88 return socket.write(client_fd, netpack.pack(head .. bin))
77 end 89 end
78 end 90 end
@@ -153,6 +165,7 @@ function rpcOtherUnion(id, funcName, ...) @@ -153,6 +165,7 @@ function rpcOtherUnion(id, funcName, ...)
153 end 165 end
154 end 166 end
155 167
  168 +
156 skynet.register_protocol { 169 skynet.register_protocol {
157 name = "client", 170 name = "client",
158 id = skynet.PTYPE_CLIENT, 171 id = skynet.PTYPE_CLIENT,
@@ -175,6 +188,13 @@ skynet.register_protocol { @@ -175,6 +188,13 @@ skynet.register_protocol {
175 return 188 return
176 end 189 end
177 190
  191 + if string.sub(actionName, -3, -1) == "Rpc" then
  192 + -- 是请求 -- 有session号
  193 + local codeSession = string.unpack("H", string.sub(data, 1, 2))
  194 + _codeSession[cmd] = codeSession
  195 + data = string.sub(data, 3)
  196 + end
  197 +
178 local method 198 local method
179 if _hotfixActions[actionName] then 199 if _hotfixActions[actionName] then
180 method = _hotfixActions[actionName] 200 method = _hotfixActions[actionName]
@@ -207,6 +227,9 @@ skynet.register_protocol { @@ -207,6 +227,9 @@ skynet.register_protocol {
207 agentInfo.role:endActionUcode() 227 agentInfo.role:endActionUcode()
208 end 228 end
209 229
  230 + -- 清掉请求session
  231 + _codeSession[cmd] = nil
  232 +
210 if not result or type(result) == "number" then 233 if not result or type(result) == "number" then
211 SendPacket(actionCodes.Sys_innerErrorMsg, MsgPack.pack({id = cmd * 100 + (result or 0)})) 234 SendPacket(actionCodes.Sys_innerErrorMsg, MsgPack.pack({id = cmd * 100 + (result or 0)}))
212 end 235 end