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.
104 lines
4.0 KiB
104 lines
4.0 KiB
1 month ago
|
/*
|
||
|
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<T>(long sessionId, int iMsgID, ref T structMessage)
|
||
|
where T : struct, IStructMessage<T>
|
||
|
{
|
||
|
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<T>(PlayerOnChat player, int iMsgID, ref T structMessage)
|
||
|
where T : struct, IStructMessage<T>
|
||
|
{
|
||
|
GateService.SendToGate(0, ChatServerUtils.GetApp().GetCluster()
|
||
|
, player.GateServerID, player.SessionID, iMsgID, ref structMessage);
|
||
|
}
|
||
|
|
||
|
|
||
|
/// <summary>
|
||
|
/// 直接转发
|
||
|
/// </summary>
|
||
|
/// <param name="playerSession"></param>
|
||
|
/// <param name="packet"></param>
|
||
|
public static void SendToPlayer<T>(PlayerOnChat player, StructPacket packet)
|
||
|
where T : struct, IStructMessage<T>
|
||
|
{
|
||
|
GateService.SendToGate(0,ChatServerUtils.GetApp().GetCluster()
|
||
|
, player.GateServerID, player.SessionID, packet.MsgID, ref packet.GetMessage<T>());
|
||
|
}
|
||
|
|
||
|
//广播消息给sessionIDList
|
||
|
public static void BroadcastToGate<T>(PlayerOnChat player, int iMsgID, ref T structMessage)
|
||
|
where T : struct, IStructMessage<T>
|
||
|
{
|
||
|
List<long> 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<T>(PlayerOnChat player, int iMsgID, ref T structMessage)
|
||
|
where T : struct, IStructMessage<T>
|
||
|
{
|
||
|
List<long> 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);
|
||
|
}
|
||
|
}
|
||
|
}
|