Example #1
0
        // -------------------------------------------------------------------------------
        // RequestUserRegister
        // @Client
        // -------------------------------------------------------------------------------
        protected override bool RequestUserRegister(NetworkConnection conn, string userName, string password, string usermail)
        {
            if (!base.RequestUserRegister(conn, userName, password, usermail))
            {
                return(false);
            }

            ClientMessageRequestUserRegister message = new ClientMessageRequestUserRegister
            {
                username = userName,
                password = Tools.GenerateHash(name, password),
                email    = usermail,
                deviceid = Tools.GetDeviceId
            };

            conn.Send(message);

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

            if (DatabaseManager.singleton.TryUserRegister(msg.username, msg.password, msg.email, msg.deviceid))
            {
                DatabaseManager.singleton.SaveDataUser(msg.username, false);
                message.text = systemText.userRegisterSuccess;
            }
            else
            {
                message.text    = systemText.userRegisterFailure;
                message.success = false;
            }

            conn.Send(message);
        }
        // -------------------------------------------------------------------------------
        // OnClientMessageRequestUserRegister
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Event <c>OnClientMessageRequestUserRegister</c>.
        /// Triggered when the server receives a user registration request from the client.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        void OnClientMessageRequestUserRegister(NetworkConnection conn, ClientMessageRequestUserRegister msg)
        {
            ServerMessageResponseUserRegister message = new ServerMessageResponseUserRegister
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };

            if (DatabaseManager.singleton.TryUserRegister(msg.username, msg.password, msg.email, msg.deviceid))
            {
                RegisterUser(msg.username);
                message.text = systemText.userRegisterSuccess;
            }
            else
            {
                message.text    = systemText.userRegisterFailure;
                message.success = false;

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

            conn.Send(message);
        }