コード例 #1
0
        /// <summary>
        /// Stop everything.
        /// </summary>

        void Disconnect()
        {
            mGame.Stop();

            if (mLobby != null)
            {
                mLobby.Stop();
                mLobby = null;
            }
            mUp.Close();
        }
コード例 #2
0
        /// <summary>
        /// Start a new server.
        /// </summary>

        bool StartRemote(int tcpPort, int udpPort, string fileName, IPEndPoint remoteLobby, Type type, bool openPort)
        {
            if (mGame.isActive)
            {
                Disconnect();
            }

            if (remoteLobby != null && remoteLobby.Port > 0)
            {
                if (type == Type.Tcp)
                {
                    mLobby          = new TcpLobbyServer();
                    mGame.lobbyLink = new TcpLobbyServerLink(remoteLobby);
                }
                else if (type == Type.Udp)
                {
                    mLobby          = new UdpLobbyServer();
                    mGame.lobbyLink = new UdpLobbyServerLink(remoteLobby);
                }
                else
                {
                    Debug.LogWarning("The remote lobby server type must be either UDP or TCP, not LAN");
                }
            }

            if (mGame.Start(tcpPort, udpPort))
            {
                if (openPort)
                {
                    mUp.OpenTCP(tcpPort);
                    mUp.OpenUDP(udpPort);
                }
                if (!string.IsNullOrEmpty(fileName))
                {
                    mGame.Load(fileName);
                }
                return(true);
            }

            Disconnect();
            return(false);
        }
コード例 #3
0
        /// <summary>
        /// Create a new local lobby server link. Expects a local server to work with.
        /// </summary>

        public LobbyServerLink(LobbyServer lobbyServer)
        {
            mLobby = lobbyServer;
        }
コード例 #4
0
        /// <summary>
        /// Start a new server.
        /// </summary>

        bool StartLocal(int tcpPort, int udpPort, string fileName, int lobbyPort, Type type, bool openPort)
        {
            // Ensure that everything has been stopped first
            if (mGame.isActive)
            {
                Disconnect();
            }

            // If there is a lobby port, we should set up the lobby server and/or link first.
            // Doing so will let us inform the lobby that we are starting a new server.

            if (lobbyPort > 0)
            {
                if (type == Type.Tcp)
                {
                    mLobby = new TcpLobbyServer();
                }
                else
                {
                    mLobby = new UdpLobbyServer();
                }

                // Start a local lobby server
                if (mLobby.Start(lobbyPort))
                {
                    if (openPort)
                    {
                        if (type == Type.Tcp)
                        {
                            mUp.OpenTCP(lobbyPort);
                        }
                        else
                        {
                            mUp.OpenUDP(lobbyPort);
                        }
                    }
                }
                else
                {
                    mLobby = null;
                    return(false);
                }

                // Create the local lobby link
                mGame.lobbyLink = new LobbyServerLink(mLobby);
            }

            // Start the game server
            if (mGame.Start(tcpPort, udpPort))
            {
                if (openPort)
                {
                    mUp.OpenTCP(tcpPort);
                    if (udpPort > 0)
                    {
                        mUp.OpenUDP(udpPort);
                    }
                }
                if (!string.IsNullOrEmpty(fileName))
                {
                    mGame.Load(fileName);
                }
                return(true);
            }

            // Something went wrong -- stop everything
            Disconnect();
            return(false);
        }
コード例 #5
0
    /// <summary>
    /// Start a new server.
    /// </summary>
    bool StartRemote(int tcpPort, int udpPort, string fileName, IPEndPoint remoteLobby, Type type)
    {
        if (mGame.isActive) Disconnect();

        if (remoteLobby != null && remoteLobby.Port > 0)
        {
            if (type == Type.Tcp)
            {
                mLobby = new TcpLobbyServer();
                mGame.lobbyLink = new TcpLobbyServerLink(remoteLobby);
            }
            else if (type == Type.Udp)
            {
                mLobby = new UdpLobbyServer();
                mGame.lobbyLink = new UdpLobbyServerLink(remoteLobby);
            }
            else
            {
                Debug.LogWarning("The remote lobby server type must be either UDP or TCP, not LAN");
            }
        }

        if (mGame.Start(tcpPort, udpPort))
        {
            mUp.OpenTCP(tcpPort);
            mUp.OpenUDP(udpPort);
            if (!string.IsNullOrEmpty(fileName)) mGame.LoadFrom(fileName);
            return true;
        }

        Disconnect();
        return false;
    }
コード例 #6
0
    /// <summary>
    /// Start a new server.
    /// </summary>
    bool StartLocal(int tcpPort, int udpPort, string fileName, int lobbyPort)
    {
        // Ensure that everything has been stopped first
        if (mGame.isActive) Disconnect();

        // If there is a lobby port, we should set up the lobby server and/or link first.
        // Doing so will let us inform the lobby that we are starting a new server.

        if (lobbyPort > 0)
        {
            mLobby = new UdpLobbyServer();

            // Start a local lobby server
            if (mLobby.Start(lobbyPort))
            {
                mUp.OpenUDP(lobbyPort);
            }
            else
            {
                mLobby = null;
                return false;
            }

            // Create the local lobby link
            mGame.lobbyLink = new LobbyServerLink(mLobby);
        }

        // Start the game server
        if (mGame.Start(tcpPort, udpPort))
        {
            mUp.OpenTCP(tcpPort);
            mUp.OpenUDP(udpPort);
            if (!string.IsNullOrEmpty(fileName)) mGame.LoadFrom(fileName);
            return true;
        }

        // Something went wrong -- stop everything
        Disconnect();
        return false;
    }
コード例 #7
0
    /// <summary>
    /// Stop everything.
    /// </summary>
    void Disconnect()
    {
        mGame.Stop();

        if (mLobby != null)
        {
            mLobby.Stop();
            mLobby = null;
        }
        mUp.Close();
    }
コード例 #8
0
ファイル: TNLobbyLink.cs プロジェクト: jeffmun/BalloonPop
 /// <summary>
 /// Create a new local lobby server link. Expects a local server to work with.
 /// </summary>
 public LobbyServerLink(LobbyServer lobbyServer)
 {
     mLobby = lobbyServer;
 }