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

            if (DatabaseManager.singleton.TryPlayerRegister(msg.playerName, msg.userName, msg.prefabName))
            {
                RegisterPlayer(msg.userName, msg.playerName, msg.prefabName);
                message.text = systemText.playerRegisterSuccess;
            }
            else
            {
                message.text    = systemText.playerRegisterFailed;
                message.success = false;

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

            conn.Send(message);
        }
Example #2
0
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Event <c>OnServerMessageResponsePlayerRegister</c>.
        /// Triggered when the client receives a player register response from the server.
        /// Triggers the <c>OnServerMessageResponse</c> event.
        /// Occurs on the client.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        void OnServerMessageResponsePlayerRegister(NetworkConnection conn, ServerMessageResponsePlayerRegister msg)
        {
            if (msg.success)
            {
                playerPreviews.Add(new PlayerPreview {
                    name = msg.playername
                });
                UIWindowPlayerSelect.singleton.UpdatePlayerPreviews(true);
            }

            debug.LogFormat(this.name, nameof(OnServerMessageResponsePlayerRegister), conn.Id(), msg.success.ToString()); //DEBUG

            OnServerMessageResponse(conn, msg);
        }