コード例 #1
0
        private void Client_Load(object sender, EventArgs e)
        {
            Hide();

            //Get login info and try connecting
            using (Login login = new Login())
            {
                login.ShowDialog();

                //if no username or server specified, and not self host, close window
                //if parameters are met, start self hoster if applicable or connect to server with username
                if (string.IsNullOrEmpty(login.Username) && string.IsNullOrEmpty(login.ServerIP))
                {
                    Close();
                }
                else if (login.IsSelfHost)
                {
                    SelfHoster.RunWorkerAsync();
                    serverIP = Array.Find(Dns.GetHostEntry(string.Empty).AddressList,
                                          a => a.AddressFamily == AddressFamily.InterNetwork).ToString();
                    Window_Title.Text = $"Cynobroad Client - Local Server Running at {serverIP}";
                }
                else
                {
                    serverIP = login.ServerIP;
                }

                username = login.Username;
                User_UsernameLabel.Text   = username;
                User_ConnectedServer.Text = serverIP;

                try
                {
                    _client     = new TcpClient();
                    isConnected = true;
                    InitializeConnection();

                    //show main form and close login dialog
                    Show();
                    SendMsgBox.Focus();
                }
                catch
                {
                    isConnected = false;
                }
            }

            //if connection failed set status to red, else green
            if (!isConnected)
            {
                User_ConnectionStatus.BackColor = Color.FromArgb(224, 102, 102);
            }
            else
            {
                User_ConnectionStatus.BackColor = Color.FromArgb(147, 196, 125);
            }
        }
コード例 #2
0
 /// <summary>
 /// Checkbox true/false. Change, how message will send. By pressing Enter or clicking button.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void checkBox1_CheckedChanged(object sender, EventArgs e)
 {
     SendMsgBox.Focus();
     if (ShiftEnter == true)
     {
         ShiftEnter = false;
     }
     else
     {
         ShiftEnter = true;
     }
 }
コード例 #3
0
        private void Send_Click(object sender, EventArgs e)
        {
            //remove whitespace
            SendMsgBox.Text = SendMsgBox.Text.TrimEnd();

            //check requirements
            if (SendMsgBox.Text.Length > 1024)
            {
                MessageBox.Show("Woah woah woah! Our stingy network hamsters simply don't want to deal with all your bytes. " +
                                "We've limited each message to 1024 characters. Like Twitter, but not as bad.");
                return;
            }
            if (string.IsNullOrEmpty(SendMsgBox.Text))
            {
                return;
            }

            //add msg to queue and clear msg box
            CreateAndSendPacket("send", SendMsgBox.Text);
            SendMsgBox.Text = "";
            SendMsgBox.Focus();
        }