public void TestCommandFail(bool useUTF8) { var server = new RemoteConServer(IPAddress.Any, 27015); server.StartListening(); server.UseUTF8 = useUTF8; string commandResult = null; using (var waitEvent = new AutoResetEvent(false)) { var client = new RemoteConClient(); client.UseUTF8 = useUTF8; client.OnAuthResult += success => { client.SendCommand("testing", result => { commandResult = result; client.Disconnect(); server.StopListening(); waitEvent.Set(); }); }; client.Connect("127.0.0.1", 27015); client.Authenticate("changeme"); waitEvent.WaitOne(); } Assert.Contains("Invalid command", commandResult); }
public void TestCommandSuccess(bool useUTF8) { var server = new RemoteConServer(IPAddress.Any, 27015); server.CommandManager.Add("hello", "Replies with world", (command, args) => "world"); server.UseUTF8 = true; server.StartListening(); string commandResult = null; using (var waitEvent = new AutoResetEvent(false)) { var client = new RemoteConClient(); client.UseUTF8 = useUTF8; client.OnAuthResult += success => { client.SendCommand("hello", result => { commandResult = result; client.Disconnect(); server.StopListening(); waitEvent.Set(); }); }; client.Connect("127.0.0.1", 27015); client.Authenticate("changeme"); waitEvent.WaitOne(); } Assert.Contains("world", commandResult); }
public void TestAuthSuccess(bool useUTF8) { var server = new RemoteConServer(IPAddress.Any, 27015); server.UseUTF8 = useUTF8; server.StartListening(); bool authResult = false; using (var waitEvent = new AutoResetEvent(false)) { var client = new RemoteConClient(); client.UseUTF8 = useUTF8; client.OnAuthResult += success => { authResult = success; client.Disconnect(); server.StopListening(); waitEvent.Set(); }; client.Connect("127.0.0.1", 27015); client.Authenticate("changeme"); waitEvent.WaitOne(); } Assert.True(authResult); }
public void TestAuthFail(bool useUtf8) { var server = new RemoteConServer(IPAddress.Any, 27015) { UseUtf8 = useUtf8 }; server.StartListening(); var authResult = true; var waitEvent = new AutoResetEvent(false); var client = new RemoteConClient { UseUtf8 = useUtf8 }; client.OnAuthResult += success => { authResult = success; client.Disconnect(); server.StopListening(); waitEvent.Set(); }; client.Connect("127.0.0.1", 27015); client.Authenticate("unitfail"); waitEvent.WaitOne(); Assert.False(authResult); }
public static void Main(string[] args) { var server = new RemoteConServer(IPAddress.Any, 27015) { SendAuthImmediately = true, Debug = true, }; server.CommandManager.Add("hello", "Echos back world", (command, arguments) => { return("world"); }); server.CommandManager.Add("help", "(command)", "Shows this help", (cmd, arguments) => { if (arguments.Count == 1) { var helpCmdStr = arguments[0]; var helpCmd = server.CommandManager.GetCommand(helpCmdStr); if (helpCmd == null) { return("Command not found."); } return(string.Format("{0} - {1}", helpCmd.Name, helpCmd.Description)); } else { var sb = new StringBuilder(); var all = server.CommandManager.Commands.Count; var i = 0; foreach (var command in server.CommandManager.Commands) { if (command.Value.Usage == "") { sb.AppendFormat("{0}", command.Value.Name); } else { sb.AppendFormat("{0} {1}", command.Value.Name, command.Value.Usage); } if (i < all) { sb.Append(", "); } i++; } return(sb.ToString()); } }); server.StartListening(); Console.WriteLine("Server started. Press any key to stop."); Console.ReadKey(); }
private static void startRconServer() { server = new RemoteConServer(IPAddress.Any, port) { SendAuthImmediately = true, Debug = true, UseCustomCommandHandler = true, EnableIpWhitelist = false, MaxConnections = uint.MaxValue, MaxConnectionsPerIp = uint.MaxValue, MaxPasswordTries = 3, BanMinutes = 60 * 24, Password = ServerConfigurationFileManager.CurrentConfigurationFile.ServerAdminPassword }; server.OnCommandReceived += Server_OnCommandReceived; server.StartListening(); }
public void TestAuthFail() { var server = new RemoteConServer(IPAddress.Any, 27015); server.StartListening(); var client = new RemoteConClient(); client.OnAuthResult += success => { Assert.False(success); client.Disconnect(); server.StopListening(); }; client.Connect("127.0.0.1", 27015); client.Authenticate("unitfail"); }
public void TestCommandSuccess() { var server = new RemoteConServer(IPAddress.Any, 27015); server.StartListening(); var client = new RemoteConClient(); client.OnAuthResult += success => { //Assert.True(success); client.SendCommand("hello", result => { Assert.Contains("world", result); client.Disconnect(); server.StopListening(); }); }; client.Connect("127.0.0.1", 27015); client.Authenticate("changeme"); }