Пример #1
0
        public bool ServerStart(string serverName)
        {
            Debug.Log("Server start " + serverName);
            // Check if we already have a local server running
            if (TNServerInstance.isActive)
            {
                return(false);
            }

            // Don't want you being connected to a server and making your own
            if (IsConnected)
            {
                TNManager.Disconnect();
            }

            // Someone order a name?
            TNServerInstance.serverName = serverName;

            // Start it ... or not ... we'll let it decide.
            TNServerInstance.Start(TCPPort, UDPPort, "", LANPort);

            // Connect to server I created
            AgentConnect(new ConnectionString("127.0.0.1", TCPPort));

            return(true);
        }
Пример #2
0
 private void Start()
 {
     if (TNServerInstance.Start(S_TCPPort, S_Port, "ServerData.dat", false))
     {
         TNManager.Connect();
     }
 }
Пример #3
0
        /// <summary>
        /// Stops the Server Instance.
        /// </summary>
        public void ServerStop()
        {
            // Better disconnect just in case.
            TNManager.Disconnect();

            // Stop the server.
            TNServerInstance.Stop();
        }
Пример #4
0
    void OnStartServer()
    {
#if UNITY_WEBPLAYER
        mMessage = "Can't host from the Web Player due to Unity's security restrictions";
#else
        // Start a local server, loading the saved data if possible
        // The UDP port of the server doesn't matter much as it's optional,
        // and the clients get notified of it via Packet.ResponseSetUDP.
        int         udpPort       = Random.Range(10000, 40000);
        LobbyClient lobby         = GetComponent <LobbyClient>();
        var         serverStarted = false;
        if (lobby == null)
        {
            serverStarted = TNServerInstance.Start(serverTcpPort, udpPort, serverFileName);
        }
        else
        {
            TNServerInstance.Type type = (lobby is TNUdpLobbyClient) ?
                                         TNServerInstance.Type.Udp : TNServerInstance.Type.Tcp;
            serverStarted = TNServerInstance.Start(serverTcpPort, udpPort, serverFileName, type, Tools.ResolveEndPoint(lobby.remoteAddress, lobby.remotePort));
//            TNServerInstance.Start(serverTcpPort, udpPort, lobby.remotePort, serverFileName, type);

            var servername = InputDialog.instance.GetValueString(INPUT_SERVERNAME);
            if (!string.IsNullOrEmpty(servername))
            {
                TNServerInstance.serverName = servername;
            }
        }
        if (serverStarted)
        {
            mMessage = "Server started";

            InputDialog.instance.CloseDialog();
        }
#endif
    }
Пример #5
0
    /// <summary>
    /// This menu is shown if the client has not yet connected to the server.
    /// </summary>

    void DrawConnectMenu()
    {
        Rect rect = new Rect(Screen.width * 0.5f - 200f * 0.5f - mAlpha * 120f,
                             Screen.height * 0.5f - 100f, 200f, 220f);

        // Show a half-transparent box around the upcoming UI
        GUI.color = new Color(1f, 1f, 1f, 0.5f);
        GUI.Box(UnityTools.PadRect(rect, 8f), "");
        GUI.color = Color.white;

        GUILayout.BeginArea(rect);
        {
            GUILayout.Label("Server Address", text);
            mAddress = GUILayout.TextField(mAddress, input, GUILayout.Width(200f));

            if (GUILayout.Button("Connect", button))
            {
                // We want to connect to the specified destination when the button is clicked on.
                // "OnNetworkConnect" function will be called sometime later with the result.
                TNManager.Connect(mAddress);
                mMessage = "Connecting...";
            }

            if (TNServerInstance.isActive)
            {
                GUI.backgroundColor = Color.red;

                if (GUILayout.Button("Stop the Server", button))
                {
                    // Stop the server, saving all the data
                    TNServerInstance.Stop("server.dat");
                    mMessage = "Server stopped";
                }
            }
            else
            {
                GUI.backgroundColor = Color.green;

                if (GUILayout.Button("Start a Local Server", button))
                {
#if UNITY_WEBPLAYER
                    mMessage = "Can't host from the Web Player due to Unity's security restrictions";
#else
                    int udpPort = Random.Range(10000, 40000);

                    // Start a local server, loading the saved data if possible
                    // The UDP port of the server doesn't matter much as it's optional,
                    // and the clients get notified of it via Packet.ResponseSetUDP.
                    TNUdpLobbyClient lan = GetComponent <TNUdpLobbyClient>();
                    int lobbyPort        = (lan != null) ? lan.remotePort : 0;
                    TNServerInstance.Start(serverTcpPort, udpPort, "server.dat", lobbyPort);
                    mMessage = "Server started";
#endif
                }
            }
            GUI.backgroundColor = Color.white;

            if (!string.IsNullOrEmpty(mMessage))
            {
                GUILayout.Label(mMessage, text);
            }
        }
        GUILayout.EndArea();

        if (mAlpha > 0.01f)
        {
            rect.x = rect.x + (Screen.width - rect.xMin - rect.xMax) * mAlpha;
            DrawServerList(rect);
        }
    }
Пример #6
0
 void OnStopServer()
 {
     TNServerInstance.Stop();
     mMessage = "Server Stopped.";
 }