private static StartServerResponse StartServerByServerSettings(ServerSettings serverSettings) { StartServerResponse response; try { //serverSettings.ServerConfigFilepath = serverSettings.ServerConfigFilepath.Replace(".xml", serverSettings.WorldGenSeed + ".xml"); serverSettings.ServerConfigFilepath = serverSettings.ServerConfigFilepath.Replace(".xml", RandomString(12) + ".xml"); //todo set ports range from settings serverSettings.ServerPort = GetFreePortInRange(26903, 26909); serverSettings.TelnetPort = GetFreePortInRange(8083, 8089); if (serverSettings.ServerPort == 0 || serverSettings.TelnetPort == 0) { return(new StartServerResponse(StartServerResult.NO_FREE_PORT)); } string sDaysToDiePath = SDaysToDiePath; if (serverSettings.GameMod != "" && serverSettings.GameMod != "Default") { sDaysToDiePath = GetGameFilesPathByGameMod(serverSettings.GameMod); Console.WriteLine("Start Server from Path: '" + sDaysToDiePath + "'"); } serverSettings.SaveToFile(sDaysToDiePath + SEP + serverSettings.ServerConfigFilepath); SDaysTDieServersByUserIds.Add(serverSettings.UserUuid, new SDaysTDieServer(sDaysToDiePath, serverSettings)); SDaysTDieServersByUserIds[serverSettings.UserUuid].Start(); response = new StartServerResponse(StartServerResult.SERVER_STARTED); } catch (Exception ex) { Console.WriteLine(ex.ToString()); response = new StartServerResponse(StartServerResult.EXCEPTION); } return(response); }
internal async static Task StartServer(WebSocketHandler webSocketHandler) { StartServerResponse response = await TryStartServer(webSocketHandler); Command command = new Command("StartServerResponse", response); await webSocketHandler.Send(command); }
private static async Task <StartServerResponse> TryStartServer(WebSocketHandler webSocketHandler) { StartServerResponse response = null; ServerSetting serverSetting = JsonConvert.DeserializeObject <ServerSetting>(webSocketHandler.ReceivedCommand.CommandData.ToString()); if (!HasUserStartServerAndUseSettingsRights(webSocketHandler, serverSetting)) { return(new StartServerResponse(StartServerResult.RIGHT_VIOLATION)); } GetSettingsResponse getSettingsResponse = await ServerSettingsHandler.GetServerSettingsByIdAndUser(webSocketHandler, webSocketHandler.User, serverSetting.Id); if (getSettingsResponse.Result != GetSettingsResult.OK) { return(ExtractNotOKGetSettingsResult(response, getSettingsResponse)); } else { return(StartServerBySettingsResponse(getSettingsResponse)); } }
private static StartServerResponse ExtractNotOKGetSettingsResult(StartServerResponse response, GetSettingsResponse getSettingsResponse) { switch (getSettingsResponse.Result) { case GetSettingsResult.RIGHT_VIOLATION: response = new StartServerResponse(StartServerResult.RIGHT_VIOLATION_SERVERSETTING); break; case GetSettingsResult.SETTING_NOT_FOUND: response = new StartServerResponse(StartServerResult.SETTING_NOT_FOUND); break; case GetSettingsResult.EXCEPTION: response = new StartServerResponse(StartServerResult.EXCEPTION); break; default: response = new StartServerResponse(StartServerResult.UNKNOWN_SETTINGS_RESPONSE); break; } return(response); }