Commit 5dfc497874aa081fff5f73e3a2d30d32178dbb9f

Authored by zhouhaihai
1 parent c384626d

好友完善

Showing 2 changed files with 33 additions and 27 deletions   Show diff stats
src/actions/FriendAction.lua
... ... @@ -136,6 +136,7 @@ function _M.applyRpc(agent, data)
136 136 red:hlen(FRIEND_KEY:format(roleId))
137 137 red:hlen(FRIEND_KEY:format(objectId))
138 138 end)
  139 +
139 140 -- 玩家id不存在
140 141 if not result and redret[1] ~= 1 then
141 142 result = 1
... ... @@ -155,7 +156,7 @@ function _M.applyRpc(agent, data)
155 156 end
156 157  
157 158 -- 你把对方拉黑了
158   - if not result and redret[4] == 1 then
  159 + if not result and redret[5] == 1 then
159 160 result = 5
160 161 end
161 162  
... ... @@ -280,7 +281,7 @@ function _M.handleApplyRpc(agent, data)
280 281 redisproxy:del(FRIEND_APPLY_KEY:format(roleId))
281 282 elseif cmd == 3 then -- 一键同意
282 283 local redret = redisproxy:pipelining(function(red)
283   - red:zrange(FRIEND_APPLY_KEY:format(roleId))
  284 + red:zrange(FRIEND_APPLY_KEY:format(roleId), 0, -1)
284 285 red:SMEMBERS(FRIEND_POINT:format(roleId))
285 286 end)
286 287 local allIds = redret[1]
... ... @@ -429,6 +430,8 @@ function _M.blockRpc(agent, data)
429 430 red:hdel(FRIEND_KEY:format(objectId), roleId)
430 431 red:sadd(FRIEND_BLACK_KEY:format(roleId), objectId)
431 432 end)
  433 + rpcRole(objectId, "SendPacket", actionCodes.Friend_updateProperty, MsgPack.pack({deleteFriend = 1, roleId = roleId}))
  434 +
432 435 end
433 436 elseif cmd == 2 then
434 437 redisproxy:SREM(FRIEND_BLACK_KEY:format(roleId), objectId)
... ... @@ -456,6 +459,7 @@ function _M.blockListRpc(agent, data)
456 459  
457 460 }))
458 461 end
  462 +
459 463 SendPacket(actionCodes.Friend_blockListRpc, MsgPack.pack({list = blockList}))
460 464 return true
461 465 end
... ... @@ -588,38 +592,44 @@ function _M.randomRpc(agent, data)
588 592  
589 593 local redret = redisproxy:pipelining(function (red)
590 594 red:hgetall(FRIEND_KEY:format(roleId))
591   - red:zrevrange(FRIEND_RECOMMEND, 0, globalCsv.friendRecommendLimit + globalCsv.friendListLimit)
  595 + red:zrevrange(FRIEND_RECOMMEND, 0, globalCsv.friendRecommendLimit + globalCsv.friendListLimit + 10) --扩充10个
  596 + red:SMEMBERS(FRIEND_BLACK_KEY:format(roleId))
592 597 end)
593   -
594   - local friends = redret[1]
  598 + local friends = {}
  599 + for i = 1, #redret[1], 2 do
  600 + friends[tonumber(redret[1][i])] = redret[1][i + 1]
  601 + end
  602 +
595 603 local newList = redret[2]
  604 + local hadBlack = formatArray(redret[3])
  605 +
596 606 local needRoleIds = {}
597 607 for _, newId in pairs(newList) do
598 608 local numNewId = tonumber(newId)
599   - if numNewId ~= roleId and not friends[newId] then
  609 + if numNewId ~= roleId and not friends[numNewId] and not hadBlack[numNewId] then
600 610 table.insert(needRoleIds, numNewId)
601 611 end
602 612 end
603 613  
604 614 local randomRoles = {}
605   - for _, objId in ipairs(needRoleIds) do
606   - local online, info = getRoleInfo(objId)
607   - local redret = redisproxy:pipelining(function (red)
  615 + local redret = redisproxy:pipelining(function (red)
  616 + for _, objId in ipairs(needRoleIds) do
608 617 red:zscore(FRIEND_APPLY_KEY:format(objId), roleId)
609   - red:sismember(FRIEND_BLACK_KEY:format(roleId), objId)
610   - end)
611   - local hadApply = redret[1] and 1 or nil
612   - local inBlack = redret[2] == 1 and 1 or nil
613   -
614   - table.insert(randomRoles, table_merge({
615   - roleId = objId,
616   - online = online,
617   - hadApply = hadApply,
618   - inBlack = inBlack,
619   - }, info, {
620   -
621   - }))
622   - if #randomRoles >= globalCsv.friendRecommendLimit then break end
  618 + end
  619 + end)
  620 + for idx, objId in ipairs(needRoleIds) do
  621 + if not redret[idx] then
  622 + local online, info = getRoleInfo(objId)
  623 + table.insert(randomRoles, table_merge({
  624 + roleId = objId,
  625 + online = online,
  626 + hadApply = hadApply,
  627 + inBlack = inBlack,
  628 + }, info, {
  629 +
  630 + }))
  631 + if #randomRoles >= globalCsv.friendRecommendLimit then break end
  632 + end
623 633 end
624 634  
625 635 SendPacket(actionCodes.Friend_randomRpc, MsgPack.pack({list = randomRoles}))
... ...
src/models/RoleTask.lua
... ... @@ -394,10 +394,6 @@ function RoleTask.bind(Role)
394 394 end
395 395 nStatus = math.max(nStatus, n)
396 396 end
397   - if achiveData.id == 35 then
398   - print(nStatus)
399   - end
400   -
401 397 if nStatus > curStatus then
402 398 table.insert(change, {type = "achiveT", field = tId, value = nStatus})
403 399 end
... ...