// Constructor public Game(uint ID, string Name, string Address, CountryClass Country, string Hoster, bool Password) { this.ID = ID; this.Address = Address; try { Locked = new BitmapImage(); Locked.DecodePixelWidth = 16; Locked.DecodePixelHeight = 16; Locked.CacheOption = BitmapCacheOption.OnLoad; Locked.BeginInit(); if (Password) { Locked.UriSource = new Uri("pack://application:,,,/Resources/locked.png"); } else { Locked.UriSource = new Uri("pack://application:,,,/Resources/nolock.png"); } Locked.EndInit(); } catch (Exception e) { ErrorLog.Log(e); } this.Name = Name; this.Country = Country; this.Hoster = Hoster; }
public bool Equals(CountryClass cc) { // If parameter is null return false: if ((object)cc == null) { return(false); } // Return true if the fields match: return(ID == cc.ID); }
public override bool Equals(System.Object obj) { // If parameter is null return false. if (obj == null) { return(false); } // If parameter cannot be cast to Point return false. CountryClass cc = obj as CountryClass; if ((System.Object)cc == null) { return(false); } // Return true if the fields match: return(ID == cc.ID); }
private bool ProcessServerMessage(string line, int spacePos) { // Get the number out of the message // :wormnet1.team17.com 322 Test #Help 10 :05 A place to get help, or help others int number; int spacePos2 = line.IndexOf(' ', spacePos + 1); if (spacePos2 == -1 || !int.TryParse(line.Substring(spacePos + 1, spacePos2 - spacePos - 1), out number)) { return(false); } // Find the space after our nickname in the message spacePos = line.IndexOf(' ', spacePos2 + 1); if (spacePos == -1) { return(false); } spacePos++; // we will start all the regex match from this position // Process the message switch (number) { // Connection success case 4: spacePos2 = line.IndexOf(' ', spacePos); if (spacePos2 != -1) { this.serverIrcAddress = ':' + line.Substring(spacePos, spacePos2 - spacePos).ToLower(); //if (!this.IsWormNet) // Send("authserv auth " + this.User.Name + " " + Properties.Settings.Default.WormsPassword); if (ConnectionState != null) { ConnectionState.BeginInvoke(this, new ConnectionStateEventArgs(ConnectionStates.Connected), null, null); } } break; // This nickname is already in use! case 433: if (serverIrcAddress == string.Empty) { return(true); } else { // nickname is in use when we tried to change with /NICK command GlobalManager.UITasks.Enqueue(new NickNameInUseTask(this)); } break; // A channel (answer for the LIST command) case 322: // :wormnet1.team17.com 322 Test #Help 10 :05 A place to get help, or help others Match chMatch = channelRegex.Match(line, spacePos); if (chMatch.Success) { string channelName = chMatch.Groups[1].Value; string description = chMatch.Groups[3].Value; if (!channelListHelper.ContainsKey(channelName)) { channelListHelper.Add(channelName, description); } } break; // LIST END case 323: GlobalManager.UITasks.Enqueue(new ChannelListUITask(this, channelListHelper)); break; // A client (answer for WHO command) case 352: // :wormnet1.team17.com 352 Test #AnythingGoes ~UserName no.address.for.you wormnet1.team17.com Herbsman H :0 68 7 LT The Wheat Snooper 2.8 Match clMatch = clientRegex.Match(line, spacePos); if (clMatch.Success) { string channelHash = clMatch.Groups[1].Value.ToLower(); string clan = clMatch.Groups[2].Value.ToLower() == "username" ? string.Empty : clMatch.Groups[2].Value; string clientName = clMatch.Groups[3].Value; string[] realName = clMatch.Groups[4].Value.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); // 68 7 LT The Wheat Snooper CountryClass country = CountriesClass.DefaultCountry; int rank = 0; bool clientGreatSnooper = false; string clientApp = clMatch.Groups[4].Value; if (realName.Length >= 3) { if (int.TryParse(realName[1], out rank)) { if (rank > 13) { rank = 13; } if (rank < 0) { rank = 0; } } int countrycode; if (int.TryParse(realName[0], out countrycode) && countrycode >= 0 && countrycode <= 52) { if (countrycode == 49 && realName[2].Length == 2) // use cc as countricode { if (realName[2] == "UK") { realName[2] = "GB"; } else if (realName[2] == "EL") { realName[2] = "GR"; } country = CountriesClass.GetCountryByCC(realName[2]); } else { country = CountriesClass.GetCountryByID(countrycode); } } else if (realName[2].Length == 2) // use cc if countrycode is bigger than 52 { if (realName[2] == "UK") { realName[2] = "GB"; } else if (realName[2] == "EL") { realName[2] = "GR"; } country = CountriesClass.GetCountryByCC(realName[2]); } clientGreatSnooper = realName.Length >= 6 && realName[3] == "Great" && realName[4] == "Snooper" && gsVersionRegex.IsMatch(realName[5]); StringBuilder sb = new StringBuilder(); for (int i = 3; i < realName.Length; i++) { sb.Append(realName[i]); if (i + 1 < realName.Length) { sb.Append(" "); } } clientApp = sb.ToString(); } GlobalManager.UITasks.Enqueue(new ClientUITask(this, channelHash, clientName, country, clan, rank, clientGreatSnooper, clientApp)); } break; // The user is offline message case 401: // :wormnet1.team17.com 401 Test sToOMiToO :No such nick/channel spacePos2 = line.IndexOf(' ', spacePos); if (spacePos2 != -1) { string clientName = line.Substring(spacePos, spacePos2 - spacePos); GlobalManager.UITasks.Enqueue(new OfflineUITask(this, clientName)); } break; } return(false); }
public ClientUITask(IRCCommunicator sender, string channelHash, string clientName, CountryClass country, string clan, int rank, bool clientGreatSnooper, string clientApp) { this.Sender = sender; this.ChannelHash = channelHash; this.ClientName = clientName; this.Country = country; this.Clan = clan; this.Rank = rank; this.ClientGreatSnooper = clientGreatSnooper; this.ClientApp = clientApp; }
public Login() { if (firstStart) { WormNetCharTable.Initialize(); if (!Properties.Settings.Default.SettingsUpgraded) { try { Properties.Settings.Default.Upgrade(); if (Properties.Settings.Default.Group0List.Length == 0) { Properties.Settings.Default.Group0List = Properties.Settings.Default.BuddyList; } // new colors if (Properties.Settings.Default.ChannelMessageStyle == "F0FFFF|13|0|0|0|0|Tahoma") { Properties.Settings.Default.ChannelMessageStyle = (string)Properties.Settings.Default.Properties["ChannelMessageStyle"].DefaultValue; } if (Properties.Settings.Default.JoinMessageStyle == "808000|12|0|0|0|0|Tahoma") { Properties.Settings.Default.JoinMessageStyle = (string)Properties.Settings.Default.Properties["JoinMessageStyle"].DefaultValue; } if (Properties.Settings.Default.PartMessageStyle == "808000|12|0|0|0|0|Tahoma") { Properties.Settings.Default.PartMessageStyle = (string)Properties.Settings.Default.Properties["PartMessageStyle"].DefaultValue; } if (Properties.Settings.Default.QuitMessageStyle == "808000|12|0|0|0|0|Tahoma") { Properties.Settings.Default.QuitMessageStyle = (string)Properties.Settings.Default.Properties["QuitMessageStyle"].DefaultValue; } if (Properties.Settings.Default.OfflineMessageStyle == "FF0000|13|0|0|0|0|Tahoma") { Properties.Settings.Default.OfflineMessageStyle = (string)Properties.Settings.Default.Properties["OfflineMessageStyle"].DefaultValue; } if (Properties.Settings.Default.ActionMessageStyle == "FFFF00|13|0|0|0|0|Tahoma") { Properties.Settings.Default.ActionMessageStyle = (string)Properties.Settings.Default.Properties["ActionMessageStyle"].DefaultValue; } if (Properties.Settings.Default.UserMessageStyle == "E9967A|13|0|0|0|0|Tahoma") { Properties.Settings.Default.UserMessageStyle = (string)Properties.Settings.Default.Properties["UserMessageStyle"].DefaultValue; } if (Properties.Settings.Default.NoticeMessageStyle == "E9967A|13|0|0|0|0|Tahoma") { Properties.Settings.Default.NoticeMessageStyle = (string)Properties.Settings.Default.Properties["NoticeMessageStyle"].DefaultValue; } } catch (Exception) { } var validator = new GSVersionValidator(); string quitMessage = Properties.Settings.Default.QuitMessagee; if (Properties.Settings.Default.QuitMessagee == string.Empty || validator.Validate(ref quitMessage) != string.Empty) { Properties.Settings.Default.QuitMessagee = "Great Snooper v" + App.GetVersion(); } Properties.Settings.Default.SettingsUpgraded = true; Properties.Settings.Default.Save(); } MessageSettings.Initialize(); CountriesClass.Initialize(); GlobalManager.Initialize(); UserGroups.Initialize(); Sounds.Initialize(); // Reducing Timeline frame rate Timeline.DesiredFrameRateProperty.OverrideMetadata( typeof(Timeline), new FrameworkPropertyMetadata { DefaultValue = 25 } ); } InitializeComponent(); DataContext = this; nickRegex = new Regex(@"^[a-z`]", RegexOptions.IgnoreCase); nickRegex2 = new Regex(@"^[a-z`][a-z0-9`\-]*$", RegexOptions.IgnoreCase); ServerList = new SortedObservableCollection <string>(); ServerList.DeSerialize(Properties.Settings.Default.ServerAddresses); Server.SelectedItem = Properties.Settings.Default.ServerAddress; switch (Properties.Settings.Default.LoginType) { case "simple": LoginTypeChooser.SelectedIndex = 0; break; default: LoginTypeChooser.SelectedIndex = 1; break; } AutoLogIn.IsChecked = Properties.Settings.Default.AutoLogIn; Nick.Text = Properties.Settings.Default.UserName; Country.ItemsSource = CountriesClass.Countries; if (Properties.Settings.Default.UserCountry != -1) { CountryClass country = CountriesClass.GetCountryByID(Properties.Settings.Default.UserCountry); Country.SelectedItem = country; } else { CultureInfo ci = CultureInfo.InstalledUICulture; CountryClass country; if (ci != null) { country = CountriesClass.GetCountryByCC(ci.TwoLetterISOLanguageName.ToUpper()); } else { country = CountriesClass.DefaultCountry; } Country.SelectedItem = country; } Rank.ItemsSource = RanksClass.Ranks; Rank.SelectedIndex = Properties.Settings.Default.UserRank; Clan.Text = Properties.Settings.Default.UserClan; TUSNick.Text = Properties.Settings.Default.TusNick; TUSPass.Password = Properties.Settings.Default.TusPass; }
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; } }