public void LocalClientActiveTest() { Assert.That(server.LocalClientActive, Is.False); client.ConnectHost(server); Assert.That(server.LocalClientActive, Is.True); client.Disconnect(); }
public void IsConnectedTest() { Assert.That(!client.IsConnected); client.ConnectHost(server); Assert.That(client.IsConnected); }
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; }
// 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)); }
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); }
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(); }
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); }
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>(); });
// 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; }
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); }
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(); }
public void ConnectHost() { NetworkClient.ConnectHost(); }
public void isConnected() { Assert.That(NetworkClient.isConnected, Is.False); NetworkClient.ConnectHost(); Assert.That(NetworkClient.isConnected, Is.True); }
public void serverIp() { NetworkClient.ConnectHost(); Assert.That(NetworkClient.serverIp, Is.EqualTo("localhost")); }