private void confirm_pass_Click(object sender, EventArgs e) { if (ServerPass.Text == "") { MessageBox.Show("You need to enter a key for the server", "No Key Entered", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (UsernameBox.Text == "") { MessengerWindow.username = "******"; } else { MessengerWindow.username = UsernameBox.Text; } Server server = new Server(Server.GetLocalIPAddress(), 45455); int error = server.CreateServer(int.Parse(Max_Person.Text), ServerPass.Text); if (error == 1) { MessageBox.Show("No internet connection detected", "No Internet", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (error == 2) { MessageBox.Show("Failed to create a server", "Failed to create a server", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessengerWindow.server = server; MessengerWindow.isadmin = true; MessengerWindow.password = ServerPass.Text; this.Hide(); var Messenger = new MessengerWindow(); Messenger.Closed += (s, args) => this.Close(); Messenger.Show(); } }
private void connect_button_Click(object sender, EventArgs e) { Client client = new Client(); int err = client.Connect(IpBox.Text, 45455, PassBox.Text, UsernameBox.Text); if (err == 1) { MessageBox.Show("Failed to Connect to the server!", "Failed to connect", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (err == 2) { MessageBox.Show("Wrong password!", "Wrong password", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (err == 3) { MessageBox.Show("No room left to join in the server!", "No room", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (err == 4) { MessageBox.Show("This name is available in the server!", "Name available", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else { MessengerWindow.ip_address = IpBox.Text; MessengerWindow.client = client; MessengerWindow.username = UsernameBox.Text; MessengerWindow.isadmin = false; MessengerWindow.password = PassBox.Text; this.Hide(); var Messenger = new MessengerWindow(); Messenger.Closed += (s, args) => this.Close(); Messenger.Show(); } }