Exemple #1
0
        private void Login()
        {
            try
            {
                ChannelFactory <Servicegame> cf =
                    new ChannelFactory <Servicegame>("MyEndpoint");

                ServiceProxy.Proxy = cf.CreateChannel();

                //0 success
                //1 incorrect pass
                //2 already online
                //3 hacking attempt

                int res = ServiceProxy.Proxy.Login(login, passw);

                Thread.Sleep(2000); //emulate conntion procc

                this.Dispatcher.Invoke(new Action(delegate
                {
                    loginBtn.IsEnabled = true;
                }));

                if (res == 0)
                {
                    App.UserName    = login;
                    App.isConnected = true;

                    App.iamonlineTread = new Thread(App.iAmOnline)
                    {
                        IsBackground = true
                    };
                    App.iamonlineTread.Start();

                    bool isError = false;

                    bool contains = false;

                    App.ProxyMutex.WaitOne();
                    try
                    {
                        contains = ServiceProxy.Proxy.isAccountContainsAnyCharacter(login);
                    }
                    catch
                    {
                        App.OnException();
                        isError = true;
                    }

                    App.ProxyMutex.ReleaseMutex();

                    if (isError)
                    {
                        return;
                    }


                    if (!contains)
                    {
                        this.Dispatcher.Invoke(new Action(delegate
                        {
                            if (!App.WindowList.ContainsKey("CharacterCreateWnd"))
                            {
                                CharacterCreateScreen ccs = new CharacterCreateScreen();
                                App.WindowList.Add(ccs.Name, ccs);
                            }
                            else
                            {
                                (App.WindowList["CharacterCreateWnd"] as CharacterCreateScreen).OnWindowShow();
                            }

                            App.WindowList["CharacterCreateWnd"].Show();
                            //loginTextBox.Text = "";
                            passwordTextBox.Password = "";
                        }));
                    }
                    else
                    {
                        this.Dispatcher.Invoke(new Action(delegate
                        {
                            if (!App.WindowList.ContainsKey("LobbyWnd"))
                            {
                                LobbyScreen ls = new LobbyScreen();
                                App.WindowList.Add(ls.Name, ls);
                            }
                            else
                            {
                                (App.WindowList["LobbyWnd"] as LobbyScreen).OnWindowShow();
                            }

                            App.WindowList["LobbyWnd"].Show();
                            //loginTextBox.Text = "";
                            passwordTextBox.Password = "";
                        }));
                    }

                    Thread.Sleep(1000);

                    this.Dispatcher.Invoke(new Action(delegate
                    {
                        errorPopupInfo.HideWaitInfo();
                        Hide();
                    }));
                }
                else if (res == 1)
                {
                    this.Dispatcher.Invoke(new Action(delegate {
                        errorPopupInfo.HideWaitInfoAndShowError("Неправильный логин или пароль!");
                    }));
                }
                else if (res == 2)
                {
                    this.Dispatcher.Invoke(new Action(delegate {
                        errorPopupInfo.HideWaitInfoAndShowError("Кто-то другой использует ваш аккаунт!");
                    }));
                }
                else if (res == 3)
                {
                    this.Dispatcher.Invoke(new Action(delegate {
                        errorPopupInfo.HideWaitInfoAndShowError("Поля заполнены некорректено!");
                    }));
                }


                if (!App.isConnected)
                {
                    this.Dispatcher.Invoke(new Action(delegate
                    {
                        DoubleAnimation da = new DoubleAnimation(1, 0, TimeSpan.FromMilliseconds(100));
                        da.BeginTime       = TimeSpan.FromMilliseconds(2000);
                        da.FillBehavior    = FillBehavior.Stop;
                        da.Completed      += new EventHandler(da_Completed);
                        LoginErrorInfo.BeginAnimation(OpacityProperty, da);
                    }));
                }
            }
            catch (CommunicationException)
            {
                this.Dispatcher.Invoke(new Action(delegate
                {
                    App.isConnected    = false;
                    loginBtn.IsEnabled = true;
                    errorPopupInfo.HideWaitInfoAndShowError(
                        "Ошибка подключения!\r\nПопробуйте повторить попытку позже..."
                        );
                }));
            }
            catch (Exception exc)
            {
                this.Dispatcher.Invoke(new Action(delegate
                {
                    App.isConnected    = false;
                    loginBtn.IsEnabled = true;
                    App.dumpException(exc);
                    MessageBox.Show(exc.Message, "Критическая ошибка!");
                }));
            }
        }
Exemple #2
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.CharacterCreateWnd = ((CardGameClient.CharacterCreateScreen)(target));

            #line 5 "..\..\..\CharacterCreateScreen.xaml"
                this.CharacterCreateWnd.Closing += new System.ComponentModel.CancelEventHandler(this.Window_Closing);

            #line default
            #line hidden

            #line 5 "..\..\..\CharacterCreateScreen.xaml"
                this.CharacterCreateWnd.Closed += new System.EventHandler(this.Window_Closed);

            #line default
            #line hidden

            #line 5 "..\..\..\CharacterCreateScreen.xaml"
                this.CharacterCreateWnd.Loaded += new System.Windows.RoutedEventHandler(this.Window_Loaded);

            #line default
            #line hidden

            #line 5 "..\..\..\CharacterCreateScreen.xaml"
                this.CharacterCreateWnd.ContentRendered += new System.EventHandler(this.Window_ContentRendered);

            #line default
            #line hidden

            #line 5 "..\..\..\CharacterCreateScreen.xaml"
                this.CharacterCreateWnd.IsVisibleChanged += new System.Windows.DependencyPropertyChangedEventHandler(this.CharacterCreateWnd_IsVisibleChanged);

            #line default
            #line hidden
                return;

            case 2:
                this.characterNameTextBox = ((CardGameClient.StyledTextBox)(target));
                return;

            case 3:
                this.exitBtn = ((CardGameClient.StyledBtn)(target));
                return;

            case 4:
                this.createCharBtn = ((CardGameClient.StyledBtn)(target));
                return;

            case 5:
                this.grid2 = ((System.Windows.Controls.Grid)(target));
                return;

            case 6:
                this.errorText = ((System.Windows.Controls.Label)(target));
                return;

            case 7:
                this.gridHeroes = ((System.Windows.Controls.Grid)(target));
                return;

            case 8:
                this.errorPopupInfo = ((CardGameClient.PopupInfo)(target));
                return;
            }
            this._contentLoaded = true;
        }