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 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 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 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); }
static void Main(string[] args) { var ip = "40.121.144.70"; var port = 25575; var password = "******"; if (args.Length == 3) { ip = args[0]; int.TryParse(args[1], out port); password = args[2]; } var client = new RemoteConClient(); client.OnLog += message => { Console.WriteLine(string.Format("Client Log: {0}", message)); }; client.OnAuthResult += result => { _authProcessed = true; }; client.OnConnectionStateChange += state => { Console.WriteLine("Connection changed: " + state); if (state == 0) { client.Authenticate(password); } }; client.Connect(ip, port); while (true) { if (!client.Connected) { Console.ReadKey(); client.Connect(ip, port); continue; } if (_authProcessed && !client.Authenticated) { _authProcessed = false; Console.WriteLine("Password: "******"exit" || cmd == "quit") { client.Disconnect(); return; } client.SendCommand(cmd, result => { Console.WriteLine("CMD Result: " + result); }); } }
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"); }
/// <summary> /// Sends a RCON command to a playtest server. /// </summary> /// <param name="serverId">ID of server to send command to</param> /// <param name="command">RCON Command to send</param> /// <returns></returns> public async Task <string> RconCommand(string serverId, string command) { string reply = null; var server = DatabaseHandler.GetTestServer(serverId); if (server == null) { return(null); } IPHostEntry iPHostEntry = null; try { iPHostEntry = Dns.GetHostEntry(server.Address); if (RSettings.ProgramSettings.Debug) { _ = _log.LogMessage($"Server Address: {iPHostEntry.AddressList.FirstOrDefault()}", false, color: LOG_COLOR); } } catch { //No address } int retryCount = 0; var client = new RemoteConClient(); client.Connect(iPHostEntry.AddressList.FirstOrDefault().ToString(), 27015); //Delay until the client is connected, time out after 20 tries while (!client.Authenticated && client.Connected && retryCount < 20) { await Task.Delay(50); client.Authenticate(server.RconPassword); retryCount++; if (RSettings.ProgramSettings.Debug) { _ = _log.LogMessage($"Waiting for authentication from rcon server, tried: {retryCount} time.", false, color: LOG_COLOR); } } //Are we connected and authenticated? if (client.Connected && client.Authenticated) { //Send command and and store the server's response in reply. //However for some reason it takes a while for the server to reply //As a result we will wait for a proper reply below. client.SendCommand(command, result => { reply = result; }); await _log.LogMessage($"Sending RCON command:\n{command}\nTo server: {server.Address}", channel : false, color : LOG_COLOR); retryCount = 0; //Delay until we have a proper reply from the server. while (reply == null && retryCount < 20) { await Task.Delay(50); retryCount++; if (RSettings.ProgramSettings.Debug) { _ = _log.LogMessage($"Waiting for string from rcon server, tried: {retryCount} time.", false, color: LOG_COLOR); } } client.Disconnect(); } else { reply = $"Unable to connect or authenticate to RCON server with the ID of {serverId}."; } return(FormatRconServerReply(reply)); }
static void Main(string[] args) { var ip = "127.0.0.1"; var port = 27015; var password = "******"; if (args.Length == 3) { ip = args[0]; int.TryParse(args[1], out port); password = args[2]; } var client = new RemoteConClient(); client.OnLog += message => { Console.WriteLine(string.Format("Client Log: {0}", message)); }; client.OnAuthResult += result => { _authProcessed = true; }; client.OnConnectionStateChange += state => { Console.WriteLine("Connection changed: " + state); if (state == 0) { client.Authenticate(password); } }; client.Connect(ip, port); while (true) { if (!client.Connected) { Console.ReadKey(); client.Connect(ip, port); continue; } if (_authProcessed && !client.Authenticated) { _authProcessed = false; Console.WriteLine("Password: "******"exit" || cmd == "quit") { client.Disconnect(); return; } client.SendCommand(StringToUnicode(cmd), result => { Console.WriteLine(">>" + UnicodeToString(result) .Replace("<br/>", "")); }); } }