Esempio n. 1
0
        // ========================== MESSAGE HANDLERS - AUTH ============================

        // -------------------------------------------------------------------------------
        // OnAuthRequestMessage
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        void OnClientMessageRequestAuth(NetworkConnection conn, ClientMessageRequestAuth msg)
        {
            ServerMessageResponseAuth message = new ServerMessageResponseAuth
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };

            if (checkApplicationVersion && msg.clientVersion != Application.version)
            {
                message.text    = systemText.versionMismatch;
                message.success = false;
            }
            else
            {
                base.OnServerAuthenticated.Invoke(conn);
            }

            conn.Send(message);

            if (!message.success)
            {
                conn.isAuthenticated = false;
                conn.Disconnect();
            }
        }
Esempio n. 2
0
        // ========================== MESSAGE HANDLERS - AUTH ============================

        // -------------------------------------------------------------------------------
        void OnServerMessageResponseAuth(NetworkConnection conn, ServerMessageResponseAuth msg)
        {
            // -- show popup if error message is not empty
            if (!String.IsNullOrWhiteSpace(msg.text))
            {
                UIPopupConfirm.singleton.Init(msg.text);
            }

            // -- disconnect and un-authenticate if anything went wrong
            if (!msg.success || msg.causesDisconnect)
            {
                conn.isAuthenticated = false;
                conn.Disconnect();
                NetworkManager.singleton.StopClient();
            }

            // -- ready client
            if (msg.success && !msg.causesDisconnect)
            {
                CancelInvoke();
                base.OnClientAuthenticated.Invoke(conn);
                UIWindowAuth.singleton.Hide();
                UIWindowMain.singleton.Show();
            }
        }
        void OnClientMessageRequestAuth(NetworkConnection conn, ClientMessageRequestAuth msg)
        {
            ServerMessageResponseAuth message = new ServerMessageResponseAuth
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };
            bool portalChecked = true;

            if (GetComponent <ZoneManager>() != null && !Getcomponent <ZoneManager>().GetIsMainZone)
            {
                portalChecked = false;
            }
            if ((checkApplicationVersion && msg.clientVersion != Application.version) || !portalChecked)
            {
                message.text    = systemText.versionMismatch;
                message.success = false;
            }
            else
            {
                base.OnServerAuthenticated.Invoke(conn);
                debug.LogFormat(this.name, nameof(OnClientMessageRequestAuth), conn.ID(), "Authenticated");
            }

            conn.Send(message);
            if (!message.success)
            {
                conn.isAuthenticated = false;
                conn.Disconnect();
                debug.LogFormat(this.name, nameof(OnClientMessageRequestAuth), conn.ID(), "DENIED");
            }
        }
        // ========================== MESSAGE HANDLERS - AUTH ============================

        // -------------------------------------------------------------------------------
        /// <summary>
        /// Event <c>OnServerMessageResponseAuth</c>.
        /// Is triggered when the server returns a authentication response message.
        /// Either authenicates the client, disconnects the client and returns an error message if there is one.
        /// If the authentication was succesful the client is readied.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        void OnServerMessageResponseAuth(NetworkConnection conn, ServerMessageResponseAuth msg)
        {
            // -- show popup if error message is not empty
            if (!String.IsNullOrWhiteSpace(msg.text))
            {
                UIPopupConfirm.singleton.Init(msg.text);
            }

            // -- disconnect and un-authenticate if anything went wrong
            if (msg.causesDisconnect)//!msg.success ||
            {
                conn.isAuthenticated = false;
                conn.Disconnect();
                NetworkManager.singleton.StopClient();

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

            // -- ready client
            if (msg.success)// && !msg.causesDisconnect
            {
                CancelInvoke();
                base.OnClientAuthenticated.Invoke(conn);

                UIWindowAuth.singleton.Hide();
                UIWindowMain.singleton.Show();

                debug.LogFormat(this.name, nameof(OnServerMessageResponseAuth), conn.Id(), "Authenticated");                 //DEBUG
            }
        }
Esempio n. 5
0
        // ========================== MESSAGE HANDLERS - AUTH ============================

        // -------------------------------------------------------------------------------
        // OnAuthRequestMessage
        // Direction: @Client -> @Server
        // Execution: @Server
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Event <c>OnClientMessageRequestAuth</c>.
        /// Triggered when the server received an authentiation request from a client.
        /// The event attempts to authenticate the client.
        /// Occurs on the server.
        /// </summary>
        /// <param name="conn"></param>
        /// <param name="msg"></param>
        void OnClientMessageRequestAuth(NetworkConnection conn, ClientMessageRequestAuth msg)
        {
            ServerMessageResponseAuth message = new ServerMessageResponseAuth
            {
                success          = true,
                text             = "",
                causesDisconnect = false
            };

            // -- Check for Network Portals
            // This prevents players from logging into a Network Zone. Directly logging
            // into a zone should not be possible and can only be done by warping to
            // that zone instead.
            bool portalChecked = true;

            if (GetComponent <ZoneManager>() != null && !GetComponent <ZoneManager>().GetIsMainZone)
            {
                portalChecked = false;
            }

            if ((checkApplicationVersion && msg.clientVersion != Application.version) || !portalChecked)
            {
                message.text    = systemText.versionMismatch;
                message.success = false;
            }
            else
            {
                base.OnServerAuthenticated.Invoke(conn);                                                    //EVENT
                debug.LogFormat(this.name, nameof(OnClientMessageRequestAuth), conn.Id(), "Authenticated"); //DEBUG
            }

            conn.Send(message);

            if (!message.success)
            {
                conn.isAuthenticated = false;
                conn.Disconnect();

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