From 8474ca362f0466e3e24cc9c60c3ea8ad02f21b6a Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Tue, 19 Nov 2019 15:19:47 +0800 Subject: [PATCH] 聊天 --- src/actions/FriendAction.lua | 4 ++-- src/actions/RoleAction.lua | 64 +++++++++++++++++++++++++++++++++++++++++++++++++--------------- src/models/Role.lua | 1 + src/services/mcast_util.lua | 13 ------------- 4 files changed, 52 insertions(+), 30 deletions(-) diff --git a/src/actions/FriendAction.lua b/src/actions/FriendAction.lua index 04d7765..d884636 100644 --- a/src/actions/FriendAction.lua +++ b/src/actions/FriendAction.lua @@ -307,7 +307,7 @@ function _M.handleApplyRpc(agent, data) redisproxy:pipelining(function (red) red:ZREM(FRIEND_APPLY_KEY:format(roleId), table_unpack(needAdd)) - red:hsetnx(FRIEND_KEY:format(roleId), table_unpack(needAddMy)) + red:HMSET(FRIEND_KEY:format(roleId), table_unpack(needAddMy)) for _, objectId in pairs(needAdd) do red:ZREM(FRIEND_APPLY_KEY:format(objectId), roleId) red:hsetnx(FRIEND_KEY:format(objectId), roleId, newTag)--告知对放有新好友 @@ -577,7 +577,7 @@ function _M.pointRpc(agent, data) reward = role:award({[ItemId.FriendPoint] = getCount}) role.dailyData:updateProperty({field = "getFP", value = getP}) else - result = result + 2 + result = (result or 0) + 2 end end else diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index bcb0ffc..6fa9b31 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -601,27 +601,61 @@ function _M.chatRpc(agent, data) time = now, } - local check = { - ["world"] = function () + + local waitTime = nil + local check = { + -- 世界聊天 + [1] = function () if role:getProperty("silent") > now then --禁言 result = 1 return end + + role._worldChatLimit = role._worldChatLimit or {start = 0, count = 0, canSayt = 0} --第一次开始说话时间 从第一次说话次数 能说话的时间 + + if now < role._worldChatLimit.canSayt then + result = 2 + waitTime = canSayt - now + return + end + + if now - role._worldChatLimit.start >= globalCsv.chat_world_limit.time then + role._worldChatLimit.start = now + role._worldChatLimit.count = 1 + else + role._worldChatLimit.count = role._worldChatLimit.count + 1 + if role._worldChatLimit.count > globalCsv.chat_world_limit.count then + role._worldChatLimit.count = 0 + role._worldChatLimit.start = 0 + role._worldChatLimit.canSayt = now + globalCsv.chat_world_limit.wait + result = 2 + waitTime = globalCsv.chat_world_limit.wait + return + end + end + mcast_util.pub_world(actionCodes.Role_chat, MsgPack.pack(response)) pcall(skynet.call, 'GLOBALD', "lua", "sendWorldMsg", role._channelIdx, response) end, - ["p2p"] = function () - -- local result - -- local objectId = msg.objectId - -- if redisproxy:hexists(FRIEND_KEY:format(roleId), objectId) then - -- response.to = objectId - -- result = mcast_util.pub_person(agent.client_fd, objectId, actionCodes.Role_chat, MsgPack.pack(response)) - -- else - -- result = SYS_ERR_CHAT_NOT_FRIEND - -- end - -- if result then - -- role:sendSysErrMsg(result) - -- end + -- 私聊 + [2] = function () + local objectId = msg.roleId + + if 0 == redisproxy:exists(string.format("role:%d", objectId)) then + result = 1 + return + end + + -- 若在线,实时发送聊天信息 + local agent = datacenter.get("agent", toRoleId) + if not agent then + result = 2 + return + end + local bin = MsgPack.pack(response) + SendPacket(actionCode, bin, agent.fd) + SendPacket(actionCode, bin, fromFd) + end, } if not check[cmd] then return end @@ -629,7 +663,7 @@ function _M.chatRpc(agent, data) if not result then check[cmd]() end - SendPacket(actionCodes.Role_chatRpc, MsgPack.pack({result = result})) + SendPacket(actionCodes.Role_chatRpc, MsgPack.pack({result = result, waitTime = waitTime})) return true end diff --git a/src/models/Role.lua b/src/models/Role.lua index 6b9227d..d04536d 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -196,6 +196,7 @@ function Role:data() loveStatus = self:getProperty("loveStatus"):toNumMap(), diamond = self:getAllDiamond(), bagLimit = self:getProperty("bagLimit"), + silent = self:getProperty("silent"), advPass = self:getProperty("advPass"), advInfo = self:getProperty("advInfo"), diff --git a/src/services/mcast_util.lua b/src/services/mcast_util.lua index 495d74d..85346f1 100644 --- a/src/services/mcast_util.lua +++ b/src/services/mcast_util.lua @@ -92,18 +92,5 @@ function _M.pub_union(actionCode, bin) chan_g:publish(actionCode, bin) end -function _M.pub_person(fromFd, toRoleId, actionCode, bin) - if 0 == redisproxy:exists(string.format("role:%d", toRoleId)) then - return SYS_ERROR_CHAT_NOT_EXIST - end - -- 若在线,实时发送聊天信息 - local agent = datacenter.get("agent", toRoleId) - if agent then - SendPacket(actionCode, bin, agent.fd) - SendPacket(actionCode, bin, fromFd) - return - end - return SYS_ERROR_CHAT_NOT_ONLINE -end return _M \ No newline at end of file -- libgit2 0.21.2