HomeServer/Server/AllServer/MultiServer/ChatManage.lua
2024-11-20 15:41:37 +08:00

135 lines
5.0 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local skynet = require "skynet"
local oo = require "Class"
local gameCmd = require "GameCmd"
local json =require "json"
local log = require "Log"
local sqlUrl = require "SqlUrl"
local errorInfo = require "ErrorInfo"
local dataType = require "DataType"
local serverId = tonumber(skynet.getenv "serverId")
local redisKeyUrl = require "RedisKeyUrl"
local serverManage = require "ServerManage"
local personal = require "Personal"
local partner = require "Partner"
local ChatManage = oo.class()
ChatManage.OpType_Ban = 1 --开始禁言
ChatManage.OpType_UnBan = 2 --取消禁言
--初始化
function ChatManage:Init()
end
--用户禁言
function ChatManage:Ban( c2sData , s2cData )
if not c2sData.account or not c2sData.opType then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
return s2cData
end
local account = c2sData.account
local opType = c2sData.opType
local banTime = c2sData.banTime or 0
banTime = banTime * 60
--获取用户数据库信息
local userDBInfo = skynet.server.redisCenter:GetRedisDBInfo( account )
if not userDBInfo then
s2cData.code = errorInfo.ErrorCode.NoExistUser
return s2cData
end
local dbIndex = userDBInfo.DBIndex
local userId = userDBInfo.UserID
local myPartnerId = userDBInfo.PartnerId
local redisBanChatKey = string.format( redisKeyUrl.ChatManageBanChatTimeString, myPartnerId )
if self.OpType_Ban == opType then
--设置禁言标记
skynet.server.redis:set( redisBanChatKey , skynet.GetTime() + banTime )
skynet.server.redis:expire( redisBanChatKey, banTime )
--清屏
self:ClearScreen( account , myPartnerId )
elseif self.OpType_UnBan == opType then
skynet.server.redis:del( redisBanChatKey )
end
end
--用户清屏
function ChatManage:Clear( c2sData , s2cData )
--验证登陆接口参数
if not c2sData.account then
s2cData.code = errorInfo.ErrorCode.ErrRequestParam
return s2cData
end
--获取用户数据库信息
local account = c2sData.account
local userDBInfo = skynet.server.redisCenter:GetRedisDBInfo( account )
if not userDBInfo then
s2cData.code = errorInfo.ErrorCode.NoExistUser
return s2cData
end
local dbIndex = userDBInfo.DBIndex
local userId = userDBInfo.UserID
local myPartnerId = userDBInfo.PartnerId
--清屏
self:ClearScreen( account , myPartnerId )
end
--清屏
function ChatManage:ClearScreen( account , myPartnerId )
--获取所有好友
local redisKey = string.format( redisKeyUrl.GameServerPartnerMyFriendZSet , myPartnerId )
local friendList = skynet.server.redis:zrange( redisKey , 0 , -1 )
--遍历每个好友
for k, otherPartnerId in pairs( friendList ) do
local msgRedisKey = skynet.server.partner:GetMsgKey( myPartnerId , otherPartnerId )
local msgList = skynet.server.redis:zrange( msgRedisKey , 0 , -1 , "withscores" ) --将我与该好友的消息全部取出
msgList = redisKeyUrl:CovertTable(msgList)
--遍历该好友的所有聊天记录
for stringData , score in pairs( msgList ) do
local msgData = json:decode( stringData )
--被禁玩家发送的 并且文本消息 并且 isShowMsg为true 或者 isShowMsg为nil 才处理
if msgData.sendPartnerId == myPartnerId and msgData.msgType == skynet.server.partner.MsgType_Text and ( msgData.isShowMsg or nil == msgData.isShowMsg ) then
msgData.isShowMsg = false
--先删除之前的数据,再把修改后的数据填充进去
skynet.server.redis:zremrangebyscore( msgRedisKey , score, score)
skynet.server.redis:zadd( msgRedisKey , score , json:encode(msgData))
log.info(string.format("玩家 %s 成功清屏好友消息记录 %d", account , score ))
end
end
end
--遍历家园的聊天记录
local groupId = skynet.server.personal:GetCurDetail( myPartnerId , "groupId" ) or ""
if "" ~= groupId then
local msgRedisKey = string.format( redisKeyUrl.GameServerGroupMsgRecordZSet , groupId )
local msgList = skynet.server.redis:zrange( msgRedisKey, 0, -1, "withscores" )
msgList = redisKeyUrl:CovertTable( msgList )
--遍历家园所有的聊天记录
for stringData, score in pairs( msgList ) do
local msgData = json:decode( stringData )
if msgData.sendPartnerId == myPartnerId and ( msgData.isShowMsg or nil == msgData.isShowMsg ) then
msgData.isShowMsg = false
--先删除之前的数据,再把修改后的数据填充进去
skynet.server.redis:zremrangebyscore( msgRedisKey , score, score)
skynet.server.redis:zadd( msgRedisKey , score , json:encode(msgData))
log.info(string.format("玩家 %s 成功清屏家园消息记录 %d", account , score ))
end
end
end
end
skynet.server.chatManage = ChatManage
return ChatManage