Пример #1
0
        /// <summary>
        /// Creates the cookie to the player in question
        /// </summary>
        /// <param name="userType">The type of user that is playing</param>
        /// <param name="id">The id of the player in question</param>
        /// <param name="response">The HttpResponseBase used to send something to browser</param>
        /// <param name="request">The HttpRequestBase used to query for the cookie in the browser</param>
        public void CreateCookie(PlayerEntity.UserType userType, int id, HttpResponseBase response, HttpRequestBase request)
        {
            // First, check if the cookie exists
            if (CheckIfCookieExists(request) == true)
            {
                // Just leave

                return;
            }

            // Otherwise, create the cookie
            HttpCookie lutExplorerCookie = new HttpCookie(cookieName);

            // Set the cookie values
            lutExplorerCookie[playerType] = userType.ToString();
            lutExplorerCookie[playerId] = id.ToString();

            // Set the expiration date
            lutExplorerCookie.Expires = DateTime.Now.AddDays(expirationDays);

            // And finally, save the cookie to the browser
            response.Cookies.Add(lutExplorerCookie);
        }
Пример #2
0
        /// <summary>
        /// Tries to create the database entry with the player in question
        /// </summary>
        /// <param name="playerId">The id to be inserted</param>
        /// <param name="playerType">The type of the player</param>
        /// <returns>True if succesful, false if not</returns>
        public bool TryCreateDatabasePlayerEntry(int playerId, PlayerEntity.UserType playerType)
        {
            // First, try to find if the player entity exists
            PlayerEntity playerEntity = DatabaseManager.Instance.FindPlayerEntity(playerType.ToString(), playerId.ToString());
            // If the value is not null (== already exists)
            if (playerEntity != null)
            {
                // Return false, as this cannot be created
                return false;
            }

            // Otherwise, keep on going
            // First, create the new player entity to be stored
            playerEntity = new PlayerEntity(playerType, playerId);

            // Then, store it to the database
            DatabaseManager.Instance.SavePlayer(playerEntity);

            // And finally return true as a mark of success
            return true;
        }