private void TUSLoginWorker_DoWork(object sender, DoWorkEventArgs e) { try { using (WebClient tusRequest = new WebClient() { Proxy = null }) { string testlogin = tusRequest.DownloadString("http://www.tus-wa.com/testlogin.php?u=" + System.Web.HttpUtility.UrlEncode(nickName) + "&p=" + System.Web.HttpUtility.UrlEncode(tusPassword)); if (testlogin[0] == '1') // 1 sToOMiToO { if (tusLoginWorker.CancellationPending) { e.Cancel = true; return; } string tempNick = nickName; nickName = testlogin.Substring(2); if (nickRegexTUS == null) { nickRegexTUS = new Regex(@"^[^a-z`]+", RegexOptions.IgnoreCase); } if (nickRegex2TUS == null) { nickRegex2TUS = new Regex(@"[^a-z0-9`\-]", RegexOptions.IgnoreCase); } nickName = nickRegexTUS.Replace(nickName, ""); // Remove bad characters nickName = nickRegex2TUS.Replace(nickName, ""); // Remove bad characters for (int j = 0; j < 10; j++) { string userlist = tusRequest.DownloadString("http://www.tus-wa.com/userlist.php?update=" + System.Web.HttpUtility.UrlEncode(tempNick) + "&league=classic"); if (tusLoginWorker.CancellationPending) { e.Cancel = true; return; } string[] rows = userlist.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < rows.Length; i++) { if (rows[i].Substring(0, nickName.Length) == nickName) { tusState = TUSStates.OK; string[] data = rows[i].Split(new char[] { ' ' }); tusNickStr = data[1]; if (clanRegexTUS == null) { clanRegexTUS = new Regex(@"[^a-z0-9]", RegexOptions.IgnoreCase); } nickClan = clanRegexTUS.Replace(data[5], ""); // Remove bad characters if (nickClan.Length == 0) { nickClan = "Username"; } if (int.TryParse(data[2].Substring(1), out nickRank)) { nickRank--; } else { nickRank = 13; } nickCountry = CountriesClass.GetCountryByCC(data[3].ToUpper()); break; } } if (tusState == TUSStates.OK) { break; } Thread.Sleep(2500); if (tusLoginWorker.CancellationPending) { e.Cancel = true; return; } } } else { tusState = TUSStates.UserError; } } } catch (Exception ex) { tusState = TUSStates.ConnectionError; ErrorLog.Log(ex); } if (tusLoginWorker.CancellationPending) { e.Cancel = true; return; } }
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; } }