예제 #1
0
 internal CommandData(string command, Channel channel, PlayerIdentity playerIdentity, ChatIdentity chatIdentity)
 {
     this.command   = command;
     this.channel   = channel;
     PlayerIdentity = playerIdentity;
     ChatIdentity   = chatIdentity;
 }
 internal CommandData(string command, Channel channel, ChatIdentity chatIdentity, bool isFriend, string playerName, PlayerIdentity playerIdentity)
 {
     Command        = command;
     Channel        = channel;
     ChatIdentity   = chatIdentity;
     IsFriend       = isFriend;
     PlayerName     = playerName;
     PlayerIdentity = playerIdentity;
 }
 /// <summary>
 /// Compares chat identity.
 /// </summary>
 /// <param name="other">The other ChatIdentity to compare to.</param>
 /// <returns>Returns true if the chat identities are equal.</returns>
 public bool CompareIdentities(ChatIdentity other)
 {
     return(CompareIdentities(this, other));
 }
        // Checks if an executed command should be added to the list of commands, then adds it.
        private string AddExecutedCommand(int y, int namelength, int[] seed, string command
#if DEBUG
                                          , List <LetterResult> letterInfos
#endif
                                          )
        {
            #region Command Cleanup
            ListenTo ltd = null;

            int nameSeperator = command.IndexOf(']') + 2;

            if (nameSeperator == 1 || nameSeperator > command.Length)
            {
                return(command);
            }

            command = command.Substring(nameSeperator)
                      .Trim();
            string firstWord = command.Split(' ')[0];

#if DEBUG
            letterInfos.RemoveRange(0, nameSeperator);
            cg.DebugMenu?.ShowScan(letterInfos);
#endif

            lock (ListenToAccessLock)
                foreach (ListenTo listenData in ListenTo)
                {
                    if (listenData.Command == firstWord)
                    {
                        ltd = listenData;
                        break;
                    }
                }

            if (ltd == null || !ltd.Listen)
            {
                return(command);
            }
            #endregion

            #region Chat Identity
            // Store executor noise data in a bitmap.
            var          executorscan = new Rectangle(0, y - 4, namelength, 6);
            DirectBitmap executor     = Capture.Clone(executorscan);
            // Set name pixels to black and everything else to white
            for (int xi = 0; xi < executor.Width; xi++)
            {
                for (int yi = 0; yi < executor.Height; yi++)
                {
                    if (executor.CompareColor(xi, yi, seed, Chat.ChatFade))
                    {
                        executor.SetPixel(xi, yi, Color.Black);
                    }
                    else
                    {
                        executor.SetPixel(xi, yi, Color.White);
                    }
                }
            }

            ChatIdentity ci = new ChatIdentity(executor);
            #endregion

            #region Profile and Friend Check
            bool           isFriend = false;
            string         name     = null;
            PlayerIdentity pi       = null;

            // If it was not found, pi is still null. Register the profile if _registerPlayerProfiles is true.
            if (ltd.GetNameAndProfile || ltd.CheckIfFriend)
            {
                Point openMenuAt = new Point(56, y);

                // Open the chat
                cg.Chat.OpenChat();

                // Open the career profile
                cg.RightClick(openMenuAt, Timing.OPTION_MENU);

                // If the Send Friend Request option exists, they are not a friend.
                isFriend = !(bool)cg.Interact.MenuOptionScan(openMenuAt, OptionScanFlags.ReturnFound, null, Markups.SEND_FRIEND_REQUEST);

                if (ltd.GetNameAndProfile)
                {
                    using (cg.LockHandler.Interactive)
                    {
                        // By default, the career profile option is selected and we can just press enter to open it.
                        cg.KeyPress(Keys.Enter);

                        // Wait for the career profile to load.
                        WaitForCareerProfileToLoad();

                        // Get the player name
                        name = cg.GetPlayerName();

                        // Take a screenshot of the career profile.
                        DirectBitmap careerProfileSnapshot = Capture.Clone(Rectangles.LOBBY_CAREER_PROFILE);

                        // Register the player identity.
                        pi = new PlayerIdentity(careerProfileSnapshot);

                        // Go back to the lobby.
                        cg.GoBack(1);
                        //cg.//ResetMouse();

                        // If opening the career profile failed, the state of the chat could be incorrect,
                        // like being wrongly opened or wrongly closed because of when enter was pressed earlier.
                        // This will fix it.
                        cg.Chat.OpenChat();
                        if (!cg.OpenChatIsDefault)
                        {
                            cg.KeyPress(Keys.Enter);
                        }
                    }
                }
                else
                {
                    cg.Interact.CloseOptionMenu();
                }
            }
            #endregion

            CommandData commandData = new CommandData(command, GetChannelFromSeed(seed), ci, isFriend, name, pi);
            if (ltd.Callback != null)
            {
                ltd.Callback.Invoke(commandData);
            }
            else
            {
                commandData.ChatIdentity.Dispose();
                commandData.PlayerIdentity?.Dispose();
            }

            return(command);
        }
예제 #5
0
 /// <summary>
 /// Returns true if the 2 player identities are identicle.
 /// </summary>
 /// <param name="ci1">First player identity</param>
 /// <param name="ci2">Second player identity</param>
 /// <returns>Returns true if the player identities are identicle.</returns>
 public static bool CompareChatIdentities(ChatIdentity ci1, ChatIdentity ci2)
 {
     return(CompareIdentities(ci1, ci2));
 }
예제 #6
0
        // Checks if an executed command should be added to the list of commands, then adds it.
        void AddExecutedCommand(Bitmap bmp, int y, int namelength, int[] seed, int seedfade, string word)
        {
            // Clean up the word. makes something like "] $APPLE " into "$APPLE"
            var wordtemp = word.Split(new char[] { ']' }, 2);

            if (wordtemp.Length > 1)
            {
                word = wordtemp[1];
            }
            word = word.Trim();

            string   commandFirstWord = word.Split(' ')[0];
            ListenTo ltd = ListenTo.FirstOrDefault(v => v.Command == commandFirstWord);

            // See if command is being listened to. If it is, continue.
            if (word.Length > 0 && ltd != null && ltd.Listen)
            {
                lock (CommandLock)
                {
                    PlayerIdentity pi = null;

                    // If it was not found, pi is still null. Register the profile if _registerPlayerProfiles is true.
                    if (ltd.RegisterProfile)
                    {
                        Point openMenuAt = new Point(54, Rectangles.LOBBY_CHATBOX.Y + y);

                        // Open the chat
                        cg.Chat.OpenChat();

                        // Open the career profile
                        cg.RightClick(openMenuAt, 500);

                        // By default, the career profile option is selected and we can just press enter to open it.
                        cg.KeyPress(Keys.Enter);

                        // Wait for the career profile to load.
                        WaitForCareerProfileToLoad();

                        // Take a screenshot of the career profile.
                        cg.updateScreen();
                        Bitmap careerProfileSnapshot = cg.BmpClone(Rectangles.LOBBY_CAREER_PROFILE);

                        // Register the player identity.
                        pi = new PlayerIdentity(careerProfileSnapshot);

                        // Go back to the lobby.
                        cg.GoBack(1);
                        cg.ResetMouse();

                        // If opening the career profile failed, the state of the chat could be incorrect,
                        // like being wrongly opened or wrongly closed because of when enter was pressed earlier.
                        // This will fix it.
                        cg.Chat.OpenChat();
                        if (!cg.OpenChatIsDefault)
                        {
                            cg.KeyPress(Keys.Enter);
                        }
                    }

                    // Store executor noise data in a bitmap.
                    var    executorscan = new Rectangle(0, y - 4, namelength, 6);
                    Bitmap executor     = bmp.Clone(executorscan, bmp.PixelFormat);
                    // Set name pixels to black and everything else to white
                    for (int xi = 0; xi < executor.Width; xi++)
                    {
                        for (int yi = 0; yi < executor.Height; yi++)
                        {
                            if (executor.CompareColor(xi, yi, seed, seedfade))
                            {
                                executor.SetPixel(xi, yi, Color.Black);
                            }
                            else
                            {
                                executor.SetPixel(xi, yi, Color.White);
                            }
                        }
                    }

                    ChatIdentity ci = new ChatIdentity(executor);

                    CommandData commandData = new CommandData(word, GetChannelFromSeed(seed), pi, ci);
                    if (ltd?.Callback != null)
                    {
                        ltd.Callback.Invoke(commandData);
                    }

                    System.Threading.Thread.Sleep(50);
                } // lock
            }     // if command is being listened to
        }