public NewConnectionWindow(ClientHandle handle, RecentWorld recentWorld, bool isDebug)
        {
            this._recentWorld = recentWorld;
            this._isDebug = isDebug;
            this.InitializeComponent();

            this._handle = handle;
            this._handle.ReceiveClose += this._handle_ReceiveClose;

            this.Closed += this.NewConnectionWindow_Closed;

            foreach (Profile profile in SettingsManager.Settings.Profiles.OrderBy(v => v.Id))
            {
                var item = new TextBlock(new Run(profile.Name.GetVisualName())) {Tag = profile};
                this.ProfileComboBox.Items.Add(item);

                if (recentWorld.Profile == profile.Id)
                    this.ProfileComboBox.SelectedItem = item;
            }

            foreach (Account account in SettingsManager.Settings.Accounts.OrderBy(v => v.Id))
            {
                var item = new TextBlock(new Run((account.Name ?? account.Email).GetVisualName())) {Tag = account};
                this.AccountComboBox.Items.Add(item);

                if (recentWorld.Account == account.Id)
                    this.AccountComboBox.SelectedItem = item;
            }

            this.WorldIdTextBox.Text = recentWorld.WorldId;
        }
        public ConnectionUserControl(ClientHandle handle)
        {
            this.InitializeComponent();

            this.Loaded += this.ConnectionUserControl_Loaded;

            this._handle = handle;
            this._handle.ReceiveOutput += this.ClientOutput;
            this._handle.ReceiveClose += this._handle_ConnectionClose;
            this._handle.ReceiveTitle += this._handle_ReceiveTitle;
            this._handle.ReceiveStatus += this._handle_ReceiveStatus;
            this._handle.ReceiveWrongAuth += this._handle_ReceiveWrongAuth;
        }
Exemplo n.º 3
0
        private static void SendBuffer(ClientHandle h)
        {
            h.DoSendTitle(_title);
            h.DoSendStatus(_status);

            foreach (string output in _outputs.Skip(_outputs.Count - 200))
            {
                h.DoSendOutput(output);
            }
        }
Exemplo n.º 4
0
        private static void OnConnection(ClientHandle h)
        {
            bool authenticated = false;
            if (String.IsNullOrEmpty(_settings.Pin))
            {
                authenticated = true;
                SendBuffer(h);
            }

            Output += s =>
            {
                if (!authenticated) return;

                h.DoSendOutput(s);
            };

            Title += s =>
            {
                if (!authenticated) return;

                h.DoSendTitle(s);
            };

            Status += s =>
            {
                if (!authenticated) return;

                h.DoSendStatus(s);
            };

            h.ReceiveAuthentication += authentication =>
            {
                if (_settings.Pin == authentication.Pin || authenticated)
                {
                    authenticated = true;
                    SendBuffer(h);
                }
                else
                {
                    h.DoSendWrongAuth();
                    h.DoSendClose();
                }
            };

            h.ReceiveInput += input =>
            {
                if (!authenticated) return;

                _clientEx.Input(input.Text);
            };

            h.ReceiveSetData += data =>
            {
                if (!authenticated) return;

                if (data.Settings != null)
                    _settings = XmlSerialize.Deserialize<CupCakeServerSettings>(data.Settings);

                if (_settings.Email == null)
                    _settings.Email = data.Email;
                if (_settings.Password == null)
                    _settings.Password = data.Password;
                if (_settings.World == null)
                    _settings.World = data.World;
                if (_settings.ConnectionString == null)
                    _settings.DatabaseType = data.DatabaseType;
                if (_settings.ConnectionString == null)
                    _settings.ConnectionString = data.ConnectionString;

                if (data.Directories != null)
                    _settings.Dirs.InsertRange(0, data.Directories);

                Start();
            };
        }
Exemplo n.º 5
0
        private void HandleIncoming(ClientHandle handle)
        {
            Dispatch.Invoke(() =>
            {
                this.ConnectionCount++;

                var userControl = new ConnectionUserControl(handle);
                var tabItem = new TabItem
                {
                    Header = String.Empty.GetVisualName(),
                    Content = userControl
                };

                userControl.Title += s => { tabItem.Header = s; };

                userControl.Status += s =>
                {
                    if (tabItem.IsSelected)
                    {
                        this.StatusTextBlock.Text = s;
                    }
                };

                Selector.AddSelectedHandler(tabItem, (sender, args) =>
                {
                    if (tabItem.IsSelected)
                    {
                        this.StatusTextBlock.Text = userControl.StatusString;
                    }
                });

                this.ConnectionsTabControl.Items.Add(tabItem);
                tabItem.IsSelected = true;

                handle.ReceiveClose += () => Dispatch.Invoke(() => { this.ConnectionCount--; });

                handle.ReceiveRequestData += data => Dispatch.BeginInvoke(() =>
                {
                    userControl.IsDebug = data.IsDebug;

                    // Use requested settings
                    RecentWorld recent = this.IncomingSettings;
                    this.IncomingSettings = null;

                    bool isNew = false;
                    if (recent == null)
                    {
                        isNew = true;

                        recent = SettingsManager.Settings.RecentWorlds.Count == 0
                            ? new RecentWorld()
                            : SettingsManager.Settings.RecentWorlds.OrderByDescending(r => r.Id).First().Clone();
                    }

                    if (new NewConnectionWindow(handle, recent, data.IsDebug) {Owner = this}.ShowDialog() == true)
                    {
                        if (isNew)
                            this.AddRecent(recent);
                    }
                    else
                    {
                        userControl.RemoveTab();
                    }

                    recent.UpdateId();
                    SettingsManager.Save();
                    this.RefreshRecent();
                });
            });
        }