Commit cc5ca7f30974819bdce0024506528c11cece9e1f
1 parent
d8ba6e11
缓存battleKey
Showing
1 changed file
with
4 additions
and
6 deletions
Show diff stats
src/actions/HangAction.lua
| @@ -120,6 +120,7 @@ function _M.checkRpc(agent, data) | @@ -120,6 +120,7 @@ function _M.checkRpc(agent, data) | ||
| 120 | return true | 120 | return true |
| 121 | end | 121 | end |
| 122 | 122 | ||
| 123 | +local _BattleKey = nil | ||
| 123 | function _M.startBattleRpc(agent, data) | 124 | function _M.startBattleRpc(agent, data) |
| 124 | local role = agent.role | 125 | local role = agent.role |
| 125 | local msg = MsgPack.unpack(data) | 126 | local msg = MsgPack.unpack(data) |
| @@ -141,10 +142,8 @@ function _M.startBattleRpc(agent, data) | @@ -141,10 +142,8 @@ function _M.startBattleRpc(agent, data) | ||
| 141 | return 3 | 142 | return 3 |
| 142 | end | 143 | end |
| 143 | 144 | ||
| 144 | - local key = tostring(math.random()) | ||
| 145 | - hangInfo.key = key | ||
| 146 | - local nowTime = skynet.timex() | ||
| 147 | - role:updateProperty({field = "hangInfo", value = hangInfo}) | 145 | + _BattleKey = tostring(math.random()) |
| 146 | + | ||
| 148 | role:checkTaskEnter("HangBattle", {id = carbonId}) | 147 | role:checkTaskEnter("HangBattle", {id = carbonId}) |
| 149 | SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = key})) | 148 | SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = key})) |
| 150 | return true | 149 | return true |
| @@ -154,7 +153,7 @@ function _M.endBattleRpc(agent, data) | @@ -154,7 +153,7 @@ function _M.endBattleRpc(agent, data) | ||
| 154 | local role = agent.role | 153 | local role = agent.role |
| 155 | local msg = MsgPack.unpack(data) | 154 | local msg = MsgPack.unpack(data) |
| 156 | local hangInfo = role:getProperty("hangInfo") | 155 | local hangInfo = role:getProperty("hangInfo") |
| 157 | - if not msg.key or msg.key ~= hangInfo.key then | 156 | + if not msg.key or msg.key ~= _BattleKey then |
| 158 | return 1 | 157 | return 1 |
| 159 | end | 158 | end |
| 160 | local carbonId = msg.carbonId | 159 | local carbonId = msg.carbonId |
| @@ -190,7 +189,6 @@ function _M.endBattleRpc(agent, data) | @@ -190,7 +189,6 @@ function _M.endBattleRpc(agent, data) | ||
| 190 | 189 | ||
| 191 | role:checkTaskEnter("HangPass", {id = carbonId}) | 190 | role:checkTaskEnter("HangPass", {id = carbonId}) |
| 192 | end | 191 | end |
| 193 | - hangInfo.key = nil | ||
| 194 | role:updateProperty({field = "hangInfo", value = hangInfo}) | 192 | role:updateProperty({field = "hangInfo", value = hangInfo}) |
| 195 | 193 | ||
| 196 | role:log("hang_action", {desc = "hangBattle", short1 = msg.starNum > 0 and 1 or 0, int1 = carbonId}) | 194 | role:log("hang_action", {desc = "hangBattle", short1 = msg.starNum > 0 and 1 or 0, int1 = carbonId}) |