Commit cb3b7127d4e8c63a2ba2b60a35808cecabfa8f5d

Authored by zhouhaihai
2 parents 377a0dae bc36785e

Merge branch 'develop' into player

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