private void SpreadBroadcastpacket(BroadcastPacket sentPacket)
        {
            if (Sessions == null || sentPacket?.Packet == null)
            {
                return;
            }

            switch (sentPacket.Receiver)
            {
            case ReceiverType.AllExceptMe:
            case ReceiverType.AllExceptGroup:
            case ReceiverType.AllNoEmoBlocked:
            case ReceiverType.AllNoHeroBlocked:
            case ReceiverType.Group:
            case ReceiverType.AllInRange:
            case ReceiverType.All:
                Parallel.ForEach(Sessions, session =>
                {
                    if (!session.Value.HasSelectedCharacter)
                    {
                        return;
                    }

                    session.Value.SendPacket(sentPacket.Packet);
                });
                break;
            }
        }
 public void Broadcast(BroadcastPacket packet)
 {
     try
     {
         SpreadBroadcastpacket(packet);
     }
     catch (Exception ex)
     {
         Logger.Error(ex);
     }
 }
Esempio n. 3
0
        private void SpreadBroadcastpacket(BroadcastPacket sentPacket)
        {
            if (Sessions == null || sentPacket?.Packet == null)
            {
                return;
            }

            switch (sentPacket.Receiver)
            {
            case ReceiverType.AllExceptMeAndBlacklisted:
                Parallel.ForEach(
                    Sessions.Where(s => s.Value.HasSelectedCharacter &&
                                   s.Value.Character.CharacterId != sentPacket.Sender.Character.CharacterId &&
                                   !s.Value.Character.IsRelatedToCharacter(sentPacket.Sender.Character.CharacterId,
                                                                           CharacterRelationType.Blocked)),
                    session => session.Value.SendPacket(sentPacket.Packet));
                break;

            case ReceiverType.AllExceptMe:
                Parallel.ForEach(
                    Sessions.Values.Where(s =>
                                          s.HasSelectedCharacter &&
                                          s.Character.CharacterId != sentPacket.Sender.Character.CharacterId),
                    session => session.SendPacket(sentPacket.Packet));
                break;

            case ReceiverType.Group:
                Parallel.ForEach(
                    sentPacket.Sender.Character.Group.Values.Where(s => s.Item2.VisualType == VisualType.Player),
                    entity =>
                {
                    var session =
                        Sessions.Values.FirstOrDefault(s => s.Character.CharacterId == entity.Item2.VisualId);

                    session?.SendPacket(sentPacket.Packet);
                });
                break;

            case ReceiverType.AllExceptGroup:
            case ReceiverType.AllNoEmoBlocked:
            case ReceiverType.AllNoHeroBlocked:
            case ReceiverType.AllInRange:
            case ReceiverType.All:
                Parallel.ForEach(Sessions.Where(s => s.Value.HasSelectedCharacter),
                                 session => session.Value.SendPacket(sentPacket.Packet));
                break;

            default:
                return;
            }
        }
Esempio n. 4
0
        private void SpreadBroadcastpacket(BroadcastPacket sentPacket)
        {
            if (Sessions == null || sentPacket?.Packet == null)
            {
                return;
            }

            switch (sentPacket.Receiver)
            {
            case ReceiverType.AllExceptMeAndBlacklisted:
                Parallel.ForEach(
                    Sessions.Where(s => s.Value.HasSelectedCharacter && s.Value.Character.CharacterId != sentPacket.Sender.Character.CharacterId &&
                                   !s.Value.Character.IsRelatedToCharacter(sentPacket.Sender.Character.CharacterId, CharacterRelationType.Blocked)),
                    session =>
                {
                    session.Value.SendPacket(sentPacket.Packet);
                });
                break;

            case ReceiverType.AllExceptMe:
                Parallel.ForEach(
                    Sessions.Values.Where(s => s.HasSelectedCharacter && s.Character.CharacterId != sentPacket.Sender.Character.CharacterId),
                    session =>
                {
                    session.SendPacket(sentPacket.Packet);
                });
                break;

            case ReceiverType.AllExceptGroup:
            case ReceiverType.AllNoEmoBlocked:
            case ReceiverType.AllNoHeroBlocked:
            case ReceiverType.Group:
            case ReceiverType.AllInRange:
            case ReceiverType.All:
                Parallel.ForEach(Sessions.Where(s => s.Value.HasSelectedCharacter), session =>
                {
                    session.Value.SendPacket(sentPacket.Packet);
                });
                break;
            }
        }