private static async Task <Command> GetServerSettings(Func <Task <GetSettingsResponse> > getAction, string actionName, WebSocketHandler webSocketHandler, int?ressourceId = null)
 {
     try
     {
         GetSettingsResponse response = null;
         if (RightControl.IsGranted(webSocketHandler.ConnectedUserToken, actionName, "ServerSetting", ressourceId))
         {
             response = await getAction();
         }
         else if (RightControl.IsGranted(webSocketHandler.ConnectedUserToken, actionName + "_" + webSocketHandler.User.Username, "ServerSetting"))
         {
             response = await getAction();
         }
         else
         {
             response = new GetSettingsResponse(GetSettingsResult.RIGHT_VIOLATION, null);
         }
         return(new Command(actionName + "Response", response));
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return(new Command(actionName + "Response", GetSettingsResult.EXCEPTION));
     }
 }
Пример #2
0
        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));
            }
        }
Пример #3
0
        private static StartServerResponse StartServerBySettingsResponse(GetSettingsResponse getSettingsResponse)
        {
            ServerSettings serverSettings = ServerSettings.LoadFromFile <ServerSettings>(SDaysToDiePath + SEP + "serverconfig.xml");

            serverSettings.FromServerSetting(getSettingsResponse.ServerSettings[0]);
            if (IsServerCountOfUserExceeding(serverSettings))
            {
                return(new StartServerResponse(StartServerResult.SERVER_COUNT_OF_USER_EXCEEDING));
            }
            if (IsServerLimitOnMachineReached())
            {
                return(new StartServerResponse(StartServerResult.SERVER_COUNT_OF_MACHINE_EXCEEDING));
            }
            else if (IsServerOfSettingsRunning(serverSettings))
            {
                return(new StartServerResponse(StartServerResult.SERVER_ALREADY_RUNNING));
            }
            else
            {
                return(StartServerByServerSettings(serverSettings));
            }
        }
Пример #4
0
        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);
        }