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);
        }
예제 #5
0
        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();
        }
예제 #6
0
 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();
 }
예제 #7
0
        public void RemoteConAuthFailureTest()
        {
            var server = new RemoteConServer(IPAddress.Any, 27015);

            server.CommandManager.Add("test", "Test", (command, args) => "test");

            var client = new RemoteConTcpClient(server);

            // Auth wrong test
            client.ParsePacket(new byte[]
            {
                0x15, 0x00, 0x00, 0x00,             // Size
                0x02, 0x00, 0x00, 0x00,             // Id
                0x03, 0x00, 0x00, 0x00,             // Type
                0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00,
                0x00,
            });
        }
        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");
        }
예제 #9
0
        public void RemoteConCommandTest()
        {
            var server = new RemoteConServer(IPAddress.Any, 27015);

            server.CommandManager.Add("test", "Test", (command, args) => "test");

            var client = new RemoteConTcpClient(server);

            client.Authenticated = true;

            // Command test
            client.ParsePacket(new byte[]
            {
                0x0E, 0x00, 0x00, 0x00,             // Size
                0x02, 0x00, 0x00, 0x00,             // Id
                0x02, 0x00, 0x00, 0x00,             // Type
                0x74, 0x65, 0x73, 0x74, 0x00,
                0x00,
            });
        }
예제 #10
0
        public void RemoteConInvalidCommandTest()
        {
            var server = new RemoteConServer(IPAddress.Any, 27015);

            server.CommandManager.Add("test", "Test", (command, args) => "test");

            var client = new RemoteConTcpClient(server);

            client.Authenticated = true;

            // No command found test
            client.ParsePacket(new byte[]
            {
                0x15, 0x00, 0x00, 0x00,             // Size
                0x02, 0x00, 0x00, 0x00,             // Id
                0x02, 0x00, 0x00, 0x00,             // Type
                0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00,
                0x00,
            });
        }
예제 #11
0
        public void RemoteConInvalidAuthPacketTypeTest()
        {
            var server = new RemoteConServer(IPAddress.Any, 27015);

            server.CommandManager.Add("test", "Test", (command, args) => "test");

            var client = new RemoteConTcpClient(server);

            // Wrong Auth packet type test
            Assert.Throws <NotAuthenticatedException>(() =>
            {
                client.ParsePacket(new byte[]
                {
                    0x15, 0x00, 0x00, 0x00,                 // Size
                    0x02, 0x00, 0x00, 0x00,                 // Id
                    0x02, 0x00, 0x00, 0x00,                 // Type
                    0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x00,
                    0x00,
                });
            });
        }
예제 #12
0
        public void RemoteConAuthSuccessTest()
        {
            var server = new RemoteConServer(IPAddress.Any, 27015)
            {
                Password = "******"
            };

            server.CommandManager.Add("test", "Test", (command, args) => "test");

            var client = new RemoteConTcpClient(server);

            // Auth correct test
            client.ParsePacket(new byte[]
            {
                0x1D, 0x00, 0x00, 0x00,             // Size
                0x02, 0x00, 0x00, 0x00,             // Id
                0x03, 0x00, 0x00, 0x00,             // Type
                0x73, 0x75, 0x70, 0x65, 0x72, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6F, 0x72, 0x64, 0x00,
                0x00,
            });
        }
예제 #13
0
        public void RemoteConInvalidPacketTypeTest()
        {
            var server = new RemoteConServer(IPAddress.Any, 27015);

            server.CommandManager.Add("test", "Test", (command, args) => "test");

            var client = new RemoteConTcpClient(server);

            client.Authenticated = true;

            // Type other than execcommand
            Assert.Throws <InvalidPacketTypeException>(() =>
            {
                client.ParsePacket(new byte[]
                {
                    0x0E, 0x00, 0x00, 0x00,                 // Size
                    0x02, 0x00, 0x00, 0x00,                 // Id
                    0x00, 0x00, 0x00, 0x00,                 // Type
                    0x74, 0x65, 0x73, 0x74, 0x00,
                    0x00,
                });
            });
        }
예제 #14
0
        public void RemoteConEmptyPayloadTest()
        {
            var server = new RemoteConServer(IPAddress.Any, 27015);

            server.CommandManager.Add("test", "Test", (command, args) => "test");

            var client = new RemoteConTcpClient(server);

            client.Authenticated = true;

            // Empty payload test
            Assert.Throws <EmptyPacketPayloadException>(() =>
            {
                client.ParsePacket(new byte[]
                {
                    0x0A, 0x00, 0x00, 0x00,                 // Size
                    0x02, 0x00, 0x00, 0x00,                 // Id
                    0x02, 0x00, 0x00, 0x00,                 // Type
                    0x00,
                    0x00,
                });
            });
        }
예제 #15
0
        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");
        }