示例#1
0
        public int CountType(int ItemID, int Color = -1, int Cont = 0)
        {
            int itemcnt = ScanItems(true);

            if (Cont == 0)
            {
                Cont = BackpackID;
            }
            int Stack = 0;

            for (int i = 0; i < itemcnt; i++)
            {
                FoundItem item = GetItem(i);
                if (item != null)
                {
                    if (IgnoreList.Contains(item.ID))
                    {
                        continue;
                    }

                    if (item.Type == ItemID && item.ContID == Cont &&
                        (item.Col == Color || Color == -1))
                    {
                        Stack += item.Stack;
                    }
                }
            }
            return(Stack);
        }
示例#2
0
        /// <summary>
        /// Sets a warning with the given text to run on the warning system.
        /// If multiple warnings are occurring at once, the text will slide by.
        /// To stop the warning, use the StopWarning() method
        /// </summary>
        /// <param name="text">The warning message teo display</param>
        public void SetWarning(string text, bool fromRobot = false)
        {
            // If it's already being warned of or it's in the ignore list, don't do anything
            if (WarningList.Contains(text) || IgnoreList.Contains(text))
            {
                return;
            }
            // If the warning is being sent from the robot, add it to the robot's list of warnings
            if (fromRobot)
            {
                NtAddedWarnings.Add(text);
            }
            WarningList.Add(text);

            // Set the counter so that this warning is displayed next.
            counter = WarningList.IndexOf(text) - 1;

            if (WarningList.Count > 1)
            {
                // Execute once to start right away
                Execute();

                StartExecuting();
            }
            else
            {
                WarningMessage = text;
                StartExecuting(false);
            }
        }
 /// <summary>
 /// Adds word to user's ignore word list.
 /// </summary>
 /// <param name="word">The word to add to the user ignore word list.</param>
 public void AddIgnoreWord(string word)
 {
     if (!IgnoreList.Contains(word))
     {
         IgnoreList.Add(word);
     }
 }
示例#4
0
        public FoundItem FindItem(int ID, int containerID = 0)
        {
            ClearFoundVars();

            int itemcnt = ScanItems(true);

            // if (ID.GetType() == typeof(int))
            for (int i = 0; i < itemcnt; i++)
            {
                FoundItem item = GetItem(i);
                if (item != null)
                {
                    if (IgnoreList.Contains(item.ID))
                    {
                        continue;
                    }
                    if ((item.ID == ID || ID == 0) && (containerID == 0 || item.ContID == containerID))
                    {
                        SetFoundVars(item);
                        return(item);
                    }
                }
            }
            return(null);
        }
示例#5
0
        public void UseType(int TYPE, int Color = -1, int Cont = 0)
        {
            int itemcnt = ScanItems(true);

            if (Cont == 0)
            {
                Cont = BackpackID;
            }
            int Serial = 0;

            for (int i = 0; i < itemcnt; i++)
            {
                FoundItem item = GetItem(i);
                if (item != null)
                {
                    if (IgnoreList.Contains(item.ID))
                    {
                        continue;
                    }

                    if (item.Type == TYPE && item.ContID == Cont &&
                        (item.Col == Color || Color == -1))
                    {
                        Serial = item.ID;
                        break;
                    }
                }
            }
            LObjectID = Serial;
            EventMacro(17, 0);
        }
 private void BuildTocs(DirectoryInfo aDirectoryInfo)
 {
     if (!IgnoreList.Contains(aDirectoryInfo.Name))
     {
         Console.WriteLine($"Checking Directory: {aDirectoryInfo.FullName}");
         bool hasManualToc = HasManualToc(aDirectoryInfo);
         if (aDirectoryInfo.GetFiles("*.md", SearchOption.AllDirectories).Any() && !hasManualToc)
         {
             BuildToc(aDirectoryInfo);
         }
         else
         {
             if (hasManualToc)
             {
                 Console.WriteLine($"Has a manual {TocFileName} thus will not generate");
             }
             else
             {
                 Console.WriteLine($"No Markdown files in this dir or any child directories so won't generate {TocFileName}");
             }
         };
         foreach (DirectoryInfo childDirectory in aDirectoryInfo.GetDirectories())
         {
             BuildTocs(childDirectory);
         }
     }
     ;
 }
示例#7
0
 private void FindDifferencies(object entity1, object entity2, String path, ICollection <string> errorList)
 {
     foreach (PropertyInfo pinfo in entity1.GetType().GetProperties(BindingFlagsForReflection))
     {
         if (IgnoreList.Contains(pinfo.Name))
         {
             continue;
         }
         Object value1 = pinfo.GetValue(entity1, new Object[] { });
         Object value2 = pinfo.GetValue(entity2, new Object[] { });
         string name   = pinfo.Name;
         CompareValue(value1, value2, errorList, name, path, pinfo.PropertyType);
     }
     foreach (FieldInfo pinfo in entity1.GetType().GetFields(BindingFlagsForReflection))
     {
         if (pinfo.Name.Contains("BackingField"))
         {
             continue;
         }
         if (IgnoreList.Contains(pinfo.Name))
         {
             continue;
         }
         Object value1 = pinfo.GetValue(entity1);
         Object value2 = pinfo.GetValue(entity2);
         string name   = pinfo.Name;
         CompareValue(value1, value2, errorList, name, path, pinfo.FieldType);
     }
 }
        private void BuildToc(DirectoryInfo aDirectoryInfo)
        {
            var builder = new StringBuilder();

            // Add files in this dir
            Console.WriteLine($"Generate the {aDirectoryInfo.FullName}/{TocFileName} for ");

            //builder.AppendLine($"# {AutoGeneratedTag}");
            foreach (FileInfo aFileInfo in aDirectoryInfo.GetFiles("*.md"))
            {
                AddEntry(builder, ConvertToDisplayName(aFileInfo), aFileInfo.Name);
            }

            // Add references to child dirs
            foreach (DirectoryInfo childDirectory in aDirectoryInfo.GetDirectories())
            {
                if (!IgnoreList.Contains(childDirectory.Name) && childDirectory.GetFiles("*.md", SearchOption.AllDirectories).Any())
                {
                    AddEntry(builder, childDirectory.Name, $"{ childDirectory.Name}/{TocFileName}");
                }
            }
            builder.Insert(0, $"# {AutoGeneratedTag}{Environment.NewLine}");
            Console.Write(builder.ToString());
            File.WriteAllText($"{aDirectoryInfo.FullName}/{TocFileName}", builder.ToString(), Encoding.UTF8);
        }
示例#9
0
        public List <FoundItem> FindInCont(object TYPE, int Color = -1, int containerID = -1)
        {
            ClearFoundVars();

            int itemcnt = ScanItems(true);

            if (containerID == -1)
            {
                containerID = BackpackID;
            }
            List <FoundItem> items = new List <FoundItem>();

            if (TYPE.GetType() == typeof(int))
            {
                for (int i = 0; i < itemcnt; i++)
                {
                    FoundItem item = GetItem(i);
                    if (item != null)
                    {
                        if (IgnoreList.Contains(item.ID))
                        {
                            continue;
                        }
                        if ((item.Type == (int)TYPE || (int)TYPE == 0) &&
                            (item.ContID == containerID) &&
                            (item.Col == Color || Color == -1))
                        {
                            items.Add(item);
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < itemcnt; i++)
                {
                    FoundItem item = GetItem(i);
                    if (item != null)
                    {
                        if (IgnoreList.Contains(item.ID))
                        {
                            continue;
                        }
                        if ((((int[])TYPE).Contains(item.Type)) &&
                            (item.ContID == containerID) &&
                            (item.Col == Color || Color == -1))
                        {
                            items.Add(item);
                        }
                    }
                }
            }
            if (items.Count > 0)
            {
                SetFoundVars(items[0]);
                return(items);
            }
            return(null);
        }
示例#10
0
 /// <summary>
 /// Removes the given text warning from the ignore list so that it isn't ignored anymore
 /// </summary>
 /// <param name="text">The text warning to remove from the ignore list</param>
 private void RemoveFromIgnoreList(string text)
 {
     // Removes the given text from the Ignore List
     if (!IgnoreList.Contains(text))
     {
         return;
     }
     IgnoreList.Remove(text);
 }
示例#11
0
        /// <summary>
        ///     Spell checks a range of words in the <see cref="Text"/> property starting
        ///     at the <see cref="WordIndex"/> position and ending at endWordIndex.
        /// </summary>
        /// <param name="startWordIndex" type="int">
        ///     <para>
        ///         The index of the word to start checking from.
        ///     </para>
        /// </param>
        /// <param name="endWordIndex" type="int">
        ///     <para>
        ///         The index of the word to end checking with.
        ///     </para>
        /// </param>
        /// <returns>
        ///     Returns true if there is a word found in the text
        ///     that is not in the dictionaries
        /// </returns>
        /// <seealso cref="CurrentWord"/>
        /// <seealso cref="WordIndex"/>
        public bool SpellCheck(int startWordIndex, int endWordIndex)
        {
            if (startWordIndex > endWordIndex || _words == null || _words.Count == 0)
            {
                // make sure end index is not greater then word count
                OnEndOfText(System.EventArgs.Empty);    // raise event
                return(false);
            }

            Initialize();

            string currentWord    = "";
            bool   misspelledWord = false;

            for (int i = startWordIndex; i <= endWordIndex; i++)
            {
                WordIndex   = i; // saving the current word index
                currentWord = CurrentWord;

                if (CheckString(currentWord))
                {
                    if (!TestWord())
                    {
                        if (ReplaceList.ContainsKey(currentWord))
                        {
                            ReplacementWord = ReplaceList[currentWord];
                            ReplaceWord();
                        }
                        else if (!IgnoreList.Contains(currentWord))
                        {
                            misspelledWord = true;
                            OnMisspelledWord(new SpellingEventArgs(currentWord, i, _words[i].Index));       // raise event

                            // break;
                        }
                    }
                    else if (i > 0 && _words[i - 1].Value == currentWord &&
                             (_words[i - 1].Index + _words[i - 1].Length + 1) == _words[i].Index)
                    {
                        misspelledWord = true;
                        OnDoubledWord(new SpellingEventArgs(currentWord, i, _words[i].Index));      // raise event

                        // break;
                    }
                }
            } // for

            if (_wordIndex >= _words.Count - 1 && !misspelledWord)
            {
                OnEndOfText(System.EventArgs.Empty);    // raise event
            }

            return(misspelledWord);
        } // SpellCheck
示例#12
0
        public FoundItem FindType(object TYPE, int Color = -1, int containerID = 0)
        {
            ClearFoundVars();

            int itemcnt = ScanItems(true);

            if (TYPE.GetType() == typeof(int))
            {
                for (int i = 0; i < itemcnt; i++)
                {
                    FoundItem item = GetItem(i);
                    if (item != null)
                    {
                        if (IgnoreList.Contains(item.ID))
                        {
                            continue;
                        }
                        if ((item.Type == (int)TYPE || (int)TYPE == 0) &&
                            (containerID == 0 || item.ContID == containerID) &&
                            (item.Col == Color || Color == -1))
                        {
                            SetFoundVars(item);
                            return(item);
                        }
                    }
                }
            }
            else if (TYPE.GetType() == typeof(int[]) || TYPE.GetType() == typeof(List <int>))
            {
                for (int i = 0; i < itemcnt; i++)
                {
                    FoundItem item = GetItem(i);
                    if (item == null || IgnoreList.Contains(item.ID))
                    {
                        continue;
                    }
                    if ((((int[])TYPE).Contains(item.Type)) &&
                        (containerID == 0 || item.ContID == containerID) &&
                        (item.Col == Color || Color == -1))
                    {
                        SetFoundVars(item);
                        return(item);
                    }
                }
            }
            return(null);
        }
            /// <summary>
            /// Read ignore list from file
            /// </summary>
            /// <param name="filePath">Path to the ignore list</param>
            /// <returns>Ignore list</returns>
            public static IgnoreList FromFile(string filePath)
            {
                IgnoreList ignoreList = new IgnoreList();

                foreach (string line in FileMonitor.ReadAllLinesWithRetries(filePath))
                {
                    if (!line.StartsWith("#"))
                    {
                        string entry = line.ToLower();
                        if (!ignoreList.Contains(entry))
                        {
                            ignoreList.Add(entry);
                        }
                    }
                }
                return(ignoreList);
            }
示例#14
0
        private void Context_PreRequestHandlerExecute(object sender, EventArgs e)
        {
            var app = (HttpApplication)sender;
            var req = app.Request;

            var ext = GetExtend(req.Url.ToString());

            if (!IgnoreList.Contains(ext))
            {
                var sign = req["sign"];
                var rdn  = req["rdn"];

                if (string.IsNullOrWhiteSpace(sign) || string.IsNullOrWhiteSpace(rdn))
                {
                    WriteBadResponse(app.Response);
                }
                else
                {
                    var  curRdn = (HelpSup.Get10BitTimeStamp2(DateTime.Now));
                    long _rdn   = 0;
                    if (long.TryParse(rdn, out _rdn))
                    {
                        if ((curRdn - _rdn) > (1 * 60 * 1000))//超过1分钟表示sign签名失效
                        {
                            WriteBadResponse(app.Response);
                        }

                        var sign2 = HelpSup.Get32bitMd5(singKey + rdn);
                        if (sign2 != sign.ToUpper())
                        {
                            WriteBadResponse(app.Response);
                        }
                    }
                    else
                    {
                        WriteBadResponse(app.Response);
                    }
                }
            }
        }
示例#15
0
        /// <summary>
        /// Filters an item from the collection view. Ignores items in the IgnoreList
        /// </summary>
        /// <param name="o">Current Item</param>
        /// <returns>false if the item is in the list, otherwise true</returns>
        private bool Filter(object o)
        {
            Process p = o as Process;

            return(IgnoreList != null ? !IgnoreList.Contains(p.ProcessName) : true);
        }
        /// <summary>
        /// Process chat messages from the server
        /// </summary>
        public override void GetText(string text)
        {
            string message  = "";
            string username = "";

            text = GetVerbatim(text);

            if (IsPrivateMessage(text, ref message, ref username) || (Settings.Mailer_PublicInteractions && IsChatMessage(text, ref message, ref username)))
            {
                string usernameLower = username.ToLower();
                if (!ignoreList.Contains(usernameLower))
                {
                    string command = message.Split(' ')[0].ToLower();
                    switch (command)
                    {
                    case "mail":
                    case "tellonym":
                        if (usernameLower != GetUsername().ToLower() &&
                            mailDatabase.Count < Settings.Mailer_MaxDatabaseSize &&
                            mailDatabase.Where(mail => mail.SenderLowercase == usernameLower).Count() < Settings.Mailer_MaxMailsPerPlayer)
                        {
                            Queue <string> args = new Queue <string>(Command.getArgs(message));
                            if (args.Count >= 2)
                            {
                                bool   anonymous = (command == "tellonym");
                                string recipient = args.Dequeue();
                                message = string.Join(" ", args);

                                if (IsValidName(recipient))
                                {
                                    if (message.Length <= maxMessageLength)
                                    {
                                        Mail mail = new Mail(username, recipient, message, anonymous, DateTime.Now);
                                        LogToConsole("Saving message: " + mail.ToString());
                                        lock (readWriteLock)
                                        {
                                            mailDatabase.Add(mail);
                                            mailDatabase.SaveToFile(Settings.Mailer_DatabaseFile);
                                        }
                                        SendPrivateMessage(username, "信息已保存!");
                                    }
                                    else
                                    {
                                        SendPrivateMessage(username, "你的信息长度不能大于 " + maxMessageLength + " 字节.");
                                    }
                                }
                                else
                                {
                                    SendPrivateMessage(username, "'" + recipient + "' 不是一个有效的玩家名.");
                                }
                            }
                            else
                            {
                                SendPrivateMessage(username, "使用方法: " + command + " <玩家名> <信息>");
                            }
                        }
                        else
                        {
                            SendPrivateMessage(username, "数据库达到上线,无法保存!");
                        }
                        break;
                    }
                }
                else
                {
                    LogDebugToConsole(username + " 已经被忽略!");
                }
            }
        }
        /// <summary>
        /// Loops the given text through spell check <see cref="ISpellCheck.RunSpellCheck"/> interface
        /// method implementation amd returns the user given corrections for the given.
        /// </summary>
        /// <param name="spellCheck">A class instance which implements the <see cref="ISpellCheck"/> interface.</param>
        /// <param name="text">The text to be spell-checked by the user.</param>
        /// <param name="nullOnClose">A value indicating whether to return null if the spell checking was not completed by a user.</param>
        /// <returns>A list of corrections made to the text spell-checked by user.</returns>
        public List <SpellingCorrection> RunSpellCheckInterface(ISpellCheck spellCheck, string text, bool nullOnClose)
        {
            ChecksDoneOnPreviousRun = false;
            var result = new List <SpellingCorrection>(); // create the result instance..

            // attach the methods to the interface-implementing class..
            spellCheck.AddIgnoreWordAction    = AddIgnoreWord;
            spellCheck.AddUserDictionaryWord  = AddUserDictionaryWord;
            spellCheck.RequestWordSuggestion  = SuggestWords;
            spellCheck.CanAddToUserDictionary = CanAddToUserDictionary;
            spellCheck.CanAddToUserIgnoreList = CanAddToUserIgnoreList;

            // run the spell checking for the text..
            var missSpelledWords = SpellCheckFast(text);

            // a value indicating whether the spell checking was created successfully..
            var interrupted = false;

            // ReSharper disable once ForCanBeConvertedToForeach, the collection will change..
            for (int i = 0; i < missSpelledWords.Count; i++)
            {
                // the misspelled word..
                var word = missSpelledWords[i];

                // if the user's personal ignore list contains the word, the skip it..
                if (IgnoreList.Contains(word.Word))
                {
                    continue;
                }

                // check if the word is set to be replaced with the same word at all times..
                var replaceAll = missSpelledWords.FirstOrDefault(f => f.ReplaceAll && f.Word ==
                                                                 word.Word && f.CorrectedWord != null);

                if (replaceAll != null)
                {
                    word.ReplaceAll = true; // set the replace all flag to true..

                    // multiply the replace all to the result for easier implementation..
                    result.Add(new SpellingCorrection
                    {
                        Word          = word.Word,
                        CorrectedWord = replaceAll.CorrectedWord,
                        StartLocation = word.StartLocation,
                        EndLocation   = word.StartLocation + word.Length,
                        ReplaceAll    = word.ReplaceAll,
                    });

                    // clone the found instance of this replace all word..
                    var newWord = replaceAll.Clone();
                    newWord.StartLocation = word.StartLocation;       // change the locations..
                    newWord.EndLocation   = word.EndLocation;
                    newWord.CorrectedWord = replaceAll.CorrectedWord; // set the word correction..

                    // raise the event in case the the spell checking is done in real-time..
                    SpellCheckLocationChanged?.Invoke(this, new SpellCheckLocationChangeEventArgs {
                        SpellingError = newWord, AfterSpellCheck = true
                    });
                    continue; // this case there is no need to go on further..
                }

                // the ignore all case..
                if (missSpelledWords.Any(f => f.IgnoreAll && f.Word == word.Word))
                {
                    // ..the user has made choice to ignore all instances of this misspelled word..
                    continue;
                }

                // raise the event in case the the spell checking is done in real-time so
                // that the whatever-GUI can mark the word before the user makes a choice
                // how to handle the word..
                SpellCheckLocationChanged?.Invoke(this, new SpellCheckLocationChangeEventArgs {
                    SpellingError = word, AfterSpellCheck = false
                });

                // call the ISpellCheck implementation instance to choose the action for a
                // new misspelled word..
                ChecksDoneOnPreviousRun = true;
                if (!spellCheck.RunSpellCheck(word, SuggestWords(word.Word), i + 1, missSpelledWords.Count))
                {
                    // set the interrupted flag to true so the result of this
                    // method can be set accordingly and break the lood..
                    interrupted = true;
                    break;
                }

                // if the word is supposed to be ignored or to be ignored at all times
                // the loop doesn't need to continue any further..
                if (word.IgnoreAll || word.Ignore)
                {
                    continue;
                }

                // if for some reason the corrected word would be null
                // the loop doesn't need to continue any further..
                if (word.CorrectedWord == null)
                {
                    continue;
                }

                // raise the event in case the the spell checking is done in real-time so
                // the corrected word can be applied to the text..
                SpellCheckLocationChanged?.Invoke(this, new SpellCheckLocationChangeEventArgs {
                    SpellingError = word, AfterSpellCheck = true
                });

                // add the corrected word to the result..
                result.Add(new SpellingCorrection
                {
                    Word          = word.Word,
                    CorrectedWord = word.CorrectedWord,
                    StartLocation = word.StartLocation,
                    EndLocation   = word.StartLocation + word.Length,
                    ReplaceAll    = word.ReplaceAll,
                });
            }

            // if the spell checking was interrupted and
            // a null result was requested on interruption, return null..
            if (interrupted && nullOnClose)
            {
                return(null);
            }

            // order the result backwards..
            result =
                result.OrderByDescending(f => f.StartLocation).
                ThenByDescending(f => f.Length).ToList();

            // return the result..
            return(result);
        }
示例#18
0
 /// <summary>
 /// Checks to see if a user is in the ignore list.
 /// </summary>
 /// <param name="ident">The IRC identifier of the user.</param>
 /// <returns></returns>
 public bool IsIgnored(string ident) => IgnoreList.Contains(ident);
示例#19
0
        /// <summary>
        /// Process chat messages from the server
        /// </summary>
        public override void GetText(string text)
        {
            string message  = "";
            string username = "";

            text = GetVerbatim(text);

            if (IsPrivateMessage(text, ref message, ref username) || (Settings.Mailer_PublicInteractions && IsChatMessage(text, ref message, ref username)))
            {
                string usernameLower = username.ToLower();
                if (!ignoreList.Contains(usernameLower))
                {
                    string command = message.Split(' ')[0].ToLower();
                    switch (command)
                    {
                    case "mail":
                    case "tellonym":
                        if (usernameLower != GetUsername().ToLower() &&
                            mailDatabase.Count < Settings.Mailer_MaxDatabaseSize &&
                            mailDatabase.Where(mail => mail.SenderLowercase == usernameLower).Count() < Settings.Mailer_MaxMailsPerPlayer)
                        {
                            Queue <string> args = new Queue <string>(Command.getArgs(message));
                            if (args.Count >= 2)
                            {
                                bool   anonymous = (command == "tellonym");
                                string recipient = args.Dequeue();
                                message = string.Join(" ", args);

                                if (IsValidName(recipient))
                                {
                                    if (message.Length <= maxMessageLength)
                                    {
                                        Mail mail = new Mail(username, recipient, message, anonymous, DateTime.Now);
                                        LogToConsoleTranslated("bot.mailer.saving", mail.ToString());
                                        lock (readWriteLock)
                                        {
                                            mailDatabase.Add(mail);
                                            mailDatabase.SaveToFile(Settings.Mailer_DatabaseFile);
                                        }
                                        SendPrivateMessage(username, "Message saved!");
                                    }
                                    else
                                    {
                                        SendPrivateMessage(username, "Your message cannot be longer than " + maxMessageLength + " characters.");
                                    }
                                }
                                else
                                {
                                    SendPrivateMessage(username, "Recipient '" + recipient + "' is not a valid player name.");
                                }
                            }
                            else
                            {
                                SendPrivateMessage(username, "Usage: " + command + " <recipient> <message>");
                            }
                        }
                        else
                        {
                            SendPrivateMessage(username, "Couldn't save Message. Limit reached!");
                        }
                        break;
                    }
                }
                else
                {
                    LogDebugToConsoleTranslated("bot.mailer.user_ignored", username);
                }
            }
        }