Ejemplo n.º 1
0
        public override async Task RunClient(IAsyncStreamReader <ClientArgs> requestStream, IServerStreamWriter <ClientStatus> responseStream, ServerCallContext context)
        {
            if (!await requestStream.MoveNext())
            {
                throw new InvalidOperationException();
            }
            var clientConfig = requestStream.Current.Setup;
            var clientRunner = ClientRunner.Start(_loggerFactory, clientConfig);

            try
            {
                await responseStream.WriteAsync(new ClientStatus
                {
                    Stats = clientRunner.GetStats(false)
                });

                while (await requestStream.MoveNext())
                {
                    var reset = requestStream.Current.Mark.Reset;
                    await responseStream.WriteAsync(new ClientStatus
                    {
                        Stats = clientRunner.GetStats(reset)
                    });
                }
            }
            finally
            {
                _logger.LogInformation("Exiting RunClient.");
                await clientRunner.StopAsync();
            }
        }
Ejemplo n.º 2
0
        /*
         * helper: If you dont like duplicationg code. Use this
         */
        private static (ServerRunner serverRunner, Player playerInit, ClientRunner clientRunner) InitiateServer()
        {
            var server = new ServerRunner();

            server.Start();
            var client = new ClientRunner("127.0.0.1", 32123);

            client.Start();
            client.JoinServer("player");
            return(server, server.GetPlayer("player"), client);
        }
Ejemplo n.º 3
0
        public void TestGetPlayerShouldNotBeNull()
        {
            var server = new ServerRunner();

            server.Start();
            var client = new ClientRunner("127.0.0.1", 32123);

            client.Start();
            client.JoinServer("player");
            server.GetPlayer("player").Should().NotBeNull();
            server.Stop();
        }
Ejemplo n.º 4
0
        public void TestLeavePlayer()
        {
            var server = new ServerRunner();

            server.Start();
            var client = new ClientRunner("127.0.0.1", 32123);

            client.Start();
            client.JoinServer("player");
            Thread.Sleep(1000);
            var player = server.GetPlayer("player");

            server.LeavePlayer(server.GetPlayerInfo(player.Pseudo)).Should().Be(true);
            server.Stop();
        }
Ejemplo n.º 5
0
        public void TestGetPlayerPosition()
        {
            var server = new ServerRunner();

            server.Start();
            var client = new ClientRunner("127.0.0.1", 32123);

            client.Start();
            client.JoinServer("player");
            Thread.Sleep(1000);
            var player = server.GetPlayer("player");

            Thread.Sleep(1000);
            server.Invoking(o => o.GetPlayerPosition(player)).ShouldNotThrow <NullReferenceException>();
            server.Stop();
        }