Esempio n. 1
0
        public string DeleteCharacter(int character_id)
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionOwnsCharacter(Session, character_id, out response.result))
            {
                CharacterDeleteRequestProcessor requestProcessor =
                    new CharacterDeleteRequestProcessor(
                        RestUtilities.GetSessionAccountID(Session),
                        character_id);

                if (requestProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    Session["CharacterIDs"] = requestProcessor.RemainingCharacterIDs;

                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 2
0
        public string CreateCharacter(
            string name,
            int archetype,
            int gender,
            int picture_id)
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result))
            {
                int archetypeCount = EnumUtilities.GetEnumValues<GameConstants.eArchetype>().Count();
                CharacterCreateRequestProcessor requestProcessor =
                    new CharacterCreateRequestProcessor(
                        RestUtilities.GetSessionAccountID(Session),
                        name,
                        (gender > 0) ? GameConstants.eGender.Male : GameConstants.eGender.Female,
                        (GameConstants.eArchetype)Math.Max(Math.Min(archetype, archetypeCount - 1), 0),
                        picture_id);

                if (requestProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    Session["CharacterIDs"] = requestProcessor.AccountCharacterIDs;

                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 3
0
        public string AccountDeleteRequest(string username)
        {
            BasicResponse response = new BasicResponse();

            //TODO: Implement AccountDeleteRequest

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 4
0
        public string AccountEmailChangeRequest(string username, string newEmailAddress)
        {
            BasicResponse response = new BasicResponse();

            //TODO Implement Email change request

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 5
0
        public string AccountChangePasswordRequest(string username, string oldPassword, string newPassword)
        {
            BasicResponse response = new BasicResponse();

            //TODO Implement account change password request

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 6
0
        public string DebugClearCachedWorld(int game_id)
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionHasAdminOpsLevel(Session, out response.result))
            {
                WorldCache.ClearWorld(Application, game_id);
                WorldBuilderCache.ClearWorldBuilder(Application);

                response.result = SuccessMessages.GENERAL_SUCCESS;
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 7
0
        public string BindCharacterToGame(
            int character_id,
            int game_id)
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionOwnsCharacter(Session, character_id, out response.result))
            {
                BindCharacterToGameRequestProcessor requestProcessor =
                    new BindCharacterToGameRequestProcessor(character_id, game_id);

                if (requestProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 8
0
        public string AccountCreateRequest(string username, string password, string emailAddress)
        {
            BasicResponse response = new BasicResponse();

            string webServiceURL =
                (ApplicationConstants.IsDebuggingEnabled)
                    ? ApplicationConstants.ACCOUNT_DEBUG_WEB_SERVICE_URL
                    : ApplicationConstants.ACCOUNT_WEB_SERVICE_URL;

            CreateAccountRequestProcessor requestProcessor =
                new CreateAccountRequestProcessor(
                    username,
                    password,
                    emailAddress,
                    webServiceURL);

            requestProcessor.ProcessRequest(
                    ApplicationConstants.CONNECTION_STRING,
                    Application,
                    out response.result);

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 9
0
        public string CreateGame(
            string game_name,
            int dungeon_size,
            int dungeon_difficulty,
            bool irc_enabled,
            string irc_server,
            int irc_port,
            bool irc_encryption_enabled)
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result))
            {
                int account_id = RestUtilities.GetSessionAccountID(Session);

                GameCreateRequestProcessor requestProcessor =
                    new GameCreateRequestProcessor(
                        RestUtilities.GetSessionAccountID(Session),
                        game_name,
                        (GameConstants.eDungeonSize)dungeon_size,
                        (GameConstants.eDungeonDifficulty)dungeon_difficulty,
                        irc_enabled,
                        irc_server,
                        irc_port,
                        irc_encryption_enabled);

                if (requestProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 10
0
        public string DeleteGame(
            int game_id)
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result))
            {
                GameDeleteRequestProcessor requestProcessor =
                    new GameDeleteRequestProcessor(
                        RestUtilities.GetSessionAccountID(Session),
                        game_id);

                if (requestProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 11
0
        public string RecreateDatabase()
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionHasAdminOpsLevel(Session, out response.result))
            {
                StringBuilder result = new StringBuilder();
                Logger logger = new Logger((string message) => { result.AppendLine(message); });

                try
                {
                    string constructionResult = "";
                    DatabaseManagerConfig dbConfig =
                        new DatabaseManagerConfig(
                            ApplicationConstants.CONNECTION_STRING,
                            ApplicationConstants.MOBS_DIRECTORY,
                            ApplicationConstants.MAPS_DIRECTORY);
                    DatabaseManager dbManager = new DatabaseManager(dbConfig);

                    if (!dbManager.ReCreateDatabase(logger, out constructionResult))
                    {
                        logger.LogError(constructionResult);
                    }
                }
                catch (System.Exception ex)
                {
                    logger.LogError(string.Format("Failed to recreate database: {0}", ex.Message));
                }

                response.result = result.ToString();
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 12
0
        public string SetAccountOpsLevel(int account_id, int ops_level)
        {
            BasicResponse response = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionHasAdminOpsLevel(Session, out response.result))
            {
                if (AccountQueries.SetAccountOpsLevel(
                        ApplicationConstants.CONNECTION_STRING,
                        account_id,
                        (DatabaseConstants.OpsLevel)ops_level,
                        out response.result))
                {
                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 13
0
        public string AccountResetPasswordRequest(string username)
        {
            BasicResponse response = new BasicResponse();

            //TODO Implement reset password request

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(response);
        }
Esempio n. 14
0
        public string AccountPlainTextLoginRequest(string username, string password)
        {
            BasicResponse loginResponse = new BasicResponse();

            if (RestUtilities.GetSessionUsername(Session) == null)
            {
                // Initially, we are not authenticated yet
                Session["Authenticated"] = false;

                if (username.Length > 0 && password.Length > 0)
                {
                    string hashedPassword = AccountQueries.ClientPasswordHash(password);

                    AccountLoginRequestProcessor loginProcessor =
                        new AccountLoginRequestProcessor(username, hashedPassword);

                    if (loginProcessor.ProcessRequest(
                            ApplicationConstants.CONNECTION_STRING,
                            Application,
                            out loginResponse.result))
                    {
                        Session["Authenticated"] = true;
                        Session["AccountId"] = loginProcessor.AccountID;
                        Session["OpsLevel"] = loginProcessor.OpsLevel;
                        Session["EmailAddress"] = loginProcessor.EmailAddress;
                        Session["CharacterIDs"] = loginProcessor.AccountCharacterIDs;
                        Session["Username"] = username;

                        loginResponse.result = SuccessMessages.GENERAL_SUCCESS;
                    }
                }
                else
                {
                    loginResponse.result = ErrorMessages.MALFORMED_REQUEST;
                }
            }
            else
            {
                loginResponse.result = ErrorMessages.ALREADY_LOGGED_IN;
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(loginResponse);
        }
Esempio n. 15
0
        public string AccountLogoutRequest(string username)
        {
            BasicResponse logoutResponse = new BasicResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out logoutResponse.result) &&
                RestUtilities.ValidateJSONRequestSessionLoggedInAsUser(Session, username, out logoutResponse.result))
            {
                logoutResponse.result = SuccessMessages.GENERAL_SUCCESS;
                Session.Abandon();
            }

            return JSONUtilities.SerializeJSONResponse<BasicResponse>(logoutResponse);
        }