Exemplo n.º 1
0
        public static string ToJSONString(List <IncomeStatistics> listData)
        {
            try
            {
                string jsonStr = "";

                jsonStr += "{";
                jsonStr += "\"message\": \"Okay\",";
                jsonStr += "\"data\": [";
                for (int i = 0, lenght = listData.Count; i < lenght; i++)
                {
                    jsonStr += "[";

                    long ticks = JSONUtilities.GetJavascriptTimestamp(listData[i].OrderDate);
                    jsonStr += ticks + ", ";
                    jsonStr += listData[i].DetailTotal.ToString();
                    jsonStr += "]";
                    if (i < lenght - 1)
                    {
                        jsonStr += ", ";
                    }
                }


                jsonStr += "]";

                jsonStr += "}";

                return(jsonStr);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes the indicated macro.
        /// </summary>
        /// <param name="macro"></param>
        private void RemoveMacro(Macro macro, bool save = true)
        {
            if (macro != null && tagService.AllTags.Tags != null)
            {
                foreach (Tag tag in tagService.AllTags.Tags)
                {
                    if (tag.Macros.Any(m => m.Equals(macro)))
                    {
                        tag.Macros.Remove(macro);
                        break;
                    }
                }
            }

            if (macro == null)
            {
                Messages.ShowWarningMessage($"The macro '{macro.Name}' was not found", "Not found");
            }
            else if (tagService.AllTags.Tags == null)
            {
                Messages.ShowWarningMessage($"The tag from the macro '{macro}' was not found", "Tag not found");
            }

            if (save)
            {
                JSONUtilities.Write(tagService.AllTags);
                RefreshMacrosHandler?.Invoke(macro.Name, null);
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 4
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));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates a macro inside the given tag.
        /// </summary>
        /// <param name="tagName"></param>
        /// <param name="macro"></param>
        /// <param name="save"></param>
        private void CreateMacro(string tagName, Macro macro, bool save = true)
        {
            if (GetMacro(tagName, macro.Name) != null)
            {
                Messages.ShowWarningMessage($"The macro '{macro.Name}' already exists", "Already exists");
            }
            else if (tagService.AllTags.Tags == null)
            {
                Messages.ShowWarningMessage($"The tag '{tagName}' was not found", "Tag not found");
            }
            else
            {
                if (tagService.AllTags.Tags != null)
                {
                    foreach (Tag tag in tagService.AllTags.Tags)
                    {
                        if (tag.Name.Equals(tagName))
                        {
                            if (tag.Macros == null)
                            {
                                tag.Macros = new List <Macro>();
                            }
                            tag.Macros.Add(macro);
                            break;
                        }
                    }
                }

                if (save)
                {
                    JSONUtilities.Write(tagService.AllTags);
                    RefreshMacrosHandler?.Invoke(null, null);
                }
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 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));
        }
        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));
        }
Exemplo n.º 9
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));
        }
Exemplo n.º 10
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));
        }
Exemplo n.º 11
0
        public string AccountResetPasswordRequest(string username)
        {
            BasicResponse response = new BasicResponse();

            //TODO Implement reset password request

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

            //TODO Implement Email change request

            return(JSONUtilities.SerializeJSONResponse <BasicResponse>(response));
        }
Exemplo n.º 13
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));
        }
Exemplo n.º 14
0
        public string AccountDeleteRequest(string username)
        {
            BasicResponse response = new BasicResponse();

            //TODO: Implement AccountDeleteRequest

            return(JSONUtilities.SerializeJSONResponse <BasicResponse>(response));
        }
Exemplo n.º 15
0
        /// <summary>
        /// Removes the original macro and creates the new one inside the given tag.
        /// </summary>
        /// <param name="originalMacroName"></param>
        /// <param name="tagNameForNewMacro"></param>
        /// <param name="newMacro"></param>
        /// <param name="save"></param>
        private void EditMacro(Macro originalMacro, string tagNameForNewMacro, Macro newMacro, bool save = true)
        {
            RemoveMacro(originalMacro, false);
            CreateMacro(tagNameForNewMacro, newMacro, false);

            if (save)
            {
                JSONUtilities.Write(tagService.AllTags);
                RefreshMacrosHandler?.Invoke(null, null);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Removes the original tag and creates the new one.
        /// </summary>
        /// <param name="originalTag"></param>
        /// <param name="tag"></param>
        /// <param name="save"></param>
        private void EditTag(Tag originalTag, Tag tag, bool save = true)
        {
            RemoveTag(originalTag, false);
            CreateTag(tag, false);

            if (save)
            {
                JSONUtilities.Write(AllTags);
                refreshTagsHandler?.Invoke(null, null);
            }
        }
Exemplo n.º 17
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));
        }
Exemplo n.º 18
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));
        }
Exemplo n.º 19
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));
        }
Exemplo n.º 20
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));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Removes the indicated tag.
        /// </summary>
        /// <param name="tag"></param>
        private void RemoveTag(Tag tag, bool save)
        {
            if (tag == null)
            {
                Messages.ShowWarningMessage($"The tag '{tag.Name}' was not found", "Not found");
            }
            else
            {
                AllTags.Tags.Remove(tag);

                if (save)
                {
                    JSONUtilities.Write(AllTags);
                    refreshTagsHandler?.Invoke(tag.Name, null);
                }
            }
        }
Exemplo n.º 22
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));
        }
Exemplo n.º 23
0
        /// <summary>
        /// Returns the macro found with the given name on macroName.
        /// </summary>
        /// <returns></returns>
        private Macro GetMacro()
        {
            if (pressedAndpersand && !string.IsNullOrWhiteSpace(macroName))
            {
                AllTags allTags = JSONUtilities.Read();
                foreach (Tag tag in allTags.Tags)
                {
                    foreach (Macro macro in tag.Macros)
                    {
                        if (macro.Name.ToUpperInvariant().Trim().Equals(macroName.ToUpperInvariant().Trim()))
                        {
                            return(macro);
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 24
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));
        }
Exemplo n.º 25
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));
        }
Exemplo n.º 26
0
        protected string getRequest(out int assignedID)
        {
            int newID = ID;

            assignedID = newID;

            Action <JsonWriter> addData = delegate(JsonWriter writer) {
                writer.WritePropertyName("type");
                writer.WriteValue(Type);
                writer.WritePropertyName("id");
                writer.WriteValue(newID);
                writer.WritePropertyName("content");
                writer.WriteStartObject();
                writer.WritePropertyName("device");
                writer.WriteValue(Device);
                writer.WritePropertyName("action");
                writer.WriteValue(Action);
                writer.WritePropertyName("parameters");
                writer.WriteStartArray();
                if (ParamStrings.Count > 0)
                {
                    foreach (string param in ParamStrings)
                    {
                        writer.WriteValue(param);
                    }
                }
                else
                {
                    foreach (int param in ParamInt)
                    {
                        writer.WriteValue(param);
                    }
                }
                writer.WriteEndArray();
                writer.WriteEndObject();
            };

            string result = JSONUtilities.getJSON(addData);

            return(result);
        }
Exemplo n.º 27
0
        /// <summary>
        /// Creates an empty tag.
        /// </summary>
        /// <param name="tag"></param>
        /// <param name="save"></param>
        private void CreateTag(Tag tag, bool save = true)
        {
            if (GetTag(tag.Name) == null)
            {
                if (AllTags.Tags == null)
                {
                    AllTags.Tags = new List <Tag>();
                }
                AllTags.Tags.Add(tag);

                if (save)
                {
                    JSONUtilities.Write(AllTags);
                    refreshTagsHandler?.Invoke(null, null);
                }
            }
            else
            {
                Messages.ShowWarningMessage($"The tag '{tag.Name}' already exists", "Already exists");
            }
        }
Exemplo n.º 28
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));
        }
Exemplo n.º 29
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));
        }
Exemplo n.º 30
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));
        }