예제 #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, "Критическая ошибка!");
                }));
            }
        }
예제 #2
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.LobbyWnd = ((CardGameClient.LobbyScreen)(target));

            #line 6 "..\..\..\LobbyScreen.xaml"
                this.LobbyWnd.Closing += new System.ComponentModel.CancelEventHandler(this.Window_Closing);

            #line default
            #line hidden

            #line 6 "..\..\..\LobbyScreen.xaml"
                this.LobbyWnd.Closed += new System.EventHandler(this.Window_Closed);

            #line default
            #line hidden

            #line 6 "..\..\..\LobbyScreen.xaml"
                this.LobbyWnd.Loaded += new System.Windows.RoutedEventHandler(this.Window_Loaded);

            #line default
            #line hidden

            #line 6 "..\..\..\LobbyScreen.xaml"
                this.LobbyWnd.ContentRendered += new System.EventHandler(this.Window_ContentRendered_1);

            #line default
            #line hidden

            #line 6 "..\..\..\LobbyScreen.xaml"
                this.LobbyWnd.IsVisibleChanged += new System.Windows.DependencyPropertyChangedEventHandler(this.LobbyWnd_IsVisibleChanged);

            #line default
            #line hidden
                return;

            case 2:
                this.MainLobbyGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 3:
                this.findBtn = ((CardGameClient.FindButton)(target));
                return;

            case 4:
                this.NickNameLevel = ((CardGameClient.StyledTextBox)(target));
                return;

            case 5:
                this.Wins = ((CardGameClient.StyledTextBox)(target));
                return;

            case 6:
                this.Games = ((CardGameClient.StyledTextBox)(target));
                return;

            case 7:
                this.Exp = ((CardGameClient.StyledTextBox)(target));
                return;

            case 8:
                this.Rating = ((CardGameClient.StyledTextBox)(target));
                return;

            case 9:
                this.MainLobbyBackBtn = ((CardGameClient.StyledBtn)(target));
                return;

            case 10:
                this.AllCardsBtn = ((CardGameClient.StyledBtn)(target));
                return;

            case 11:
                this.ratingGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 12:
                this.MyCardsGrid = ((System.Windows.Controls.Grid)(target));

            #line 60 "..\..\..\LobbyScreen.xaml"
                this.MyCardsGrid.IsVisibleChanged += new System.Windows.DependencyPropertyChangedEventHandler(this.MyCardsGrid_IsVisibleChanged);

            #line default
            #line hidden
                return;

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

            case 14:
                this.AllCardsGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 15:

            #line 142 "..\..\..\LobbyScreen.xaml"
                ((System.Windows.Controls.Image)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Image_MouseDown);

            #line default
            #line hidden
                return;

            case 16:
                this.currPageLabel = ((System.Windows.Controls.Label)(target));
                return;

            case 17:

            #line 144 "..\..\..\LobbyScreen.xaml"
                ((System.Windows.Controls.Image)(target)).MouseDown += new System.Windows.Input.MouseButtonEventHandler(this.Image_MouseDown_1);

            #line default
            #line hidden
                return;

            case 18:
                this.SlotGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 19:
                this.Slot1Card = ((CardGameClient.CardPlace)(target));
                return;

            case 20:
                this.Slot2Card = ((CardGameClient.CardPlace)(target));
                return;

            case 21:
                this.Slot3Card = ((CardGameClient.CardPlace)(target));
                return;

            case 22:
                this.Slot4Card = ((CardGameClient.CardPlace)(target));
                return;

            case 23:
                this.Slot5Card = ((CardGameClient.CardPlace)(target));
                return;

            case 24:
                this.Slo6Card = ((CardGameClient.CardPlace)(target));
                return;

            case 25:
                this.Slot7Card = ((CardGameClient.CardPlace)(target));
                return;

            case 26:
                this.Slot8Card = ((CardGameClient.CardPlace)(target));
                return;

            case 27:
                this.CardsExitBtn = ((CardGameClient.StyledBtn)(target));
                return;

            case 28:
                this.CardsScore = ((CardGameClient.StyledTextBox)(target));
                return;

            case 29:
                this.CardsShopBtn = ((CardGameClient.StyledBtn)(target));
                return;

            case 30:
                this.ShopGrid = ((System.Windows.Controls.Grid)(target));
                return;

            case 31:

            #line 192 "..\..\..\LobbyScreen.xaml"
                ((System.Windows.Controls.Image)(target)).MouseUp += new System.Windows.Input.MouseButtonEventHandler(this.Image_MouseUp);

            #line default
            #line hidden
                return;

            case 32:
                this.nabor1Btn = ((CardGameClient.StyledBtn)(target));
                return;

            case 33:
                this.nabor2Btn = ((CardGameClient.StyledBtn)(target));
                return;

            case 34:
                this.nabor3Btn = ((CardGameClient.StyledBtn)(target));
                return;
            }
            this._contentLoaded = true;
        }
        private void CreateCharacter()
        {
            try
            {
                bool isError = false;
                bool result  = false;

                App.ProxyMutex.WaitOne();
                try
                {
                    result = ServiceProxy.Proxy.createCharacter(App.UserName, App.NickName, CardIndex);
                }
                catch
                {
                    App.OnException();
                    isError = true;
                }

                App.ProxyMutex.ReleaseMutex();

                if (isError)
                {
                    App.OnConnectionError();
                    return;
                }


                if (result)
                {
                    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();

                        /*selectedCardPlace.selected = false;
                         * characterNameTextBox.Text = "";
                         * CardIndex = -1;
                         * errorText.Content = "Имя персонажа: Введите от 3 до 16 символов";*/

                        Hide();
                    }));

                    Thread.Sleep(2000);
                }

                else
                {
                    this.Dispatcher.Invoke(new Action(() =>
                                                      errorPopupInfo.ShowError("Ошибка при создании персонажа. Персонаж с таким именем уже существует...")
                                                      ));
                }
            }
            catch (Exception exc)
            {
                this.Dispatcher.Invoke(new Action(delegate {
                    MessageBox.Show(exc.Message, "Критическая ошибка!");
                    App.isConnected = false;
                    App.dumpException(exc);
                    Application.Current.Shutdown();
                }));
            }
        }