コード例 #1
0
        /// <summary>
        /// Signal that the client connection is ready to enter the game.
        /// <para>This could be for example when a client enters an ongoing game and has finished loading the current scene. The server should respond to the SYSTEM_READY event with an appropriate handler which instantiates the players object for example.</para>
        /// </summary>
        /// <param name="conn">The client connection which is ready.</param>
        /// <returns>True if succcessful</returns>
        public bool Ready(NetworkConnectionToServer conn)
        {
            if (ready)
            {
                Debug.LogError("A connection has already been set as ready. There can only be one.");
                return(false);
            }

            if (LogFilter.Debug)
            {
                Debug.Log("ClientScene.Ready() called with connection [" + conn + "]");
            }

            if (conn != null)
            {
                // Set these before sending the ReadyMessage, otherwise host client
                // will fail in InternalAddPlayer with null readyConnection.
                ready              = true;
                Connection         = conn;
                Connection.isReady = true;

                // Tell server we're ready to have a player object spawned
                conn.Send(new ReadyMessage());

                return(true);
            }
            Debug.LogError("Ready() called with invalid connection object: conn=null");
            return(false);
        }
コード例 #2
0
        public void OnAuthenticated(NetworkConnectionToServer conn)
        {
            // set connection to authenticated
            conn.isAuthenticated = true;

            Authenticated?.Invoke(conn);
        }
コード例 #3
0
 /// <summary>
 /// Called on clients when a scene has completed loaded, when the scene load was initiated by the server.
 /// <para>Scene changes can cause player objects to be destroyed. The default implementation of OnClientSceneChanged in the NetworkManager is to add a player object for the connection if no player object exists.</para>
 /// </summary>
 /// <param name="conn">The network connection that the scene change message arrived on.</param>
 public virtual void OnClientSceneChanged(NetworkConnectionToServer conn)
 {
     // always become ready.
     if (!client.ready)
     {
         client.Ready(conn);
     }
 }
コード例 #4
0
        // called after successful authentication
        void OnClientAuthenticated(NetworkConnectionToServer conn)
        {
            RegisterClientMessages(conn);

            if (LogFilter.Debug)
            {
                Debug.Log("NetworkManager.OnClientAuthenticated");
            }

            // will wait for scene id to come from the server.
            clientLoadedScene = true;
            client.Connection = conn;
        }
コード例 #5
0
        /// <summary>
        /// Called on the client when connected to a server.
        /// <para>The default implementation of this function sets the client as ready and adds a player. Override the function to dictate what happens when the client connects.</para>
        /// </summary>
        /// <param name="conn">Connection to the server.</param>
        private void OnClientAuthenticated(NetworkConnectionToServer connection)
        {
            // OnClientConnect by default calls AddPlayer but it should not do
            // that when we have online/offline scenes. so we need the
            // clientLoadedScene flag to prevent it.
            // Ready/AddPlayer is usually triggered by a scene load completing. if no scene was loaded, then Ready/AddPlayer it here instead.
            if (!client.ready)
            {
                client.Ready(connection);
            }

            client.Send(new AddPlayerMessage());
        }
コード例 #6
0
        internal void ConnectHost(NetworkServer server)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("Client Connect Host to Server");
            }
            connectState = ConnectState.Connected;

            InitializeAuthEvents();

            // create local connection objects and connect them
            (IConnection c1, IConnection c2) = PipeConnection.CreatePipe();

            server.SetLocalConnection(this, c2);
            hostServer = server;
            Connection = new NetworkConnectionToServer(c1);
            RegisterHostHandlers(Connection);
            _ = OnConnected();
        }
コード例 #7
0
        /// <summary>
        /// Connect client to a NetworkServer instance.
        /// </summary>
        /// <param name="uri">Address of the server to connect to</param>
        public async Task ConnectAsync(Uri uri)
        {
            if (LogFilter.Debug)
            {
                Debug.Log("Client Connect: " + uri);
            }

            AsyncTransport transport = Transport;

            if (transport == null)
            {
                transport = GetComponent <AsyncTransport>();
            }

            connectState = ConnectState.Connecting;

            try
            {
                IConnection transportConnection = await transport.ConnectAsync(uri);


                RegisterSpawnPrefabs();
                InitializeAuthEvents();

                // setup all the handlers
                Connection = new NetworkConnectionToServer(transportConnection);
                Time.Reset();

                RegisterMessageHandlers(Connection);
                Time.UpdateClient(this);
                _ = OnConnected();
            }
            catch (Exception)
            {
                connectState = ConnectState.Disconnected;
                throw;
            }
        }
コード例 #8
0
 /// <summary>
 /// Called on client from OnClientAuthenticateInternal when a client needs to authenticate
 /// </summary>
 /// <param name="conn">Connection of the client.</param>
 public virtual void OnClientAuthenticate(NetworkConnectionToServer conn)
 {
     OnClientAuthenticated?.Invoke(conn);
 }
コード例 #9
0
 // This will get more code in the near future
 internal void OnClientAuthenticateInternal(NetworkConnectionToServer conn)
 {
     OnClientAuthenticate(conn);
 }