Esempio n. 1
0
        public async Task AddAlreadyExistingServerSettingsInDatabase()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await Task.Delay(50);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            byte[]        buffer         = new byte[1024 * 4];
            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();

            Command command    = new Command("AddServerSetting", serverSettings);
            string  sendString = command.ToJson();

            byte[] sendBytes = System.Text.UTF8Encoding.UTF8.GetBytes(sendString);
            await webSocket.SendAsync(new ArraySegment <byte>(sendBytes, 0, sendBytes.Length), WebSocketMessageType.Text, true, CancellationToken.None);

            await webSocketHandler.ExtractCompleteMessage(buffer, 60);

            ModifySettingsResponse response = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(response, ModifySettingsResult.SETTING_ADDED);

            await webSocket.SendAsync(new ArraySegment <byte>(sendBytes, 0, sendBytes.Length), WebSocketMessageType.Text, true, CancellationToken.None);

            await webSocketHandler.ExtractCompleteMessage(buffer, 60);

            response = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());
            TestHelper.ValiateResponse(response, ModifySettingsResult.GAME_SEED_ALREADY_EXISTS);
        }
Esempio n. 2
0
        public async Task EditServerSettingsInDatabase()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await Task.Delay(50);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();

            Command command = new Command("AddServerSetting", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_ADDED);

            command = new Command("GetServerSettingsOfLoggedInUser", null);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            GetSettingsResponse getResponse = JsonConvert.DeserializeObject <GetSettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(getResponse, GetSettingsResult.OK);

            getResponse.ServerSettings[0].GameName = "Edited!";
            command = new Command("EditServerSettings", getResponse.ServerSettings[0]);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());
            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_EDITED);
        }
Esempio n. 3
0
        public async Task AlreadyExistingSeed_Add()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await Task.Delay(50);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();

            Command command = new Command("AddServerSetting", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_ADDED);

            command = new Command("GetServerSettingsOfLoggedInUser", null);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            GetSettingsResponse getResponse = JsonConvert.DeserializeObject <GetSettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(getResponse, GetSettingsResult.OK);

            serverSettings = TestHelper.GenerateNewServerSetting();
            serverSettings.WorldGenSeed = getResponse.ServerSettings[0].WorldGenSeed;
            command = new Command("AddServerSetting", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());
            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.GAME_SEED_ALREADY_EXISTS);
        }
        public async Task StartAndShutdownServerWithGameMod()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();

            serverSettings.GameMod = "FastProgress";
            Command command = new Command("AddServerSetting", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_ADDED);

            command = new Command("GetServerSettingsOfLoggedInUser", null);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            GetSettingsResponse getResponse = JsonConvert.DeserializeObject <GetSettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(getResponse, GetSettingsResult.OK);

            bool foundServerSetting = false;

            foreach (var item in getResponse.ServerSettings)
            {
                if (serverSettings.WorldGenSeed == item.WorldGenSeed)
                {
                    serverSettings     = item;
                    foundServerSetting = true;
                }
            }
            if (!foundServerSetting)
            {
                Assert.Fail("Added ServerSettingsId not found in response");
            }

            command = new Command("StartServer", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            StartServerResponse startResponse = JsonConvert.DeserializeObject <StartServerResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(startResponse, StartServerResult.SERVER_STARTED);

            command = new Command("StopServer", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            StopServerResponse stopResponse = JsonConvert.DeserializeObject <StopServerResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(stopResponse, StopServerResult.SERVER_STOPPED);
        }
Esempio n. 5
0
        public async Task EditNotExistingServerSettingsInDatabase()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await Task.Delay(50);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();

            serverSettings.GameName = "Edited!";
            serverSettings.Id       = 532345823;

            await AmazonDynamoDBFactory.ExecuteInTransactionContext(async (client, context) =>
            {
                BesteRightsAuthorization besteRightsAuthorization = new BesteRightsAuthorization
                {
                    TableId          = TABLE_ID,
                    Namespace        = "Beste.GameServer.SDaysTDie.ServerSettings",
                    Operation        = "EditServerSettings",
                    RecourceModule   = "ServerSetting",
                    RecourceId       = serverSettings.Id,
                    Authorized       = true,
                    LegitimationUuid = webSocketHandler.User.Uuid,
                    Uuid             = Guid.NewGuid().ToString()
                };
                await AmazonDynamoDBFactory.Context.SaveAsync(besteRightsAuthorization);
            });

            await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, webSocketHandler.Result.CloseStatusDescription, CancellationToken.None);

            webSocket        = new ClientWebSocket();
            webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);



            Command command = new Command("EditServerSettings", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_NOT_FOUND);
        }
Esempio n. 6
0
        public async Task NoRightsOnDeleteServerSettings()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await Task.Delay(50);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();

            serverSettings.GameName = "Edited!";
            serverSettings.Id       = 532345828;

            Command command = new Command("DeleteServerSettings", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.RIGHT_VIOLATION);
        }
        public async Task StartTwoServers()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            ServerSetting serverSettingOne = new ServerSetting
            {
                GameName              = "MyGameStartTwoServesOne",
                GameWorld             = Beste.GameServer.SDaysTDie.Modules.Types.GameWorld.Navezgane.ToString(),
                ServerConfigFilepath  = "MyGameConfigFilePath" + TestHelper.RandomString(8) + ".xml",
                ServerDescription     = "My Server Desc",
                ServerName            = "MyServerStartTwoServesOne",
                ServerPassword        = "******",
                ServerPort            = 50001,
                TelnetPassword        = "******",
                TelnetPort            = 8089,
                TerminalWindowEnabled = false,
                WorldGenSeed          = "MyGameStartTwoServesOne"
            };

            Command command = new Command("AddServerSetting", serverSettingOne);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_ADDED);

            command = new Command("GetServerSettingsOfLoggedInUser", null);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            GetSettingsResponse getResponse = JsonConvert.DeserializeObject <GetSettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(getResponse, GetSettingsResult.OK);

            bool foundServerSetting = false;

            foreach (var item in getResponse.ServerSettings)
            {
                if (serverSettingOne.WorldGenSeed == item.WorldGenSeed)
                {
                    serverSettingOne   = item;
                    foundServerSetting = true;
                    break;
                }
            }
            if (!foundServerSetting)
            {
                Assert.Fail("Added ServerSettingsId not found in response");
            }



            command = new Command("StartServer", serverSettingOne);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            StartServerResponse startResponse = JsonConvert.DeserializeObject <StartServerResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(startResponse, StartServerResult.SERVER_STARTED);

            ClientWebSocket  webSocketTwo        = new ClientWebSocket();
            WebSocketHandler webSocketHandlerTwo = new WebSocketHandler(webSocketTwo);
            await webSocketTwo.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await TestHelper.Login("Admin", "Passwort1$", webSocketTwo, webSocketHandlerTwo);

            ServerSetting serverSettingTwo = new ServerSetting
            {
                GameName              = "MyGameStartTwoServesTwo",
                GameWorld             = Beste.GameServer.SDaysTDie.Modules.Types.GameWorld.Navezgane.ToString(),
                ServerConfigFilepath  = "MyGameConfigFilePath" + TestHelper.RandomString(8) + ".xml",
                ServerDescription     = "My Server Desc",
                ServerName            = "MyServerNameStartTwoServesTwo",
                ServerPassword        = "******",
                ServerPort            = 50001,
                TelnetPassword        = "******",
                TelnetPort            = 8089,
                TerminalWindowEnabled = false,
                WorldGenSeed          = "MyGameStartTwoServesTwo"
            };

            command = new Command("AddServerSetting", serverSettingTwo);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocketTwo, webSocketHandlerTwo, command);

            modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandlerTwo.ReceivedCommand.CommandData.ToString());
            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_ADDED);

            command = new Command("GetServerSettingsOfLoggedInUser", null);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocketTwo, webSocketHandlerTwo, command);

            getResponse = JsonConvert.DeserializeObject <GetSettingsResponse>(webSocketHandlerTwo.ReceivedCommand.CommandData.ToString());
            TestHelper.ValiateResponse(getResponse, GetSettingsResult.OK);

            foundServerSetting = false;
            foreach (var item in getResponse.ServerSettings)
            {
                if (serverSettingTwo.WorldGenSeed == item.WorldGenSeed)
                {
                    serverSettingTwo   = item;
                    foundServerSetting = true;
                    break;
                }
            }
            if (!foundServerSetting)
            {
                Assert.Fail("Added ServerSettingsId not found in response");
            }



            command = new Command("StartServer", serverSettingTwo);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocketTwo, webSocketHandlerTwo, command);

            startResponse = JsonConvert.DeserializeObject <StartServerResponse>(webSocketHandlerTwo.ReceivedCommand.CommandData.ToString());
            TestHelper.ValiateResponse(startResponse, StartServerResult.SERVER_STARTED);

            await Task.Delay(10000);

            int processCount = 0;

            foreach (var process in Process.GetProcessesByName("7DaysToDie"))
            {
                processCount++;
            }
            if (processCount != 2)
            {
                Assert.Fail("processCount != 2");
            }

            command = new Command("StopServer", serverSettingOne);
            await TestHelper.ExecuteCommandAndAwaitCommandResponse(webSocket, webSocketHandler, command, "StopServerResponse");

            StopServerResponse stopResponse = JsonConvert.DeserializeObject <StopServerResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(stopResponse, new StopServerResult[] { StopServerResult.SERVER_STOPPED, StopServerResult.SERVER_KILLED });

            command = new Command("StopServer", serverSettingTwo);
            await TestHelper.ExecuteCommandAndAwaitCommandResponse(webSocketTwo, webSocketHandlerTwo, command, "StopServerResponse");

            stopResponse = JsonConvert.DeserializeObject <StopServerResponse>(webSocketHandlerTwo.ReceivedCommand.CommandData.ToString());
            TestHelper.ValiateResponse(stopResponse, new StopServerResult[] { StopServerResult.SERVER_STOPPED, StopServerResult.SERVER_KILLED });
        }
        public async Task StartServerAndConnectToTelnet()
        {
            ClientWebSocket  webSocket        = new ClientWebSocket();
            WebSocketHandler webSocketHandler = new WebSocketHandler(webSocket);
            await webSocket.ConnectAsync(new Uri("ws://localhost:80/ws"), CancellationToken.None);

            await TestHelper.Login("User", "Passwort1$", webSocket, webSocketHandler);

            ServerSetting serverSettings = TestHelper.GenerateNewServerSetting();
            Command       command        = new Command("AddServerSetting", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ModifySettingsResponse modifyResponse = JsonConvert.DeserializeObject <ModifySettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(modifyResponse, ModifySettingsResult.SETTING_ADDED);

            command = new Command("GetServerSettingsOfLoggedInUser", null);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            GetSettingsResponse getResponse = JsonConvert.DeserializeObject <GetSettingsResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(getResponse, GetSettingsResult.OK);

            bool foundServerSetting = false;

            foreach (var item in getResponse.ServerSettings)
            {
                if (serverSettings.WorldGenSeed == item.WorldGenSeed)
                {
                    serverSettings     = item;
                    foundServerSetting = true;
                    break;
                }
            }
            if (!foundServerSetting)
            {
                Assert.Fail("Added ServerSettingsId not found in response");
            }

            command = new Command("StartServer", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            StartServerResponse startResponse = JsonConvert.DeserializeObject <StartServerResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(startResponse, StartServerResult.SERVER_STARTED);

            command = new Command("ConnectTelnet", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitResponse(webSocket, webSocketHandler, command);

            ConnectTelnetResponse connectResponse = JsonConvert.DeserializeObject <ConnectTelnetResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(connectResponse, ConnectTelnetResult.OK);

            byte[] buffer = new byte[1024 * 4];
            int    receivedTelnetMessages = 0;

            for (int i = 0; receivedTelnetMessages < 1; i++)
            {
                await webSocketHandler.ExtractCompleteMessage(buffer);

                if (webSocketHandler.ReceivedCommand.CommandName == "OnTelnetReceived")
                {
                    Console.WriteLine(webSocketHandler.ReceivedCommand.CommandData.ToString());
                    Trace.Write(webSocketHandler.ReceivedCommand.CommandData.ToString());
                    receivedTelnetMessages++;
                }
                else
                {
                    Console.WriteLine("*** NO TELNET MESSAGE ***");
                }
            }

            command = new Command("StopServer", serverSettings);
            await TestHelper.ExecuteCommandAndAwaitCommandResponse(webSocket, webSocketHandler, command, "StopServerResponse");

            StopServerResponse stopResponse = JsonConvert.DeserializeObject <StopServerResponse>(webSocketHandler.ReceivedCommand.CommandData.ToString());

            TestHelper.ValiateResponse(stopResponse, new StopServerResult[] { StopServerResult.SERVER_STOPPED, StopServerResult.SERVER_KILLED });
        }