// Use this for initialization void Start() { nvs = GameObject.FindWithTag("NetObj").GetComponent("networkVariables") as networkVariables; // get server version serverVersion = nvs.serverVersion; // get NATmode NATmode = nvs.NATmode; // sudo make me a camera nvs.myCam = new GameObject("theCamera").AddComponent <Camera>() as Camera; nvs.myCam.gameObject.AddComponent <AudioListener>(); nvs.myCam.gameObject.SetActive(false); // disable it until we have joined a game // get them servers MasterServer.ClearHostList(); MasterServer.RequestHostList(serverVersion); // check if we don't have a valid NATmode if (NATmode == -1) { // test the current setup rather than poll for the result connectionTestResult = Network.TestConnection(true); doneTesting = false; } else { SetMessage(); doneTesting = true; } }
void Awake(){ DontDestroyOnLoad(gameObject); connectionTestResult = Network.TestConnection(); if(Network.HavePublicAddress()) Debug.Log("This machine has a public IP address"); else Debug.Log("This machine has a private IP address"); }
IEnumerator TestNAT() { while (Network.TestConnectionNAT() == ConnectionTesterStatus.Undetermined) { yield return(new WaitForEndOfFrame()); } natStatus = Network.TestConnectionNAT(); UnityEngine.Debug.Log(Network.TestConnectionNAT()); }
void ShowGUI() { if (GUI.Button(new Rect(100, 10, 120, 30), "Retest connection")) { Debug.Log("Redoing connection test"); probingPublicIP = false; doneTesting = false; natCapable = Network.TestConnection(true); } subGUIDelegate(); }
// START UP ///////////////////////// protected PurpleNetworkServerSanityTester() { formerIP = Network.connectionTesterIP; formerPort = Network.connectionTesterPort; testDone = true; testResult = ConnectionTesterStatus.Undetermined; currentServerReference = null; pingObject = new pingData (); }
void Awake() { DontDestroyOnLoad(this); // Start connection test natCapable = Network.TestConnection(); // What kind of IP does this machine have? TestConnection also indicates this in the // test results if (Network.HavePublicAddress()) Debug.Log("This machine has a public IP address"); else Debug.Log("This machine has a private IP address"); }
void Awake() { windowRect = new Rect(Screen.width-300,50,300,100); serverListRect = new Rect(0, 0, Screen.width - windowRect.width, 100); // Start connection test connectionTestResult = Network.TestConnection(); // What kind of IP does this machine have? TestConnection also indicates this in the // test results if (Network.HavePublicAddress()) Debug.Log("This machine has a public IP address"); else Debug.Log("This machine has a private IP address"); }
public bool CanConnectTo(ConnectionTesterStatus source, ConnectionTesterStatus destination) { if (source == ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted && destination == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric) return false; else if (source == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric && destination == ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted) return false; else if (source == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric && destination == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric) return false; return true; }
public bool CheckConnection() { //TODO return(false); // ConnectionTesterStatus connectionStatus = UnityEngine.Network.TestConnection(); if (connectionStatus == ConnectionTesterStatus.Error) { return(false); } return(true); }
// Use this for initialization public void Start(GUIDone doneDelegate) { //DontDestroyOnLoad(this); guiDone = doneDelegate; //Start connection test natCapable = Network.TestConnection(); /*What kind of IP does this machine have? TestConnection also indicates this * in the test results*/ if(Network.HavePublicAddress()) Debug.Log("This machine has a public IP address"); else Debug.Log("This machine has a private IP address"); }
void CheckNetwork() { ConnectionTesterStatus status = Network.TestConnection(); if (status == ConnectionTesterStatus.Undetermined) { return; } switch (status) { case ConnectionTesterStatus.Error: Debug.Log("Network test: Error"); break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: Debug.Log("Network test: LimitedNATPunchthroughPortRestricted"); break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: Debug.Log("Network test: LimitedNATPunchthroughSymmetric"); break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: Debug.Log("Network test: NATpunchthroughAddressRestrictedCone"); break; case ConnectionTesterStatus.NATpunchthroughFullCone: Debug.Log("Network test: NATpunchthroughFullCone"); break; case ConnectionTesterStatus.PublicIPIsConnectable: Debug.Log("Network test: PublicIPIsConnectable"); break; case ConnectionTesterStatus.PublicIPNoServerStarted: Debug.Log("Network test: PublicIPNoServerStarted"); break; case ConnectionTesterStatus.PublicIPPortBlocked: Debug.Log("Network test: PublicIPPortBlocked"); break; case ConnectionTesterStatus.Undetermined: Debug.Log("Network test: Undetermined"); break; } doneTesting = true; }
void MakeWindow(int id) { hideTest = GUILayout.Toggle(hideTest, "Hide test info"); if (!hideTest) { GUILayout.Label(testMessage); if (GUILayout.Button("Retest connection")) { Debug.Log("Redoing connection test"); probingPublicIP = false; doneTesting = false; connectionTestResult = Network.TestConnection(true); } } if (Network.peerType == NetworkPeerType.Disconnected) { GUILayout.BeginHorizontal(); GUILayout.Space(10); // Start a new server if (GUILayout.Button("Start Server")) { Network.InitializeServer(32, serverPort, useNat); MasterServer.RegisterHost(gameName, "stuff", "l33t game for all"); } // Refresh hosts if (GUILayout.Button("Refresh available Servers") || Time.realtimeSinceStartup > lastHostListRequest + hostListRefreshTimeout) { MasterServer.RequestHostList(gameName); lastHostListRequest = Time.realtimeSinceStartup; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { if (GUILayout.Button("Disconnect")) { Network.Disconnect(); MasterServer.UnregisterHost(); } GUILayout.FlexibleSpace(); } GUI.DragWindow(new Rect(0, 0, 1000, 1000)); }
void HandleOnAdFailedToLoad(object sender, EventArgs args) { #if UNITY_ANDROID || UNITY_IPHONE connectionTestResult = Network.TestConnection(); Debug.Log("FailedToLoad testConnection=" + connectionTestResult + " and internetReachability=" + Application.internetReachability); #endif if (Application.internetReachability == NetworkReachability.NotReachable) { StartCoroutine(RequestInterstialAfterSeconds(10f)); } else { StartCoroutine(RequestInterstialAfterSeconds(2f)); } }
// Use this for initialization IEnumerator Start() { natCapable = Network.TestConnection(); yield return(new WaitForEndOfFrame()); if (Network.HavePublicAddress()) { Debug.Log("This machine has a public IP address"); } else { Debug.Log("This machine has a private IP address"); } }
void TestConnection() { //Start/Poll the connection test, report the results in a label and react to //the results accordingly natCapable = Network.TestConnection(); switch (natCapable) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectible public IP address (port " + serverPort + " blocked)," + " running a server is impossible."; //If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { Debug.Log("Testing if firewall can be circumvented"); natCapable = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } else if (Time.time > timer) { probingPublicIP = false; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized," + " it must be started to check server accessibility. " + "Restart connection test when ready."; break; default: testMessage = "Error in test routine, got " + natCapable; break; } }
public override void PrintGUI() { GUILayout.Space(20); if(doneTesting && GUILayout.Button("Start Test")){ //new Rect(0,0,position.width/2,20), doneTesting = false; testResult = ConnectionTesterStatus.Undetermined; }else if(!doneTesting){ GUILayout.Box("Testing..."); } GUILayout.Label(testMessage); if(!doneTesting && Event.current.type == EventType.Layout){ TestConnection(); }if(doneTesting){ GUILayout.Label("use of nat recommended: "+ (useNat ? "yes" : "no")); } }
void Awake() { DontDestroyOnLoad(this); natCapable = Network.TestConnection(); if (Network.HavePublicAddress()) { Debug.Log("This machine has a PUBLIC IP Address"); } else { Debug.Log("This machine has a PRIVATE IP address"); } gamemenustate = menustate.networklobby; }
void Awake() { windowRect = new Rect(Screen.width - 300, 50, 300, 100); serverListRect = new Rect(0, 0, Screen.width - windowRect.width, 100); // Start connection test connectionTestResult = Network.TestConnection(); // What kind of IP does this machine have? TestConnection also indicates this in the // test results if (Network.HavePublicAddress()) { Debug.Log("This machine has a public IP address"); } else { Debug.Log("This machine has a private IP address"); } }
// Use this for initialization public void Start(GUIDone doneDelegate) { //DontDestroyOnLoad(this); guiDone = doneDelegate; //Start connection test natCapable = Network.TestConnection(); /*What kind of IP does this machine have? TestConnection also indicates this * in the test results*/ if (Network.HavePublicAddress()) { Debug.Log("This machine has a public IP address"); } else { Debug.Log("This machine has a private IP address"); } }
//return value: empty string means fine public static string check_InternetConnection() { ConnectionTesterStatus connectionTestResult = ConnectionTesterStatus.Undetermined; connectionTestResult = Network.TestConnection(); string testMessage = ""; //bool probingPublicIP = false; int serverPort = 9999; switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = ""; //testMessage = "Directly connectable public IP address."; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectable public IP address (port " + serverPort + " blocked), running a server is impossible."; break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized, " + "it must be started to check server accessibility. Restart " + "connection test when ready."; break; default: //testMessage = "Error in test routine, got " + connectionTestResult; break; } return(testMessage); }
void Awake() { DontDestroyOnLoad(this); // Start connection test natCapable = Network.TestConnection(); // What kind of IP does this machine have? TestConnection also indicates // this in the test results //if (Network.HavePublicAddress()) // Debug.Log("This machine has a public IP address"); //else // Debug.Log("This machine has a private IP address"); // The game can have several menus and states, so I like to use // an enum to keep track of what state we’re in. In this case we’re // in the MGS lobby gamemenustate = menustate.networklobby; }
void TestConnection() { //Start/Poll the connection test, report the results in a label and react to //the results accordingly natCapable = Network.TestConnection(); switch(natCapable) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectible public IP address (port " + serverPort + " blocked)," + " running a server is impossible."; //If no NAT punchthrough test has been performed on this public IP, force a test if(!probingPublicIP) { Debug.Log("Testing if firewall can be circumvented"); natCapable = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } else if(Time.time > timer) { probingPublicIP = false; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized," + " it must be started to check server accessibility. " + "Restart connection test when ready."; break; default: testMessage = "Error in test routine, got " + natCapable; break; } }
// Called once per frame when the state is active. public override void Update() { ConnectionTesterStatus connectionTestResult = Network.TestConnection(); if (connectionTestResult == ConnectionTesterStatus.Error) { Debug.LogError("Network connection unavailable"); database.GetReference(path).ValueChanged -= HandleResult; isComplete = true; } if (isComplete) { manager.PopState(); } else { UpdateLabelText(); } }
void TestConnection() { string externalip = ""; try { externalip = new WebClient().DownloadString("http://icanhazip.com"); } catch (Exception e) { externalip = ""; } if (Network.HavePublicAddress() || externalip != "") { doneTesting = false; connectionTestResult = ConnectionTesterStatus.Undetermined; } else { connectionStatus = Status.NO_CONNECTION; testMessage = noConnection; EventManager.TriggerEvent(CONNECTION_STATUS_UPDATE, connectionStatus); Debug.Log(TAG + connectionStatus + "\t" + "Status: No public IP"); } }
void TestConnection() { // Start/Poll the connection test, report the results in a label and // react to the results accordingly if (probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); } else { connectionTestResult = Network.TestConnection(); } switch (connectionTestResult) { case ConnectionTesterStatus.Error: // check your internet connection testStatus = "Error testing your connection.\nMake sure you are connected to the internet and try again."; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: // still connecting break; case ConnectionTesterStatus.PublicIPIsConnectable: // everythings fine testStatus = ""; doneTesting = true; NATmode = 0; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: case ConnectionTesterStatus.PublicIPNoServerStarted: // ignore the fact it needs a server and just go for it! testStatus = "Checking NAT punchthough capabilities..."; // If no NAT punchthrough test has been performed on this public // IP, force a test if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(true); // force a pull probingPublicIP = true; NATtimer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked - ie it did it again else if (Time.time > NATtimer) { testStatus = ""; probingPublicIP = false; // reset - don't see the point in this? NATmode = 1; // could be 2? I have no idea what I'm doing! doneTesting = true; } break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: // cannot connect to or from sym testStatus = "You may have issues hosting a server.\n" + "Any servers you can't connect to have also been removed."; doneTesting = true; NATmode = 1; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: // sym cannot connect to anything using NAT-punch testStatus = "You may have issues hosting a server.\n" + "Any servers you can't connect to have also been removed."; doneTesting = true; NATmode = 2; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: // everything works case ConnectionTesterStatus.NATpunchthroughFullCone: // everything works testStatus = ""; doneTesting = true; NATmode = 0; break; default: // error testStatus = "Error in test routine, got " + connectionTestResult + ".\nTell a dev!"; break; } if (doneTesting) { // if we're done then update nvs nvs.NATmode = NATmode; // get them servers MasterServer.ClearHostList(); MasterServer.RequestHostList(serverVersion); } }
// UNTESTED FUNCTIONS ///////////////////////// private bool test_client_server_connecion(ConnectionTesterStatus type1, ConnectionTesterStatus type2) { if (type1 == ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted && type2 == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric) return false; else if (type1 == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric && type2 == ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted) return false; else if (type1 == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric && type2 == ConnectionTesterStatus.LimitedNATPunchthroughSymmetric) return false; return true; }
void TestConnection() { // Start/Poll the connection test, report the results in a label and react to the results accordingly natCapable = Network.TestConnection(); switch (natCapable) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PrivateIPNoNATPunchthrough: testMessage = "Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections," +" local LAN games only."; filterNATHosts = true; Network.useNat = true; doneTesting = true; break; case ConnectionTesterStatus.PrivateIPHasNATPunchThrough: if (probingPublicIP) testMessage = "Non-connectable public IP address (port "+ serverPort +" blocked)," +" NAT punchthrough can circumvent the firewall."; else testMessage = "NAT punchthrough capable. Enabling NAT punchthrough functionality."; // NAT functionality is enabled in case a server is started, // clients should enable this based on if the host requires it Network.useNat = true; doneTesting = true; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; Network.useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // use the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port " + serverPort +" blocked)," +" running a server is impossible."; Network.useNat = false; // If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { Debug.Log("Testing if firewall can be circumnvented"); natCapable = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized," +"it must be started to check server accessibility. Restart connection test when ready."; break; default: testMessage = "Error in test routine, got " + natCapable; break; } }
void TestConnection() { // Start/Poll the connection test, report the results in a label and react to the results accordingly connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port " + ServerPort + " blocked), running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { Debug.Log("Testing if firewall can be circumvented"); connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready."; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: Debug.Log("LimitedNATPunchthroughPortRestricted"); testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: Debug.Log("LimitedNATPunchthroughSymmetric"); testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers. Running a server is ill adviced as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: Debug.Log("NATpunchthroughAddressRestrictedCone || NATpunchthroughFullCone"); testMessage = "NAT punchthrough capable. Can connect to all servers and receive connections from all clients. Enabling NAT punchthrough functionality."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughFullCone: Debug.Log("NATpunchthroughAddressRestrictedCone || NATpunchthroughFullCone"); testMessage = "NAT punchthrough capable. Can connect to all servers and receive connections from all clients. Enabling NAT punchthrough functionality."; useNat = true; doneTesting = true; break; default: testMessage = "Error in test routine, got " + connectionTestResult; break; } }
IEnumerator WaitForRaknet() { for (int a = 0; a < 600; a++) { bool testDone = false; if (ipStatus != ConnectionTesterStatus.Undetermined && natStatus != ConnectionTesterStatus.Undetermined) { testDone = true; } if (ipStatus == ConnectionTesterStatus.Error) { ipStatus = ConnectionTesterStatus.Undetermined; testDone = false; Network.TestConnection(true); StartCoroutine("TestIP"); } if (natStatus == ConnectionTesterStatus.Error) { natStatus = ConnectionTesterStatus.Undetermined; testDone = false; Network.TestConnectionNAT(true); StartCoroutine("TestNAT"); } if (NATNetworkManager_PHP.connectedToFac && testDone) { if (ipStatus == ConnectionTesterStatus.PublicIPIsConnectable || ipStatus == ConnectionTesterStatus.PublicIPNoServerStarted) { natCapability = NATCapabilityIndex.publicIPPortOpen; } else if (hasUpnp) { natCapability = NATCapabilityIndex.upnp; } else { switch (ipStatus) { case ConnectionTesterStatus.NATpunchthroughFullCone: { natCapability = NATCapabilityIndex.natFullCone; break; } case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: { natCapability = NATCapabilityIndex.natAddressRestricted; break; } case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: { natCapability = NATCapabilityIndex.natPortRestricted; break; } case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: { natCapability = NATCapabilityIndex.natSymmetrical; break; } } } if (!connectedToFacTest) { ConnectFacTest(); } StartCoroutine("WaitForRaknetTest"); yield break; } yield return(new WaitForSecondsRealtime(0.1f)); } if (!NATNetworkManager_PHP.connectedToFac) { NATNetworkManager_PHP.DisplayLog("ConnectFac failed"); if (Application.internetReachability == NetworkReachability.NotReachable) { StartCoroutine("WaitForNetwork"); } else { TryCoroutine(); } } }
bool useNat = false; // natパンチスルーを使用するか. IEnumerator CheckNat() { bool doneTesting = false; // 接続テストが終わったか. bool probingPublicIP = false; float timer = 0; useNat = false; // 接続テストをしてNATパンチスルーが必要かしらべる. while (!doneTesting) { ConnectionTesterStatus connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: // 問題が発生した. doneTesting = true; break; case ConnectionTesterStatus.Undetermined: // 調査中. doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: // パブリックIPアドレスを持っているのでNATパンチスルーは使わなくていい. useNat = false; doneTesting = true; break; case ConnectionTesterStatus.PublicIPPortBlocked: // パブリックIPアドレスを持っているようだがポートがブロックされていて接続できない. useNat = false; if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: // パブリックIPアドレスを持っているがサーバーが起動していない. break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: // NATパンチスルーに制限がある. // サーバーに接続できないクライアントがあるかもしれない. useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: // NATパンチスルーによりサーバーとクライアンは問題なく接続できる. useNat = true; doneTesting = true; break; default: Debug.Log("Error in test routine, got " + connectionTestResult); break; } yield return(null); } }
void ShowGUI() { if(GUI.Button (new Rect(100, 10, 120, 30), "Retest connection")) { Debug.Log ("Redoing connection test"); probingPublicIP = false; doneTesting = false; natCapable = Network.TestConnection(true); } subGUIDelegate(); }
void MakeWindow (int id) { hideTest = GUILayout.Toggle(hideTest, "Hide test info"); if (!hideTest) { GUILayout.Label(testMessage); if (GUILayout.Button ("Retest connection")) { Debug.Log("Redoing connection test"); probingPublicIP = false; doneTesting = false; connectionTestResult = Network.TestConnection(true); } } if (Network.peerType == NetworkPeerType.Disconnected) { GUILayout.BeginHorizontal(); GUILayout.Space(10); // Start a new server if (GUILayout.Button ("Start Server")) { Network.InitializeServer(12, serverPort, useNat); MasterServer.RegisterHost(gameName, "Sitel", "Blah blah"); } // Refresh hosts if (GUILayout.Button ("Refresh available Servers") || Time.realtimeSinceStartup > lastHostListRequest + hostListRefreshTimeout) { MasterServer.RequestHostList (gameName); lastHostListRequest = Time.realtimeSinceStartup; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else { if (GUILayout.Button ("Disconnect")) { Network.Disconnect(); MasterServer.UnregisterHost(); } GUILayout.FlexibleSpace(); } GUI.DragWindow (new Rect (0,0,1000,1000)); }
void TestConnectionNAT() { connectionTestResult = Network.TestConnectionNAT(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = noConnection; doneTesting = true; connectionStatus = Status.NO_CONNECTION; break; case ConnectionTesterStatus.Undetermined: testMessage = noConnection; doneTesting = false; connectionStatus = Status.UNKNOWN; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = goodConnection; useNat = false; doneTesting = true; connectionStatus = Status.CONNECTED; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = limitedConnection; useNat = false; // If no NAT punchthrough test has been performed on this public // IP, force a test if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; connectionStatus = Status.LIMITED; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = goodConnection; useNat = true; doneTesting = true; connectionStatus = Status.CONNECTED; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessage = limitedConnection; useNat = true; doneTesting = true; connectionStatus = Status.LIMITED; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: testMessage = limitedConnection; useNat = true; doneTesting = true; connectionStatus = Status.LIMITED; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: testMessage = limitedConnection; useNat = true; doneTesting = true; connectionStatus = Status.LIMITED; break; default: testMessage = noConnection; connectionStatus = Status.NO_CONNECTION; break; } if (doneTesting) { EventManager.TriggerEvent(CONNECTION_STATUS_UPDATE, connectionStatus); Debug.Log(TAG + connectionStatus + "\t" + "Status: " + connectionTestResult); } }
// Test Connection is used to check the connection to the Game Server (GS) to determine if it's behind a router/FW // with a different public IP and private IP. This helps us determine if we need to try using NAT Punch Through to connect // Network.useNat will be set based on the tested findings. This is used on the client to figure out how to connect // On the GS we check !Network.HavePublicAddress() and pass it into the MGS when we register so it know if NPT is required void TestConnection() { // Start/Poll the connection test, report the results in a label and react to the results accordingly natCapable = Network.TestConnection(); switch (natCapable) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Testing NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // use the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port " + serverPort + " blocked)," + " running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { //Debug.Log("Testing if firewall can be circumnvented"); natCapable = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized," + "it must be started to check server accessibility. Restart connection test when ready."; doneTesting = true; break; default: testMessage = "Error in test routine, got " + natCapable; if (string.Compare("Limited", 0, natCapable.ToString(), 0, 7) == 0) { useNat = true; } doneTesting = true; break; } // end switch //Debug.Log(testMessage); }
void TestConnection() { // Start/Poll the connection test, report the results in a label and // react to the results accordingly connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = "Problem"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectable public IP address (port " + serverPort + " blocked), running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public // IP, force a test if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; testStatus = "Testing if blocked public IP can be circumvented"; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Test Failed"; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessage = "Limited"; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: testMessage = "Limited"; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: testMessage = "Open"; useNat = true; doneTesting = true; break; default: testMessage = "Error in test routine, got " + connectionTestResult; break; } if (doneTesting) { if (useNat) shouldEnableNatMessage = "Yes"; else shouldEnableNatMessage = "No"; testStatus = "Done testing"; } }
/**************************************************** * * DO EDIT THIS SCRIPT * ****************************************************/ // Use this for initialization void Start() { // change to custom master server MasterServer.ipAddress = "37.157.247.37"; MasterServer.port = 23466; // NAT punchthrough (finally) Network.natFacilitatorIP = "37.157.247.37"; Network.natFacilitatorPort = 50005; nvs = GameObject.FindWithTag("NetObj").GetComponent("networkVariables") as networkVariables; // get server version serverVersion = nvs.serverVersion; // get NATmode NATmode = nvs.NATmode; // sudo make me a camera nvs.myCam = new GameObject("theCamera").AddComponent("Camera") as Camera; nvs.myCam.gameObject.AddComponent("AudioListener"); nvs.myCam.gameObject.SetActive(false); // disable it until we have joined a game // get them servers MasterServer.ClearHostList(); MasterServer.RequestHostList(serverVersion); // check if we don't have a valid NATmode if (NATmode==-1) { // test the current setup rather than poll for the result connectionTestResult = Network.TestConnection(true); doneTesting = false; } else { SetMessage(); doneTesting = true; } }
private void TestConnection() { testResult = Network.TestConnection(); switch(testResult){ case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectable public IP address, running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public // IP, force a test // if (!probingPublicIP) { // connectionTestResult = Network.TestConnectionNAT(); // probingPublicIP = true; // testStatus = "Testing if blocked public IP can be circumvented"; // timer = Time.time + 10; // } // // NAT punchthrough test was performed but we still get blocked // else if (Time.time > timer) { // probingPublicIP = false; // reset // useNat = true; // doneTesting = true; // } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized, "+ "it must be started to check server accessibility. Restart "+ "connection test when ready."; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessage = "Limited NAT punchthrough capabilities (Port Restricted). Cannot "+ "connect to all types of NAT servers. Running a server "+ "is ill advised as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: testMessage = "Limited NAT punchthrough capabilities (Symmetric). Cannot "+ "connect to all types of NAT servers. Running a server "+ "is ill advised as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: testMessage = "NAT punchthrough capable. Can connect to all "+ "servers and receive connections from all clients. Enabling "+ "NAT punchthrough functionality."; useNat = true; doneTesting = true; break; default: testMessage = "Error in test routine, got " + testResult; break; } }
void TestConnection() { float timer = Time.time; // Start/Poll the connection test, report the results in a label and // react to the results accordingly connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessageText = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessageText = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessageText = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessageText = "Non-connectable public IP address (port " + advancedSettings.serverPort + " blocked), running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public // IP, force a test if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; testMessage.text = "Testing if blocked public IP can be circumvented"; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessageText = "Public IP address but server not initialized, " + "it must be started to check server accessibility. Restart " + "connection test when ready."; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessageText = "Limited NAT punchthrough capabilities. Cannot " + "connect to all types of NAT servers. Running a server " + "is ill advised as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: testMessageText = "Limited NAT punchthrough capabilities. Cannot " + "connect to all types of NAT servers. Running a server " + "is ill advised as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: testMessageText = "NAT punchthrough capable. Can connect to all " + "servers and receive connections from all clients. Enabling " + "NAT punchthrough functionality."; useNat = true; doneTesting = true; break; default: testMessageText = "Error in test routine, got " + connectionTestResult; break; } if (doneTesting) { if (useNat) { shouldEnableNatMessage = "When starting a server the NAT " + "punchthrough feature should be enabled (useNat parameter)"; } else { shouldEnableNatMessage = "NAT punchthrough not needed"; } testMessage.text = shouldEnableNatMessage + "Done testing"; } }
IEnumerator TestConnection() { if (hasTestedNAT) { yield break; } while (!hasLoadedMasterserverSettings) { yield return(0); } testedUseNat = !Network.HavePublicAddress(); ConnectionTesterStatus connectionTestResult = ConnectionTesterStatus.Undetermined; float timeoutAt = Time.realtimeSinceStartup + 10; float timer = 0; bool probingPublicIP = false; string testMessage = ""; while (!hasTestedNAT) { yield return(0); if (Time.realtimeSinceStartup >= timeoutAt) { Debug.LogWarning("TestConnect NAT test aborted; timeout"); break; } connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; hasTestedNAT = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; hasTestedNAT = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; testedUseNat = false; hasTestedNAT = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port " + defaultServerPort + " blocked), running a server is impossible."; hasTestedNAT = false; // If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { Debug.Log("Testing if firewall can be circumvented"); connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset testedUseNat = true; hasTestedNAT = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready."; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers. Running a server is ill adviced as not everyone can connect."; testedUseNat = true; hasTestedNAT = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers. Running a server is ill adviced as not everyone can connect."; testedUseNat = true; hasTestedNAT = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: testMessage = "NAT punchthrough capable. Can connect to all servers and receive connections from all clients. Enabling NAT punchthrough functionality."; testedUseNat = true; hasTestedNAT = true; break; default: testMessage = "Error in test routine, got " + connectionTestResult; break; } } hasTestedNAT = true; Debug.Log("TestConnection result: testedUseNat=" + testedUseNat + " connectionTestResult=" + connectionTestResult + " probingPublicIP=" + probingPublicIP + " hasTestedNAT=" + hasTestedNAT + " testMessage=" + testMessage); }
private IEnumerator DetermineNetworkStatus() { do { NetworkTestStatus = Network.TestConnection(); yield return null; } while (NetworkTestStatus == ConnectionTesterStatus.Undetermined); }
// Test Connection is used to check the connection to the Game Server (GS) to determine if it's behind a router/FW // with a different public IP and private IP. This helps us determine if we need to try using NAT Punch Through to connect // Network.useNat will be set based on the tested findings. This is used on the client to figure out how to connect // On the GS we check !Network.HavePublicAddress() and pass it into the MGS when we register so it know if NPT is required void TestConnection() { // Start/Poll the connection test, report the results in a label and react to the results accordingly natCapable = Network.TestConnection(); switch (natCapable) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Testing NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // use the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port " + serverPort +" blocked)," +" running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { //Debug.Log("Testing if firewall can be circumnvented"); natCapable = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized," +"it must be started to check server accessibility. Restart connection test when ready."; doneTesting = true; break; default: testMessage = "Error in test routine, got " + natCapable; if ( string.Compare("Limited",0,natCapable.ToString(),0,7) == 0 ) useNat = true; doneTesting = true; break; } // end switch //Debug.Log(testMessage); }
void TestConnection() { natCapable = Network.TestConnection(); switch (natCapable) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Testing NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address"; useNat = false; doneTesting = true; break; case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectable public IP address (port " + serverPort + " blocked) running a server is impossible."; useNat = false; if (!probingPublicIP) { Debug.Log("Testing if firewall can be circumvented"); natCapable = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } else if (Time.time > timer) { probingPublicIP = false; useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not inititalized, it must be started to check server accessiblity. Restart connect test when ready."; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessage = "Limited NAT punchthrough capabilities. Cannot " + "connect to all types of NAT servers. Running a server " + "is ill advised as not everyone can connect."; useNat = true; doneTesting = true; break; default: testMessage = "Error in test routine, got " + natCapable; if (string.Compare("Limited", 0, natCapable.ToString(), 0, 7) == 0) { useNat = true; doneTesting = true; break; } break; } Debug.Log(testMessage); }
IEnumerator TestConnection() { testing = true; natCapable = Network.TestConnection(); yield return(new WaitForSeconds(0.5f)); switch (natCapable) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTestingNAT = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTestingNAT = false; break; case ConnectionTesterStatus.PrivateIPNoNATPunchthrough: testMessage = "Cannot do NAT punchthrough, filtering NAT enabled hosts for client connections, local LAN games only."; filterNATHosts = true; Network.useNat = true; doneTestingNAT = true; break; case ConnectionTesterStatus.PrivateIPHasNATPunchThrough: if (probingPublicIP) { testMessage = "Non-connectable public IP address (port blocked), NAT punchthrough can circumvent the firewall."; } else { testMessage = "NAT punchthrough capable. Enabling NAT punchthrough functionality."; } // NAT functionality is enabled in case a server is started, // clients should enable this based on if the host requires it Network.useNat = true; doneTestingNAT = true; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; Network.useNat = false; doneTestingNAT = true; break; // This case is a bit special as we now need to check if we can // cicrumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port blocked), running a server is impossible."; Network.useNat = false; // If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { Debug.Log("Testing if firewall can be circumnvented"); natCapable = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset Network.useNat = true; doneTestingNAT = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready."; break; default: testMessage = "Error in test routine, got " + natCapable; break; } Debug.Log(testMessage); if (doneTestingNAT) { JoinMenu.officialNATstatus = Network.useNat; Debug.Log("TestConn:" + testMessage); Debug.Log("TestConn:" + natCapable + " " + probingPublicIP + " " + doneTestingNAT); } testing = false; }
void ShowGUI() { if (GUI.Button (new Rect(100,10,120,30),"Retest connection")) { Debug.Log("Redoing connection test"); probingPublicIP = false; doneTesting = false; natCapable = Network.TestConnection(true); } if (Network.peerType == NetworkPeerType.Disconnected) { // Start a new server if (GUI.Button(new Rect(10,10,90,30),"Start Server")) { Network.InitializeServer(32, serverPort, false); MasterServer.updateRate = 3; MasterServer.RegisterHost(gameName, "stuff", "profas chat test"); } // Refresh hosts if (GUI.Button(new Rect(10,40,210,30),"Refresh available Servers") || Time.realtimeSinceStartup > lastHostListRequest + hostListRefreshTimeout) { MasterServer.ClearHostList(); MasterServer.RequestHostList (gameName); lastHostListRequest = Time.realtimeSinceStartup; Debug.Log("Refresh Click"); } HostData[] data = MasterServer.PollHostList(); int _cnt = 0; foreach(var element in data) { // Do not display NAT enabled games if we cannot do NAT punchthrough if ( !(filterNATHosts && element.useNat) ) { string name= element.gameName + " " + element.connectedPlayers + " / " + element.playerLimit; string hostInfo; hostInfo = "["; // Here we display all IP addresses, there can be multiple in cases where // internal LAN connections are being attempted. In the GUI we could just display // the first one in order not confuse the end user, but internally Unity will // do a connection check on all IP addresses in the element.ip list, and connect to the // first valid one. foreach(var host in element.ip) { hostInfo = hostInfo + host + ":" + element.port + " "; } hostInfo = hostInfo + "]"; if (GUI.Button(new Rect(20,(_cnt*50)+90,400,40),hostInfo.ToString())) { // Enable NAT functionality based on what the hosts if configured to do Network.useNat = element.useNat; if (Network.useNat) print("Using Nat punchthrough to connect"); else print("Connecting directly to host"); Network.Connect(element.ip, element.port); } } } } else { if (GUI.Button (new Rect(10,10,90,30),"Disconnect")) { Network.Disconnect(); MasterServer.UnregisterHost(); } } }
void MakeWindow (int id){ //Debug.Log(id.ToString()); hideTest = GUILayout.Toggle(hideTest, "Hide test info"); if (!hideTest){ GUILayout.Label(testMessage); if (GUILayout.Button ("Retest connection")){ Debug.Log("Redoing connection test"); probingPublicIP = false; doneTesting = false; connectionTestResult = Network.TestConnection(true); } } if (Network.peerType == NetworkPeerType.Disconnected){ GUILayout.BeginHorizontal(); GUILayout.Space(10); if(canCreateServer){ if (GUILayout.Button ("Start Server")){ //static function InitializeServer (connections : int, listenPort : int, useNat : boolean) : NetworkConnectionError Network.InitializeServer(32, serverPort, useNat); //(gameTypeName : String, gameName : String, comment : String = "") MasterServer.RegisterHost(gameName, "Server", ""); networkView.RPC( "LoadLevel", RPCMode.AllBuffered); } } // Refresh hosts if (GUILayout.Button ("Refresh available Servers") || Time.realtimeSinceStartup > lastHostListRequest + hostListRefreshTimeout){ MasterServer.RequestHostList (gameName); lastHostListRequest = Time.realtimeSinceStartup; } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } else{ if (GUILayout.Button ("Disconnect")){ Network.Disconnect(); MasterServer.UnregisterHost(); } GUILayout.FlexibleSpace(); } GUI.DragWindow (new Rect (0,0,1000,1000)); }
void TestConnection() { // Start/Poll the connection test, report the results in a label and // react to the results accordingly connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = "Problem"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectable public IP address (port " + serverPort + " blocked), running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public // IP, force a test if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; testStatus = "Testing if blocked public IP can be circumvented"; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Test Failed"; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessage = "Limited"; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: testMessage = "Limited"; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: testMessage = "Open"; useNat = true; doneTesting = true; break; default: testMessage = "Error in test routine, got " + connectionTestResult; break; } if (doneTesting) { if (useNat) { shouldEnableNatMessage = "Yes"; } else { shouldEnableNatMessage = "No"; } testStatus = "Done testing"; } }
void Awake (){ DontDestroyOnLoad(gameObject); windowRect = new Rect(Screen.width-300,0,300,100); serverListRect = new Rect(0, 0, Screen.width - windowRect.width, 100); connectionTestResult = Network.TestConnection(); if (Network.HavePublicAddress()) Debug.Log("This machine has a public IP address"); else Debug.Log("This machine has a private IP address"); }
void TestConnection() { float timer = Time.time; // Start/Poll the connection test, report the results in a label and // react to the results accordingly connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessageText = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessageText = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessageText = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessageText = "Non-connectable public IP address (port " + advancedSettings.serverPort + " blocked), running a server is impossible."; useNat = false; // If no NAT punchthrough test has been performed on this public // IP, force a test if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessageText = "Public IP address but server not initialized, " + "it must be started to check server accessibility. Restart " + "connection test when ready."; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: testMessageText = "Limited NAT punchthrough capabilities. Cannot " + "connect to all types of NAT servers. Running a server " + "is ill advised as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: testMessageText = "Limited NAT punchthrough capabilities. Cannot " + "connect to all types of NAT servers. Running a server " + "is ill advised as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: testMessageText = "NAT punchthrough capable. Can connect to all " + "servers and receive connections from all clients. Enabling " + "NAT punchthrough functionality."; useNat = true; doneTesting = true; break; default: testMessageText = "Error in test routine, got " + connectionTestResult; break; } chatBoard.ReceiveMessage(testMessageText); if (doneTesting) { if (useNat) shouldEnableNatMessage = "When starting a server the NAT " + "punchthrough feature should be enabled (useNat parameter)"; else shouldEnableNatMessage = "NAT punchthrough not needed"; } }
void TestConnection(){ connectionTestResult = Network.TestConnection(); switch(connectionTestResult){ case ConnectionTesterStatus.Error: testMessage="Problem determining NAT capabilities"; doneTesting=true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; useNat = false; doneTesting = true; break; case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port " + serverPort +" blocked), running a server is impossible."; useNat = false; if (!probingPublicIP){ Debug.Log("Testing if firewall can be circumvented"); connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } else if (Time.time > timer){ probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready."; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: Debug.Log("LimitedNATPunchthroughPortRestricted"); testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: Debug.Log("LimitedNATPunchthroughSymmetric"); testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers. Running a server is ill adviced as not everyone can connect."; useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: break; case ConnectionTesterStatus.NATpunchthroughFullCone: Debug.Log("NATpunchthroughAddressRestrictedCone || NATpunchthroughFullCone"); testMessage = "NAT punchthrough capable. Can connect to all servers and receive connections from all clients. Enabling NAT punchthrough functionality."; useNat = true; doneTesting = true; break; default: testMessage = "Error in test routine, got " + connectionTestResult; break; } }
// Connection tests and debugging void Connection_Test() { // Start/Poll the connection test, report the results in a label and react to the results accordingly connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: testMessage = "Problem determining NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: testMessage = "Undetermined NAT capabilities"; doneTesting = true; break; case ConnectionTesterStatus.PublicIPIsConnectable: testMessage = "Directly connectable public IP address."; Use_Nat = false; doneTesting = true; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: testMessage = "Non-connectble public IP address (port " + Connection_Port + " blocked), running a server is impossible."; Use_Nat = false; // If no NAT punchthrough test has been performed on this public IP, force a test if (!probingPublicIP) { Debug.Log("Testing if firewall can be circumvented"); connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; IP_Probe_Timer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked else if (Time.time > IP_Probe_Timer) { probingPublicIP = false; // reset Use_Nat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: testMessage = "Public IP address but server not initialized, it must be started to check server accessibility. Restart connection test when ready."; break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: Debug.Log("LimitedNATPunchthroughPortRestricted"); testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers."; Use_Nat = true; doneTesting = true; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: Debug.Log("LimitedNATPunchthroughSymmetric"); testMessage = "Limited NAT punchthrough capabilities. Cannot connect to all types of NAT servers. Running a server is ill adviced as not everyone can connect."; Use_Nat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: goto case ConnectionTesterStatus.NATpunchthroughFullCone; case ConnectionTesterStatus.NATpunchthroughFullCone: Debug.Log("NATpunchthroughAddressRestrictedCone || NATpunchthroughFullCone"); testMessage = "NAT punchthrough capable. Can connect to all servers and receive connections from all clients. Enabling NAT punchthrough functionality."; Use_Nat = true; doneTesting = true; break; default: testMessage = "Error in test routine, got " + connectionTestResult; break; } //Debug.Log(connectionTestResult + " " + probingPublicIP + " " + doneTesting); Debug.Log(testMessage); }
void TestConnection() { // Start/Poll the connection test, report the results in a label and // react to the results accordingly if (probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); } else { connectionTestResult = Network.TestConnection(); } switch (connectionTestResult) { case ConnectionTesterStatus.Error: // check your internet connection testStatus = "Error testing your connection.\nMake sure you are connected to the internet and try again."; doneTesting = true; break; case ConnectionTesterStatus.Undetermined: // still connecting break; case ConnectionTesterStatus.PublicIPIsConnectable: // everythings fine testStatus = ""; doneTesting = true; NATmode = 0; break; // This case is a bit special as we now need to check if we can // circumvent the blocking by using NAT punchthrough case ConnectionTesterStatus.PublicIPPortBlocked: case ConnectionTesterStatus.PublicIPNoServerStarted: // ignore the fact it needs a server and just go for it! testStatus = "Checking NAT punchthough capabilities..."; // If no NAT punchthrough test has been performed on this public // IP, force a test if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(true); // force a pull probingPublicIP = true; NATtimer = Time.time + 10; } // NAT punchthrough test was performed but we still get blocked - ie it did it again else if (Time.time > NATtimer) { testStatus = ""; probingPublicIP = false; // reset - don't see the point in this? NATmode = 1; // could be 2? I have no idea what I'm doing! doneTesting = true; } break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: // cannot connect to or from sym testStatus = "You may have issues hosting a server.\n"+ "Any servers you can't connect to have also been removed."; doneTesting = true; NATmode = 1; break; case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: // sym cannot connect to anything using NAT-punch testStatus = "You may have issues hosting a server.\n"+ "Any servers you can't connect to have also been removed."; doneTesting = true; NATmode = 2; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: // everything works case ConnectionTesterStatus.NATpunchthroughFullCone: // everything works testStatus = ""; doneTesting = true; NATmode = 0; break; default: // error testStatus = "Error in test routine, got " + connectionTestResult + ".\nTell a dev!"; break; } if (doneTesting) { // if we're done then update nvs nvs.NATmode = NATmode; // get them servers MasterServer.ClearHostList(); MasterServer.RequestHostList(serverVersion); } }
bool useNat = false; // NAT 펀치스루를 사용하는가. IEnumerator CheckNat() { bool doneTesting = false; // 접속 테스트가 끝났는가. bool probingPublicIP = false; float timer = 0; useNat = false; // 접속 테스트를 하고 NAT 펀치스루가 필요한지 조사한다. while (!doneTesting) { ConnectionTesterStatus connectionTestResult = Network.TestConnection(); switch (connectionTestResult) { case ConnectionTesterStatus.Error: // 문제가 발생했다. doneTesting = true; break; case ConnectionTesterStatus.Undetermined: // 조사 중. doneTesting = false; break; case ConnectionTesterStatus.PublicIPIsConnectable: // 공인 IP 주소를 가지고 있으므로 NAT 펀치스루는 사용하지 않아도 된다. useNat = false; doneTesting = true; break; case ConnectionTesterStatus.PublicIPPortBlocked: // 공인 IP 주소인 것 같지만 포트가 막혀 접속할 수 없다. useNat = false; if (!probingPublicIP) { connectionTestResult = Network.TestConnectionNAT(); probingPublicIP = true; timer = Time.time + 10; } else if (Time.time > timer) { probingPublicIP = false; // reset useNat = true; doneTesting = true; } break; case ConnectionTesterStatus.PublicIPNoServerStarted: // 공인 IP 주소를 가지고 있지만 서버가 실행되지 않았다. break; case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted: case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric: // NAT 펀치스루에 제한이 있다. // 서버에 접속할 수 없는 클라이언트가 있을지도 모른다. useNat = true; doneTesting = true; break; case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone: case ConnectionTesterStatus.NATpunchthroughFullCone: // 서버와 클라이언트는 NAT 펀치스루로 문제 없이 접속할 수 있다. useNat = true; doneTesting = true; break; default: Debug.Log("Error in test routine, got " + connectionTestResult); break; } yield return(null); } }
private void test_connection() { testResult = Network.TestConnection(); if(testResult != ConnectionTesterStatus.Undetermined) { countdown.CancelCountDown(); reset_connection(); } }