public static void SendFinfo(this ICharacterEntity visualEntity, IFriendHttpClient friendHttpClient,
                                     IPacketHttpClient packetHttpClient, ISerializer packetSerializer, bool isConnected)
        {
            var friendlist = friendHttpClient.GetListFriends(visualEntity.VisualId);

            foreach (var friend in friendlist)
            {
                packetHttpClient.BroadcastPacket(new PostedPacket
                {
                    Packet = packetSerializer.Serialize(new[]
                    {
                        new FinfoPacket
                        {
                            FriendList = new List <FinfoSubPackets>
                            {
                                new FinfoSubPackets
                                {
                                    CharacterId = visualEntity.VisualId,
                                    IsConnected = isConnected
                                }
                            }
                        }
                    }),
                    ReceiverType    = ReceiverType.OnlySomeone,
                    SenderCharacter = new Data.WebApi.Character {
                        Id = visualEntity.VisualId, Name = visualEntity.Name
                    },
                    ReceiverCharacter = new Data.WebApi.Character
                    {
                        Id   = friend.CharacterId,
                        Name = friend.CharacterName
                    }
                });
            }
        }
Beispiel #2
0
        public override void Execute(BtkPacket btkPacket, ClientSession session)
        {
            var friendlist = _friendHttpClient.GetListFriends(session.Character.VisualId);

            if (!friendlist.Any(s => s.CharacterId == btkPacket.CharacterId))
            {
                _logger.Error(Language.Instance.GetMessageFromKey(LanguageKey.USER_IS_NOT_A_FRIEND,
                                                                  session.Account.Language));
                return;
            }

            var message = btkPacket.Message;

            if (message.Length > 60)
            {
                message = message.Substring(0, 60);
            }

            message = message.Trim();
            var receiverSession =
                Broadcaster.Instance.GetCharacter(s =>
                                                  s.VisualId == btkPacket.CharacterId);

            if (receiverSession != null)
            {
                receiverSession.SendPacket(session.Character.GenerateTalk(message));
                return;
            }

            var receiver = _connectedAccountHttpClient.GetCharacter(btkPacket.CharacterId, null);

            if (receiver.Item2 == null) //TODO: Handle 404 in WebApi
            {
                session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.FRIEND_OFFLINE, session.Account.Language)
                });
                return;
            }

            _packetHttpClient.BroadcastPacket(new PostedPacket
            {
                Packet            = _packetSerializer.Serialize(new[] { session.Character.GenerateTalk(message) }),
                ReceiverCharacter = new Character
                {
                    Id = btkPacket.CharacterId, Name = receiver.Item2.ConnectedCharacter?.Name
                },
                SenderCharacter = new Character
                {
                    Name = session.Character.Name, Id = session.Character.CharacterId
                },
                OriginWorldId = MasterClientListSingleton.Instance.ChannelId,
                ReceiverType  = ReceiverType.OnlySomeone
            }, receiver.Item2.ChannelId);
        }
Beispiel #3
0
        public override void Execute(WhisperPacket whisperPacket, ClientSession session)
        {
            try
            {
                var messageBuilder = new StringBuilder();

                //Todo: review this
                var messageData  = whisperPacket.Message.Split(' ');
                var receiverName = messageData[whisperPacket.Message.StartsWith("GM ") ? 1 : 0];

                for (var i = messageData[0] == "GM" ? 2 : 1; i < messageData.Length; i++)
                {
                    messageBuilder.Append(messageData[i]).Append(" ");
                }

                var message = new StringBuilder(messageBuilder.ToString().Length > 60
                    ? messageBuilder.ToString().Substring(0, 60) : messageBuilder.ToString());

                session.SendPacket(session.Character.GenerateSpk(new SpeakPacket
                {
                    SpeakType = SpeakType.Player,
                    Message   = message.ToString()
                }));

                var speakPacket = session.Character.GenerateSpk(new SpeakPacket
                {
                    SpeakType = session.Account.Authority >= AuthorityType.GameMaster ? SpeakType.GameMaster
                        : SpeakType.Player,
                    Message = message.ToString()
                });

                var receiverSession =
                    Broadcaster.Instance.GetCharacter(s => s.Name == receiverName);

                var receiver = _connectedAccountHttpClient.GetCharacter(null, receiverName);

                if (receiver.Item2 == null) //TODO: Handle 404 in WebApi
                {
                    session.SendPacket(session.Character.GenerateSay(
                                           Language.Instance.GetMessageFromKey(LanguageKey.CHARACTER_OFFLINE, session.Account.Language),
                                           SayColorType.Yellow));
                    return;
                }

                var blacklisteds = _blacklistHttpClient.GetBlackLists(session.Character.VisualId);
                if (blacklisteds.Any(s => s.CharacterId == receiver.Item2.ConnectedCharacter.Id))
                {
                    session.SendPacket(new SayPacket
                    {
                        Message = Language.Instance.GetMessageFromKey(LanguageKey.BLACKLIST_BLOCKED,
                                                                      session.Account.Language),
                        Type = SayColorType.Yellow
                    });
                    return;
                }

                speakPacket.Message = receiverSession != null ? speakPacket.Message :
                                      $"{speakPacket.Message} <{Language.Instance.GetMessageFromKey(LanguageKey.CHANNEL, receiver.Item2.Language)}: {MasterClientListSingleton.Instance.ChannelId}>";

                _packetHttpClient.BroadcastPacket(new PostedPacket
                {
                    Packet            = _packetSerializer.Serialize(new[] { speakPacket }),
                    ReceiverCharacter = new Character {
                        Name = receiverName
                    },
                    SenderCharacter = new Character {
                        Name = session.Character.Name
                    },
                    OriginWorldId = MasterClientListSingleton.Instance.ChannelId,
                    ReceiverType  = ReceiverType.OnlySomeone
                }, receiver.Item2.ChannelId);

                session.SendPacket(session.Character.GenerateSay(
                                       Language.Instance.GetMessageFromKey(LanguageKey.SEND_MESSAGE_TO_CHARACTER,
                                                                           session.Account.Language), SayColorType.Purple));
            }
            catch (Exception e)
            {
                _logger.Error("Whisper failed.", e);
            }
        }