Ejemplo n.º 1
0
        private void Authenticate()
        {
            if (!_passwordattempted)
            {
                _responseData = Chatstream.Read();
            }
            if (_responseData.IndexOf(AuthenticationProtocolValues.CommandPrompt, StringComparison.Ordinal) >= 0)
            {
                if (rb_register.Checked)
                {
                    Chatstream.Write(rb_register.Text);
                }
                if (rb_login.Checked)
                {
                    Chatstream.Write(rb_login.Text);
                }
                _responseData = Chatstream.Read();
            }

            if (_responseData.IndexOf(AuthenticationProtocolValues.UseridPrompt, StringComparison.Ordinal) >= 0)
            {
                rb_register.Enabled = false;
                rb_login.Enabled    = false;
                Chatstream.Write(tb_username.Text);
                _responseData = Chatstream.Read();
            }

            if (_responseData.IndexOf(AuthenticationProtocolValues.PasswordPrompt, StringComparison.Ordinal) >= 0)
            {
                tb_username.Enabled = false;
                Chatstream.Write(tb_userpassword.Text);
                _responseData = Chatstream.Read();
                if (rb_login.Checked)
                {
                    _passwordattempted = true;
                }
            }

            MessageBox.Show(FormatMessage(_responseData));

            if (_responseData.IndexOf(AuthenticationProtocolValues.QuitMsg, StringComparison.Ordinal) == 0)
            {
                DialogResult = DialogResult.Abort;
                Close();
            }

            if (_responseData.IndexOf(AuthenticationProtocolValues.AutenticatedMsg, StringComparison.Ordinal) == 0)
            {
                DialogResult = DialogResult.OK;
                Close();
            }
            if (_responseData.IndexOf(AuthenticationProtocolValues.UserAlreadyLoggedIn, StringComparison.Ordinal) != 0)
            {
                return;
            }
            DialogResult = DialogResult.No;
            Close();
        }
Ejemplo n.º 2
0
 public void Listen()
 {
     while (!_formActivated)
     {
         Thread.Sleep(0);
     }
     try
     {
         while (true)
         {
             _action       = null;
             _responseData = _chatstream.Read();
             while (_pauseListening)
             {
                 Thread.Sleep(0);
             }
             if (_responseData == "")
             {
                 continue;
             }
             if (WindowState == FormWindowState.Minimized)
             {
                 FlashWindow(Handle.ToInt32(), true);
             }
             if (_responseData != "")
             {
                 _action = action_message;
             }
             if (checkbox.Checked)
             {
                 if (
                     _responseData.IndexOf(ChatProtocolValues.PIC_FROM_MSG("", _nickname),
                                           StringComparison.Ordinal) == 0)
                 {
                     _action = action_auto_get_pic;
                 }
             }
             if (checkbox.Checked)
             {
                 if (
                     _responseData.IndexOf(ChatProtocolValues.MEDIA_FROM_MSG("", _nickname),
                                           StringComparison.Ordinal) == 0)
                 {
                     _action = action_auto_get_media;
                 }
             }
             if (_responseData.IndexOf(ChatProtocolValues.QuitMsg, StringComparison.Ordinal) == 0)
             {
                 _action = action_server_says_quit;
             }
             if (_responseData.IndexOf(ChatProtocolValues.ConnectionHeaderMsg, StringComparison.Ordinal) == 0)
             {
                 _action = action_connection;
             }
             if (_responseData == ChatProtocolValues.GetPicMsg)
             {
                 _action = action_server_get_pic;
             }
             if (_responseData == ChatProtocolValues.SendPicMsg)
             {
                 _action = action_server_send_pic;
             }
             if (_responseData == ChatProtocolValues.GetMediaMsg)
             {
                 _action = action_server_get_media;
             }
             if (_responseData == ChatProtocolValues.SendMediaMsg)
             {
                 _action = action_server_send_media;
             }
             _action?.Invoke();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
         _action = action_handle_error;
         _action();
     }
 }