// -------------------------------------------------------------------------------
        // OnClientMessageRequestPlayerDelete
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Event <c>OnClientMessageRequestPlayerDelete</c>.
        /// Triggered by the server receiving a player deletion request from the client.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        void OnClientMessageRequestPlayerDelete(NetworkConnection conn, ClientMessageRequestPlayerDelete msg)
        {
            ServerMessageResponsePlayerDelete message = new ServerMessageResponsePlayerDelete
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };

            if (DatabaseManager.singleton.TryPlayerDeleteSoft(msg.playerName, msg.userName))
            {
                message.text = systemText.playerDeleteSuccess;

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

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

            conn.Send(message);
        }
Example #2
0
        // -------------------------------------------------------------------------------
        // RequestPlayerDelete
        // @Client
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Protected override function <c>RequestPlayerDelete</c> that returns a boolean.
        /// Sends a player deletion request to the server.
        /// Checks whether the player 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="playerName"></param>
        /// <param name="userName"></param>
        /// <param name="action"></param>
        /// <returns> Returns a boolean detailing whether the request was sent to the server. </returns>
        protected override bool RequestPlayerDelete(NetworkConnection conn, string playerName, string userName, int action = 1)
        {
            if (!base.RequestPlayerDelete(conn, playerName, userName))
            {
                return(false);
            }

            ClientMessageRequestPlayerDelete message = new ClientMessageRequestPlayerDelete
            {
                playername = playerName,
                username   = userName
            };

            conn.Send(message);

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

            return(true);
        }