/* Sog 游戏基础库 2016 by zouwei */ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Sog; using Sog.Gate; using ProtoCSStruct; namespace Chat { // 实现 SendToPlayer public static class PlayerPacketSender { public static void SendToPlayer(long sessionId, int iMsgID, ref T structMessage) where T : struct, IStructMessage { PlayerOnChat playerSession = ChatServerUtils.GetPlayerTableOp().GetPlayerOnChat(sessionId); if (playerSession != null) { GateService.SendToGate(0, ChatServerUtils.GetApp().GetCluster() , playerSession.GateServerID, playerSession.SessionID, iMsgID, ref structMessage); } else { TraceLog.Debug("PlayerPacketSender.SendToPlayer sessionId {0} no PlayerSession object!", sessionId); } } public static void SendToPlayer(PlayerOnChat player, int iMsgID, ref T structMessage) where T : struct, IStructMessage { GateService.SendToGate(0, ChatServerUtils.GetApp().GetCluster() , player.GateServerID, player.SessionID, iMsgID, ref structMessage); } /// /// 直接转发 /// /// /// public static void SendToPlayer(PlayerOnChat player, StructPacket packet) where T : struct, IStructMessage { GateService.SendToGate(0,ChatServerUtils.GetApp().GetCluster() , player.GateServerID, player.SessionID, packet.MsgID, ref packet.GetMessage()); } //广播消息给sessionIDList public static void BroadcastToGate(PlayerOnChat player, int iMsgID, ref T structMessage) where T : struct, IStructMessage { List sessionIDList = ChatServerUtils.GetPlayerTableOp().GetAllSameLogicWorldPlayer(player.LogicWorldID); if (sessionIDList == null || sessionIDList.Count == 0) return; sessionIDList = ChatSvc.GetFilterChatBlackPlayer(player, sessionIDList); //过滤聊天屏蔽黑名单 if (sessionIDList == null || sessionIDList.Count == 0) return; //广播给所有的玩家 while (sessionIDList.Count > GateMsgDefine.TransMultiSessionCountMax) { GateService.BroadcastToGate(0, ChatServerUtils.GetApp().GetCluster(), player.GateServerID, sessionIDList.Take(GateMsgDefine.TransMultiSessionCountMax).ToList() , iMsgID, ref structMessage); sessionIDList.RemoveRange(0, GateMsgDefine.TransMultiSessionCountMax); } GateService.BroadcastToGate(0, ChatServerUtils.GetApp().GetCluster(), player.GateServerID, sessionIDList , iMsgID, ref structMessage); } public static void BroadcastToBigRealm(PlayerOnChat player, int iMsgID, ref T structMessage) where T : struct, IStructMessage { List sessionIDList = ChatServerUtils.GetPlayerTableOp().GetAllSameBigRealmIDPlayer(player); if (sessionIDList == null || sessionIDList.Count == 0) return; sessionIDList = ChatSvc.GetFilterChatBlackPlayer(player, sessionIDList); //过滤聊天屏蔽黑名单 if (sessionIDList == null || sessionIDList.Count == 0) return; //广播给所有的玩家 while (sessionIDList.Count > GateMsgDefine.TransMultiSessionCountMax) { GateService.BroadcastToGate(0, ChatServerUtils.GetApp().GetCluster(), player.GateServerID, sessionIDList.Take(GateMsgDefine.TransMultiSessionCountMax).ToList() , iMsgID, ref structMessage); sessionIDList.RemoveRange(0, GateMsgDefine.TransMultiSessionCountMax); } GateService.BroadcastToGate(0, ChatServerUtils.GetApp().GetCluster(), player.GateServerID, sessionIDList , iMsgID, ref structMessage); } } }