Ejemplo n.º 1
0
        public void LocalClientActiveTest()
        {
            Assert.That(server.LocalClientActive, Is.False);

            client.ConnectHost(server);

            Assert.That(server.LocalClientActive, Is.True);

            client.Disconnect();
        }
Ejemplo n.º 2
0
        public void IsConnectedTest()
        {
            Assert.That(!client.IsConnected);

            client.ConnectHost(server);

            Assert.That(client.IsConnected);
        }
Ejemplo n.º 3
0
        public void HostMode_IsFlags_Test()
        {
            // start the server
            Transport.activeTransport = Substitute.For <Transport>();
            NetworkServer.Listen(1000);

            // start the client
            NetworkClient.ConnectHost();

            // create a networkidentity+component
            GameObject      gameObject             = new GameObject();
            NetworkIdentity identity               = gameObject.AddComponent <NetworkIdentity>();
            IsClientServerCheckComponent component = gameObject.AddComponent <IsClientServerCheckComponent>();

            // set is as local player
            ClientScene.InternalAddPlayer(identity);

            // spawn it
            NetworkServer.Spawn(gameObject);

            // OnStartServer should have been called. check the flags.
            Assert.That(component.OnStartServer_isClient, Is.EqualTo(true));
            Assert.That(component.OnStartServer_isLocalPlayer, Is.EqualTo(true));
            Assert.That(component.OnStartServer_isServer, Is.EqualTo(true));

            // stop the client
            NetworkClient.Shutdown();
            NetworkServer.RemoveLocalConnection();
            ClientScene.Shutdown();

            // stop the server
            NetworkServer.Shutdown();
            Transport.activeTransport = null;
        }
Ejemplo n.º 4
0
 // fully connect HOST client to local server
 // sets NetworkServer.localConnection / NetworkClient.connection.
 protected void ConnectHostClientBlocking()
 {
     NetworkClient.ConnectHost();
     NetworkClient.ConnectLocalServer();
     UpdateTransport();
     Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));
 }
Ejemplo n.º 5
0
        public void DisconnectInHostMode()
        {
            NetworkClient.ConnectHost();
            Assert.That(NetworkClient.isConnected, Is.True);
            Assert.That(NetworkServer.localConnection, !Is.Null);

            NetworkClient.Disconnect();
            Assert.That(NetworkClient.isConnected, Is.False);
            Assert.That(NetworkServer.localConnection, Is.Null);
        }
Ejemplo n.º 6
0
 public void Setup()
 {
     // start server/client
     NetworkServer.Listen(1);
     NetworkClient.ConnectHost();
     NetworkServer.SpawnObjects();
     NetworkServer.ActivateHostScene();
     NetworkClient.ConnectLocalServer();
     NetworkServer.localConnection.isAuthenticated = true;
     NetworkClient.connection.isAuthenticated      = true;
     NetworkClient.Ready();
 }
Ejemplo n.º 7
0
        public IEnumerator UnitySetUp()
        {
            Transport.activeTransport = new GameObject().AddComponent <MemoryTransport>();

            // start server and wait 1 frame
            NetworkServer.Listen(1);
            yield return(null);

            // connection host and wait 1 frame
            NetworkClient.ConnectHost();
            NetworkClient.ConnectLocalServer();
            yield return(null);
        }
Ejemplo n.º 8
0
        public IEnumerator SetUp() => RunAsync(async() =>
        {
            serverGO = new GameObject();
            serverGO.AddComponent <MockTransport>();
            server = serverGO.AddComponent <NetworkServer>();
            client = serverGO.AddComponent <NetworkClient>();
            await server.ListenAsync();
            client.ConnectHost(server);


            gameObject = new GameObject();
            identity   = gameObject.AddComponent <NetworkIdentity>();
        });
Ejemplo n.º 9
0
        // fully connect HOST client to local server
        // sets NetworkServer.localConnection / NetworkClient.connection.
        protected void ConnectHostClientBlocking()
        {
            NetworkClient.ConnectHost();
            NetworkClient.ConnectLocalServer();
            UpdateTransport();
            Assert.That(NetworkServer.connections.Count, Is.EqualTo(1));

            // set isSpawnFinished flag.
            // so that any Spawn() calls will call OnStartClient and set isClient=true
            // for the client objects.
            // otherwise this would only happen after AddPlayerForConnection.
            // but not all tests have a player.
            NetworkClient.isSpawnFinished = true;
        }
Ejemplo n.º 10
0
        public void Setup()
        {
            Transport.activeTransport = new GameObject().AddComponent <MemoryTransport>();

            // start server/client
            NetworkServer.Listen(1);
            NetworkClient.ConnectHost();
            NetworkServer.SpawnObjects();
            NetworkServer.ActivateHostScene();
            NetworkClient.ConnectLocalServer();

            NetworkServer.localConnection.isAuthenticated = true;
            NetworkClient.connection.isAuthenticated      = true;

            ClientScene.Ready(NetworkClient.connection);
        }
Ejemplo n.º 11
0
        public void DisconnectCallsOnClientDisconnected_HostMode()
        {
            // setup hook
            bool called = false;

            NetworkClient.OnDisconnectedEvent = () => called = true;

            // connect host
            NetworkClient.ConnectHost();

            // disconnect & process everything
            NetworkClient.Disconnect();
            UpdateTransport();

            // was it called?
            Assert.That(called, Is.True);
        }
        /// <summary>
        /// This starts a network "host" - a server and client in the same application.
        /// <para>The client returned from StartHost() is a special "local" client that communicates to the in-process server using a message queue instead of the real network. But in almost all other cases, it can be treated as a normal client.</para>
        /// </summary>
        public UniTask StartHost(NetworkClient client)
        {
            if (client is null)
            {
                throw new InvalidOperationException("NetworkClient not assigned. Unable to StartHost()");
            }

            // start listening to network connections
            UniTask task = ListenAsync();

            Active = true;

            client.ConnectHost(this);

            // call OnStartHost AFTER SetupServer. this way we can use
            // NetworkServer.Spawn etc. in there too. just like OnStartServer
            // is called after the server is actually properly started.
            OnStartHost?.Invoke();

            logger.Log("NetworkServer StartHost");
            return(task);
        }
        public void HostMode_IsFlags_Test()
        {
            CreateNetworked(out GameObject gameObject, out NetworkIdentity identity, out IsClientServerCheckComponent component);

            // start the server
            NetworkServer.Listen(1000);

            // start the client
            NetworkClient.ConnectHost();

            // set is as local player
            NetworkClient.InternalAddPlayer(identity);

            // spawn it
            NetworkServer.Spawn(gameObject);

            // OnStartServer should have been called. check the flags.
            Assert.That(component.OnStartServer_isClient, Is.EqualTo(true));
            Assert.That(component.OnStartServer_isLocalPlayer, Is.EqualTo(true));
            Assert.That(component.OnStartServer_isServer, Is.EqualTo(true));

            // stop the client
            NetworkServer.RemoveLocalConnection();
        }
Ejemplo n.º 14
0
 public void ConnectHost()
 {
     NetworkClient.ConnectHost();
 }
Ejemplo n.º 15
0
 public void isConnected()
 {
     Assert.That(NetworkClient.isConnected, Is.False);
     NetworkClient.ConnectHost();
     Assert.That(NetworkClient.isConnected, Is.True);
 }
Ejemplo n.º 16
0
 public void serverIp()
 {
     NetworkClient.ConnectHost();
     Assert.That(NetworkClient.serverIp, Is.EqualTo("localhost"));
 }