Example #1
0
 public SpyStyler(ClientStyler connectionInfoStyler, ClientStyler stranger1, ClientStyler stranger2) :
     base(connectionInfoStyler.Instance, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.LowerLeft, HorizontalAlignment.Center,
          System.Windows.Media.Color.FromArgb(255, 255, 0, 255), 0, "")
 {
     stranger1Styler = stranger1;
     stranger2Styler = stranger2;
 }
Example #2
0
        private void generalSendTo(ClientStyler cs)
        {
            messageLLS.Focus();
            if (messageEntryBox.Text.Equals(""))
            {
                return;
            }

            cs.Instance.send(messageEntryBox.Text);

            generalMessageAdd(userStyle, String.Format("{0}:\n\"{1}\"", String.Format(AppResources.SendToText, cs.Number.ToString()), messageEntryBox.Text));
            messageEntryBox.Text = "";
        }
Example #3
0
        public ChatPage()
        {
            InitializeComponent();
            BuildLocalizedApplicationBar();

            clientList  = new List <ClientStyler>();
            appSettings = IsolatedStorageSettings.ApplicationSettings;

            systemStyle = new ClientStyler(null, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                                           HorizontalAlignment.Center, System.Windows.Media.Colors.Gray, 0, AppResources.SystemText);

            recaptchaBox        = new Popup();
            recaptchaBox.Margin = new Thickness(5, 60, 5, 0);
        }
Example #4
0
        public Message(ClientStyler instance, string text)
        {
            this.ParentName = String.Copy(instance.Name);
            this.Text       = text;

            this.Date = DateTime.Now.ToString("MM/dd/yy");
            this.Time = DateTime.Now.ToString("HH:mm:ss");


            this.Direction          = instance.Direction;
            this.ContainerAlignment = instance.ContainerAlignment;
            this.Color = instance.Color.Color;
            this.Brush = new SolidColorBrush(this.Color);
        }
Example #5
0
        private async void showRecaptchaBox(ClientStyler cs, string challengeRequest)
        {
            canvas = new Canvas();
            System.Windows.Media.Color bgC = (System.Windows.Media.Color)Application.Current.Resources["PhoneAccentColor"];
            canvas.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255, (byte)(bgC.R * .85), (byte)(bgC.G * .85), (byte)(bgC.B * .85)));
            canvas.Margin     = new Thickness(-50, 0, 0, 0);
            canvas.Width      = 1000;
            canvas.Opacity    = .5;
            ContentPanel.Children.Add(canvas);

            if (recaptchaBox.Child == null)
            {
                RecaptchaDialog daBox = new RecaptchaDialog();

                Uri                 requestChallengeUri = new Uri(String.Format(Client.recaptchaChallenge, challengeRequest));
                HttpClient          browser             = new HttpClient();
                HttpResponseMessage result;
                string              challenge = "";

                HttpContent content = new StringContent("");
                content.Headers.ContentLength = 0;

                int autoSolveCredit = 0;
                if (appSettings.Contains("solvecredit"))
                {
                    autoSolveCredit = (int)appSettings["solvecredit"];
                }
                else
                {
                    appSettings["solvecredit"] = autoSolveCredit;
                    appSettings.Save();
                }

                if (autoSolveCredit == 0)
                {
                    daBox.AutoSolveButton.IsEnabled = false;
                }
                daBox.AutoSolveButton.Content = String.Format(AppResources.AutoSolveText, autoSolveCredit);

                try {
                    result = await browser.PostAsync(requestChallengeUri, content);

                    string response = result.Content.ReadAsStringAsync().Result;

                    System.Text.RegularExpressions.Regex challengeRegex = new System.Text.RegularExpressions.Regex(Client.challengeRegex);
                    System.Text.RegularExpressions.Match challengeMatch = challengeRegex.Match(response);
                    challenge = challengeMatch.Value.Substring(challengeMatch.Value.IndexOf(" : ") + " : '".Length);
                    challenge = challenge.Substring(0, challenge.Length - 1);
                } catch {}

                if (challenge.Equals(""))
                {
                    MessageBox.Show(AppResources.ConnectionError);
                }

                daBox.recapchaImageBox.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri(String.Format(Client.recaptchaImage, challenge), UriKind.Absolute));
                Debug.WriteLine(String.Format(Client.recaptchaImage, challenge));

                daBox.NewCaptchaButton.Click += delegate(object sender, RoutedEventArgs e) {
                    cs.Instance.recapcha(challenge, "0");

                    if (recaptchaBox != null)
                    {
                        recaptchaBox.IsOpen = false;
                        ContentPanel.Children.Remove(canvas);

                        recaptchaBox.Child         = null;
                        daBox.recapchaImageBox     = null;
                        daBox.responseTextBox.Text = "";

                        unpauseAll();
                    }
                };
                daBox.SubmitCaptchaButton.Click += delegate(object sender, RoutedEventArgs e) {
                    cs.Instance.recapcha(Uri.EscapeDataString(challenge), Uri.EscapeDataString(daBox.responseTextBox.Text));
                    Debug.WriteLine(Uri.EscapeUriString(daBox.responseTextBox.Text));
                    if (recaptchaBox != null)
                    {
                        recaptchaBox.IsOpen = false;
                        ContentPanel.Children.Remove(canvas);

                        recaptchaBox.Child         = null;
                        daBox.recapchaImageBox     = null;
                        daBox.responseTextBox.Text = "";

                        unpauseAll();

                        if (chatMode == ChatMode.Intercept)
                        {
                            generalDisconnect();
                            generalReconnect();
                        }
                    }
                };

                /*daBox.AutoSolveButton.Click += async delegate(object sender, RoutedEventArgs e) {
                 *      string dbcResponse = "";
                 *      //change button: disabled and solving text
                 *      //download captcha image and convert to base64
                 *      //send to dbc api
                 *      //poll every 4 seconds
                 *      //submit attempt to omegle
                 *
                 *      Debug.WriteLine(Uri.EscapeUriString(dbcResponse));
                 *      if (recaptchaBox != null) {
                 *              recaptchaBox.IsOpen = false;
                 *              ContentPanel.Children.Remove(canvas);
                 *
                 *              recaptchaBox.Child = null;
                 *              daBox.recapchaImageBox = null;
                 *              daBox.responseTextBox.Text = "";
                 *
                 *              unpauseAll();
                 *
                 *              if (chatMode == ChatMode.Intercept) {
                 *                      generalDisconnect();
                 *                      generalReconnect();
                 *              }
                 *      }
                 *      return; return;
                 * };*/
                recaptchaBox.Child = daBox;
            }

            recaptchaBox.IsOpen = true;
        }
Example #6
0
 private void generalMessageAdd(ClientStyler styler, string msg)
 {
     messageList.Add(new Message(styler, msg));
     messageLLS.ItemsSource = messageList;
     messageLLS.ScrollTo(messageList.LastOrDefault());
 }
Example #7
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (clientList.Count > 0)
            {
                unpauseAll(); return;
            }                                                               //came from choosertask

            //load data from save
            topics = new List <String>();
            if (appSettings.Contains("topics"))
            {
                foreach (Topic topic in appSettings["topics"] as ObservableCollection <Topic> )
                {
                    if (topic.IsActive)
                    {
                        topics.Add(topic.Content);
                        Debug.WriteLine("topic " + topic.Content);
                    }
                }
            }

            recentChatList = new ObservableCollection <Chat>();
            if (appSettings.Contains("recents"))
            {
                recentChatList = appSettings["recents"] as ObservableCollection <Chat>;
            }
            else
            {
                appSettings["recents"] = recentChatList;
                appSettings.Save();
            }

            imageList = new ObservableCollection <ImgurImage>();
            if (appSettings.Contains("images"))
            {
                imageList = appSettings["images"] as ObservableCollection <ImgurImage>;
            }
            else
            {
                appSettings["images"] = imageList;
                appSettings.Save();
            }

            var param = "";

            //set mode from param passed
            if (NavigationContext.QueryString.TryGetValue("mode", out param))
            {
                if (param.Equals(ChatMode.Chat.ToString()))
                {
                    chatMode     = ChatMode.Chat;
                    chatModeText = AppResources.ChatModeText;
                }
                else if (param.Equals(ChatMode.AskQuestion.ToString()))
                {
                    chatMode     = ChatMode.AskQuestion;
                    chatModeText = AppResources.QuestionModeText;
                }
                else if (param.Equals(ChatMode.AnswerQuestion.ToString()))
                {
                    chatMode     = ChatMode.AnswerQuestion;
                    chatModeText = AppResources.QuestionModeText;
                }
                else if (param.Equals(ChatMode.Intercept.ToString()))
                {
                    chatMode     = ChatMode.Intercept;
                    chatModeText = AppResources.InterceptModeText;
                }
                else if (param.Equals(ChatMode.ViewLog.ToString()))
                {
                    chatMode     = ChatMode.ViewLog;
                    chatModeText = AppResources.LogPageText;
                }
            }

            string host = Client.defaultHost;

            if (appSettings.Contains("usingCustomHost") && appSettings.Contains("customHost"))
            {
                if ((bool)(appSettings["usingCustomHost"]))
                {
                    host = (string)(appSettings["customHost"]);
                }
            }

            chatLanguage = "en";
            if (NavigationContext.QueryString.TryGetValue("lang", out param))
            {
                //perhaps check for valid language
                chatLanguage = param;
                Debug.WriteLine(chatLanguage);
            }

            ask = "";
            if (NavigationContext.QueryString.TryGetValue("ask", out param))
            {
                ask = param;
            }

            canSaveQuestion = false;
            if (NavigationContext.QueryString.TryGetValue("cansave", out param))
            {
                canSaveQuestion = Boolean.Parse(param);
            }

            wantsSpy = false;
            if (NavigationContext.QueryString.TryGetValue("wantsspy", out param))
            {
                wantsSpy = Boolean.Parse(param);
            }

            chatHash = 0;
            if (NavigationContext.QueryString.TryGetValue("chathash", out param))
            {
                chatHash = int.Parse(param);
            }

            usingSavedChat = false;
            if (NavigationContext.QueryString.TryGetValue("saved", out param))
            {
                usingSavedChat = Boolean.Parse(param);
            }

            //setup page from mode
            switch (chatMode)
            {
            case ChatMode.Chat:
                userStyle = new ClientStyler(null, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.LowerRight,
                                             HorizontalAlignment.Right, System.Windows.Media.Colors.Blue, 0, AppResources.YouText);
                clientList.Add(new ClientStyler(new Client(topics, chatLanguage, host),
                                                Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                                                System.Windows.HorizontalAlignment.Left,
                                                System.Windows.Media.Colors.Red, 1, AppResources.StrangerText));

                //start in different thread as to not block the UI
                Task.Factory.StartNew(() => {
                    updateTitleBar();
                    chatLoop(clientList[0]);
                });

                break;

            case ChatMode.Intercept:

                userStyle = new ClientStyler(null, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.LowerRight,
                                             HorizontalAlignment.Center, System.Windows.Media.Colors.Green, 0, AppResources.YouText);
                clientList.Add(new ClientStyler(new Client(topics, chatLanguage, host),
                                                Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                                                System.Windows.HorizontalAlignment.Left,
                                                System.Windows.Media.Colors.Red, 1, AppResources.StrangerText));
                clientList.Add(new ClientStyler(new Client(topics, chatLanguage, host),
                                                Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                                                System.Windows.HorizontalAlignment.Right,
                                                System.Windows.Media.Colors.Blue, 2, AppResources.StrangerText));

                if (appSettings.Contains("regexps"))
                {
                    regexps = appSettings["regexps"] as ObservableCollection <Regexp>;
                }

                //start in different thread as to not block the UI
                Task.Factory.StartNew(() => {
                    //very basic omegle client
                    chatLoop(clientList[0]);
                });
                Task.Factory.StartNew(() => {
                    updateTitleBar();
                    chatLoop(clientList[1]);
                });

                break;

            case ChatMode.AskQuestion:
                userStyle = new ClientStyler(null, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.LowerRight,
                                             HorizontalAlignment.Right, System.Windows.Media.Colors.Blue, 0, AppResources.YouText);
                clientList.Add(new SpyStyler(
                                   new ClientStyler(new Client(ask, canSaveQuestion, chatLanguage, host),
                                                    Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                                                    System.Windows.HorizontalAlignment.Left, System.Windows.Media.Colors.Red, 1, AppResources.StrangerText),

                                   new ClientStyler(null, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.LowerRight,
                                                    HorizontalAlignment.Left, System.Windows.Media.Colors.Red, 1, AppResources.StrangerText),

                                   new ClientStyler(null, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                                                    HorizontalAlignment.Right, System.Windows.Media.Colors.Blue, 2, AppResources.StrangerText)));

                //start in different thread as to not block the UI
                Task.Factory.StartNew(() => {
                    updateTitleBar();
                    chatLoop(clientList[0]);
                });

                break;

            case ChatMode.AnswerQuestion:
                userStyle = new ClientStyler(null, Coding4Fun.Toolkit.Controls.ChatBubbleDirection.LowerRight,
                                             HorizontalAlignment.Right, System.Windows.Media.Colors.Blue, 0, AppResources.YouText);
                clientList.Add(new ClientStyler(new Client(true, chatLanguage, host),
                                                Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                                                System.Windows.HorizontalAlignment.Left, System.Windows.Media.Colors.Red, 1, AppResources.StrangerText));

                //start in different thread as to not block the UI
                Task.Factory.StartNew(() => {
                    updateTitleBar();
                    chatLoop(clientList[0]);
                });

                break;

            case ChatMode.ViewLog:
                string chatSpec;
                if (usingSavedChat)
                {
                    chatSpec = "savedchats";
                }
                else
                {
                    chatSpec = "recents";
                }

                ObservableCollection <Chat> chatList = new ObservableCollection <Chat>();

                if (appSettings.Contains(chatSpec))
                {
                    chatList = appSettings[chatSpec] as ObservableCollection <Chat>;
                }
                else
                {
                    appSettings[chatSpec] = chatList;
                    appSettings.Save();
                }

                Dispatcher.BeginInvoke(() => {
                    ApplicationBar.Buttons.Clear();

                    updateTitleBar();
                    foreach (Chat chat in chatList)
                    {
                        if (chat.Hash == chatHash)
                        {
                            messageList = chat.Messages;
                        }
                    }

                    foreach (Message msg in messageList)
                    {
                        msg.Brush = new SolidColorBrush(msg.Color);
                    }

                    messageLLS.ItemsSource = messageList;

                    foreach (ApplicationBarMenuItem abmi in ApplicationBar.MenuItems)
                    {
                        abmi.IsEnabled = false;
                    }

                    newChatAppBarButton.IsEnabled = false;
                    ApplicationBar.Buttons.Add(newChatAppBarButton);
                    ApplicationBar.Buttons.Add(shareChatAppBarButton);
                    if (usingSavedChat)
                    {
                        saveChatAppBarButton.IsEnabled = false;
                    }
                    ApplicationBar.Buttons.Add(saveChatAppBarButton);
                    if (usingSavedChat)
                    {
                        ApplicationBar.Buttons.Add(deleteChatAppBarButton);
                    }
                });

                break;
            }
        }
Example #8
0
        private void chatLoop(ClientStyler clientStyler)
        {
            clientStyler.isConnecting = true;
            clientStyler.isTyping     = false;
            isDying = false;             //when error event is recieved, set isDying so you don't get loads of msgboxes

            clientStyler.Instance.Start();

            Dispatcher.BeginInvoke(() => {
                foreach (ApplicationBarMenuItem abmi in ApplicationBar.MenuItems)
                {
                    abmi.IsEnabled = false;
                }

                ApplicationBar.Buttons.Clear();
                ApplicationBar.Mode = ApplicationBarMode.Minimized;

                updateTitleBar();
                messageList            = new ObservableCollection <Message>();
                messageLLS.ItemsSource = messageList;
            });

            while (true)
            {
                clientStyler.Instance.eventInQueueSignal.WaitOne();
                lock (clientStyler.Instance.eventQueue) {
                    while (true)
                    {
                        Event currentEvent;

                        //is there a better way to empty the queue?
                        try {
                            currentEvent = clientStyler.Instance.eventQueue.Dequeue();
                        } catch {
                            break;
                        }

                        //high level event handling
                        switch (currentEvent.type)
                        {
                        case (EventType.Waiting):
                            //sucessfully connected to omegle, waiting for stranger
                            break;

                        case (EventType.GotMessage):
                            Dispatcher.BeginInvoke(() => {
                                string msg = currentEvent.parameters[0];

                                clientStyler.isTyping = false;
                                updateTitleBar();

                                if (chatMode == ChatMode.Intercept)
                                {
                                    if (regexps != null)
                                    {
                                        foreach (Regexp regexp in regexps)
                                        {
                                            if (WordPage.IsValidRegex(regexp.Find))
                                            {
                                                msg = System.Text.RegularExpressions.Regex.Replace(msg.ToLower(), regexp.Find, regexp.Replace);
                                            }
                                        }
                                    }

                                    foreach (ClientStyler cs in clientList)
                                    {
                                        if (cs != clientStyler)
                                        {
                                            cs.Instance.send(msg);
                                            Debug.WriteLine("Relayed message");
                                        }
                                    }
                                }

                                if (!msg.Equals(currentEvent.parameters[0]))
                                {
                                    msg = String.Format("\"{0}\"\n{1}:\n\"{2}\"", currentEvent.parameters[0], AppResources.ChangedText, msg);
                                }

                                generalMessageAdd(clientStyler, msg);
                            });
                            break;

                        case (EventType.Typing):
                            Dispatcher.BeginInvoke(() => {
                                clientStyler.isTyping = true;
                                updateTitleBar();

                                if (chatMode == ChatMode.Intercept)
                                {
                                    foreach (ClientStyler cs in clientList)
                                    {
                                        if (!(cs.Equals(clientStyler)))
                                        {
                                            cs.Instance.typing();
                                        }
                                    }
                                }
                            });
                            break;

                        case (EventType.StoppedTyping):
                            Dispatcher.BeginInvoke(() => {
                                clientStyler.isTyping = false;
                                updateTitleBar();

                                if (chatMode == ChatMode.Intercept)
                                {
                                    foreach (ClientStyler cs in clientList)
                                    {
                                        if (!(cs.Equals(clientStyler)))
                                        {
                                            cs.Instance.stoppedTyping();
                                        }
                                    }
                                }
                            });
                            break;

                        case (EventType.Connected):
                            Dispatcher.BeginInvoke(() => {
                                clientStyler.isConnecting = false;
                                if (chatMode == ChatMode.AskQuestion)
                                {
                                    generalMessageAdd(systemStyle, AppResources.StrangersConnectedText);
                                }
                                else
                                {
                                    generalMessageAdd(systemStyle, String.Format(AppResources.ConnectedText, clientStyler.Number));
                                }
                                updateTitleBar();
                                generalConnected();
                            });
                            break;

                        case (EventType.StrangerDisconnected):
                            Dispatcher.BeginInvoke(() => {
                                clientStyler.Instance.disconnect();

                                //clientStyler.Color = new SolidColorBrush(Colors.Gray);

                                checkAllDone();

                                generalMessageAdd(systemStyle, String.Format(AppResources.DisconnectedText, clientStyler.Number));
                            });
                            break;

                        case (EventType.Question):
                            Dispatcher.BeginInvoke(() => {
                                generalMessageAdd(systemStyle, String.Format(AppResources.GotQuestionText, currentEvent.parameters[0]));
                            });
                            break;

                        case (EventType.RecaptchaRequired):
                            Dispatcher.BeginInvoke(() => {
                                pauseAll();
                                showRecaptchaBox(clientStyler, currentEvent.parameters[0]);
                            });
                            break;

                        case (EventType.RecaptchaRejected):
                            Dispatcher.BeginInvoke(() => {
                                pauseAll();
                                if (usingAutoSolver)
                                {
                                    int autoSolveCredit = 0;
                                    if (appSettings.Contains("solvecredit"))
                                    {
                                        autoSolveCredit = (int)appSettings["solvecredit"];
                                    }
                                    else
                                    {
                                        appSettings["solvecredit"] = autoSolveCredit;
                                        appSettings.Save();
                                    }
                                    appSettings["solvecredit"] = autoSolveCredit + 1;
                                    appSettings.Save();
                                    MessageBox.Show(AppResources.AutoSolveFailedText);
                                    usingAutoSolver = false;
                                    //report failed solve to DBC
                                    return; return;
                                }
                                showRecaptchaBox(clientStyler, currentEvent.parameters[0]);
                            });
                            break;

                        case (EventType.CommonLikes):
                            Dispatcher.BeginInvoke(() => {
                                string topics = ""; Boolean isFirst = true;
                                foreach (string topic in currentEvent.parameters)
                                {
                                    if (!isFirst)
                                    {
                                        topics += ","; isFirst = false;
                                    }
                                    topics += String.Format(" \"{0}\"", topic);
                                }

                                generalMessageAdd(systemStyle, String.Format(AppResources.YouBothLikeText, topics));
                            });
                            break;

                        case (EventType.SpyMessage):
                            Dispatcher.BeginInvoke(() => {
                                int stranger = 0;
                                int.TryParse(currentEvent.parameters[0].Substring(currentEvent.parameters[0].Length - 1), out stranger);
                                string msg = currentEvent.parameters[1];

                                if (stranger == 1)
                                {
                                    generalMessageAdd(((SpyStyler)clientStyler).stranger1Styler, msg);
                                }
                                else if (stranger == 2)
                                {
                                    generalMessageAdd(((SpyStyler)clientStyler).stranger2Styler, msg);
                                }
                                else
                                {
                                    //internal error
                                    Debug.WriteLine("Stranger number not 1 or 2!");
                                }
                            });
                            break;

                        case (EventType.SpyDisconnected):
                            Dispatcher.BeginInvoke(() => {
                                int stranger = 0;
                                int.TryParse(currentEvent.parameters[0].Substring(currentEvent.parameters[0].Length - 1), out stranger);

                                clientStyler.Instance.disconnect();

                                generalMessageAdd(systemStyle, String.Format(AppResources.DisconnectedText, stranger));

                                checkAllDone();
                            });
                            break;

                        case (EventType.Error):
                            Dispatcher.BeginInvoke(() => {
                                if ((((ErrorEvent)currentEvent).exception is System.Net.Http.HttpRequestException) &&
                                    (((System.Net.Http.HttpRequestException)(((ErrorEvent)currentEvent).exception)).InnerException is WebException) &&
                                    (((WebException)((System.Net.Http.HttpRequestException)(((ErrorEvent)currentEvent).exception)).InnerException).Status == WebExceptionStatus.RequestCanceled))
                                {
                                    Debug.WriteLine("threw out requestcancelled error");
                                    return;                                             //no big deal, just try again on next eventthread trigger
                                }

                                clientStyler.Instance.Stop();

                                if (isDying)
                                {
                                    return;
                                }
                                isDying = true;

                                checkAllDone();
                                MessageBox.Show(AppResources.ConnectionError);

                                LimitedCrashExtraDataList extrasExtraDataList = new LimitedCrashExtraDataList {
                                    new CrashExtraData("Omeddle", "Generic ErrorEvent")
                                };
#if DEBUG
                                throw ((ErrorEvent)currentEvent).exception;
#else
                                BugSenseLogResult sendResult = BugSense.BugSenseHandler.Instance.LogException(((ErrorEvent)currentEvent).exception);
#endif
                            });
                            break;
                        }
                    }
                }
            }
        }