private void EjecutarComando() { string[] comando = txtComando.Text.ToLower().Split(' '); switch (comando[0]) { case "list": { if (comando[1] == "connected") { List <string> users = local.UsersOnline(); if (users.Count != 0) { lstConsola.Items.Add("Usuarios conectados:"); foreach (string c in users) { lstConsola.Items.Add("\t-> " + c); } } else { lstConsola.Items.Add("No hay usuarios conectados"); } } break; } case "kill": { if (comando[1] == "user") { if (local.LivesRoom(comando[2])) { int aux = local.KillUser(comando[2]); if (aux == 1) { lstConsola.Items.Add("El Usuario " + comando[2] + " eliminado."); } else { lstConsola.Items.Add("El Usuario " + comando[2] + " no pudo ser eliminado."); } } else { lstConsola.Items.Add("Este usuario no existe."); } } break; } } txtComando.Text = ""; }
private void ConnectToServer(string ip_port, string username) { if (txtUser.Text != "") { Login(txtUser.Text); } else { MessageBox.Show("Ingresar un userName."); } try { if (Channel == null) //verifica si el canal ya fue registrado tanto como server como por el { Channel = new TcpChannel(Convert.ToInt32(txtPuerto.Text)); //registra el canal y el puerto por el cual entramos ChannelServices.RegisterChannel(Channel, false); } Remota RemotedObject = (Remota)Activator.GetObject(typeof(Remota), "tcp://" + ip_port + "/chat"); try { RemotedObject.IsInstance(); } catch (Exception ex) { throw new Exception("No existe un servidor con esa ruta."); } if (RemotedObject.LivesRoom(chatUser.userName, chatUser.ip, chatUser.Puerto)) //verifica si existo { MessageBox.Show("Este userName ya esta siendo utilizado."); } else { RemotedObject.JoinChat(chatUser.userName, chatUser.ip, chatUser.Puerto); //me agrega remotes.Add(RemotedObject); //invoca servicio remoto server_name.Add("tcp://" + ip_port + "/chat"); //agrega direccio de la sala tiempos.Add(0); tbVentas.SelectedIndex = 1; } } catch (Exception ex) { MessageBox.Show("Error a intentar acceder a un chat: " + ex.Message); } }