示例#1
0
        //AUTOMATICALLY INDICATE TO SERVER TO GET MEDIA
        private void action_auto_get_media()
        {
            string[] s      = responseData.Split(' ');
            string   sender = "";

            //the triggering special message is
            //"server> <target> picture from <sender>
            //note that there are at least 4 spaces
            //and thus at least 5 subtexts
            //the 5th subtext is expected to be the sender name
            if (s.Length >= 5)
            {
                sender = s[s.Length - 1];
            }

            action_message();

            string ext = shp1.Text.Substring(shp1.Text.Length - 3);

            //automatically send command to the server
            _chatstream.Write(":get media:" + sender + ":" + ext);
        }
示例#2
0
        public bool Authenticate()
        {
            //if we had attempted a password before
            //do not get new response
            //just process the old response ( which is password prompt)
            if (!_passwordattempted)
            {
                responseData = _chatstream.Read();
            }


            //Console.Write("**" +responseData+"**");


            //step 1
            if (responseData.IndexOf(AuthenticationProtocolValues.COMMAND_PROMPT) >= 0)
            {
                if (rb_register.Checked)
                {
                    _chatstream.Write(rb_register.Text);
                }
                if (rb_login.Checked)
                {
                    _chatstream.Write(rb_login.Text);
                }

                responseData = _chatstream.Read();
                //Console._chatstream.Write(responseData);
            }


            //step 2
            if (responseData.IndexOf(AuthenticationProtocolValues.USERID_PROMPT) >= 0)
            {
                rb_register.Enabled = false;
                rb_login.Enabled    = false;
                _chatstream.Write(tb_username.Text);
                responseData = _chatstream.Read();
                //Console.Write(responseData);
            }



            //step 3 .. up to 3 tries
            if (responseData.IndexOf(AuthenticationProtocolValues.PASSWORD_PROMPT) >= 0)
            {
                //we are processing the password,
                // do not allow user to change userid
                tb_username.Enabled = false;
                _chatstream.Write(tb_userpassword.Text);
                responseData = _chatstream.Read();
                //Console.Write(responseData);
                //password verification has been attempted
                if (rb_login.Checked)
                {
                    _passwordattempted = true;
                }
            }

            //show the message from server on results of
            //the authenication
            MessageBox.Show(FormatMessage(responseData));

            if (responseData.IndexOf(AuthenticationProtocolValues.QUIT_MSG) == 0)
            {
                // _authenticated = false;
                this.DialogResult = DialogResult.Abort;
                this.Close();
                // authForm.Close();
            }

            if (responseData.IndexOf(AuthenticationProtocolValues.AUTENTICATED_MSG) == 0)
            {
                // _authenticated = true;
                this.DialogResult = DialogResult.OK;
                this.Close();
                // authForm.Close();
            }

            if (responseData.IndexOf(AuthenticationProtocolValues.USER_ALREADY_LOGGED_IN) == 0)
            {
                // _authenticated = false;
                this.DialogResult = DialogResult.No;
                this.Close();
                //authForm.Close();
            }



            return(true); //dummy return
        }