Пример #1
0
        private void LoginWindow_ContentRendered(object sender, EventArgs e)
        {
            if (Properties.Settings.Default.WaExe.Length == 0)
            {
                try
                {
                    object WALoc = Registry.GetValue(@"HKEY_CURRENT_USER\Software\Team17SoftwareLTD\WormsArmageddon", "PATH", null);
                    if (WALoc != null)
                    {
                        string WAPath = WALoc.ToString() + @"\WA.exe";
                        if (File.Exists(WAPath))
                        {
                            Properties.Settings.Default.WaExe = WAPath;
                            Properties.Settings.Default.Save();
                        }
                    }
                }
                catch (Exception ex)
                {
                    ErrorLog.Log(ex);
                }

                if (Properties.Settings.Default.WaExe.Length == 0 && !Properties.Settings.Default.WAExeAsked)
                {
                    Properties.Settings.Default.WAExeAsked = true;
                    Properties.Settings.Default.Save();

                    MessageBoxResult res = MessageBox.Show(this, "Ooops, it seems like Great Snooper can not find your WA.exe! You can not host or join a game without that file. Would you like to locate your WA.exe now? You can do it later in the settings too.", "WA.exe needs to be located", MessageBoxButton.YesNo, MessageBoxImage.Information);
                    if (res == MessageBoxResult.Yes)
                    {
                        OpenFileDialog dlg = new OpenFileDialog();
                        dlg.Filter = "Worms Armageddon Exe|*.exe";

                        // Display OpenFileDialog by calling ShowDialog method
                        Nullable <bool> result = dlg.ShowDialog();

                        // Get the selected file name
                        if (result.HasValue && result.Value)
                        {
                            // Set the WA.exe
                            Properties.Settings.Default.WaExe = dlg.FileName;
                            Properties.Settings.Default.Save();
                        }
                    }
                }
            }

            if (Properties.Settings.Default.TrayNotifications)
            {
                myNotifyIcon.ShowBalloonTip(null, "Welcome to Great Snooper!", Hardcodet.Wpf.TaskbarNotification.BalloonIcon.Info);
            }

            // Delete old logs
            string logsDirectory = GlobalManager.SettingsPath + @"\Logs";

            if (Properties.Settings.Default.DeleteLogs && Directory.Exists(logsDirectory))
            {
                Regex  DateRegex = new Regex(@"[^0-9]");
                string date      = DateRegex.Replace(DateTime.Now.ToString("d"), "-");
                if (date != Properties.Settings.Default.TimeLogsDeleted)
                {
                    Properties.Settings.Default.TimeLogsDeleted = date;
                    Properties.Settings.Default.Save();

                    string[] dirs = Directory.GetDirectories(logsDirectory);
                    DateTime old  = DateTime.Now - new TimeSpan(30, 0, 0, 0);
                    for (int i = 0; i < dirs.Length; i++)
                    {
                        string[] files = Directory.GetFiles(dirs[i]);
                        for (int j = 0; j < files.Length; j++)
                        {
                            FileInfo info = new FileInfo(files[j]);
                            if (info.LastWriteTime < old)
                            {
                                File.Delete(files[j]);
                            }
                        }

                        if (Directory.GetFiles(dirs[i]).Length == 0)
                        {
                            Directory.Delete(dirs[i]);
                        }
                    }
                }
            }

            if (Properties.Settings.Default.AutoLogIn && firstStart)
            {
                firstStart = false;
                this.LogIn();
            }
            firstStart = false;
        }
Пример #2
0
        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;
            }
        }
Пример #3
0
        public bool AddNewMessage(Channel ch, MessageClass message, bool insert = false)
        {
            if (Properties.Settings.Default.ChatMode && (
                    message.Style.Type == MessageTypes.Part ||
                    message.Style.Type == MessageTypes.Join ||
                    message.Style.Type == MessageTypes.Quit)
                )
            {
                return(false);
            }

            try
            {
                Paragraph p = new Paragraph();
                MessageSettings.LoadSettingsFor(p, message.Style);
                p.Foreground            = message.Style.MessageColor;
                p.Margin                = new Thickness(0, 2, 0, 2);
                p.Tag                   = message;
                p.MouseRightButtonDown += InstantColorMenu;

                // Time when the message arrived
                if (Properties.Settings.Default.MessageTime)
                {
                    Run word = new Run(message.Time.ToString("T") + " ");
                    MessageSettings.LoadSettingsFor(word, MessageSettings.MessageTimeStyle);
                    word.Foreground = MessageSettings.MessageTimeStyle.NickColor;
                    p.Inlines.Add(word);
                }

                // Sender of the message
                Run nick = (message.Style.Type == MessageTypes.Action) ? new Run(message.Sender.Name + " ") : new Run(message.Sender.Name + ": ");

                SolidColorBrush b;
                // Instant color
                if (InstantColors.TryGetValue(message.Sender.LowerName, out b))
                {
                    nick.Foreground = b;
                }
                // Group color
                else if (message.Sender.Group.ID != UserGroups.SystemGroupID)
                {
                    nick.Foreground = message.Sender.Group.TextColor;
                    nick.FontStyle  = FontStyles.Italic;
                }
                else
                {
                    nick.Foreground = message.Style.NickColor;
                }
                nick.FontWeight = FontWeights.Bold;
                p.Inlines.Add(nick);

                // Message content
                if (message.Style.IsFixedText)
                {
                    p.Inlines.Add(new Run(message.Message));
                }
                else
                {
                    string[] words;
                    if (message.Words != null)
                    {
                        words = message.Words;
                    }
                    else
                    {
                        words = message.Message.Split(' ');
                    }
                    Uri             uri = null;
                    HightLightTypes highlightType;
                    sb.Clear(); // this StringBuilder is for minimizing the number on Runs in a paragraph
                    for (int i = 0; i < words.Length; i++)
                    {
                        if (message.HighlightWords != null && message.HighlightWords.TryGetValue(i, out highlightType))
                        {
                            // Flush the sb content
                            if (sb.Length > 0)
                            {
                                p.Inlines.Add(new Run(sb.ToString()));
                                sb.Clear();
                            }

                            Run word = new Run(words[i]);
                            if (highlightType == HightLightTypes.Highlight)
                            {
                                word.FontStyle = FontStyles.Italic;
                            }
                            else
                            {
                                MessageSettings.LoadSettingsFor(word, MessageSettings.LeagueFoundMessage);
                                word.Foreground = MessageSettings.LeagueFoundMessage.NickColor;
                            }
                            p.Inlines.Add(word);
                        }
                        // Links
                        else if (
                            (
                                words[i].StartsWith("ftp://", StringComparison.OrdinalIgnoreCase) ||
                                words[i].StartsWith("http://", StringComparison.OrdinalIgnoreCase) ||
                                words[i].StartsWith("https://", StringComparison.OrdinalIgnoreCase)
                            ) && Uri.TryCreate(words[i], UriKind.RelativeOrAbsolute, out uri)
                            )
                        {
                            // Flush the sb content
                            if (sb.Length > 0)
                            {
                                p.Inlines.Add(new Run(sb.ToString()));
                                sb.Clear();
                            }

                            Hyperlink word = new Hyperlink(new Run(words[i]));
                            MessageSettings.LoadSettingsFor(word, MessageSettings.HyperLinkStyle);
                            word.Foreground       = MessageSettings.HyperLinkStyle.NickColor;
                            word.NavigateUri      = new Uri(words[i]);
                            word.RequestNavigate += OpenURLInBrowser;
                            p.Inlines.Add(word);
                        }
                        else
                        {
                            sb.Append(words[i]);
                        }
                        if (i + 1 < words.Length)
                        {
                            sb.Append(' ');
                        }
                    }

                    // Flush the sb content
                    if (sb.Length > 0)
                    {
                        p.Inlines.Add(new Run(sb.ToString()));
                    }
                }

                // Insert the new paragraph
                if (insert)
                {
                    ch.TheFlowDocument.Blocks.InsertBefore(ch.TheFlowDocument.Blocks.FirstBlock, p);
                }
                else
                {
                    ch.TheFlowDocument.Blocks.Add(p);
                }

                while (ch.TheFlowDocument.Blocks.Count > GlobalManager.MaxMessagesInMemory)
                {
                    ch.TheFlowDocument.Blocks.Remove(ch.TheFlowDocument.Blocks.FirstBlock);
                }

                return(true);
            }
            catch (Exception e)
            {
                ErrorLog.Log(e);
            }
            return(false);
        }