Disconnect() public method

Disconnects this connection.

public Disconnect ( ) : void
return void
コード例 #1
0
 public bool ReconnectToNewHost(string serverIp, int serverPort)
 {
     if (!active)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("Reconnect - NetworkClient must be active");
         }
         return(false);
     }
     if (m_Connection == null)
     {
         if (LogFilter.logError)
         {
             Debug.LogError("Reconnect - no old connection exists");
         }
         return(false);
     }
     if (LogFilter.logInfo)
     {
         Debug.Log("NetworkClient Reconnect " + serverIp + ":" + serverPort);
     }
     ClientScene.HandleClientDisconnect(m_Connection);
     ClientScene.ClearLocalPlayers();
     m_Connection.Disconnect();
     m_Connection = null;
     m_ClientId   = NetworkTransport.AddHost(m_HostTopology, m_HostPort);
     m_ServerPort = serverPort;
     if (Application.platform == RuntimePlatform.WebGLPlayer)
     {
         m_ServerIp     = serverIp;
         m_AsyncConnect = ConnectState.Resolved;
     }
     else if (serverIp.Equals("127.0.0.1") || serverIp.Equals("localhost"))
     {
         m_ServerIp     = "127.0.0.1";
         m_AsyncConnect = ConnectState.Resolved;
     }
     else
     {
         if (LogFilter.logDebug)
         {
             Debug.Log("Async DNS START:" + serverIp);
         }
         m_AsyncConnect = ConnectState.Resolving;
         Dns.BeginGetHostAddresses(serverIp, GetHostAddressesCallback, this);
     }
     return(true);
 }
コード例 #2
0
 public override void OnServerConnect(NetworkConnection conn)
 {
     if (base.numPlayers >= this.maxPlayers)
     {
         conn.Disconnect();
         return;
     }
     if (Application.loadedLevelName != this.m_LobbyScene)
     {
         conn.Disconnect();
         return;
     }
     base.OnServerConnect(conn);
     this.OnLobbyServerConnect(conn);
 }
コード例 #3
0
 public override void OnServerConnect(NetworkConnection conn)
 {
     if (this.numPlayers >= this.maxPlayers)
     {
         conn.Disconnect();
     }
     else if (SceneManager.GetSceneAt(0).name != this.m_LobbyScene)
     {
         conn.Disconnect();
     }
     else
     {
         base.OnServerConnect(conn);
         this.OnLobbyServerConnect(conn);
     }
 }
コード例 #4
0
        private void HandleDisconnect(int connectionId, byte error)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkServerSimple disconnect client:" + connectionId);
            }
            NetworkConnection networkConnection = FindConnection(connectionId);

            if (networkConnection == null)
            {
                return;
            }
            networkConnection.lastError = (NetworkError)error;
            if (error != 0 && error != 6)
            {
                m_Connections[connectionId] = null;
                if (LogFilter.logError)
                {
                    Debug.LogError("Server client disconnect error, connectionId: " + connectionId + " error: " + (NetworkError)error);
                }
                OnDisconnectError(networkConnection, error);
                return;
            }
            networkConnection.Disconnect();
            m_Connections[connectionId] = null;
            if (LogFilter.logDebug)
            {
                Debug.Log("Server lost client:" + connectionId);
            }
            OnDisconnected(networkConnection);
        }
コード例 #5
0
        private void HandleDisconnect(int connectionId, byte error)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log((object)("NetworkServerSimple disconnect client:" + (object)connectionId));
            }
            NetworkConnection connection = this.FindConnection(connectionId);

            if (connection == null)
            {
                return;
            }
            if ((int)error != 0 && (int)error != 6)
            {
                this.m_Connections[connectionId] = (NetworkConnection)null;
                if (LogFilter.logError)
                {
                    Debug.LogError((object)("Server client disconnect error:" + (object)connectionId));
                }
                this.OnDisconnectError(connection, error);
            }
            else
            {
                connection.Disconnect();
                this.m_Connections[connectionId] = (NetworkConnection)null;
                if (LogFilter.logDebug)
                {
                    Debug.Log((object)("Server lost client:" + (object)connectionId));
                }
                this.OnDisconnected(connection);
            }
        }
コード例 #6
0
        private void HandleDisconnect(int connectionId, byte error)
        {
            if (LogFilter.logDebug)
            {
                Debug.Log("NetworkServerSimple disconnect client:" + connectionId);
            }
            NetworkConnection conn = this.FindConnection(connectionId);

            if (conn != null)
            {
                conn.lastError = (NetworkError)error;
                if ((error != 0) && (error != 6))
                {
                    this.m_Connections[connectionId] = null;
                    if (LogFilter.logError)
                    {
                        Debug.LogError(string.Concat(new object[] { "Server client disconnect error, connectionId: ", connectionId, " error: ", (NetworkError)error }));
                    }
                    this.OnDisconnectError(conn, error);
                }
                else
                {
                    conn.Disconnect();
                    this.m_Connections[connectionId] = null;
                    if (LogFilter.logDebug)
                    {
                        Debug.Log("Server lost client:" + connectionId);
                    }
                    this.OnDisconnected(conn);
                }
            }
        }
コード例 #7
0
        public void Disconnect(int connectionId)
        {
            NetworkConnection networkConnection = this.FindConnection(connectionId);

            if (networkConnection != null)
            {
                networkConnection.Disconnect();
                this.m_Connections[connectionId] = null;
            }
        }
        // ------------------------ server handlers ------------------------

        public override void OnServerConnect(NetworkConnection conn)
        {
            if (numPlayers >= maxPlayers)
            {
                conn.Disconnect();
                return;
            }

            // cannot join game in progress
            string loadedSceneName = SceneManager.GetSceneAt(0).name;

            if (loadedSceneName != m_LobbyScene)
            {
                conn.Disconnect();
                return;
            }

            base.OnServerConnect(conn);
            OnLobbyServerConnect(conn);
        }
コード例 #9
0
        /// <summary>
        ///   <para>This disconnects the connection of the corresponding connection id.</para>
        /// </summary>
        /// <param name="connectionId">The id of the connection to disconnect.</param>
        public void Disconnect(int connectionId)
        {
            NetworkConnection connection = this.FindConnection(connectionId);

            if (connection == null)
            {
                return;
            }
            connection.Disconnect();
            this.m_Connections[connectionId] = (NetworkConnection)null;
        }
コード例 #10
0
 public void DisconnectAllConnections()
 {
     for (int i = 0; i < this.m_Connections.Count; i++)
     {
         NetworkConnection networkConnection = this.m_Connections[i];
         if (networkConnection != null)
         {
             networkConnection.Disconnect();
             networkConnection.Dispose();
         }
     }
 }
コード例 #11
0
 /// <summary>
 ///   <para>This disconnects all of the active connections.</para>
 /// </summary>
 public void DisconnectAllConnections()
 {
     for (int index = 0; index < this.m_Connections.Count; ++index)
     {
         NetworkConnection connection = this.m_Connections[index];
         if (connection != null)
         {
             connection.Disconnect();
             connection.Dispose();
         }
     }
 }
コード例 #12
0
 public void DisconnectAllConnections()
 {
     for (int i = 0; i < m_Connections.Count; i++)
     {
         NetworkConnection conn = m_Connections[i];
         if (conn != null)
         {
             conn.Disconnect();
             conn.Dispose();
         }
     }
 }
コード例 #13
0
 public virtual void Disconnect()
 {
     m_AsyncConnect = ConnectState.Disconnected;
     ClientScene.HandleClientDisconnect(m_Connection);
     if (m_Connection != null)
     {
         m_Connection.Disconnect();
         m_Connection.Dispose();
         m_Connection = null;
         NetworkTransport.RemoveHost(m_ClientId);
     }
 }
コード例 #14
0
        // ------------------------ server handlers ------------------------

        public override void OnServerConnect(NetworkConnection conn)
        {
            // numPlayers returns the player count including this one, so ok to be equal
            if (numPlayers > maxPlayers)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkLobbyManager can't accept new connection [" + conn + "], too many players connected.");
                }
                conn.Disconnect();
                return;
            }

            // cannot join game in progress
            string loadedSceneName = SceneManager.GetSceneAt(0).name;

            if (loadedSceneName != m_LobbyScene)
            {
                if (LogFilter.logWarn)
                {
                    Debug.LogWarning("NetworkLobbyManager can't accept new connection [" + conn + "], not in lobby and game already in progress.");
                }
                conn.Disconnect();
                return;
            }

            base.OnServerConnect(conn);

            // when a new client connects, set all old players as dirty so their current ready state is sent out
            for (int i = 0; i < lobbySlots.Length; ++i)
            {
                if (lobbySlots[i])
                {
                    lobbySlots[i].SetDirtyBit(1);
                }
            }

            OnLobbyServerConnect(conn);
        }
コード例 #15
0
 public override void OnServerConnect(NetworkConnection conn)
 {
     if (base.numPlayers > this.maxPlayers)
     {
         if (LogFilter.logWarn)
         {
             Debug.LogWarning("NetworkLobbyManager can't accept new connection [" + conn + "], too many players connected.");
         }
         conn.Disconnect();
     }
     else if (SceneManager.GetSceneAt(0).name != this.m_LobbyScene)
     {
         if (LogFilter.logWarn)
         {
             Debug.LogWarning("NetworkLobbyManager can't accept new connection [" + conn + "], not in lobby and game already in progress.");
         }
         conn.Disconnect();
     }
     else
     {
         base.OnServerConnect(conn);
         this.OnLobbyServerConnect(conn);
     }
 }
コード例 #16
0
        // ------------------------ server handlers ------------------------

        public override void OnServerConnect(NetworkConnection conn)
        {
            if (numPlayers >= maxPlayers)
            {
                conn.Disconnect();
                return;
            }
#warning solve the "Hot Join" problem
//			// cannot join game in progress
//			string loadedSceneName = SceneManager.GetSceneAt(0).name;
//			if (loadedSceneName != m_LobbyScene)
//			{
//				conn.Disconnect();
//				return;
//			}
//
//			base.OnServerConnect(conn);
            OnLobbyServerConnect(conn);
        }
コード例 #17
0
 public void KickPlayer(NetworkConnection conn)
 {
     conn.Disconnect();
 }
コード例 #18
0
 // override for when a new client connects to the server
 public override void OnServerConnect(NetworkConnection conn)
 {
     if (this.numPlayers >= this.maxPlayers)
     conn.Disconnect();
       else if (Application.loadedLevelName != this.m_LobbyScene) // this will prevent players from joining after game is already started
       {
     conn.Disconnect();
       }
       else // otherwise we continue the process
       {
     base.OnServerConnect(conn);
     this.OnLobbyServerConnect(conn);
       }
 }
コード例 #19
0
    // ------------------------ server handlers ------------------------
    public override void OnServerConnect(NetworkConnection conn)
    {
        if (numPlayers >= maxPlayers)
        {
            conn.Disconnect();
            return;
        }

        // cannot join game in progress
        string loadedSceneName = SceneManager.GetSceneAt(0).name;
        if (loadedSceneName != m_LobbyScene)
        {
            conn.Disconnect();
            return;
        }

        base.OnServerConnect(conn);
    }
コード例 #20
0
 public override void OnServerConnect(NetworkConnection conn)
 {
     if (base.numPlayers >= this.maxPlayers)
     {
         conn.Disconnect();
     }
     else if (Application.loadedLevelName != this.m_LobbyScene)
     {
         conn.Disconnect();
     }
     else
     {
         base.OnServerConnect(conn);
         this.OnLobbyServerConnect(conn);
     }
 }
コード例 #21
0
 public override void OnServerConnect(NetworkConnection conn)
 {
   if (this.numPlayers >= this.maxPlayers)
     conn.Disconnect();
   else if (SceneManager.GetSceneAt(0).name != this.m_LobbyScene)
   {
     conn.Disconnect();
   }
   else
   {
     base.OnServerConnect(conn);
     this.OnLobbyServerConnect(conn);
   }
 }
コード例 #22
0
    //Called on the server when a new client connects.
    public override void OnServerConnect(NetworkConnection conn){
        Debug.Log("OnServerConnect " + conn.connectionId);
        int i = 0;
		for(; i < maxPlayers; i++){
			if(lobbyPlayerArray[i] == null){
				break;
			}
		}
		if(i >= maxPlayers) {
			conn.Disconnect();
            conn.Dispose();
            Debug.Log("**********************OnServerConnect Disconnect the Client**********************");
            Debug.Log("**********************OnServerConnect Disconnect the Client**********************");
            Debug.Log("**********************OnServerConnect Disconnect the Client**********************");

            //tell the client
        }
        base.OnServerConnect(conn);
        //ask client to change panel
        ServerMessage sm = new ServerMessage();
        sm.currentMode = currentMode;
        sm.isCreatePlayer = true;
        NetworkServer.SendToClient(conn.connectionId, ServerMessage.MsgType, sm);
    }
コード例 #23
0
    public override void OnServerConnect(NetworkConnection conn)
    {
        if (numPlayers >= maxPlayers)
        {
            conn.Disconnect();
            return;
        }

        // cannot join game in progress
        if (HasGameStarted())
        {
            conn.Disconnect();
            return;
        }

        base.OnServerConnect(conn);
        OnLobbyServerConnect(conn);
    }
コード例 #24
0
        public bool ReconnectToNewHost(string serverIp, int serverPort)
        {
            if (!NetworkClient.active)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect - NetworkClient must be active");
                }
                return(false);
            }

            if (m_Connection == null)
            {
                if (LogFilter.logError)
                {
                    Debug.LogError("Reconnect - no old connection exists");
                }
                return(false);
            }

            if (LogFilter.logInfo)
            {
                Debug.Log("NetworkClient Reconnect " + serverIp + ":" + serverPort);
            }

            ClientScene.HandleClientDisconnect(m_Connection);
            ClientScene.ClearLocalPlayers();

            m_Connection.Disconnect();
            m_Connection = null;
            m_ClientId   = NetworkTransport.AddHost(m_HostTopology, 0);

            string hostnameOrIp = serverIp;

            m_ServerPort = serverPort;

            //TODO: relay reconnect

            /*
             * if (Match.NetworkMatch.matchSingleton != null)
             * {
             *  hostnameOrIp = Match.NetworkMatch.matchSingleton.address;
             *  m_ServerPort = Match.NetworkMatch.matchSingleton.port;
             * }*/

            if (UnityEngine.Application.platform == RuntimePlatform.WebGLPlayer)
            {
                m_ServerIp     = hostnameOrIp;
                m_AsyncConnect = ConnectState.Resolved;
            }
            else if (serverIp.Equals("127.0.0.1") || serverIp.Equals("localhost"))
            {
                m_ServerIp     = "127.0.0.1";
                m_AsyncConnect = ConnectState.Resolved;
            }
            else
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("Async DNS START:" + hostnameOrIp);
                }
                m_AsyncConnect = ConnectState.Resolving;
                Dns.BeginGetHostAddresses(hostnameOrIp, new AsyncCallback(GetHostAddressesCallback), this);
            }
            return(true);
        }
コード例 #25
0
ファイル: Server.cs プロジェクト: Johannesolof/DoDGame
		public void ClientRefuse(NetworkConnection nc)
		{
			// TODO: Add anti-spam support
			common.printConsole (tag, "Refusing peer: " + nc.address, true);
			nc.Disconnect();
		}