/// <summary>
/// 网络多播, 发送自定义数据到clients集合的客户端
/// </summary>
/// <param name="clients">客户端集合</param>
/// <param name="reliable">使用可靠传输?</param>
/// <param name="cmd">网络命令</param>
/// <param name="buffer">自定义字节数组</param>
public virtual void Multicast(IList<Player> clients, bool reliable, byte cmd, byte[] buffer)
{
if (buffer.Length / MTU > ushort.MaxValue)
{
Debug.LogError("数据太大,请分块发送!");
return;
}
for (int i = 0; i < clients.Count; i++)
{
var client = clients[i];
if (client == null)
continue;
if (client.CloseSend)
continue;
if (!reliable)
{
if (client.udpRPCModels.Count >= ushort.MaxValue)
{
Debug.LogError($"[{client.UserID}]数据缓存列表超出限制!");
return;
}
client.udpRPCModels.Enqueue(new RPCModel(cmd, buffer, false, false) { bigData = buffer.Length > short.MaxValue });
}
else
{
if (client.tcpRPCModels.Count >= ushort.MaxValue)
{
Debug.LogError($"[{client.UserID}]数据缓存列表超出限制!");
return;
}
client.tcpRPCModels.Enqueue(new RPCModel(cmd, buffer, false, false) { bigData = buffer.Length > short.MaxValue });
}
}
}