public override async Task ExecuteAsync(BtkPacket btkPacket, ClientSession session) { var friendlist = await _friendHttpClient.GetListFriendsAsync(session.Character.VisualId).ConfigureAwait(false); if (friendlist.All(s => s.CharacterId != btkPacket.CharacterId)) { _logger.Error(GameLanguage.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) { await receiverSession.SendPacketAsync(session.Character.GenerateTalk(message)).ConfigureAwait(false); return; } var receiver = await _connectedAccountHttpClient.GetCharacterAsync(btkPacket.CharacterId, null).ConfigureAwait(false); if (receiver.Item2 == null) //TODO: Handle 404 in WebApi { await session.SendPacketAsync(new InfoiPacket { Message = Game18NConstString.FriendOffline }).ConfigureAwait(false); return; } await _packetHttpClient.BroadcastPacketAsync(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).ConfigureAwait(false); }
public override async Task ExecuteAsync(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()); await session.SendPacketAsync(session.Character.GenerateSpk(new SpeakPacket { SpeakType = SpeakType.Player, Message = message.ToString() })).ConfigureAwait(false); 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 = await _connectedAccountHttpClient.GetCharacterAsync(null, receiverName).ConfigureAwait(false); if (receiver.Item2 == null) //TODO: Handle 404 in WebApi { await session.SendPacketAsync(session.Character.GenerateSay( GameLanguage.Instance.GetMessageFromKey(LanguageKey.CHARACTER_OFFLINE, session.Account.Language), SayColorType.Yellow)).ConfigureAwait(false); return; } var blacklisteds = await _blacklistHttpClient.GetBlackListsAsync(session.Character.VisualId).ConfigureAwait(false); if (blacklisteds.Any(s => s.CharacterId == receiver.Item2.ConnectedCharacter?.Id)) { await session.SendPacketAsync(new SayPacket { Message = GameLanguage.Instance.GetMessageFromKey(LanguageKey.BLACKLIST_BLOCKED, session.Account.Language), Type = SayColorType.Yellow }).ConfigureAwait(false); return; } speakPacket.Message = receiverSession != null ? speakPacket.Message : $"{speakPacket.Message} <{GameLanguage.Instance.GetMessageFromKey(LanguageKey.CHANNEL, receiver.Item2.Language)}: {MasterClientListSingleton.Instance.ChannelId}>"; await _packetHttpClient.BroadcastPacketAsync(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).ConfigureAwait(false); await session.SendPacketAsync(session.Character.GenerateSay( GameLanguage.Instance.GetMessageFromKey(LanguageKey.SEND_MESSAGE_TO_CHARACTER, session.Account.Language), SayColorType.Purple)).ConfigureAwait(false); } catch (Exception e) { _logger.Error("Whisper failed.", e); } }