public string DrainEnergyTank(
            int character_id,
            int energy_tank_id)
        {
            CharacterDrainEnergyTankResponse response = new CharacterDrainEnergyTankResponse();

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

                if (requestProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    response.event_list = requestProcessor.ResultEventList;
                    response.result     = SuccessMessages.GENERAL_SUCCESS;
                }
                else
                {
                    response.event_list = new GameEvent[] { };
                }
            }

            return(JSONUtilities.SerializeJSONResponse <BasicResponse>(response));
        }
Пример #2
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));
        }
Пример #3
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));
        }
Пример #4
0
        public string AccountLoginRequest(string username, string password)
        {
            BasicResponse loginResponse = new BasicResponse();

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

                AccountLoginRequestProcessor loginProcessor =
                    new AccountLoginRequestProcessor(username, password);

                if (loginProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        this.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.ALREADY_LOGGED_IN;
            }

            return(JSONUtilities.SerializeJSONResponse <BasicResponse>(loginResponse));
        }
Пример #5
0
        public string PingCharacter(int character_id)
        {
            GamePongResponse response = new GamePongResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionOwnsCharacter(Session, character_id, out response.result))
            {
                PingCharacterRequestProcessor pingProcessor = new PingCharacterRequestProcessor(character_id);

                if (pingProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    response.event_list = pingProcessor.ResultGameEvents;
                    response.result     = SuccessMessages.GENERAL_SUCCESS;
                }
                else
                {
                    response.event_list = new GameEvent[] { };
                }
            }


            return(JSONUtilities.SerializeJSONResponse <GamePongResponse>(response));
        }
Пример #6
0
        public string MoveCharacter(
            int character_id,
            float x,
            float y,
            float z,
            float angle)
        {
            CharacterMoveResponse response = new CharacterMoveResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionOwnsCharacter(Session, character_id, out response.result))
            {
                MoveRequestProcessor requestProcessor =
                    new MoveRequestProcessor(
                        character_id,
                        new Point3d(x, y, z),
                        angle);

                if (requestProcessor.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    response.event_list = requestProcessor.ResultEventList;
                    response.result     = SuccessMessages.GENERAL_SUCCESS;
                }
                else
                {
                    response.event_list = new GameEvent[] { };
                }
            }

            return(JSONUtilities.SerializeJSONResponse <CharacterMoveResponse>(response));
        }
Пример #7
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));
        }
Пример #8
0
        public string AccountResetPasswordRequest(string username)
        {
            BasicResponse response = new BasicResponse();

            //TODO Implement reset password request

            return(JSONUtilities.SerializeJSONResponse <BasicResponse>(response));
        }
Пример #9
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));
        }
Пример #10
0
        public string AccountEmailChangeRequest(string username, string newEmailAddress)
        {
            BasicResponse response = new BasicResponse();

            //TODO Implement Email change request

            return(JSONUtilities.SerializeJSONResponse <BasicResponse>(response));
        }
Пример #11
0
        public string AccountDeleteRequest(string username)
        {
            BasicResponse response = new BasicResponse();

            //TODO: Implement AccountDeleteRequest

            return(JSONUtilities.SerializeJSONResponse <BasicResponse>(response));
        }
Пример #12
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));
        }
Пример #13
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));
        }
Пример #14
0
        public string GetGameList()
        {
            GameListResponse         response         = new GameListResponse();
            GameListRequestProcessor requestProcessor = new GameListRequestProcessor();

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

            return(JSONUtilities.SerializeJSONResponse <GameListResponse>(response));
        }
Пример #15
0
        public string WorldGetFullGameStateRequest(
            int character_id)
        {
            WorldGetFullGameStateResponse response = new WorldGetFullGameStateResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionOwnsCharacter(Session, character_id, out response.result))
            {
                FullGameStateRequestProcessor fullGameRequest = new FullGameStateRequestProcessor(character_id);

                if (fullGameRequest.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    // IRC Details
                    response.irc_enabled            = fullGameRequest.IrcEnabled;
                    response.irc_server             = fullGameRequest.IrcServer;
                    response.irc_port               = fullGameRequest.IrcPort;
                    response.irc_encryption_key     = fullGameRequest.IrcEncryptionKey;
                    response.irc_encryption_enabled = fullGameRequest.IrcEncryptionEnabled;

                    // Character data for all Characters in the game
                    response.characters = fullGameRequest.Characters;

                    // List of events relevant to the requesting character since they last logged in
                    response.event_list = fullGameRequest.EventList;

                    // Room Data for the room that requesting player is in
                    response.room_x      = fullGameRequest.MyRoomKey.x;
                    response.room_y      = fullGameRequest.MyRoomKey.y;
                    response.room_z      = fullGameRequest.MyRoomKey.z;
                    response.world_x     = fullGameRequest.MyRoomWorldPosition.x;
                    response.world_y     = fullGameRequest.MyRoomWorldPosition.y;
                    response.world_z     = fullGameRequest.MyRoomWorldPosition.z;
                    response.portals     = fullGameRequest.Portals;
                    response.mobs        = fullGameRequest.Mobs;
                    response.energyTanks = fullGameRequest.EnergyTanks;
                    response.data        = fullGameRequest.StaticRoomData;

                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return(JSONUtilities.SerializeJSONResponse <WorldGetFullGameStateResponse>(response));
        }
Пример #16
0
        public string GetCharacterFullState(int character_id)
        {
            CharacterStateResponse response = new CharacterStateResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result))
            {
                if (CharacterQueries.GetFullCharacterState(
                        ApplicationConstants.CONNECTION_STRING,
                        character_id,
                        out response.character_state,
                        out response.result))
                {
                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return(JSONUtilities.SerializeJSONResponse <CharacterStateResponse>(response));
        }
Пример #17
0
        public string GetCharacterList(string username)
        {
            CharacterListResponse response = new CharacterListResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionLoggedInAsUser(Session, username, out response.result))
            {
                if (CharacterQueries.GetAccountCharacterList(
                        ApplicationConstants.CONNECTION_STRING,
                        RestUtilities.GetSessionAccountID(Session),
                        out response.character_list,
                        out response.result))
                {
                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return(JSONUtilities.SerializeJSONResponse <CharacterListResponse>(response));
        }
Пример #18
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));
        }
Пример #19
0
        public string GetCharacterPosition(
            int character_id)
        {
            CharacterGetPositionResponse response = new CharacterGetPositionResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result) &&
                RestUtilities.ValidateJSONRequestSessionOwnsCharacter(Session, character_id, out response.result))
            {
                RoomKey roomKey = null;

                float response_x     = 0.0f;
                float response_y     = 0.0f;
                float response_z     = 0.0f;
                float response_angle = 0.0f;

                if (!CharacterQueries.GetCharacterPosition(
                        ApplicationConstants.CONNECTION_STRING,
                        character_id,
                        out roomKey,
                        out response_x,
                        out response_y,
                        out response_z,
                        out response_angle))
                {
                    response.x       = (double)response_x;
                    response.y       = (double)response_y;
                    response.z       = (double)response_z;
                    response.angle   = (double)response_angle;
                    response.game_id = -1;
                    response.room_x  = 0;
                    response.room_y  = 0;
                    response.room_z  = 0;
                    response.angle   = 0;
                    response.result  = ErrorMessages.DB_ERROR;
                }
            }

            return(JSONUtilities.SerializeJSONResponse <CharacterGetPositionResponse>(response));
        }
Пример #20
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));
        }
Пример #21
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));
        }
Пример #22
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));
        }
Пример #23
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));
        }
Пример #24
0
        public string GetRoomData(
            int game_id,
            int room_x,
            int room_y,
            int room_z)
        {
            WorldGetRoomDataResponse response = new WorldGetRoomDataResponse();

            if (RestUtilities.ValidateJSONRequestHasAuthenticatedSession(Session, out response.result))
            {
                RoomRequestProcessor roomRequest =
                    new RoomRequestProcessor(new RoomKey(game_id, room_x, room_y, room_z));

                if (roomRequest.ProcessRequest(
                        ApplicationConstants.CONNECTION_STRING,
                        Application,
                        out response.result))
                {
                    // Room Data for the room that requesting player is in
                    response.room_x      = roomRequest.RoomKey.x;
                    response.room_y      = roomRequest.RoomKey.y;
                    response.room_z      = roomRequest.RoomKey.z;
                    response.world_x     = roomRequest.RoomWorldPosition.x;
                    response.world_y     = roomRequest.RoomWorldPosition.y;
                    response.world_z     = roomRequest.RoomWorldPosition.z;
                    response.portals     = roomRequest.Portals;
                    response.mobs        = roomRequest.Mobs;
                    response.energyTanks = roomRequest.EnergyTanks;
                    response.data        = roomRequest.StaticRoomData;

                    response.result = SuccessMessages.GENERAL_SUCCESS;
                }
            }

            return(JSONUtilities.SerializeJSONResponse <WorldGetRoomDataResponse>(response));
        }