public void ClientEvent_RequestAliasInfo(Client client, int remoteid) { if (!client.IsLoggedIn() || !client.HasActiveChar()) { return; } var streamedClient = ClientMethods.FindClientByPlayerID(remoteid); if (!streamedClient.IsLoggedIn() || !streamedClient.HasActiveChar()) { return; } var chData = client.GetActiveChar(); var chOtherData = streamedClient.GetActiveChar(); var alias = chData.Aliases.FirstOrDefault(i => i.AliasedID == chOtherData.ID); if (alias != null) { client.TriggerEvent(Events.ServerToClient.Character.SetAliasInfo, $"{alias.AliasName} ({streamedClient.Value})", remoteid); } else { client.TriggerEvent(Events.ServerToClient.Character.SetAliasInfo, $"({streamedClient.Value})", remoteid); } }
private void btnCambioClave_Click(object sender, EventArgs e) { StringBuilder stringBuilder = new StringBuilder(); if (this.txtNuevaClave.Text == string.Empty) { stringBuilder.Append("Nueva clave esta vacia"); } if (this.txtRepitaClave.Text == string.Empty) { stringBuilder.Append("Repita la clave esta vacia"); } if (this.txtNuevaClave.Text != string.Empty && this.txtNuevaClave.Text.Length < 5) { stringBuilder.Append("Nueva clave debe tener 5 o mas caracteres!"); } if (this.txtNuevaClave.Text != string.Empty && this.txtRepitaClave.Text == string.Empty && this.txtNuevaClave.Text != this.txtRepitaClave.Text) { stringBuilder.Append("Deben ser iguales"); } if (stringBuilder.Length == 0) { Usuario usuario = Usuario.FindByUsername(Entorno.USUARIO.NombreUsuario); usuario.Clave = ClientMethods.EncriptarClave(this.txtNuevaClave.Text); usuario.Update(); MessageBox.Show("Cambio realizado con exito!", Application.ProductName); return; } MessageBox.Show(stringBuilder.ToString(), Application.ProductName); }
public static void Main() { if (!File.Exists("PublicKey.key")) { // Assume first run, generate keys and sign document. ServerMethods.GenerateKeyPair(); var input = new XmlDocument(); input.Load("input.xml"); Debug.Assert(input.DocumentElement != null); var licNode = input.DocumentElement["lic"]; Debug.Assert(licNode != null); var licNodeXml = licNode.OuterXml; var signedNode = input.CreateElement("signature"); signedNode.InnerText = ServerMethods.CalculateSignature(licNodeXml); input.DocumentElement.AppendChild(signedNode); input.Save("output.xml"); } if (ClientMethods.IsValidLicense("output.xml")) { Console.WriteLine("VALID"); } else { Console.WriteLine("INVALID"); } }
private void btnDisconnect_Click(object sender, EventArgs e) { try { ClientMethods.Disconnect(); MyInfo = null; } catch (Exception) { MessageBox.Show("Client failed to disconnect"); } }
void BtnAceptarClick(object sender, EventArgs e) { Usuario usuario = Usuario.Login(txtUsuario.Text, ClientMethods.EncriptarClave(txtClave.Text)); if (usuario == null) { MessageBox.Show("Usuario o clave incorrecta!", "Advertencia!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); txtUsuario.Text = string.Empty; txtClave.Text = string.Empty; } else { Entorno.USUARIO = usuario; DialogResult = DialogResult.OK; Close(); } }
private void btnSend_Click(object sender, EventArgs e) { if ((txtbxMessage.TextLength > 0) && (MyInfo != null)) { MyInfo.message = txtbxMessage.Text; try { ClientMethods.SendMessage(MyInfo); } //test catch (Exception) { MessageBox.Show("Serialization failed"); } txtbxMessage.ResetText(); } }
public void CmdGoto(Client client, string trg) { Client target = ClientMethods.FindClient(trg); if (target == null) { return; } if (client == target) { client.SendChatMessage("Can't /goto to urself."); return; } client.Position = target.Position.Around(2); }
/// <summary> /// Makes a connection to the service's remoting channel. /// </summary> public void Connect() { if (this.isConnected) { return; } try { System.Collections.Hashtable props = new System.Collections.Hashtable(); props["typeFilterLevel"] = "Full"; // Both formatters only use the typeFilterLevel property BinaryClientFormatterSinkProvider cliFormatter = new BinaryClientFormatterSinkProvider(props, null); BinaryServerFormatterSinkProvider srvFormatter = new BinaryServerFormatterSinkProvider(props, null); // The channel requires these to be set that it can found by name by the service props["name"] = "ConsoleClient"; props["portName"] = "ConsoleClient"; props["authorizedGroup"] = "Everyone"; // Create the channel channel = new IpcChannel(props, cliFormatter, srvFormatter); // Register the channel for remoting use System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false); // Create the refence to the service's remoting channel remoter = (ClientMethods)Activator.GetObject(typeof(ClientMethods), "ipc://SyslogConsole/Server"); // Register the MessageReceivedCallback event on the handler RemotingConfiguration.RegisterWellKnownServiceType(typeof(MessageReceivedCallbackSink), "ServerEvents", WellKnownObjectMode.Singleton); // Setup the event subscription sink = new MessageReceivedSink(); remoter.MessageHandled += new MessageReceivedCallback(sink.FireMessageReceived); this.isConnected = true; } catch { this.isConnected = false; } }
private void btnConnect_Click(object sender, EventArgs e) { //tests MessageBox.Show("ip =" + loginC.IPAddress + ", port =" + loginC.Port + ", username ="******", color =" + loginC.color + ", fullname =" + loginC.Nickname); MyInfo = new ChatMessage { ip = loginC.IPAddress, port = loginC.Port, username = loginC.Username, color = loginC.color, fullname = loginC.Nickname }; //MyInfo = new ChatMessage { ip = loginC.IPAddress, port = loginC.Port, username = loginC.Username, color = Color.FromName("Black"), fullname = loginC.Nickname }; //MyInfo = new ChatMessage { ip = loginC.IPAddress, port = loginC.Port, username = loginC.Username, fullname = loginC.Nickname }; try { ClientMethods.Connect(MyInfo); } //test catch (Exception) { MessageBox.Show("Client failed to connect"); } this.txtbxMessage.Focus(); }
public static void Main(string[] args) { bool eof = false; String input = null; string hostName; // Handle the command line error messages. if (args.Length < 1 || args.Length > 2) { Console.WriteLine("Usage: FTP server <optional port>"); return; } //Set the HostName hostName = args[0]; //When exactly 2 arguments appear then arg[0] is host and arg[1] is port if (args.Length == 2) { port = Int32.Parse(args[1]); // Check if the port is valid. if (port < 0) { Console.WriteLine(port.ToString() + " is not in valid range"); } } //Start the server connection; try { startConnection(hostName, port); } catch (IOException e) { Console.WriteLine("Connection to the server failed." + e.Message); return; } //This must be done first. Console.WriteLine("You must enter USER command to login."); // Command line is done - accept commands do { try { Console.Write(PROMPT); input = Console.ReadLine(); } catch (Exception e) { eof = true; Console.WriteLine(e.Message); } // Keep going if we have not hit end of file if (!eof && input.Length > 0) { int cmd = -1; string[] argv = Regex.Split(input, "\\s+"); // What command was entered? for (int i = 0; i < 13 && cmd == -1; i++) { if (COMMANDS[i].Equals(argv[0], StringComparison.CurrentCultureIgnoreCase)) { cmd = i; } } // Execute the command switch (cmd) { case ASCII: if (debuggingMode) { Console.WriteLine("DEBUG: ASCII Mode Toggled"); } setASCIITransferType(); inASCIIMode = true; break; case BINARY: if (debuggingMode) { Console.WriteLine("DEBUG: Binary Mode Toggled"); } setBinaryTransferType(); inBinaryMode = true; break; case CD: if (args.Length == 1) { Console.WriteLine("Usage: CD path"); return; } if (debuggingMode) { Console.WriteLine("DEBUG: Change Directory Toggled"); } var dir = argv[1]; changeDirectory(dir); break; case CDUP: if (debuggingMode) { Console.WriteLine("DEBUG: Change Directory Parent Toggled"); } getParentDirectory(); break; case DEBUG: var methods = new ClientMethods(); debuggingMode = methods.setDebugUser(debuggingMode); if (debuggingMode) { Console.WriteLine("Debugging Mode Toggled"); } break; case DIR: if (debuggingMode) { Console.WriteLine("DEBUG: List the contents of the remote system"); } listDirectores(isPassive); break; case GET: if (args.Length == 1 || args.Length > 2) { Console.WriteLine("Usage: GET filename"); return; } if (debuggingMode) { Console.WriteLine("DEBUG: Retrieving a file from the remote system"); } if (args.Length == 2) { var fileName = argv[1]; retreiveFromServer(fileName); } else { Console.WriteLine("Usage: Something went wrong."); } break; case HELP: for (int i = 0; i < HELP_MESSAGE.Length; i++) { Console.WriteLine(HELP_MESSAGE[i]); } break; case PASSIVE: if (debuggingMode) { Console.WriteLine("DEBUG: Passive mode enabled."); } setPassiveTransferMode(); isPassive = true; break; case PWD: if (debuggingMode) { Console.WriteLine("DEBUG: Printing a list of directories."); } printWorkingDirectory(); break; case USER: if (debuggingMode) { Console.WriteLine("DEBUG: User debugging mode enabled."); } if (argv.Length != 2) { Console.WriteLine("Usage: USER username"); } else { var username = argv[1]; userLogin(username, hostName, port); } break; case QUIT: if (debuggingMode) { Console.WriteLine("DEBUG: Terminating program and closing connection."); } eof = true; //Close connection to tcpclient. closeConnection(); break; default: Console.WriteLine("Invalid command"); break; } } } while (!eof); }
public void CMD_Alias(Client client, string identifier, string aliasText = "") { if (!client.IsLoggedIn()) { client.SendChatMessage("You are not logged in."); return; } if (!client.HasActiveChar()) { client.SendChatMessage("You are not properly spawned."); return; } var otherClient = ClientMethods.FindClient(identifier); if (otherClient == null) { client.SendChatMessage("Invalid Player Identifier."); return; } if (!otherClient.IsLoggedIn()) { client.SendChatMessage("That player is not logged in."); return; } if (!otherClient.HasActiveChar()) { client.SendChatMessage("That player is not spawned."); return; } // TODO: DISTANCE CHECK var chData = client.GetActiveChar(); var chOtherData = otherClient.GetActiveChar(); if (aliasText == "") { var alias = chData.Aliases.FirstOrDefault(i => i.CharID == chData.ID && i.AliasedID == chOtherData.ID); if (alias == null) { client.SendChatMessage("No Alias set for that player."); return; } chData.Aliases.Remove(alias); ClientEvent_RequestAliasInfo(client, otherClient.Value); client.SendChatMessage("Alias removed."); return; } var exist = chData.Aliases.FirstOrDefault(i => i.CharID == chData.ID && i.AliasedID == chOtherData.ID); if (exist != null) { exist.AliasName = aliasText; } else { chData.Aliases.Add(new Alias(chData, chOtherData, aliasText)); } ClientEvent_RequestAliasInfo(client, otherClient.Value); client.SendChatMessage($"Alias set."); }
/// <summary> /// Returns a client method matching the name if it exists. /// Non-client-exposed methods will not be returned. /// </summary> /// <param name="name">The name of the method to look for. /// Coalesce doesn't support exposing method overloads - /// in the case of overloads, the first matching method will be returned.</param> /// <param name="isStatic">Whether to look for a static or instance method. /// If null, the first match will be returned.</param> /// <returns></returns> public MethodViewModel MethodByName(string name, bool?isStatic = null) { return(ClientMethods.FirstOrDefault(f => string.Equals(f.Name, name, StringComparison.InvariantCultureIgnoreCase) && (isStatic == null || f.IsStatic == isStatic))); }