public void ReturnHome(string sceneName) { if (GameObject.Find("LobbyManager") != null) { //if(!Network.isServer){ Debug.Log("server disconnect"); NetworkManager.singleton.StopClient(); NetworkManager.singleton.StopHost(); NetworkLobbyManager.singleton.StopClient(); NetworkLobbyManager.singleton.StopServer(); NetworkServer.DisconnectAll(); //NetworkServer.SetAllClientsNotReady(); //} else if(!Network.isClient){ // Debug.Log("client disconnect"); // NetworkManager.singleton.StopClient (); // //NetworkManager.singleton.StopHost (); // NetworkLobbyManager.singleton.StopClient (); // //NetworkLobbyManager.singleton.StopServer (); // Network.Disconnect(); //} if (GameObject.Find("LobbyManager") != null) { Destroy(GameObject.Find("LobbyManager")); } } SceneManager.LoadScene(sceneName); FindObjectOfType <LrsCommunicator>().viewType = LrsCommunicator.ViewType.other; }
public void Disconnect() { UDPManager.Instance.connected = false; foreach (Player player in GameManager.Instance.players.Values) { player.gameObject.SetActive(false); } for (int i = 0; i < GameManager.Instance.PlayersGB.Length; i++) { if (GameManager.Instance.PlayersGB[i].activeSelf) { GameManager.Instance.PlayersGB[i].transform.GetChild(2).GetComponent <Image>().sprite = UIManager.Instance.Anonim; } } GameManager.Instance.IsBusyPosition = new bool[8]; GameManager.Instance.ActivePlayersGB = new GameObject[8]; GameManager.Instance.ActivePlayersRoles = new int[13]; GameManager.Instance.IsGame = false; GameManager.Instance.players.Clear(); NetManager.Instance.ChangeNetType(); NetworkServer.DisconnectAll(); NetworkServer.Shutdown(); UIManager.Instance.gameScreen.SetActive(false); UIManager.Instance.netScreen.SetActive(true); UDPManager.Instance.Start(); UIManager.Instance.ClearServerList(); GameManager.Instance.ResetData(); }
public void DisconnectAllTest() { // message handlers NetworkServer.RegisterHandler <ConnectMessage>((conn, msg) => { }, false); NetworkServer.RegisterHandler <DisconnectMessage>((conn, msg) => { }, false); NetworkServer.RegisterHandler <ErrorMessage>((conn, msg) => { }, false); // listen NetworkServer.Listen(1); Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); // set local connection ULocalConnectionToClient localConnection = new ULocalConnectionToClient(); NetworkServer.SetLocalConnection(localConnection); Assert.That(NetworkServer.localConnection, Is.EqualTo(localConnection)); // add connection NetworkConnectionToClient conn42 = new NetworkConnectionToClient(42); NetworkServer.AddConnection(conn42); Assert.That(NetworkServer.connections.Count, Is.EqualTo(1)); // disconnect all connections and local connection NetworkServer.DisconnectAll(); Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); Assert.That(NetworkServer.localConnection, Is.Null); // shutdown NetworkServer.Shutdown(); }
/// <summary> /// Disconnects the connection to remote input sender. /// </summary> public virtual void DisconnectRemote() { if (this.isStarted) { NetworkServer.DisconnectAll(); // unregister handler NetworkServer.UnregisterHandler(MsgType.Connect); NetworkServer.UnregisterHandler(MsgType.Disconnect); NetworkServer.UnregisterHandler(MsgType.Error); // unregister application-specific handlers // buttons NetworkServer.UnregisterHandler(InputMsgType.ButtonPress); // mouse buttons NetworkServer.UnregisterHandler(InputMsgType.MouseButtonPress); // keys NetworkServer.UnregisterHandler(InputMsgType.KeyPress); // axis NetworkServer.UnregisterHandler(InputMsgType.Axis); // acceleration NetworkServer.UnregisterHandler(InputMsgType.Acceleration); // compass NetworkServer.UnregisterHandler(InputMsgType.Compass); // gyroscope NetworkServer.UnregisterHandler(InputMsgType.Gyroscope); } }
public void LeaveHostLobby() { if (!isNetworkActive) { Debug.LogWarning("Non-Host Back"); menuStates.Back(); return; } Debug.LogWarning("Attemp Match Destroy"); NetworkServer.DisconnectAll(); if (matchMaker != null) { matchMaker.DestroyMatch(matchInfo.networkId, matchInfo.domain, OnDestroyMatch); } matchOpen = false; this.matchInfo = null; StopCoroutine("PingServer"); menuStates.LeaveGame(); lobbyManager.Clear(); StopMatchMaker(); StopHost(); }
private static void CleanUpHost() { return; NetworkServer.ClearHandlers(); NetworkServer.ClearLocalObjects(); NetworkServer.DisconnectAll(); }
public void LeaveRoom() { Room.StopClient(); if (isServer) { NetworkServer.DisconnectAll(); } SceneManager.LoadScene("MainMenu"); }
public void Update() { if (Input.GetKey(KeyCode.R)) { NetworkServer.DisconnectAll(); NetworkServer.Reset(); SceneManager.LoadScene("ServerScene"); } }
private void ExitToMenu() { // TODO: Proper way to exit? NetworkManager.singleton.StopClient(); NetworkManager.singleton.StopHost(); Destroy(NetworkManager.singleton.gameObject); NetworkServer.DisconnectAll(); SceneManager.LoadScene("MainMenu"); }
private void OnApplicationQuit() { NetworkServer.DisconnectAll(); StopHost(); if (matchMaker != null) { matchMaker.DestroyMatch(matchInfo.networkId, matchInfo.domain, OnDestroyMatch); } }
private void RestartServer() { //NetworkServer.Reset (); NetworkServer.Listen(SERVER_PORT); NetworkServer.DisconnectAll(); NetworkServer.UnregisterHandler(MsgType.Connect); NetworkServer.UnregisterHandler(STATE_DATA); NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnected); NetworkServer.RegisterHandler(STATE_DATA, OnStateRecieved); }
/* * [ClientRpc] * private void RpcAlert(int i) * { * for (int j = 0; j < 5; j++) * { * players[j].CAlert(i); * } * } */ IEnumerator ReturnToLobby(float timing, bool normal) { yield return(new WaitForSeconds(timing)); loadingPanel.SetActive(true); if (!normal) { NetworkServer.DisconnectAll(); } LobbyManager.s_Singleton.ServerReturnToLobby(); }
public void OnMatchDestroy(BasicResponse matchResponse) { if (matchResponse.success) { Debug.Log("YAY"); } NetworkServer.DisconnectAll(); NetworkServer.Shutdown(); Object.DestroyImmediate(_networkGameObject); }
public void OnApplicationQuit() { if (NetManager.Instance.netType == NetType.CLIENT) { return; } if (NetworkServer.active) { NetworkServer.DisconnectAll(); NetworkServer.Shutdown(); } }
public void RpcGameOver() { if (isServer) { Score = 0; spawner.Reset(); PoolManager.ReturnAllPollsObject(); RpcOnClientGameOver(); NetworkServer.DisconnectAll(); MyNetworkManager.Instance.StopServerGame(); // SceneManager.LoadScene("Menu"); } }
IEnumerator LoadMainmenu() { buttonSound.clip = audioClip; buttonSound.Play(); yield return(new WaitForSeconds(audioClip.length)); NetworkLobbyManager.singleton.StopClient(); NetworkLobbyManager.singleton.StopServer(); NetworkLobbyManager.singleton.StopHost(); NetworkServer.DisconnectAll(); Destroy(GameObject.FindGameObjectWithTag("Lobby")); }
public IEnumerator ClientCanConnectAfterFailureTest() { NetworkClient.ShutdownAll(); NetworkServer.Reset(); NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnected); config = new ConnectionConfig(); config.AddChannel(QosType.ReliableFragmented); if (!NetworkServer.Configure(config, 10)) { Assert.Fail("Server configure failed"); } // Mismatched channels between client 1 and server, so connect will fail with CRCMismatch error ConnectionConfig customConfig = new ConnectionConfig(); customConfig.AddChannel(QosType.UnreliableFragmented); client1 = new NetworkClient(); if (!client1.Configure(customConfig, 10)) { Assert.Fail("Client1 configure failed"); } client1.RegisterHandler(MsgType.Connect, OnClient1Connected); client1.RegisterHandler(MsgType.Disconnect, OnClient1Disconnected); int retries = 0; while (!NetworkServer.Listen("127.0.0.1", ++kListenPort)) { Assert.IsTrue(retries++ < 10, "Couldn't Listen for more than 10 retries"); } LogAssert.Expect(LogType.Error, "UNet Client Disconnect Error: CRCMismatch"); client1.Connect("127.0.0.1", kListenPort); while (!serverRecievedConnection || !isClientConnected) { yield return(null); } NetworkServer.DisconnectAll(); while (!isTestDone) { yield return(null); } }
public void DisconnectAllTest_LocalConnection() { // listen NetworkServer.Listen(1); // set local connection LocalConnectionToClient localConnection = new LocalConnectionToClient(); NetworkServer.SetLocalConnection(localConnection); // disconnect all connections should remove local connection NetworkServer.DisconnectAll(); Assert.That(NetworkServer.localConnection, Is.Null); }
/// <summary> /// 停止服务器端 /// </summary> public void ShutdownServer() { if (NetworkServer.active) { ServerUnregisterHandler(); NetworkServer.DisconnectAll(); NetworkServer.Shutdown(); if (!NetworkServer.active) { ShowMsg("shut down server"); } } }
public IEnumerator Wait10SecondsThenCloseServer() { StartCoroutine("Wait11SecondsThenLoadLobby"); yield return(new WaitForSeconds(10F)); Debug.Log("Stopping Client"); NetworkManager.singleton.StopClient(); Debug.Log("Stopping Host"); NetworkManager.singleton.StopHost(); Debug.Log("Stopping Server"); NetworkManager.singleton.StopServer(); Debug.Log("Disconnecting connections"); NetworkServer.DisconnectAll(); }
public void DisconnectAllTest_RemoteConnection() { // listen NetworkServer.Listen(1); // add connection NetworkConnectionToClient conn42 = new NetworkConnectionToClient(42); NetworkServer.AddConnection(conn42); Assert.That(NetworkServer.connections.Count, Is.EqualTo(1)); // disconnect all connections NetworkServer.DisconnectAll(); Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); }
public void ExitMultiplayer() { if (isServer) { NetworkManager.singleton.StopHost(); NetworkServer.DisconnectAll(); } if (isClient) { CmdUpdateTotalConnectedPlayer(1); Invoke("DisconnectFromServer", 5f); } }
void OnGUI() { if (GUI.Button(new Rect(10, 10, 300, 200), solo)) { NetworkServer.DisconnectAll(); SceneManager.LoadScene(1); } if (GUI.Button(new Rect(350, 10, 300, 200), multi)) { NetworkServer.DisconnectAll(); SceneManager.LoadScene(2); } }
public void ReturnToMenu() { if (NetworkServer.active) { NetworkServer.DisconnectAll(); StopHost(); } else { StopClient(); } lobbyManager.Clear(); menuStates.LeaveGame(); }
// СЕРВЕРНАЯ СТОРОНА void ServerStart() { Debug.Log("Server Start function run ..."); Debug.Log("active = " + NetworkServer.active.ToString()); Debug.Log("NetworkServer.Listen() function run ..."); NetworkServer.Listen(NETWORK_PORT); Debug.Log("NetworkServer.DisconnectAll() function run ..."); NetworkServer.DisconnectAll(); Debug.Log("active = " + NetworkServer.active.ToString()); Debug.Log("channels = " + NetworkServer.numChannels.ToString()); Debug.Log("localClientActive = " + NetworkServer.localClientActive.ToString()); InvokeRepeating("ServerState", 5f, 5f); // Регистрация событий NetworkServer.RegisterHandler(MsgType.Connect, this.SR_Connect); NetworkServer.RegisterHandler(POINT_TO_ID, this.SR_PointToID); // Событие 1001 }
public IEnumerator DisconnectAllWorksTest() { NetworkClient.ShutdownAll(); NetworkServer.Reset(); ConnectionConfig config = new ConnectionConfig(); config.AddChannel(QosType.ReliableSequenced); config.AddChannel(QosType.Unreliable); NetworkServer.Configure(config, maxConnections); NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnected); int retries = 0; while (!NetworkServer.Listen("127.0.0.1", ++kListenPort)) { Assert.IsTrue(retries++ < 10, "Couldn't Listen for more than 10 retries"); } for (int i = 0; i < numClients; ++i) { NetworkClient myClient = new NetworkClient(); if (!myClient.Configure(config, maxConnections)) { Assert.Fail("Client configure failed"); } myClient.RegisterHandler(MsgType.Connect, OnClientConnected); myClient.RegisterHandler(MsgType.Disconnect, OnClientDisconnected); myClient.Connect("127.0.0.1", kListenPort); } while (serverConnections != numClients || clientsConnected != numClients) { yield return(null); } NetworkServer.DisconnectAll(); while (clientsDisccnnected != numClients) { yield return(null); } Assert.IsTrue(NetworkServer.active, "NetworkServer should still be active after DisconnectAll()"); }
public void ReturnToMenu() { LobbyManager.s_Singleton.GoBackButton(); NetworkManager.singleton.StopClient(); NetworkManager.singleton.StopHost(); NetworkLobbyManager.singleton.StopClient(); NetworkLobbyManager.singleton.StopHost(); NetworkServer.DisconnectAll(); /* * if (isServer) * lm.DisconnectClient(); * else * lm.DisconnectHost(); */ }
public void DisconnectAllTest_RemoteConnection() { // listen NetworkServer.Listen(1); Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); // add connection NetworkConnectionToClient conn42 = new NetworkConnectionToClient(42, false, 0); NetworkServer.AddConnection(conn42); Assert.That(NetworkServer.connections.Count, Is.EqualTo(1)); // disconnect all connections NetworkServer.DisconnectAll(); // update transports. OnTransportDisconnected should be fired and // clear all connections. Assert.That(NetworkServer.connections.Count, Is.EqualTo(0)); }
/// <summary> /// Tells the player hosting if they won /// then send updates to gamesparks /// Tells clients game is over and who won /// Disconnects server /// </summary> /// <param name="winner">Username of winning player</param> void gameOver(string winner) { if (localPlayer.GetComponent <player>().s_username == winner) { T_WinLose.text = "WINNER"; GameSpark.UpdateWin(); } else { T_WinLose.text = "LOSER\n" + winner + " won"; } GameSpark.UpdateKills(localPlayer.GetComponent <player>().i_kills); RpcGameOver(winner); NetworkServer.DisconnectAll(); NetworkManager.Shutdown(); SceneManager.LoadScene("EndGame"); }
private void IncreaseScore(Team team, float score) { if (NetworkServer.active) { switch (team) { case Team.Player: scorePlayers += score; break; case Team.Enemy: scoreEnemies += score; break; default: break; } if (scorePlayers >= 15000) { NetworkServer.DisconnectAll(); SceneManager.LoadScene(2); //CmdSwitchWinningScreen(); } else if (scoreEnemies >= 10000) { NetworkServer.DisconnectAll(); SceneManager.LoadScene(3); //CmdSwitchLosingScreen(); } } }