private void TUSLoginWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled) { this.Close(); return; } switch (tusState) { case TUSStates.TUSError: MessageBox.Show(this, "An error occoured! Please try again!", "Fail", MessageBoxButton.OK, MessageBoxImage.Error); break; case TUSStates.OK: GlobalManager.User = new Client(nickName, null, nickClan); GlobalManager.User.Country = nickCountry; GlobalManager.User.Rank = RanksClass.GetRankByInt(nickRank); GlobalManager.User.GreatSnooper = true; GlobalManager.User.TusNick = tusNickStr; if (Properties.Settings.Default.ChangeWormsNick) { Properties.Settings.Default.WormsNick = nickName; Properties.Settings.Default.Save(); } // Initialize the WormNet Communicator wormNetC = new IRCCommunicator(serverAddress, serverPort); wormNetC.ConnectionState += ConnectionState; wormNetC.Connect(); return; case TUSStates.UserError: MessageBox.Show(this, "The given username or password was incorrent!", "Wrong username or password", MessageBoxButton.OK, MessageBoxImage.Error); break; case TUSStates.ConnectionError: MessageBox.Show(this, "The communication with TUS has failed. Please try again!", "Fail", MessageBoxButton.OK, MessageBoxImage.Error); break; } Container.IsEnabled = true; LoadingRing.IsActive = false; }
private void LogIn() { serverAddress = Server.Text.Trim().ToLower(); if (serverAddress.Length == 0) { MakeErrorTooltip(Server, "Please choose a server!"); return; } int colon; if ((colon = serverAddress.IndexOf(':')) != -1) { string portstr = serverAddress.Substring(colon + 1); if (!int.TryParse(portstr, out serverPort)) { serverPort = 6667; } else { serverAddress = serverAddress.Substring(0, colon); } } else { serverPort = 6667; } switch (LoginTypeChooser.SelectedIndex) { // Simple login case 0: if (clanRegex == null) { clanRegex = new Regex(@"^[a-z0-9]*$", RegexOptions.IgnoreCase); } nickName = Nick.Text.Trim(); nickClan = Clan.Text.Trim(); if (nickName.Length == 0) { MakeErrorTooltip(Nick, "Please enter your nickname!"); } else if (!nickRegex.IsMatch(nickName)) { MakeErrorTooltip(Nick, "Your nickname should begin with a character" + Environment.NewLine + "of the English aplhabet or with ` character!"); } else if (!nickRegex2.IsMatch(nickName)) { MakeErrorTooltip(Nick, "Your nickname contains one or more" + Environment.NewLine + "forbidden characters! Use characters from" + Environment.NewLine + "the English alphabet, numbers, - or `!"); } else if (!clanRegex.IsMatch(nickClan)) { MakeErrorTooltip(Clan, "Your clan can contain only characters" + Environment.NewLine + "from the English alphabet or numbers"); } else { Container.IsEnabled = false; LoadingRing.IsActive = true; nickCountry = Country.SelectedValue as CountryClass; nickRank = Rank.SelectedIndex; Properties.Settings.Default.LoginType = "simple"; Properties.Settings.Default.ServerAddress = Server.Text.Trim().ToLower(); Properties.Settings.Default.AutoLogIn = AutoLogIn.IsChecked.Value; Properties.Settings.Default.UserName = nickName; Properties.Settings.Default.UserClan = nickClan; Properties.Settings.Default.UserCountry = nickCountry.ID; Properties.Settings.Default.UserRank = nickRank; if (Properties.Settings.Default.ChangeWormsNick) { Properties.Settings.Default.WormsNick = nickName; } Properties.Settings.Default.Save(); GlobalManager.User = new Client(nickName, null, nickClan); GlobalManager.User.Country = nickCountry; GlobalManager.User.Rank = RanksClass.GetRankByInt(nickRank); // Initialize the WormNet Communicator wormNetC = new IRCCommunicator(serverAddress, serverPort); wormNetC.ConnectionState += ConnectionState; wormNetC.Connect(); } break; // TUS login case 1: nickName = TUSNick.Text.Trim(); tusPassword = TUSPass.Password.Trim(); if (nickName.Length == 0) { MakeErrorTooltip(TUSNick, "Please enter your nickname!"); } else if (!nickRegex.IsMatch(nickName)) { MakeErrorTooltip(TUSNick, "Your nickname should begin with a character" + Environment.NewLine + "of the English aplhabet or with ` character!"); } else if (!nickRegex2.IsMatch(nickName)) { MakeErrorTooltip(TUSNick, "Your nickname contains one or more" + Environment.NewLine + "forbidden characters! Use characters from" + Environment.NewLine + "the English alphabet, numbers, - or `!"); } else if (tusPassword.Length == 0) { MakeErrorTooltip(TUSPass, "Please enter your password!"); } else { Container.IsEnabled = false; LoadingRing.IsActive = true; Properties.Settings.Default.LoginType = "tus"; Properties.Settings.Default.ServerAddress = serverAddress; Properties.Settings.Default.AutoLogIn = AutoLogIn.IsChecked.Value; Properties.Settings.Default.TusNick = nickName; Properties.Settings.Default.TusPass = tusPassword; Properties.Settings.Default.Save(); tusState = TUSStates.TUSError; if (tusLoginWorker == null) { tusLoginWorker = new BackgroundWorker(); tusLoginWorker.WorkerSupportsCancellation = true; tusLoginWorker.DoWork += TUSLoginWorker_DoWork; tusLoginWorker.RunWorkerCompleted += TUSLoginWorker_RunWorkerCompleted; } tusLoginWorker.RunWorkerAsync(); } break; } }