Exemplo n.º 1
0
        private void RestoreTabs()
        {
            string tabs = GlobalSettings.Default.OpenTabs;

            if (tabs == null)
            {
                return;
            }

            IReadOnlyCollection <TabSettings> ts = TabSettings.FromString(tabs);

            foreach (TabSettings t in ts)
            {
                ConnectedAccount sa = ConnectedAccount.RootFolder.FindConnectedAccountById(t.AccountId);
                if (sa == null)
                {
                    continue;
                }

                AddTab(sa, t.Settings, false);

                if (t.IsActive)
                {
                    SelectedAccount = ActiveStorageAccounts.Last();
                }
            }
        }
Exemplo n.º 2
0
 public DeleteFilesTask(ConnectedAccount connectedAccount, IBlobStorage storage, IReadOnlyCollection <Blob> toDelete)
     : base(Strings.BackgroundTask_Delete_TypeName)
 {
     _connectedAccount = connectedAccount;
     _storage          = storage;
     _toDelete         = toDelete;
 }
Exemplo n.º 3
0
        public void Kick(KickPacket kickPacket)
        {
            var servers = WebApiAccess.Instance.Get <List <ChannelInfo> >(WebApiRoute.Channel).Where(s => s.Type == ServerType.WorldServer);
            ServerConfiguration config  = null;
            ConnectedAccount    account = null;

            foreach (var server in servers)
            {
                config  = server.WebApi;
                account = WebApiAccess.Instance.Get <List <ConnectedAccount> >(WebApiRoute.ConnectedAccount, config)
                          .Find(s => s.ConnectedCharacter.Name == kickPacket.Name);
                if (account != null)
                {
                    break;
                }
            }

            if (account == null) //TODO: Handle 404 in WebApi
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER, Session.Account.Language)
                });
                return;
            }

            WebApiAccess.Instance.Delete <ConnectedAccount>(WebApiRoute.Session, config, account.ConnectedCharacter.Id);
        }
Exemplo n.º 4
0
        public ConnectedAccountViewModel(ConnectedAccount ca) : base(ca, null)
        {
            _ca = ca ?? throw new System.ArgumentNullException(nameof(ca));
            Tag = ca;

            AddActionCommands(ca);

            CommandGroups.Add(new HierarchicalResourceCommandGroup(
                                  new HierarchicalResourceCommand("Edit", Symbol.Edit, EditAccountCommand)));

            HierarchicalResourceCommandGroup copyGroup = AddCommandGroup(
                new HierarchicalResourceCommand("copy connection string", Symbol.Copy, () =>
            {
                ServiceLocator.SystemService.SetClipboardText(_ca.ConnectionString);
                return(Task.CompletedTask);
            }));

            if (_ca.StorageConnectionString.Parameters.TryGetValue(KnownParameter.KeyOrPassword, out string keyOrPassword))
            {
                copyGroup.Commands.Add(new HierarchicalResourceCommand("copy key/password", Symbol.Copy, () =>
                {
                    ServiceLocator.SystemService.SetClipboardText(keyOrPassword);
                    return(Task.CompletedTask);
                }));
            }
        }
Exemplo n.º 5
0
        public BlobStoragePanelViewModel(ConnectedAccount storageAccount)
        {
            Account = storageAccount;
            Storage = storageAccount.CreateBlobStorage();
            FolderBrowser.Storage = Storage;

            ViewEdit.OnDone += (done) =>
            {
                IsViewing = false;
            };

            SelectedBlobs.CollectionChanged += SelectedBlobs_CollectionChanged;
            Clipboard.PropertyChanged       += (_, args) =>
            {
                if (args.PropertyName == nameof(ClipboardViewModel.HasData))
                {
                    PasteFromClipboardCommand?.RaiseCanExecuteChanged();
                }
            };

            FolderBrowser.OnDoubleTapFolder += FolderBrowser_OnDoubleTapFolder;

            GlobalSettings.Default.PropertyChanged += ConfigPropertyChanged;

            Messenger.Default.Register <FolderUpdatedMessage>(this, OnFolderUpdated);

            CreateCommands();
        }
Exemplo n.º 6
0
        private async Task DeleteAsync()
        {
            EventLog.LogEvent("deleteAzureAccount", "name: {name}", _client?.UserInfo?.DisplayableId);

            ConnectedAccount.AzureAccounts.Remove(_connectedAzureAccount);
            ConnectedAccount.Save();
        }
Exemplo n.º 7
0
        public void AddTab(ConnectedAccount connectedAccount, string settings = null, bool makeActive = true)
        {
            if (connectedAccount == null)
            {
                return;
            }

            if (connectedAccount.System == "msg")
            {
                ActiveStorageAccounts.Add(new MessengerViewModel(connectedAccount));
            }
            else if (connectedAccount.System == "ai")
            {
                ActiveStorageAccounts.Add(new ApplicationInsightsPanelViewModel(connectedAccount));
            }
            else if (connectedAccount.System == "redis")
            {
                ActiveStorageAccounts.Add(new RedisViewModel(connectedAccount));
            }
            else
            {
                ActiveStorageAccounts.Add(new BlobStoragePanelViewModel(connectedAccount));
            }

            if (makeActive)
            {
                SelectedAccount = ActiveStorageAccounts.Last();
            }
            ActiveStorageAccounts.Last().RestoreSettings(settings);
        }
Exemplo n.º 8
0
        public ApplicationInsightsPanelViewModel(ConnectedAccount account)
        {
            Account = account;

            _client = new AppInsightsClient(
                account.StorageConnectionString.Get("appId"),
                account.StorageConnectionString.Get("apiKey"));
        }
Exemplo n.º 9
0
        public AccountsViewModel(ConnectedFolder connectedFolder, ConnectedAccount connectedAccount)
        {
            _isNew           = connectedAccount == null;
            ConnectedFolder  = connectedFolder;
            ConnectedAccount = connectedAccount;

            //bind to a subtype - https://stackoverflow.com/a/8344798/80858
        }
Exemplo n.º 10
0
 private async Task DeleteAsync()
 {
     if (await Dialogs.AskYesNoAsync("Delete Account", $"Are you sure you want to delete '{DisplayName}'? This cannot be undone."))
     {
         ConnectedAccount.RootFolder.DeleteById(_connectedEntity.Id);
         ConnectedAccount.Save();
     }
 }
Exemplo n.º 11
0
        /// <summary>
        ///     btk packet
        /// </summary>
        /// <param name="btkPacket"></param>
        public void FriendTalk(BtkPacket btkPacket)
        {
            string message = btkPacket.Message;

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

            message = message.Trim();
            var receiverSession = ServerManager.Instance.Sessions.Values.FirstOrDefault(s => s.Character.CharacterId == btkPacket.CharacterId);

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

            ConnectedAccount receiver = null;

            List <WorldServerInfo> servers = WebApiAccess.Instance.Get <List <WorldServerInfo> >("api/channels");

            foreach (var server in servers)
            {
                var accounts = WebApiAccess.Instance
                               .Get <List <ConnectedAccount> >($"api/connectedAccount", server.WebApi);

                if (accounts.Any(a => a.ConnectedCharacter?.Id == btkPacket.CharacterId))
                {
                    receiver = accounts.First(a => a.ConnectedCharacter?.Id == btkPacket.CharacterId);
                }
            }

            if (receiver == null)
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.FRIEND_OFFLINE, Session.Account.Language)
                });
                return;
            }

            ServerManager.Instance.BroadcastPacket(new PostedPacket
            {
                Packet            = PacketFactory.Serialize(Session.Character.GenerateTalk(message)),
                ReceiverCharacter = new Data.WebApi.Character()
                {
                    Id = btkPacket.CharacterId, Name = receiver.Name
                },
                SenderCharacter = new Data.WebApi.Character()
                {
                    Name = Session.Character.Name, Id = Session.Character.CharacterId
                },
                OriginWorldId = MasterClientListSingleton.Instance.ChannelId,
                ReceiverType  = ReceiverType.OnlySomeone
            }, receiver.ChannelId);
        }
Exemplo n.º 12
0
        private Task SaveAsync()
        {
            ConnectedAccount ca = CreateConnectedAccount();

            EventLog.LogEvent("saveAzureAccount", "prefix: {prefix}", ca.Prefix);

            GlobalState.LastConnectedFolder.Children.Add(ca);
            ConnectedAccount.Save();
            return(Task.CompletedTask);
        }
Exemplo n.º 13
0
        private async Task RenameAsync()
        {
            string newName = await Dialogs.AskStringInputAsync("Rename", "Name", DisplayName);

            if (!string.IsNullOrEmpty(newName))
            {
                _connectedEntity.DisplayName = newName;
                ConnectedAccount.Save();
            }
        }
Exemplo n.º 14
0
 public BlobsClipboardData(ConnectedAccount account, IBlobStorage storage, IEnumerable <Blob> blobs)
 {
     Account = account ?? throw new ArgumentNullException(nameof(account));
     Storage = storage ?? throw new ArgumentNullException(nameof(storage));
     if (blobs is null)
     {
         throw new ArgumentNullException(nameof(blobs));
     }
     Blobs = blobs.ToList();
 }
Exemplo n.º 15
0
        public AddAccountChildWindow(ConnectedFolder connectedFolder, ConnectedAccount connectedAccount)
        {
            InitializeComponent();

            this.Title = connectedAccount == null
            ? "Add New Account"
            : "Edit Account";

            this.DataContext = new AccountsViewModel(connectedFolder, connectedAccount);

            ViewModel.Committed          += _ => Close();
            ViewModel.AccountTypeSelected = connectedAccount != null;
            _connectedFolder = connectedFolder;
        }
        public override void Execute(SetHeroLevelCommandPacket levelPacket, ClientSession session)
        {
            if (string.IsNullOrEmpty(levelPacket.Name) || (levelPacket.Name == session.Character.Name))
            {
                session.Character.SetHeroLevel(levelPacket.Level);
                return;
            }

            var data = new StatData
            {
                ActionType = UpdateStatActionType.UpdateHeroLevel,
                Character  = new Character {
                    Name = levelPacket.Name
                },
                Data = levelPacket.Level
            };

            var channels = _channelHttpClient.GetChannels()
                           ?.Where(c => c.Type == ServerType.WorldServer);

            ConnectedAccount    receiver = null;
            ServerConfiguration config   = null;

            foreach (var channel in channels ?? new List <ChannelInfo>())
            {
                var accounts =
                    _connectedAccountHttpClient.GetConnectedAccount(channel);

                var target = accounts.FirstOrDefault(s => s.ConnectedCharacter.Name == levelPacket.Name);

                if (target != null)
                {
                    receiver = target;
                    config   = channel.WebApi;
                }
            }

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

            _statHttpClient.ChangeStat(data, config);
        }
Exemplo n.º 17
0
        public void JobLevel(SetJobLevelCommandPacket levelPacket)
        {
            if (string.IsNullOrEmpty(levelPacket.Name) || levelPacket.Name == Session.Character.Name)
            {
                Session.Character.SetJobLevel(levelPacket.Level);
                return;
            }

            var data = new StatData
            {
                ActionType = UpdateStatActionType.UpdateJobLevel,
                Character  = new Character {
                    Name = levelPacket.Name
                },
                Data = levelPacket.Level
            };

            var channels = WebApiAccess.Instance.Get <List <ChannelInfo> >(WebApiRoute.Channel)
                           ?.Where(c => c.Type == ServerType.WorldServer);

            ConnectedAccount    receiver = null;
            ServerConfiguration config   = null;

            foreach (var channel in channels ?? new List <ChannelInfo>())
            {
                var accounts =
                    WebApiAccess.Instance.Get <List <ConnectedAccount> >(WebApiRoute.ConnectedAccount, channel.WebApi);

                var target = accounts.FirstOrDefault(s => s.ConnectedCharacter.Name == levelPacket.Name);

                if (target != null)
                {
                    receiver = target;
                    config   = channel.WebApi;
                }
            }

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

            WebApiAccess.Instance.Post <StatData>(WebApiRoute.Stat, data, config);
        }
Exemplo n.º 18
0
        public IReadOnlyCollection <ActionGroup> GetExecutableAccountActionGroups(ConnectedAccount connectedAccount)
        {
            var result = new List <ActionGroup>();

            foreach (ActionGroup ag in _actionGroups)
            {
                IConnectedAccountAction[] actions = ag.Actions.Where(a => a.CanExecute(connectedAccount)).ToArray();
                if (actions.Length > 0)
                {
                    result.Add(new ActionGroup(ag.Name, actions));
                }
            }

            return(result);
        }
Exemplo n.º 19
0
        private async Task AddRootFolderAsync()
        {
            string name = await Dialogs.AskStringInputAsync("Add folder", "Name");

            if (name == null)
            {
                return;
            }

            EventLog.LogEvent("addRootFolder", "name: {name}", name);

            ConnectedAccount.RootFolder.Children.Add(new ConnectedFolder {
                DisplayName = name
            });
            ConnectedAccount.Save();
        }
Exemplo n.º 20
0
        public override void Execute(SetReputationPacket setReputationPacket, ClientSession session)
        {
            if (setReputationPacket.Name == session.Character.Name || string.IsNullOrEmpty(setReputationPacket.Name))
            {
                session.Character.SetReputation(setReputationPacket.Reputation);
                return;
            }

            var data = new StatData
            {
                ActionType = UpdateStatActionType.UpdateReputation,
                Character  = new Character {
                    Name = setReputationPacket.Name
                },
                Data = setReputationPacket.Reputation
            };

            var servers = WebApiAccess.Instance.Get <List <ChannelInfo> >(WebApiRoute.Channel)
                          .Where(s => s.Type == ServerType.WorldServer);
            ServerConfiguration config  = null;
            ConnectedAccount    account = null;

            foreach (var server in servers)
            {
                config  = server.WebApi;
                account = WebApiAccess.Instance.Get <List <ConnectedAccount> >(WebApiRoute.ConnectedAccount, config)
                          .Find(s => s.ConnectedCharacter.Name == setReputationPacket.Name);
                if (account != null)
                {
                    break;
                }
            }

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

            WebApiAccess.Instance.Post <StatData>(WebApiRoute.Stat, data, config);
        }
Exemplo n.º 21
0
        public void ChangeClass(ChangeClassPacket changeClassPacket)
        {
            if (changeClassPacket.Name == Session.Character.Name || string.IsNullOrEmpty(changeClassPacket.Name))
            {
                Session.Character.ChangeClass(changeClassPacket.ClassType);
                return;
            }

            var data = new StatData
            {
                ActionType = UpdateStatActionType.UpdateClass,
                Character  = new Character {
                    Name = changeClassPacket.Name
                },
                Data = (byte)changeClassPacket.ClassType,
            };

            var servers = WebApiAccess.Instance.Get <List <ChannelInfo> >(WebApiRoute.Channel)
                          .Where(s => s.Type == ServerType.WorldServer);
            ServerConfiguration config  = null;
            ConnectedAccount    account = null;

            foreach (var server in servers)
            {
                config  = server.WebApi;
                account = WebApiAccess.Instance.Get <List <ConnectedAccount> >(WebApiRoute.ConnectedAccount, config)
                          .Find(s => s.ConnectedCharacter.Name == changeClassPacket.Name);
                if (account != null)
                {
                    break;
                }
            }

            if (account == null) //TODO: Handle 404 in WebApi
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER,
                                                                  Session.Account.Language)
                });
                return;
            }

            WebApiAccess.Instance.Post <StatData>(WebApiRoute.Stat, data, config);
        }
Exemplo n.º 22
0
        private void AddActionCommands(ConnectedAccount ca)
        {
            if (!(ca.Definition is BlobApplicationAccount baa))
            {
                return;
            }

            IReadOnlyCollection <ActionGroup> actionGroups = baa.GetExecutableAccountActionGroups(ca);

            foreach (ActionGroup ag in actionGroups)
            {
                var hrg = new HierarchicalResourceCommandGroup(
                    ag.Actions.Select(
                        cmd => new HierarchicalResourceCommand(cmd.Name, cmd.Icon, () => cmd.ExecuteAsync(ca, null))).ToArray()
                    );

                CommandGroups.Add(hrg);
            }
        }
Exemplo n.º 23
0
        public void SetGold(SetGoldCommandPacket goldPacket)
        {
            var data = new StatData
            {
                ActionType = UpdateStatActionType.UpdateGold,
                Character  = new Character {
                    Name = goldPacket.Name
                },
                Data = goldPacket.Gold
            };

            var servers = WebApiAccess.Instance.Get <List <ChannelInfo> >(WebApiRoute.Channel)
                          .Where(s => s.Type == ServerType.WorldServer);
            ServerConfiguration config  = null;
            ConnectedAccount    account = null;

            foreach (var server in servers)
            {
                config  = server.WebApi;
                account = WebApiAccess.Instance.Get <List <ConnectedAccount> >(WebApiRoute.ConnectedAccount, config)
                          .Find(s => s.ConnectedCharacter.Name == goldPacket.Name);
                if (account != null)
                {
                    break;
                }
            }

            if (account == null) //TODO: Handle 404 in WebApi
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.CANT_FIND_CHARACTER,
                                                                  Session.Account.Language)
                });
                return;
            }

            WebApiAccess.Instance.Post <StatData>(WebApiRoute.Stat, data, config);
        }
Exemplo n.º 24
0
 public async Task ShowConnectedAccountDialogAsync(ConnectedFolder cf, ConnectedAccount ca)
 {
     await this.ShowChildWindowAsync(new AddAccountChildWindow(cf, ca) { IsModal = true });
 }
Exemplo n.º 25
0
        public RedisViewModel(ConnectedAccount connectedAccount)
        {
            Account = connectedAccount;

            RefreshKeysAsync().Forget();
        }
Exemplo n.º 26
0
        public MessengerViewModel(ConnectedAccount connectedAccount)
        {
            Account = connectedAccount;

            RefreshAsync().Forget();
        }
Exemplo n.º 27
0
        /// <summary>
        ///     WhisperPacket
        /// </summary>
        /// <param name="whisperPacket"></param>
        public void WhisperPacket(WhisperPacket whisperPacket)
        {
            try
            {
                var message = string.Empty;

                //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++)
                {
                    message += $"{messageData[i]} ";
                }

                message = whisperPacket.Message.Length > 60 ? whisperPacket.Message.Substring(0, 60) : message;
                message = message.Trim();

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

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

                var receiverSession =
                    ServerManager.Instance.Sessions.FirstOrDefault(s => s.Character?.Name == receiverName);
                if (receiverSession != null)
                {
                    receiverSession?.SendPacket(speakPacket);
                    return;
                }

                //Todo: Add a check for blacklisted characters when the CharacterRelation system will be done
                ConnectedAccount receiver = null;

                foreach (var server in WebApiAccess.Instance.Get <List <WorldServerInfo> >("api/channels"))
                {
                    var accounts = WebApiAccess.Instance
                                   .Get <List <ConnectedAccount> >($"api/connectedAccounts", server.WebApi);

                    if (accounts.Any(a => a.ConnectedCharacter?.Name == receiverName))
                    {
                        receiver = accounts.First(a => a.ConnectedCharacter?.Name == receiverName);
                        continue;
                    }
                }

                if (receiver == null)
                {
                    Session.SendPacket(Session.Character.GenerateSay(
                                           Language.Instance.GetMessageFromKey(LanguageKey.CHARACTER_OFFLINE, Session.Account.Language),
                                           SayColorType.Yellow));
                    return;
                }

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

                ServerManager.Instance.BroadcastPacket(new PostedPacket
                {
                    Packet = PacketFactory.Serialize(speakPacket),
                    ReceiverCharacterData = new CharacterData {
                        CharacterName = receiverName
                    },
                    SenderCharacterData = new CharacterData {
                        CharacterName = Session.Character.Name
                    },
                    OriginWorldId = MasterClientListSingleton.Instance.ChannelId,
                    ReceiverType  = ReceiverType.OnlySomeone
                }, receiver.ChannelId);

                Session.SendPacket(Session.Character.GenerateSay(
                                       Language.Instance.GetMessageFromKey(LanguageKey.SEND_MESSAGE_TO_CHARACTER,
                                                                           Session.Account.Language), SayColorType.Purple));
            }
            catch (Exception e)
            {
                Logger.Log.Error("Whisper failed.", e);
            }
        }
Exemplo n.º 28
0
        /// <summary>
        ///     WhisperPacket
        /// </summary>
        /// <param name="whisperPacket"></param>
        public void Whisper(WhisperPacket whisperPacket)
        {
            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);
                if (receiverSession != null)
                {
                    if (receiverSession.CharacterRelations.Values.Any(s =>
                                                                      s.RelatedCharacterId == Session.Character.CharacterId &&
                                                                      s.RelationType == CharacterRelationType.Blocked))
                    {
                        Session.SendPacket(new InfoPacket
                        {
                            Message = Language.Instance.GetMessageFromKey(LanguageKey.BLACKLIST_BLOCKED,
                                                                          Session.Account.Language)
                        });
                        return;
                    }

                    receiverSession.SendPacket(speakPacket);
                    return;
                }

                ConnectedAccount receiver = null;

                var servers = WebApiAccess.Instance.Get <List <WorldServerInfo> >("api/channels");
                foreach (var server in servers)
                {
                    var accounts = WebApiAccess.Instance
                                   .Get <List <ConnectedAccount> >("api/connectedAccount", server.WebApi);

                    if (accounts.Any(a => a.ConnectedCharacter?.Name == receiverName))
                    {
                        receiver = accounts.First(a => a.ConnectedCharacter?.Name == receiverName);
                        break;
                    }
                }

                if (receiver == null)
                {
                    Session.SendPacket(Session.Character.GenerateSay(
                                           Language.Instance.GetMessageFromKey(LanguageKey.CHARACTER_OFFLINE, Session.Account.Language),
                                           SayColorType.Yellow));
                    return;
                }

                if (Session.Character.RelationWithCharacter.Values.Any(s =>
                                                                       s.RelationType == CharacterRelationType.Blocked && s.CharacterId == receiver.ConnectedCharacter.Id))
                {
                    Session.SendPacket(new SayPacket
                    {
                        Message = Language.Instance.GetMessageFromKey(LanguageKey.BLACKLIST_BLOCKED,
                                                                      Session.Account.Language),
                        Type = SayColorType.Yellow
                    });
                    return;
                }

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

                WebApiAccess.Instance.BroadcastPacket(new PostedPacket
                {
                    Packet            = PacketFactory.Serialize(new[] { speakPacket }),
                    ReceiverCharacter = new Character {
                        Name = receiverName
                    },
                    SenderCharacter = new Character {
                        Name = Session.Character.Name
                    },
                    OriginWorldId = MasterClientListSingleton.Instance.ChannelId,
                    ReceiverType  = ReceiverType.OnlySomeone
                }, receiver.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);
            }
        }
Exemplo n.º 29
0
        public override void Execute(BtkPacket btkPacket, ClientSession session)
        {
            if (!session.Character.CharacterRelations.Values.Any(s =>
                                                                 s.RelatedCharacterId == btkPacket.CharacterId && s.RelationType != CharacterRelationType.Blocked))
            {
                _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;
            }

            ConnectedAccount receiver = null;

            var servers = WebApiAccess.Instance.Get <List <ChannelInfo> >(WebApiRoute.Channel)
                          ?.Where(c => c.Type == ServerType.WorldServer).ToList();

            foreach (var server in servers ?? new List <ChannelInfo>())
            {
                var accounts = WebApiAccess.Instance
                               .Get <List <ConnectedAccount> >(WebApiRoute.ConnectedAccount, server.WebApi);

                if (accounts.Any(a => a.ConnectedCharacter?.Id == btkPacket.CharacterId))
                {
                    receiver = accounts.First(a => a.ConnectedCharacter?.Id == btkPacket.CharacterId);
                }
            }

            if (receiver == null)
            {
                session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.FRIEND_OFFLINE, session.Account.Language)
                });
                return;
            }

            WebApiAccess.Instance.BroadcastPacket(new PostedPacket
            {
                Packet            = _packetSerializer.Serialize(new[] { session.Character.GenerateTalk(message) }),
                ReceiverCharacter = new Data.WebApi.Character
                {
                    Id = btkPacket.CharacterId, Name = receiver.ConnectedCharacter?.Name
                },
                SenderCharacter = new Data.WebApi.Character
                {
                    Name = session.Character.Name, Id = session.Character.CharacterId
                },
                OriginWorldId = MasterClientListSingleton.Instance.ChannelId,
                ReceiverType  = ReceiverType.OnlySomeone
            }, receiver.ChannelId);
        }
Exemplo n.º 30
0
        /// <summary>
        ///     btk packet
        /// </summary>
        /// <param name="btkPacket"></param>
        public void FriendTalk(BtkPacket btkPacket)
        {
            if (!Session.Character.CharacterRelations.Values.Any(s =>
                                                                 s.RelatedCharacterId == btkPacket.CharacterId && s.RelationType != CharacterRelationType.Blocked))
            {
                _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;
            }

            ConnectedAccount receiver = null;

            var servers = WebApiAccess.Instance.Get <List <WorldServerInfo> >("api/channels");

            foreach (var server in servers)
            {
                var accounts = WebApiAccess.Instance
                               .Get <List <ConnectedAccount> >("api/connectedAccount", server.WebApi);

                if (accounts.Any(a => a.ConnectedCharacter?.Id == btkPacket.CharacterId))
                {
                    receiver = accounts.First(a => a.ConnectedCharacter?.Id == btkPacket.CharacterId);
                }
            }

            if (receiver == null)
            {
                Session.SendPacket(new InfoPacket
                {
                    Message = Language.Instance.GetMessageFromKey(LanguageKey.FRIEND_OFFLINE, Session.Account.Language)
                });
                return;
            }

            WebApiAccess.Instance.BroadcastPacket(new PostedPacket
            {
                Packet            = PacketFactory.Serialize(new[] { Session.Character.GenerateTalk(message) }),
                ReceiverCharacter = new Character
                {
                    Id = btkPacket.CharacterId, Name = receiver.ConnectedCharacter?.Name
                },
                SenderCharacter = new Character
                {
                    Name = Session.Character.Name, Id = Session.Character.CharacterId
                },
                OriginWorldId = MasterClientListSingleton.Instance.ChannelId,
                ReceiverType  = ReceiverType.OnlySomeone
            }, receiver.ChannelId);
        }