Beispiel #1
0
        private void ReceiveResponse()
        {
            var buffer   = new byte[2048];                                 //Create buffer
            int received = ClientSocket.Receive(buffer, SocketFlags.None); //Get messages

            if (received == 0)
            {
                return;
            }
            var data = new byte[received];                //Convert data

            Array.Copy(buffer, data, received);           //Store data
            string text = Encoding.ASCII.GetString(data); //Convert to string

            LblStatus.Invoke((Action) delegate
            {
                LblStatus.Text = text;                                                                   //Have to do this to use two threads and access UI
            });
            if (LblStatus.Text.Any(char.IsDigit))                                                        //If there's a number
            {
                string VerifyNum = new String(text.ToCharArray().Where(c => Char.IsDigit(c)).ToArray()); //Get number in string
                string GameID    = VerifyNum;
                LblConnect.Invoke((Action) delegate                                                      //Have to do this to avoid crashing UI
                {
                    LblConnect.Text     = VerifyNum;                                                     //Set label with GameID
                    QuestionInterface Q = new QuestionInterface(Username, GameID);                       //Call new form
                    Q.Show();                                                                            //Show it
                    Visible = false;
                });
            }
        }
Beispiel #2
0
 private void SetStatus(string format, params object[] args)
 {
     LblStatus.Invoke((MethodInvoker) delegate()
     {
         LblStatus.Text = string.Format(format, args);
     });
 }
Beispiel #3
0
        /// <summary>
        /// User clicked button to log in.
        /// </summary>
        private void BtnLogin_Click(object sender, EventArgs e)
        {
            LoginArgsContainer Args = new LoginArgsContainer();

            if (TxtPassword.Text != "" && TxtUsername.Text != "")
            {
                NetworkFacade.Client = new NetworkClient(GlobalSettings.Default.LoginServerIP, 2106,
                                                         GonzoNet.Encryption.EncryptionMode.AESCrypto);
                NetworkFacade.Client.OnConnected += new OnConnectedDelegate(NetworkController.Client_OnConnected);

                Args.Username = TxtUsername.Text.ToUpper();
                Args.Password = TxtPassword.Text.ToUpper();

                SaltedHash Hash    = new SaltedHash(new SHA512Managed(), Args.Username.Length);
                byte[]     HashBuf = Hash.ComputePasswordHash(Args.Username.ToUpper(), Args.Password.ToUpper());
                Args.Enc    = new AESEncryptor(Convert.ToBase64String(HashBuf));
                Args.Client = NetworkFacade.Client;

                PlayerAccount.Username = TxtUsername.Text;

                LblStatus.Invoke(new MethodInvoker(delegate { LblStatus.Visible = true; }));
                LblStatus.Invoke(new MethodInvoker(delegate { LblStatus.Text = "Connecting..."; }));

                NetworkController.OnReceivedCharacters += new OnReceivedCharactersDelegate(NetworkController_OnReceivedCharacters);

                NetworkFacade.Client.Connect(Args);
            }
            else
            {
                MessageBox.Show("Please enter a username and password!");
            }
        }
Beispiel #4
0
 public void setStatus(string msg)
 {
     LblStatus.Invoke((MethodInvoker)(() =>
     {
         LblStatus.Text = msg;
     }));
 }
Beispiel #5
0
        public FrmBadges()
        {
            InitializeComponent();

            DoRefresh();

            _checkTimer = new System.Threading.Timer(delegate
            {
                try
                {
                    if (_closing)
                    {
                        return;
                    }
                    var printers = new Printers();
                    if (printers.Any())
                    {
                        if (printers.First().IsConnected)
                        {
                            LblStatus.Invoke(new MethodInvoker(delegate
                            {
                                LblStatus.ForeColor = System.Drawing.Color.DarkGreen;
                                LblStatus.Text      = "Connected";
                            }));
                        }
                        else
                        {
                            LblStatus.Invoke(new MethodInvoker(delegate
                            {
                                LblStatus.ForeColor = System.Drawing.Color.Red;
                                LblStatus.Text      = "Disconnected";
                            }));
                        }
                    }
                    else
                    {
                        LblStatus.Invoke(new MethodInvoker(delegate
                        {
                            LblStatus.ForeColor = System.Drawing.Color.Red;
                            LblStatus.Text      = "Disconnected";
                        }));
                    }
                }
                catch
                {
                    try
                    {
                        LblStatus.Invoke(new MethodInvoker(delegate
                        {
                            LblStatus.ForeColor = System.Drawing.Color.Red;
                            LblStatus.Text      = "Error (No Drivers?)";
                        }));
                    }
                    catch
                    {
                    }
                }
            }, null, 0, 1000);
        }
        private void SetStatus(StringBuilder XmlStatus)
        {
            try
            {
                // InvokeRequired required compares the thread ID of the
                // calling thread to the thread ID of the creating thread.
                // If these threads are different, it returns true.
                if (LblStatus.InvokeRequired)
                {
                    SetStatusCallback d = new SetStatusCallback(SetStatus);
                    LblStatus.Invoke(d, XmlStatus);
                }
                else
                {
                    //if(!VarGlobal.LessVerbose)Console.WriteLine(XmlStatus.ToString());
                    List <string> Result = ReadXml.GetValue(XmlStatus.ToString(), "status", "code");
                    if (Result.Count > 0)
                    {
                        string        Res    = Result[0];
                        List <string> Detail = ReadXml.GetValue(XmlStatus.ToString(), "status", "details");
                        if (Detail.Count > 0)
                        {
                            Res += " " + Detail[0];
                        }


                        LblStatus.Text = Res;
                        if (Res.IndexOf("succeeded", StringComparison.InvariantCultureIgnoreCase) > -1)
                        {
                            LblStatus.ForeColor = Color.Green;
                        }
                        if (Res.IndexOf("failed", StringComparison.InvariantCultureIgnoreCase) > -1)
                        {
                            LblStatus.ForeColor = Color.Red;
                        }
                    }
                    backgroundWorkerBuildStatus.RunWorkerAsync("FsList");
                }
            }
            catch (Exception Ex)
            {
                if (!VarGlobal.LessVerbose)
                {
                    Console.WriteLine(Ex.Message + Environment.NewLine + Ex.StackTrace);
                }
            }
        }
Beispiel #7
0
        /// <summary>
        /// Received characters from login server.
        /// </summary>
        private void NetworkController_OnReceivedCharacters()
        {
            LblStatus.Invoke(new MethodInvoker(delegate { LblStatus.Text = "Received characters..."; }));

            if (NetworkFacade.Avatars.Count == 0)
            {
                MessageBox.Show("You need to create a character before using this chat client!");
                NetworkFacade.Client.Disconnect();

                return;
            }

            PictureBox1.Invoke(new MethodInvoker(delegate
            {
                PictureBox1.Visible = true;
                PictureBox2.Visible = true;
                PictureBox3.Visible = true;

                LblUsername.Visible = false;
                LblPassword.Visible = false;

                BtnLogin.Visible    = false;
                TxtUsername.Visible = false;
                TxtPassword.Visible = false;
            }));

            switch (NetworkFacade.Avatars.Count)
            {
            case 1:
                LblName1.Invoke(new MethodInvoker(delegate
                {
                    LblName1.Visible  = true;
                    LblName1.Text     = NetworkFacade.Avatars[0].Name;
                    LblName1.Location = new Point(this.Width / 2, LblName1.Location.Y);

                    PictureBox1.Image    = NetworkFacade.Avatars[0].Thumbnail;
                    PictureBox1.Location = new Point(this.Width / 2, PictureBox1.Location.Y);

                    BtnChat1.Visible  = true;
                    BtnChat1.Location = new Point((this.Width - 20) / 2, BtnChat1.Location.Y);
                }));
                break;

            case 2:
                LblName1.Invoke(new MethodInvoker(delegate
                {
                    //Enabling LblName3 and PictureBox3 here because it looks prettier...

                    LblName1.Visible = true;
                    LblName1.Text    = NetworkFacade.Avatars[0].Name;

                    LblName3.Visible = true;
                    LblName3.Text    = NetworkFacade.Avatars[1].Name;

                    PictureBox1.Image = NetworkFacade.Avatars[0].Thumbnail;
                    PictureBox3.Image = NetworkFacade.Avatars[1].Thumbnail;

                    BtnChat1.Visible = true;
                    BtnChat3.Visible = true;
                }));
                break;

            case 3:
                LblName1.Invoke(new MethodInvoker(delegate
                {
                    LblName1.Visible = true;
                    LblName1.Text    = NetworkFacade.Avatars[0].Name;

                    LblName2.Visible = true;
                    LblName2.Text    = NetworkFacade.Avatars[1].Name;

                    LblName3.Visible = true;
                    LblName3.Text    = NetworkFacade.Avatars[2].Name;

                    PictureBox1.Image = NetworkFacade.Avatars[0].Thumbnail;
                    PictureBox2.Image = NetworkFacade.Avatars[1].Thumbnail;
                    PictureBox3.Image = NetworkFacade.Avatars[2].Thumbnail;

                    BtnChat1.Visible = true;
                    BtnChat2.Visible = true;
                    BtnChat3.Visible = true;
                }));
                break;
            }
        }