// -------------------------------------------------------------------------------
        // OnClientMessageRequestUserDelete
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Event <c>OnClientMessageRequestUserDelete</c>.
        /// Triggered when the server receives a user deletion request.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        void OnClientMessageRequestUserDelete(NetworkConnection conn, ClientMessageRequestUserDelete msg)
        {
            ServerMessageResponseUserDelete message = new ServerMessageResponseUserDelete
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };

            if (!GetIsUserLoggedIn(msg.username) && DatabaseManager.singleton.TryUserDelete(msg.username, msg.password))
            {
                message.text = systemText.userDeleteSuccess;

                debug.LogFormat(this.name, nameof(OnClientMessageRequestUserDelete), conn.Id(), "Success");                 //DEBUG
            }
            else
            {
                message.text    = systemText.userDeleteFailure;
                message.success = false;

                debug.LogFormat(this.name, nameof(OnClientMessageRequestUserDelete), conn.Id(), "DENIED");                 //DEBUG
            }

            conn.Send(message);
        }
Example #2
0
        // -------------------------------------------------------------------------------
        // RequestUserDelete
        // @Client
        // -------------------------------------------------------------------------------
        protected override bool RequestUserDelete(NetworkConnection conn, string userName, string password, int action = 1)
        {
            if (!base.RequestUserDelete(conn, userName, password))
            {
                return(false);
            }

            ClientMessageRequestUserDelete message = new ClientMessageRequestUserDelete
            {
                username = userName,
                password = Tools.GenerateHash(name, password)
            };

            conn.Send(message);

            return(true);
        }
        // -------------------------------------------------------------------------------
        // RequestUserDelete
        // @Client
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Protected override function <c>RequestUserDelete</c> that returns a boolean.
        /// Sends a user deletion request to the server.
        /// Checks whether the user deletion request is valid and can be sent to the server.
        /// Returns a boolean detailing whether the request was sent or not.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="action"></param>
        /// <returns> Returns a boolean detailing whether the request was sent to the server. </returns>
        protected override bool RequestUserDelete(NetworkConnection conn, string userName, string password, int action = 1)
        {
            if (!base.RequestUserDelete(conn, userName, password))
            {
                return(false);
            }

            ClientMessageRequestUserDelete message = new ClientMessageRequestUserDelete
            {
                username = userName,
                password = Tools.GenerateHash(name, password)
            };

            conn.Send(message);

            debug.LogFormat(this.name, nameof(RequestUserDelete), conn.Id(), userName);             //DEBUG

            return(true);
        }
        // -------------------------------------------------------------------------------
        // OnClientMessageRequestUserDelete
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        void OnClientMessageRequestUserDelete(NetworkConnection conn, ClientMessageRequestUserDelete msg)
        {
            ServerMessageResponseUserDelete message = new ServerMessageResponseUserDelete
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };

            if (DatabaseManager.singleton.TryUserDelete(msg.username, msg.password))
            {
                message.text = systemText.userDeleteSuccess;
            }
            else
            {
                message.text    = systemText.userDeleteFailure;
                message.success = false;
            }

            conn.Send(message);
        }