Пример #1
0
        private void OnUserInfo(dynamic result)
        {
            if (result["Result"].ToObject <bool>())
            {
                Program.RemoteUser = result["RemoteUser"].ToObject <RemoteUser>();

                if (_userInfoResult == null)
                {
                    _userInfoResult = ExecuteUserInfoResultCommand;
                }
                try
                {
                    Invoke(_userInfoResult, Program.RemoteUser);
                }
                catch (Exception)
                {
                    //
                }
            }
            else
            {
                var str = result["Message"].ToObject <string>();
                SkinHelper.ShowMessage($@"OnUserInfo(): {str}", @"Project Celeste",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #2
0
        private static void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (e.PropertyName)
            {
            case "State":
            {
                switch (Program.WebSocketClient.State)
                {
                case WebSocketClientState.Offline:
                {
                    if (_timer != null && _timer.Enabled)
                    {
                        _timer.Enabled = false;
                        _timer.Stop();
                    }
                    if (_loginPassed)
                    {
                        SkinHelper.ShowMessage(@"You have been disconnected from the server!",
                                               @"Project Celeste",
                                               MessageBoxButtons.OK, MessageBoxIcon.Error);
                        _forceClose = true;
                        Application.Exit();
                    }
                    break;
                }

                case WebSocketClientState.Connecting:
                    break;

                case WebSocketClientState.Logging:
                    break;

                case WebSocketClientState.Logged:
                {
                    if (_timer != null && !_timer.Enabled)
                    {
                        _timer.Enabled = true;
                        _timer.Start();
                    }
                    _loginPassed = true;
                    break;
                }

                case WebSocketClientState.Connected:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(WebSocketClient.State),
                                                          Program.WebSocketClient.State,
                                                          @"OnPropertyChanged()");
                }
                break;
            }
            }
        }
Пример #3
0
        private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length <= 0)
            {
                return;
            }
            SkinHelper.ShowMessage(@"You need to close the game first!");
            e.Cancel = true;
        }
Пример #4
0
        private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length <= 0)
            {
                return;
            }
            SkinHelper.ShowMessage(MultiLanguage.GetString("strCloseGameFirst"));
            e.Cancel = true;
        }
Пример #5
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                //
                var pname = Process.GetProcessesByName("spartan");
                if (pname.Length > 0)
                {
                    SkinHelper.ShowMessage(@"Game already runing! Close it first.");
                    return;
                }
            }
            catch (Exception)
            {
                //
            }

            try
            {
                //Only one instance
                if (AlreadyRunning())
                {
                    return;
                }
            }
            catch (Exception)
            {
                //
            }

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                    string lang = UserConfig.GameLanguage.ToString();
                    lang = $"{lang.Substring(0, 2)}-{lang.Substring(2)}";
                    System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo(lang);
                }
            }
            catch (Exception)
            {
                //
            }


            //Start Gui
            Application.Run(new MainForm());
        }
Пример #6
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0 && !_forceClose)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strCloseGameFirst"));
                e.Cancel = true;
                return;
            }
            _timer.Stop();
            Program.WebSocketClient.AgentWebSocket.Close();
            NatDiscoverer.ReleaseAll();
        }
Пример #7
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0 && !_forceClose)
            {
                SkinHelper.ShowMessage(@"You need to close the game first!");
                e.Cancel = true;
                return;
            }
            _timer.Stop();
            Program.WebSocketClient.AgentWebSocket.Close();
            NatDiscoverer.ReleaseAll();
        }
Пример #8
0
        private static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            try
            {
                //
                var pname = Process.GetProcessesByName("spartan");
                if (pname.Length > 0)
                {
                    SkinHelper.ShowMessage(@"Game already runing! Close it first.");
                    return;
                }
            }
            catch (Exception)
            {
                //
            }

            try
            {
                //Only one instance
                if (AlreadyRunning())
                {
                    return;
                }
            }
            catch (Exception)
            {
                //
            }

            //Load UserConfig
            try
            {
                if (File.Exists(UserConfigFilePath))
                {
                    UserConfig = UserConfig.Load(UserConfigFilePath);
                }
            }
            catch (Exception)
            {
                //
            }


            //Start Gui
            Application.Run(new MainForm());
        }
Пример #9
0
 private void OnChangePassword(dynamic result)
 {
     if (result["Result"].ToObject <bool>())
     {
         SkinHelper.ShowMessage(MultiLanguage.GetString("strPasswordChanged"), @"Project Celeste -- Change Password",
                                MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         var str = result["Message"].ToObject <string>();
         SkinHelper.ShowMessage($@"Error: {str}", @"Project Celeste -- Change Password",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     _changePasswordDone = true;
 }
Пример #10
0
        private void btn_Register_Click(object sender, EventArgs e)
        {
            if (!Celeste_User.Helpers.IsValideEmailAdress(tb_Mail.Text))
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strInvalidEmail"), @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (!Celeste_User.Helpers.IsValideUserName(tb_UserName.Text))
            {
                SkinHelper.ShowMessage(
                    MultiLanguage.GetString("strInvalidUserName"),
                    @"Project Celeste -- Register",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_ConfirmPassword.Text != tb_Password.Text)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("srtPasswordConfirmNotMatch"),
                                       @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_Password.Text.Length < 8 || tb_Password.Text.Length > 32)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strInvalidPassordLength"),
                                       @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_InviteCode.Text.Length != 128)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strInvalidInviteCode"),
                                       @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DoRegisterUser(tb_Mail.Text, tb_Password.Text, tb_UserName.Text, tb_InviteCode.Text);
        }
Пример #11
0
        private void btn_Register_Click(object sender, EventArgs e)
        {
            if (!Celeste_User.Helpers.IsValideEmailAdress(tb_Mail.Text))
            {
                SkinHelper.ShowMessage(@"Invalid Email!", @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (!Celeste_User.Helpers.IsValideUserName(tb_UserName.Text))
            {
                SkinHelper.ShowMessage(
                    @"Invalid User Name, only letters and digits allowed, minimum length is 3 char and maximum length is 15 char!",
                    @"Project Celeste -- Register",
                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_ConfirmPassword.Text != tb_Password.Text)
            {
                SkinHelper.ShowMessage(@"Password value and confirm password value don't match!",
                                       @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_Password.Text.Length < 8 || tb_Password.Text.Length > 32)
            {
                SkinHelper.ShowMessage(@"Password minimum length is 8 char,  maximum length is 32 char!",
                                       @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_InviteCode.Text.Length != 128)
            {
                SkinHelper.ShowMessage(@"Invalid Invite Code!",
                                       @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DoRegisterUser(tb_Mail.Text, tb_Password.Text, tb_UserName.Text, tb_InviteCode.Text);
        }
Пример #12
0
        private void btn_Login_Click(object sender, EventArgs e)
        {
            if (!Celeste_User.Helpers.IsValideEmailAdress(tb_Mail.Text))
            {
                SkinHelper.ShowMessage(@"Invalid Email!", @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_Password.Text.Length < 8 || tb_Password.Text.Length > 32)
            {
                SkinHelper.ShowMessage(@"Password minimum length is 8 char, maximum length is 32 char!",
                                       @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DoLoggedIn(tb_Mail.Text, tb_Password.Text);
        }
Пример #13
0
        private void btn_Login_Click(object sender, EventArgs e)
        {
            if (!Celeste_User.Helpers.IsValideEmailAdress(tb_Mail.Text))
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strInvalidEmail"), @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (tb_Password.Text.Length < 8 || tb_Password.Text.Length > 32)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strInvalidPassordLength"),
                                       @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DoLoggedIn(tb_Mail.Text, tb_Password.Text);
        }
Пример #14
0
        private void btnSmall1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != textBox2.Text)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strPasswordsNotMatch"),
                                       @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (textBox1.Text.Length < 8)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strPasswordMinimunLength"), @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (textBox1.Text.Length > 32)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strPasswordMaxLength"), @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Enabled = false;
            DoChangePassword(tb_Password.Text, textBox2.Text);

            var starttime = DateTime.UtcNow;

            while (!_changePasswordDone && DateTime.UtcNow.Subtract(starttime).TotalSeconds < 20) //Timeout 20sec
            {
                Application.DoEvents();
            }

            Enabled = true;

            if (!_changePasswordDone)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strErrorTimeout"), @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #15
0
        private void btnSmall1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != textBox2.Text)
            {
                SkinHelper.ShowMessage(@"New password value and confirm new password value don't match!",
                                       @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            if (textBox1.Text.Length < 8)
            {
                SkinHelper.ShowMessage(@"Password minimum length is 8 char!", @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (textBox1.Text.Length > 32)
            {
                SkinHelper.ShowMessage(@"Password maximum length is 32 char!", @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            Enabled = false;
            DoChangePassword(tb_Password.Text, textBox2.Text);

            var starttime = DateTime.UtcNow;

            while (!_changePasswordDone && DateTime.UtcNow.Subtract(starttime).TotalSeconds < 20) //Timeout 20sec
            {
                Application.DoEvents();
            }

            Enabled = true;

            if (!_changePasswordDone)
            {
                SkinHelper.ShowMessage(@"Error: Timout!", @"Project Celeste -- Change Password",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #16
0
        private static void OnLoggedIn(dynamic result)
        {
            if (result["Result"].ToObject <bool>())
            {
                Program.RemoteUser            = result["RemoteUser"].ToObject <RemoteUser>();
                Program.WebSocketClient.State = WebSocketClientState.Logged;
            }
            else
            {
                Program.WebSocketClient.State = WebSocketClientState.Connected;

                Program.WebSocketClient.ErrorMessage = result["Message"].ToObject <string>();
                SkinHelper.ShowMessage($@"{Program.WebSocketClient.ErrorMessage}", @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Program.WebSocketClient?.AgentWebSocket?.Close();
                }
            }
        }
Пример #17
0
        private void OnRegisterUser(dynamic result)
        {
            if (result["Result"].ToObject <bool>())
            {
                _registerUserFailed = false;
                SkinHelper.ShowMessage(@"Registred with success.", @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                _registerUserFailed = true;
                var str = result["Message"].ToObject <string>();
                SkinHelper.ShowMessage($@"Error: {str}", @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Offline)
            {
                Program.WebSocketClient.AgentWebSocket.Close();
            }

            _registerUserDone = true;
        }
Пример #18
0
        private void DoRegisterUser(string email, string password, string username, string inviteCode)
        {
            _registerUserDone = false;

            Enabled = false;

            if (Program.WebSocketClient.State == WebSocketClientState.Logged ||
                Program.WebSocketClient.State == WebSocketClientState.Logging)
            {
                SkinHelper.ShowMessage(@"Already logged-in or logged-in in progress!", @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                Enabled = true;
                return;
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Connected)
            {
                Program.WebSocketClient.StartConnect();

                var starttime = DateTime.UtcNow;
                while (Program.WebSocketClient.State != WebSocketClientState.Connected &&
                       Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Application.DoEvents();

                    if (DateTime.UtcNow.Subtract(starttime).TotalSeconds <= 20)
                    {
                        continue;
                    }

                    SkinHelper.ShowMessage(@"Server connection timeout (> 20sec)!", @"Project Celeste -- Login",
                                           MessageBoxButtons.OK, MessageBoxIcon.Error);

                    Enabled = true;
                    return;
                }
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Connected)
            {
                SkinHelper.ShowMessage(@"Server Offline", @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                Enabled = true;
                return;
            }

            dynamic registerUserInfo = new ExpandoObject();

            registerUserInfo.Mail       = email;
            registerUserInfo.Password   = password;
            registerUserInfo.UserName   = username;
            registerUserInfo.InviteCode = inviteCode;

            Program.WebSocketClient?.AgentWebSocket?.Query <dynamic>("REGISTER", (object)registerUserInfo,
                                                                     OnRegisterUser);

            var starttime2 = DateTime.UtcNow;

            while (!_registerUserDone)
            {
                Application.DoEvents();

                if (DateTime.UtcNow.Subtract(starttime2).TotalSeconds <= 20)
                {
                    continue;
                }

                SkinHelper.ShowMessage(@"Server response timeout (> 20sec)!", @"Project Celeste -- Register",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Program.WebSocketClient?.AgentWebSocket?.Close();
                }

                Enabled = true;
                return;
            }

            Enabled = true;

            if (_registerUserFailed)
            {
                Focus();
                return;
            }

            DialogResult = DialogResult.OK;
            Close();
        }
Пример #19
0
        public void DoLoggedIn(string email, string password)
        {
            Enabled = false;

            if (Program.WebSocketClient.State == WebSocketClientState.Logged ||
                Program.WebSocketClient.State == WebSocketClientState.Logging)
            {
                SkinHelper.ShowMessage(@"Already logged-in or logged-in in progress!", @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                Enabled = true;
                return;
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Connected)
            {
                Program.WebSocketClient.StartConnect();

                var starttime = DateTime.UtcNow;
                while (Program.WebSocketClient.State != WebSocketClientState.Connected &&
                       Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Application.DoEvents();

                    if (DateTime.UtcNow.Subtract(starttime).TotalSeconds <= 20)
                    {
                        continue;
                    }

                    SkinHelper.ShowMessage(@"Server connection timeout (> 20sec)!", @"Project Celeste -- Login",
                                           MessageBoxButtons.OK, MessageBoxIcon.Error);

                    if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                    {
                        Program.WebSocketClient?.AgentWebSocket?.Close();
                    }

                    Enabled = true;
                    return;
                }
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Connected)
            {
                SkinHelper.ShowMessage(@"Server Offline", @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Program.WebSocketClient?.AgentWebSocket?.Close();
                }

                Enabled = true;
                return;
            }

            Program.WebSocketClient.State = WebSocketClientState.Logging;

#pragma warning disable IDE0017 // Simplifier l'initialisation des objets
            dynamic loginInfo = new ExpandoObject();
            loginInfo.Mail     = email;
            loginInfo.Password = password;
            loginInfo.Version  = 134;
#pragma warning restore IDE0017 // Simplifier l'initialisation des objets

            Program.WebSocketClient.AgentWebSocket?.Query <dynamic>("LOGIN", (object)loginInfo, OnLoggedIn);

            var starttime2 = DateTime.UtcNow;
            while (Program.WebSocketClient.State == WebSocketClientState.Logging)
            {
                Application.DoEvents();

                if (DateTime.UtcNow.Subtract(starttime2).TotalSeconds <= 20)
                {
                    continue;
                }

                SkinHelper.ShowMessage(@"Server response timeout (> 20sec)!", @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Program.WebSocketClient?.AgentWebSocket?.Close();
                }

                Enabled = true;
                return;
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Logged)
            {
                Enabled = true;
                return;
            }

            //Save UserConfig
            if (Program.UserConfig == null)
            {
                Program.UserConfig = new UserConfig
                {
                    LoginInfo = new LoginInfo
                    {
                        Email      = tb_Mail.Text,
                        Password   = tb_Password.Text,
                        RememberMe = cb_RememberMe.Checked
                    }
                };
            }
            else
            {
                Program.UserConfig.LoginInfo.Email      = tb_Mail.Text;
                Program.UserConfig.LoginInfo.Password   = tb_Password.Text;
                Program.UserConfig.LoginInfo.RememberMe = cb_RememberMe.Checked;
            }
            Program.UserConfig.Save(Program.UserConfigFilePath);

            DialogResult = DialogResult.OK;
            Close();
        }
Пример #20
0
        public void DoLoggedIn(string email, string password)
        {
            Enabled = false;

            if (Program.WebSocketClient.State == WebSocketClientState.Logged ||
                Program.WebSocketClient.State == WebSocketClientState.Logging)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strAlreadyLoged"), @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                Enabled = true;
                return;
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Connected)
            {
                Program.WebSocketClient.StartConnect();

                var starttime = DateTime.UtcNow;
                while (Program.WebSocketClient.State != WebSocketClientState.Connected &&
                       Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Application.DoEvents();

                    if (DateTime.UtcNow.Subtract(starttime).TotalSeconds <= 20)
                    {
                        continue;
                    }

                    SkinHelper.ShowMessage(MultiLanguage.GetString("strServerConectionTimeot"), @"Project Celeste -- Login",
                                           MessageBoxButtons.OK, MessageBoxIcon.Error);

                    if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                    {
                        Program.WebSocketClient?.AgentWebSocket?.Close();
                    }

                    Enabled = true;
                    return;
                }
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Connected)
            {
                SkinHelper.ShowMessage(MultiLanguage.GetString("strServerOffline"), @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Program.WebSocketClient?.AgentWebSocket?.Close();
                }

                Enabled = true;
                return;
            }

            Program.WebSocketClient.State = WebSocketClientState.Logging;

#pragma warning disable IDE0017 // Simplifier l'initialisation des objets
            dynamic loginInfo = new ExpandoObject();
            loginInfo.Mail     = email;
            loginInfo.Password = password;

            var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            loginInfo.Version = Convert.ToInt32($"{version.Major}{version.Minor}{version.Build}");

#pragma warning restore IDE0017 // Simplifier l'initialisation des objets

            Program.WebSocketClient.AgentWebSocket?.Query <dynamic>("LOGIN", (object)loginInfo, OnLoggedIn);

            var starttime2 = DateTime.UtcNow;
            while (Program.WebSocketClient.State == WebSocketClientState.Logging)
            {
                Application.DoEvents();

                if (DateTime.UtcNow.Subtract(starttime2).TotalSeconds <= 20)
                {
                    continue;
                }

                SkinHelper.ShowMessage(MultiLanguage.GetString("strServerResponseTimeot"), @"Project Celeste -- Login",
                                       MessageBoxButtons.OK, MessageBoxIcon.Error);

                if (Program.WebSocketClient.State != WebSocketClientState.Offline)
                {
                    Program.WebSocketClient?.AgentWebSocket?.Close();
                }

                Enabled = true;
                return;
            }

            if (Program.WebSocketClient.State != WebSocketClientState.Logged)
            {
                Enabled = true;
                return;
            }

            //Save UserConfig
            if (Program.UserConfig == null)
            {
                Program.UserConfig = new UserConfig
                {
                    LoginInfo = new LoginInfo
                    {
                        Email      = tb_Mail.Text,
                        Password   = tb_Password.Text,
                        RememberMe = cb_RememberMe.Checked
                    }
                };
            }
            else
            {
                Program.UserConfig.LoginInfo.Email      = tb_Mail.Text;
                Program.UserConfig.LoginInfo.Password   = tb_Password.Text;
                Program.UserConfig.LoginInfo.RememberMe = cb_RememberMe.Checked;
            }
            Program.UserConfig.Save(Program.UserConfigFilePath);

            DialogResult = DialogResult.OK;
            Close();
        }
Пример #21
0
        private async void btn_Play_Click(object sender, EventArgs e)
        {
            var pname = Process.GetProcessesByName("spartan");

            if (pname.Length > 0)
            {
                SkinHelper.ShowMessage(@"Game already runing!");
                return;
            }

            //UserConfig
            if (Program.UserConfig != null)
            {
                //MpSettings
                try
                {
                    if (Program.UserConfig.MpSettings != null)
                    {
                        if (Program.UserConfig.MpSettings.IsOnline)
                        {
                            Program.UserConfig.MpSettings.PublicIp = Program.RemoteUser.Ip;

                            if (Program.UserConfig.MpSettings.AutoPortMapping)
                            {
                                var mapPortTask = OpenNat.MapPortTask(1000, 1000);
                                try
                                {
                                    await mapPortTask;
                                    NatDiscoverer.TraceSource.Close();
                                }
                                catch (AggregateException ex)
                                {
                                    NatDiscoverer.TraceSource.Close();

                                    if (!(ex.InnerException is NatDeviceNotFoundException))
                                    {
                                        throw;
                                    }

                                    SkinHelper.ShowMessage(
                                        "Error: Upnp device not found! Set \"Port mapping\" to manual in \"Mp Settings\" and configure your router.",
                                        @"Project Celeste",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    Enabled = true;
                                    return;
                                }
                            }
                        }
                    }
                }
                catch
                {
                    SkinHelper.ShowMessage(
                        "Error: Upnp device not found! Set \"Port mapping\" to manual in \"Mp Settings\" and configure your router.",
                        @"Project Celeste",
                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Enabled = true;
                    return;
                }

                //Save UserConfig
                Program.UserConfig.GameLanguage = (GameLanguage)comboBox2.SelectedIndex;
                Program.UserConfig.Save(Program.UserConfigFilePath);
            }

            //Launch Game
            var path = $"{AppDomain.CurrentDomain.BaseDirectory}Spartan.exe";

            Process.Start(path, $"LauncherLang={comboBox2.Text} LauncherLocale=1033");
        }