private static void RunUntilShutdown(RConClient rcc) { var connected = rcc.ConnectAsync().Result; Assert.IsTrue(connected, "not connected"); rcc.WaitUntilShutdown(); rcc.Close(); }
public async Task ShouldRetrySendingCommand() { var rcc = new RConClient("ip", 3333, "pass"); var connected = await rcc.ConnectAsync(); Assert.IsTrue(connected, "not connected"); var handler1 = rcc.SendCommand(0, "missions"); var handler2 = rcc.SendCommand(0, "missions"); var handler3 = rcc.SendCommand(0, "#shutdown"); Task.WaitAll(handler1.WaitForResponse(), handler2.WaitForResponse(), handler3.WaitForResponse()); rcc.Close(); Assert.IsTrue(handler1.Completed); Assert.IsTrue(handler2.Completed); Assert.IsTrue(handler3.Completed); var response1 = (CommandResponseDatagram)handler1.ResponseDatagram; var response2 = (CommandResponseDatagram)handler2.ResponseDatagram; var response3 = (CommandResponseDatagram)handler3.ResponseDatagram; Assert.AreEqual(response1.OriginalSequenceNumber, 0); Assert.AreEqual(response2.OriginalSequenceNumber, 0); Assert.AreEqual(response3.OriginalSequenceNumber, 0); string body1 = response1.Body; string body2 = response2.Body; string body3 = response3.Body; Assert.IsTrue(body1.Length > 0); Assert.IsTrue(body2.Length > 0); Assert.IsTrue(body3.Length > 0); // WOW. We can't retry sending commands with the same seq num, it executes // the three of them including #shutdown. // Maybe contact BattlEye with a bug report. }
public async Task ShouldParseMultipartCommandResponsesCorrectly() { var conf = new MockServerSetup(); var client = CreateClient(conf); var rcc = new RConClient(client, client.ServerSetup.Password); var connected = rcc.ConnectAsync().Result; Assert.IsTrue(connected, "not connected"); var handler = rcc.SendCommand("getplayersmulti"); Assert.IsNotNull(handler); CommandMultiPartResponseDatagram multiPartResponseDatagram = null; if (await handler.WaitForResponse()) { multiPartResponseDatagram = handler.ResponseDatagram as CommandMultiPartResponseDatagram; } Assert.IsNotNull(multiPartResponseDatagram); Assert.IsNotNull(multiPartResponseDatagram.Body); Assert.IsTrue(multiPartResponseDatagram.Body.StartsWith("Players on server:")); for (int i = 1; i <= 10; i++) { Assert.IsTrue(multiPartResponseDatagram.Body.Contains( string.Format("(part {0:000}/010)", i))); } rcc.Close(); }
public async Task ShouldAcceptOutOfOrderCommandResponsesCorrectly() { var conf = new MockServerSetup { DisorderedMultiPacketResponses = true }; var client = CreateClient(conf); var rcc = new RConClient(client, client.ServerSetup.Password); var connected = rcc.ConnectAsync().Result; Assert.IsTrue(connected, "not connected"); var handler = rcc.SendCommand("getplayersmulti"); Assert.IsNotNull(handler); CommandMultiPartResponseDatagram multiPartResponseDatagram = null; if (await handler.WaitForResponse()) { multiPartResponseDatagram = handler.ResponseDatagram as CommandMultiPartResponseDatagram; } rcc.Close(); Assert.IsNotNull(multiPartResponseDatagram); Assert.IsTrue(multiPartResponseDatagram.Body.StartsWith("Players on server:")); for (int i = 1; i <= 10; i++) { Assert.IsTrue(multiPartResponseDatagram.Body.Contains( string.Format("(part {0:000}/010)", i))); } Debug.WriteLine("Response assembled: {0}", (object)multiPartResponseDatagram.Body); Debug.WriteLine("Client shutdown reason: {0}", rcc.ShutdownReason); }
public async Task ShouldReturnCommandResponsesCorrectly() { var conf = new MockServerSetup(); var client = CreateClient(conf); var rcc = new RConClient(client, client.ServerSetup.Password); var connected = rcc.ConnectAsync().Result; Assert.IsTrue(connected, "not connected"); var handler = rcc.SendCommand("getplayers"); Assert.IsNotNull(handler); CommandSinglePartResponseDatagram singlePartResponse = null; if (await handler.WaitForResponse()) { singlePartResponse = handler.ResponseDatagram as CommandSinglePartResponseDatagram; } Assert.IsNotNull(singlePartResponse); Assert.IsTrue(singlePartResponse.Body.StartsWith("Players on server:")); rcc.Close(); }