예제 #1
0
        public void ShouldThrowOnLoginWithWrongPassword()
        {
            var client = CreateClient(new MockServerSetup { OnlyLogin = true });
            var rcc = new RConClient(client, "fnipw93457");

            bool threw = false;
            try
            {
                var connected = rcc.ConnectAsync().Result;
                Assert.IsFalse(connected, "should not return true");
            }
            catch (AggregateException aex)
            {
                if (aex.InnerExceptions.Count == 1
                    && aex.InnerExceptions[0] is InvalidCredentialException)
                {
                    threw = true;
                }
                else
                {
                    throw;
                }
            }
            catch (InvalidCredentialException)
            {
                threw = true;
            }

            if (!threw)
            {
                Assert.Fail("Should have thrown an Invalid Credential Exception");
            }
        }
예제 #2
0
 public void ShouldLogin()
 {
     var client = CreateClient(new MockServerSetup { OnlyLogin = true });
     var rcc = new RConClient(client, client.ServerSetup.Password);
     var connected = rcc.ConnectAsync().Result;
     Assert.IsTrue(connected, "not connected");
 }
예제 #3
0
파일: Restarter.cs 프로젝트: st4l/BEsharp
        public void KickAll()
        {
            var rcc = new RConClient(this.host, this.port, this.password);
            rcc.ConnectAsync().Wait();

            for (int i = 0; i < 100; i++)
            {
                var cmd = string.Format("kick {0} SERVER IS RESTARTING", i);
                rcc.SendCommandAsync(cmd);
            }
        }
예제 #4
0
 private static void RunUntilShutdown(RConClient rcc)
 {
     var connected = rcc.ConnectAsync().Result;
     Assert.IsTrue(connected, "not connected");
     rcc.WaitUntilShutdown();
     rcc.Close();
 }
예제 #5
0
        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.
        }
예제 #6
0
        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);

        }
예제 #7
0
        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();
        }
예제 #8
0
        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();
        }
예제 #9
0
        public void ShouldThrowWhenServerDown()
        {
            var conf = new MockServerSetup { LoginServerDown = true, OnlyLogin = true };
            var client = CreateClient(conf);
            var rcc = new RConClient(client, client.ServerSetup.Password);

            bool threw = false;
            try
            {
                var connected = rcc.ConnectAsync().Result;
                Assert.IsFalse(connected, "should not return true");
            }
            catch (AggregateException aex)
            {
                if (aex.InnerExceptions.Count == 1 && aex.InnerExceptions[0] is TimeoutException)
                {
                    threw = true;
                }
                else
                {
                    throw;
                }
            }
            catch (TimeoutException)
            {
                threw = true;
            }

            if (!threw)
            {
                Assert.Fail("Should have thrown a Timeout Exception");
            }
        }
예제 #10
0
파일: Restarter.cs 프로젝트: st4l/BEsharp
 private void SendCommand(string cmd)
 {
     var rcc = new RConClient(this.host, this.port, this.password);
     rcc.ConnectAsync().Wait();
     rcc.SendCommandAsync(cmd);
 }