コード例 #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();
            }
        }
コード例 #2
0
        // -------------------------------------------------------------------------------
        // ClientAuthenticate
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Public Method <c>ClientAuthenticate</c>
        /// Sends a authentication request message from the client to the server.
        /// </summary>
        public void ClientAuthenticate()
        {
            ClientMessageRequestAuth authRequestMessage = new ClientMessageRequestAuth
            {
                clientVersion = Application.version
            };

            NetworkClient.Send(authRequestMessage);
        }
コード例 #3
0
        // -------------------------------------------------------------------------------
        // ClientAuthenticate
        // @Client -> @Server
        // -------------------------------------------------------------------------------
        /// <summary>
        /// Public Method <c>ClientAuthenticate</c>
        /// Sends a authentication request message from the client to the server.
        /// </summary>
        public void ClientAuthenticate()
        {
            ClientMessageRequestAuth msg = new ClientMessageRequestAuth
            {
                clientVersion = Application.version
            };

            NetworkClient.Send(msg);

            debug.LogFormat(this.name, nameof(ClientAuthenticate)); //DEBUG
        }
コード例 #4
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
            }
        }