You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

200 lines
8.9 KiB

1 month ago
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Sog;
using Sog.Service;
using ProtoCSStruct;
using Org.BouncyCastle.Bcpg;
using System.Net.Sockets;
namespace Game
{
public class ChatHandler : BasePacketHandler
{
public override int GetServiceType()
{
return GameServiceType.ChatHandler;
}
//销毁的时候置空
public override void Dispose()
{
}
public ChatHandler()
{
}
public override void HandlerClientPacket(PlayerSession playerSession, StructPacket packet)
{
PlayerOnGame player = playerSession.Player;
if (player == null)
{
TraceLog.Error("ChatHandler.HandlerClientPacket can not find PlayerOnGame sessionid {0}", playerSession.SessionID);
return;
}
TraceLog.Debug("ChatHandler.HandlerClientPacket msgId {0} handle", packet.MsgID);
switch (packet.MsgID)
{
case (int)CSGameMsgID.GetChatBlacklistReq:
OnGetChatBlackListReq(player, packet);
break;
case (int)CSGameMsgID.AddChatBlacklistReq:
OnAddChatBlackListReq(player, packet);
break;
case (int)CSGameMsgID.DelChatBlacklistReq:
OnDelChatBlackListReq(player, packet);
break;
case (int)CSGameMsgID.ReportCheatReq:
ReportCheatReq(player, packet);
break;
default:
TraceLog.Error("ChatHandler.HandlerClientPacket msgId {0} not handle", packet.MsgID);
break;
}
}
public override void HandlerServerPacket(uint serverID, StructPacket packet)
{
TraceLog.Debug("HomeHandler.HandlerServerPacket msgId {0} handle", packet.MsgID);
switch (packet.MsgID)
{
case (int)SSGameMsgID.QueryRoleBaseInfoListRes:
OnWorldQueryRoleBaseInfoListRes(packet);
break;
default:
TraceLog.Error("HomeHandler.HandlerServerPacket msgId {0} not handle", packet.MsgID);
break;
}
}
//请求获取聊天屏蔽黑名单
public static void OnGetChatBlackListReq(PlayerOnGame player, StructPacket packet)
{
ref CSGetChatBlackListReq req = ref packet.GetMessage<CSGetChatBlackListReq>();
SSQueryRoleBaseInfoListReq ssReq = new SSQueryRoleBaseInfoListReq();
ssReq.Type = QueryRoleBaseInfoType.QUERY; //查询
ChatSvc.ProcessCopyChatBlackList(player, ref ssReq.RoleBaseInfoList);
TraceLog.Trace("ChatHandler.OnGetChatBlackListReq user {0} type {1}", player.UserID, ssReq.Type);
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.QueryRoleBaseInfoListReq, ref ssReq, player.UserID); //请求最新的数据
}
//加入聊天屏蔽黑名单
public static void OnAddChatBlackListReq(PlayerOnGame player, StructPacket packet)
{
ref CSAddChatBlackListReq req = ref packet.GetMessage<CSAddChatBlackListReq>();
CSAddChatBlackListRes res = new CSAddChatBlackListRes();
res.Ret = ChatSvc.ProcessCheckAddChatBlackList(player, req.ChatBlackUid);
if (res.Ret != CSErrCode.None)
{
player.SendToClient((int)CSGameMsgID.AddChatBlacklistRes, ref res);
return;
}
SSQueryRoleBaseInfoListReq ssReq = new SSQueryRoleBaseInfoListReq();
ssReq.Type = QueryRoleBaseInfoType.ADD; //增加
RoleBaseInfo roleBaseInfo = new RoleBaseInfo();
roleBaseInfo.Uid = req.ChatBlackUid;
roleBaseInfo.ChatBlackTime = GameServerUtils.GetTimeMs();
TraceLog.Trace("ChatHandler.OnAddChatBlackListReq user {0} chatBlackUid {1} chatBlackTime {2}", player.UserID, req.ChatBlackUid, roleBaseInfo.ChatBlackTime);
ssReq.RoleBaseInfoList.Add(roleBaseInfo);
GameServerUtils.GetPacketSender().SendToWorldServer((int)SSGameMsgID.QueryRoleBaseInfoListReq, ref ssReq, player.UserID); //增加详细的数据
}
//解除聊天屏蔽黑名单
public static void OnDelChatBlackListReq(PlayerOnGame player, StructPacket packet)
{
ref CSDelChatBlackListReq req = ref packet.GetMessage<CSDelChatBlackListReq>();
CSDelChatBlackListRes res = new CSDelChatBlackListRes();
res.Ret = ChatSvc.ProcessnDelChatBlackList(player, req.ChatBlackUid);
res.ChatBlackList.CopyFrom(ref player.RoleData.ExtData.ChatBlackList);
player.SendToClient((int)CSGameMsgID.DelChatBlacklistRes, ref res);
TraceLog.Trace("ChatHandler.OnDelChatBlackListReq user {0} chatBlackUid {1} ret {2} chatBlackListCount {3} chatBlackVer {4}", player.UserID, req.ChatBlackUid, res.Ret, res.ChatBlackList.Count, player.RoleData.ExtData.ChatBlackVer);
}
//最新数据回包
public static void OnWorldQueryRoleBaseInfoListRes(StructPacket packet)
{
PlayerOnGame player = GameServerUtils.GetPlayerTableOp().GetPlayerByUid(packet.ObjectID);
if (player == null)
{
TraceLog.Error("ChatHandler.OnWorldQueryRoleBaseInfoListRes no player:{0}", packet.ObjectID);
return;
}
ref SSQueryRoleBaseInfoListRes ssRes = ref packet.GetMessage<SSQueryRoleBaseInfoListRes>();
if (ssRes.Type == QueryRoleBaseInfoType.QUERY)
{
if (ssRes.Ret == CSErrCode.None)
{
player.RoleData.ExtData.ChatBlackList.CopyFrom(ref ssRes.RoleBaseInfoList); //保存一下最新的
player.MakeDirty();
}
TraceLog.Trace("ChatHandler.OnWorldQueryRoleBaseInfoListRes query user {0} ret {1} chatBlackListCount {2} chatBlackVer {3}", player.UserID, ssRes.Ret, player.RoleData.ExtData.ChatBlackList.Count, player.RoleData.ExtData.ChatBlackVer);
CSGetChatBlackListRes res = new CSGetChatBlackListRes();
res.Ret = CSErrCode.None;
res.ChatBlackList.CopyFrom(ref player.RoleData.ExtData.ChatBlackList);
player.SendToClient((int)CSGameMsgID.GetChatBlacklistRes, ref res);
}
else if (ssRes.Type == QueryRoleBaseInfoType.ADD)
{
if (ssRes.Ret == CSErrCode.None)
{
for(int i = 0; i < ssRes.RoleBaseInfoList.Count; i++)
{
if (player.RoleData.ExtData.ChatBlackList.Count < player.RoleData.ExtData.ChatBlackList.GetMaxCount())
{
TraceLog.Trace("ChatHandler.OnWorldQueryRoleBaseInfoListRes add user {0} chatBlackUid {1} chatBlackNick {2} chatBlackIcon {3} chatBlackTime {4}",
player.UserID, ssRes.RoleBaseInfoList[i].Uid, ssRes.RoleBaseInfoList[i].Nick, ssRes.RoleBaseInfoList[i].Icon, ssRes.RoleBaseInfoList[i].ChatBlackTime);
if (ssRes.RoleBaseInfoList[i].Uid == 0) continue;
player.RoleData.ExtData.ChatBlackList.Add(ref ssRes.RoleBaseInfoList[i]);
}
}
ChatSvc.AddChatBlackVer(player); //必须需要同步最新数据到chatsvr
player.MakeDirty();
}
TraceLog.Trace("ChatHandler.OnWorldQueryRoleBaseInfoListRes add user {0} ret {1} chatBlackListCount {2} chatBlackVer {3}", player.UserID, ssRes.Ret, player.RoleData.ExtData.ChatBlackList.Count, player.RoleData.ExtData.ChatBlackVer);
CSAddChatBlackListRes res = new CSAddChatBlackListRes();
res.Ret = CSErrCode.None;
res.ChatBlackList.CopyFrom(ref player.RoleData.ExtData.ChatBlackList);
player.SendToClient((int)CSGameMsgID.AddChatBlacklistRes, ref res);
}
else
{
TraceLog.Error("ChatHandler.OnWorldQueryRoleBaseInfoListRes no support user {0} type {1}", packet.ObjectID, ssRes.Type);
return;
}
}
public static void ReportCheatReq(PlayerOnGame player, StructPacket packet)
{
ref CSReportCheatReq req = ref packet.GetMessage<CSReportCheatReq>();
var res = new CSReportCheatRes();
res.Reporter = req.Reporter;
res.Cheater = req.Cheater;
player.SendToClient((int)CSGameMsgID.ReportCheatRes, ref res);
//数数打点
GameTALogUtils.LogReportCheat(player, req.Cheater);
TraceLog.Trace("ReportCheatReq report {0} target {1}", req.Reporter, req.Cheater);
}
}
}