Hello. I am following the M2H networking tutorial. Everything seems to work great. Right now I can only get players that have a wired connections to play. I spoke with M2H and they said (as I expected) that it was a problem with a NAT punch-through. I am using Unity’s master server. Here is the game, http://www.invaderstudios.com/game any suggestions will help. Thank you very much!
Suggestion: Host your own master server - connection tester - nat facilitator
The default one isn’t meant for production and its nat facilitator has a good chance of not working normally
Thats what I was thinking should be my next step.
Do you know if DimeRocker’s master server is still up and running?
Also I get this message in the console-
WARNING: ‘UnityEngine.ConnectionTesterStatus.PrivateIPHasNATPunchThrough’ is obselet. Not longer returned, use newer connection tester enums instead.
In the Help files, look up the ConnectionTesterStatus class. There should be a code snippet with all of the Unity3 test result values that you can replace into Leepo’s 2.6 code.
What are the help files?
In a script, type “ConnectionTesterStatus”, put your cursor somewhere in that word, and hit F1.
Those help files.
Well… that’s embarassing. ![]()
Invader Studios, I’ve been having similar problems, I’m trying something different:
For an individual server that you can connect to (as in, like in the UI code for Leepo’s M2H tutorial:)
MenuGUI.js section, in OnGUI():
element = connection.hostData[myElement];
GUILayout.BeginHorizontal();
// Do not display NAT enabled games if we cannot do NAT punchthrough
if ( !( connection.filterNATHosts element.useNat ) )
{
aHost=1;
var buttonText : String = element.gameName + " (" + element.connectedPlayers + "/" + element.playerLimit + ")";
GUI.color = Color( 0.8, 0.8,0.2, 1 );
if( GUILayout.Button( buttonText ) )
{
// Connect to the server.
connection.Connect( element );
// Read the gameScene info, load that level.
gameScene = parseInt( element.comment );
Debug.Log( "gameScene is: " + gameScene );
// In GUI Phase 5, the level is loaded or an error message shown.
phase = 5;
}
Connection.js:
function Connect( hostInfo : HostData ) : void
{
Debug.Log( "Connection: Connecting to " + hostInfo.ip + ":" + hostInfo.port + " with NAT puncthrough." );
Network.Connect( hostInfo );
nowConnecting = true;
}
EDIT!
Using an overload of Network.Connect that utilizes GUID information is, according to the F1 help files, the ONLY way to achieve client-side NAT puncthrough. I’m testing this to make sure it’s entirely accurate. Network.Connect overloads capable of this are:
Network.Connect( GUID );
Network.Connect( GUID, Password );
Thanks for that information!
I’ve solved the GUID problem, try Laser Cat in my signature. Make sure the version is later than 0.5.0.
Hey guys ive been keeping an eye on this thread the last few days as i am having a problem with the NAT Punchthrough aswell.Asvarduil could u please help me to understand how to use the GUID? I am new to networking and it would be of great help to get my game started with multiplayer. Or could u be so kind as to lead me in the right direction, i am using the M2H Example 2 code and trying to figure out where to and how to implement the GUID u mentioned…
Thanks Again!
First, I would use Example 4, as that’s what I used to get to the code I got.
In the Menu GUI code, find the part where it shows games being hosted. There will be a section like this:
scrollPosition = GUILayout.BeginScrollView( scrollPosition );
var aHost : int = 0;
if( connection.sortedList connection.sortedList.length >= 1 )
{
for( var myElement in connection.sortedList )
{
element = connection.hostData[myElement];
GUILayout.BeginHorizontal();
// Do not display NAT enabled games if we cannot do NAT punchthrough
if ( !( connection.filterNATHosts element.useNat ) )
{
aHost=1;
var buttonText : String = element.gameName + " (" + element.connectedPlayers + "/" + element.playerLimit + ")";
GUI.color = Color( 0.8, 0.8,0.2, 1 );
if( GUILayout.Button( buttonText ) )
{
// Connect to the server.
connection.Connect( element );
// Read the gameScene info, load that level.
gameScene = parseInt( element.comment );
Debug.Log( "gameScene is: " + gameScene );
//Application.LoadLevel( gameScene );
phase = 5;
}
GUILayout.Space( 1 );
}
GUILayout.EndHorizontal();
The part you want to keep in mind is the GUILayout.Button() if statement. Keep that open.
Now, find the menu connect code. You’re going to want to rewrite the Connect() function slightly:
function Connect( hostInfo : HostData ) : void
{
if( hostInfo.useNat ) { Network.Connect( hostInfo.guid ); }
else { Network.Connect( hostInfo ); }
nowConnecting = true;
}
Network.Connect( hostInfo.guid ) is the only way to achieve NAT punchthrough in Unity3. Go back to your menu code. Remember the if() block? There will be a “xxxxx.Connect()” call in there. Simply pass the whole “element” as the argument to the Connect function, like I already did above.
I’ll be uploading a Unity3 Master Server starting point package very soon, that will detail more about this process, and some out-of-the-box code to help your project, most likely on the Asset Store.
Thanks for the help Asvarduil, however this did not fix my problem = ( i did all the steps mentioned…and can see the other player on the masterserver list but am unable to connect successfully to eachother…
Well, there’s more to it than that, also. You also need each person to pre-check what their connection can or cannot do. The 2.6 M2H code needs a slight modification to work.
In that code, find their TestConnection() function. Replace it with this:
function TestConnection() : void
{
natCapable = Network.TestConnection();
switch( natCapable )
{
case ConnectionTesterStatus.Error:
testMessage = "Problem determining NAT capabilities";
errorMessage = "Test complete. Couldn't determine NAT punchthrough ability.";
doneTestingNAT = true;
break;
case ConnectionTesterStatus.Undetermined:
testMessage = "Undetermined NAT capabilities";
errorMessage = "Testing connection...";
doneTestingNAT = false;
break;
case ConnectionTesterStatus.NATpunchthroughFullCone:
case ConnectionTesterStatus.NATpunchthroughAddressRestrictedCone:
testMessage = "NAT can punchthrough as necessary.";
errorMessage = "";
doneTestingNAT = true;
useNAT = true;
break;
case ConnectionTesterStatus.LimitedNATPunchthroughPortRestricted:
testMessage = "Everyone except Symmetric NATs can connect.";
errorMessage = "Test complete. Some players cannot join your games.";
doneTestingNAT = true;
useNAT = true;
break;
case ConnectionTesterStatus.LimitedNATPunchthroughSymmetric:
testMessage = "NAT Punchthrough is limited to asymmetric NAT systems.";
errorMessage = "Test complete. Your NAT punchthrough is limited, do not host games.";
doneTestingNAT = true;
useNAT = true;
break;
case ConnectionTesterStatus.PublicIPIsConnectable:
testMessage = "Directly connectable public IP address.";
errorMessage = "";
doneTestingNAT = true;
useNAT = false;
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 " + address.ipPort + " blocked), running a server is impossible.";
errorMessage = "Test complete. Port " + address.ipPort + " is blocked. A server can't be started.";
// 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;
useNAT = false;
}
// NAT punchthrough test was performed but we still get blocked
else if( Time.time > timer )
{
probingPublicIP = false; // reset
doneTestingNAT = true;
useNAT = true;
}
break;
case ConnectionTesterStatus.PublicIPNoServerStarted:
testMessage = "Server not started, it is needed to check ability to connect with server. Restart the test when ready.";
break;
default:
testMessage = "Error in test routine, got " + natCapable;
errorMessage = "Test complete. There was an error in the connection test: " + natCapable;
}
if( doneTestingNAT )
{
Debug.Log( "Test Result: " + testMessage + "\n" +
"NAT Capability: " + natCapable + "\n" +
"Probing Public IP: " + probingPublicIP + "\n" +
"Done Testing NAT: " + doneTestingNAT );
}
}
This code is U3-friendly and should work a little better. The way I trigger it is:
function Awake() : void
{
// There's more here...but I omitted it, because it's
// not relevant.
PretestConnection();
}
function PretestConnection
{
while( !doneTestingNAT )
{
TestConnection();
yield;
}
}
On game startup - presuming you have an object with this code in your first loaded scene - your players should be automatically testing their own connections. This is particularly important for when they start servers, as that’s where the real ickiness of NAT happens; the client side of it is as simple as the Connect() function I already gave, as that Connect knows what to do based on whether or not the server requires NAT (which, you tell it in HostGame()…drat, I forgot that. Here ya go.)
function HostGame( players : int, port : int, scene : int ) : void
{
// Ensure that we have completed the network test...
if( natCapable == ConnectionTesterStatus.Undetermined )
{
errorMessage = "The connection test isn't complete. You can't connect until it is.";
return;
}
// Make sure that there's a number of players for a game.
errorMessage = "Starting up a game server...";
if( players < 1 ) { players = 1; }
// Tell clients what scene to load...
var descData : String = scene + "";
ambassador.gameDesc = descData;
Network.InitializeServer( players,port,useNAT );
}
Integrate all of that, make it work with the variables you already have set up, then try some connection tests.
Thanks for the help Asvarduil, u are the only person to try to help me out with this issue ive been having for a few weeks now lol…i have got all the code in place u provided and no errors…waiting til 2morrow for my buddy to get on so we can test to see if we can get a successfull connection…the pretest script u made tells me i have limited punchthrough and should not host a server…does that mean anything bad? lol thanks again man i owe u big time if it works!
I would like to mention that the M2H tutorial is outdated.
I’m in the progress myself of reworking the network code after the move to Unity 3.x.
Thanks for the help Asvaduil. I’m no programmer but I spent some time reading what you said and I am getting a few errors. First off, I am not using the Example_4 demo. I was wondering if all the scripts from the other examples are all linked together? Here is my code.
Menu_GUI.js
/*
* This file is part of the Unity networking tutorial by M2H (http://www.M2H.nl)
* The original author of this code is Mike Hergaarden, even though some small parts
* are copied from the Unity tutorials/manuals.
* Feel free to use this code for your own projects, drop us a line if you made something exciting!
*/
#pragma strict
#pragma implicit
#pragma downcast
private var windowRect1;
private var windowRect2;
private var windowRect3;
static var playNowMode : boolean = false;
static var advancedMode : boolean = false;
static var playNowModeStarted : float = 0.0;
static var myPlayerName : String = "MyPlayerName";
//GUI vars
private var hostPlayers : int = 8;
private var hostPort : int;
private var connectPort : int;
private var connectIP : String = "";
private var multiplayerScript : Menu_multiplayerCode;
private var currentMenu : String = "";
function Awake ()
{
Screen.lockCursor=false;
myPlayerName = PlayerPrefs.GetString("playerName");
multiplayerScript = GetComponent(Menu_multiplayerCode);
connectPort = hostPort = multiplayerScript.serverPort;
connectIP = "127.0.0.1";
windowRect1 = Rect (Screen.width/2-310,Screen.height/2-90,380,280);
windowRect2 = Rect (Screen.width/2+85,Screen.height/2-90,220,100);
windowRect3 = Rect (Screen.width/2+85,Screen.height/2+55,220,100);
playNowMode=false;
advancedMode=false;
}
function OnGUI ()
{
//If we've connected; load the game when it's ready to load
if(Network.isClient || Network.isServer){
//Since we're connected, load the game
GUI.Box(Rect(Screen.width/4+0,Screen.height/2-30,450,50), "");
if(Application.CanStreamedLevelBeLoaded ((Application.loadedLevel+1))){
GUI.Label(Rect(Screen.width/4+10,Screen.height/2-25,285,150), "Starting the game!");
Application.LoadLevel((Application.loadedLevel+1));
}else{
GUI.Label(Rect(Screen.width/4+10,Screen.height/2-25,285,150), "Loading the game: "+Mathf.Floor(Application.GetStreamProgressForLevel((Application.loadedLevel+1))*100)+" %");
}
return;
}
//Dirty error message popup
if(multiplayerScript.errorMessage multiplayerScript.errorMessage!=""){
GUI.Box(Rect(Screen.width/2-100,Screen.height/2-60,200,60), "Error");
GUI.Label(Rect(Screen.width/2-90,Screen.height/2-50,180,50), multiplayerScript.errorMessage);
if(GUI.Button(Rect(Screen.width/2+40,Screen.height/2-30,50,20), "Close")){
multiplayerScript.errorMessage="";
}
}
if(playNowMode){
playNowFunction();
}else if(advancedMode){
if(!multiplayerScript.errorMessage || multiplayerScript.errorMessage==""){ //Hide windows on error
if(GUI.Button(Rect(455,90,140,30), "Back to main menu")){
currentMenu="";
advancedMode=false;
}
windowRect1 = GUILayout.Window (0, windowRect1, listGUI, "Join a game via the list");
windowRect2 = GUILayout.Window (1, windowRect2, directConnectGUIWindow, "Directly join a game via an IP");
windowRect3 = GUILayout.Window (2, windowRect3, hostGUI, "Host a game");
}
}else{
GUI.Box (Rect (90, 180, 260, 105), "Playername");
GUI.Label (Rect (100, 195, 250, 100), "Please enter your name:");
myPlayerName = GUI.TextField (Rect (178, 215, 147, 27), myPlayerName);
if(GUI.changed){
//Save the name changes
PlayerPrefs.SetString("playerName", myPlayerName);
}
if(myPlayerName==""){
GUI.Label (Rect (100, 240, 260, 100), "After entering your name you can start playing!");
return;
}
GUI.Label (Rect (100, 240, 260, 100), "Click on quickplay to start playing right away!");
if(GUI.Button(Rect(400,150,150,30), "Quickplay") ){
currentMenu="playnow";
playNowMode=true;
playNowModeStarted=Time.time;
}
if(GUI.Button(Rect(400,245,150,30), "Advanced") ){
currentMenu="advanced";
advancedMode=true;
}
}
}
function playNowFunction(){
if(GUI.Button(Rect(490,185,75,20), "Cancel")){
Network.Disconnect();
currentMenu="";
playNowMode=false;
}
GUI.Box(Rect(Screen.width/4+0,Screen.height/2-50,420,50), "");
if(multiplayerScript.tryingToConnectPlayNowNumber>=10){
//If players get fed up waiting they can choose to start a host right away
if(GUI.Button(Rect(400,185,75,20), "Just host")){
multiplayerScript.StartHost(hostPlayers, multiplayerScript.serverPort);
}
}
var connectStatus = multiplayerScript.PlayNow(playNowModeStarted);
if(connectStatus=="failed"){
//Couldn't find a proper host; host ourselves
Debug.Log("PlayNow: No games hosted, so hosting one ourselves");
multiplayerScript.StartHost(7, multiplayerScript.serverPort);
}else{
//Still trying to connect to the first hit
GUI.Label(Rect(Screen.width/4+10,Screen.height/2-45,385,50), connectStatus);
}
}
function hostGUI(id : int){
GUILayout.BeginVertical();
GUILayout.Space(10);
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
GUILayout.Space(10);
GUILayout.Label("Use port: ");
hostPort = parseInt(GUILayout.TextField(hostPort.ToString(), GUILayout.MaxWidth(75)));
GUILayout.Space(10);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Space(10);
GUILayout.Label("Players: ");
hostPlayers = parseInt(GUILayout.TextField(hostPlayers.ToString(), GUILayout.MaxWidth(75)));
GUILayout.Space(10);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
// Start a new server
if (GUILayout.Button ("Start hosting a server")){
multiplayerScript.StartHost(hostPlayers, hostPort);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
function directConnectGUIWindow(id : int){
GUILayout.BeginVertical();
GUILayout.Space(5);
GUILayout.EndVertical();
GUILayout.Label(multiplayerScript.connectionInfo);
if(multiplayerScript.nowConnecting){
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("Trying to connect to "+connectIP+":"+connectPort);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
} else {
GUILayout.BeginHorizontal();
GUILayout.Space(10);
connectIP = GUILayout.TextField(connectIP, GUILayout.MinWidth(70));
connectPort = parseInt(GUILayout.TextField(connectPort+""));
GUILayout.Space(10);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Space(10);
GUILayout.FlexibleSpace();
if (GUILayout.Button ("Connect"))
{
multiplayerScript.Connect(connectIP, connectPort);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}
private var scrollPosition : Vector2;
function listGUI (id : int) {
GUILayout.BeginVertical();
GUILayout.Space(6);
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
GUILayout.Space(200);
// Refresh hosts
if (GUILayout.Button ("Refresh available Servers"))
{
multiplayerScript.FetchHostList(true);
}
multiplayerScript.FetchHostList(false);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
//scrollPosition = GUI.BeginScrollView (Rect (0,60,385,200), scrollPosition, Rect (0, 100, 350, 3000));
scrollPosition = GUILayout.BeginScrollView( scrollPosition );
var aHost : int = 0;
if( connection.sortedList connection.sortedList.length >= 1 )
{
for( var myElement in connection.sortedList )
{
element = connection.hostData[myElement];
GUILayout.BeginHorizontal();
// Do not display NAT enabled games if we cannot do NAT punchthrough
if ( !( connection.filterNATHosts element.useNat ) )
{
aHost=1;
var buttonText : String = element.gameName + " (" + element.connectedPlayers + "/" + element.playerLimit + ")";
GUI.color = Color( 0.8, 0.8,0.2, 1 );
if( GUILayout.Button( buttonText ) )
{
// Connect to the server.
connection.Connect( element );
// Read the gameScene info, load that level.
gameScene = parseInt( element.comment );
Debug.Log( "gameScene is: " + gameScene );
//Application.LoadLevel( gameScene );
phase = 5;
}
GUILayout.Space( 1 );
}
GUILayout.EndHorizontal();
}
}
GUILayout.EndScrollView ();
if(aHost==0){
GUILayout.Label("No games hosted at the moment..");
}
}
Other code in next post. Along with error messages
And here is Menu_multiplayerCode.js
/*
* This file is part of the Unity networking tutorial by M2H (http://www.M2H.nl)
* The original author of this code is Mike Hergaarden, even though some small parts
* are copied from the Unity tutorials/manuals.
* Feel free to use this code for your own projects, drop us a line if you made something exciting!
*/
#pragma strict
#pragma implicit
#pragma downcast
private var windowRect1;
private var windowRect2;
private var windowRect3;
static var playNowMode : boolean = false;
static var advancedMode : boolean = false;
static var playNowModeStarted : float = 0.0;
static var myPlayerName : String = "MyPlayerName";
//GUI vars
private var hostPlayers : int = 8;
private var hostPort : int;
private var connectPort : int;
private var connectIP : String = "";
private var multiplayerScript : Menu_multiplayerCode;
private var currentMenu : String = "";
function Awake ()
{
Screen.lockCursor=false;
myPlayerName = PlayerPrefs.GetString("playerName");
multiplayerScript = GetComponent(Menu_multiplayerCode);
connectPort = hostPort = multiplayerScript.serverPort;
connectIP = "127.0.0.1";
windowRect1 = Rect (Screen.width/2-310,Screen.height/2-90,380,280);
windowRect2 = Rect (Screen.width/2+85,Screen.height/2-90,220,100);
windowRect3 = Rect (Screen.width/2+85,Screen.height/2+55,220,100);
playNowMode=false;
advancedMode=false;
}
function OnGUI ()
{
//If we've connected; load the game when it's ready to load
if(Network.isClient || Network.isServer){
//Since we're connected, load the game
GUI.Box(Rect(Screen.width/4+0,Screen.height/2-30,450,50), "");
if(Application.CanStreamedLevelBeLoaded ((Application.loadedLevel+1))){
GUI.Label(Rect(Screen.width/4+10,Screen.height/2-25,285,150), "Starting the game!");
Application.LoadLevel((Application.loadedLevel+1));
}else{
GUI.Label(Rect(Screen.width/4+10,Screen.height/2-25,285,150), "Loading the game: "+Mathf.Floor(Application.GetStreamProgressForLevel((Application.loadedLevel+1))*100)+" %");
}
return;
}
//Dirty error message popup
if(multiplayerScript.errorMessage multiplayerScript.errorMessage!=""){
GUI.Box(Rect(Screen.width/2-100,Screen.height/2-60,200,60), "Error");
GUI.Label(Rect(Screen.width/2-90,Screen.height/2-50,180,50), multiplayerScript.errorMessage);
if(GUI.Button(Rect(Screen.width/2+40,Screen.height/2-30,50,20), "Close")){
multiplayerScript.errorMessage="";
}
}
if(playNowMode){
playNowFunction();
}else if(advancedMode){
if(!multiplayerScript.errorMessage || multiplayerScript.errorMessage==""){ //Hide windows on error
if(GUI.Button(Rect(455,90,140,30), "Back to main menu")){
currentMenu="";
advancedMode=false;
}
windowRect1 = GUILayout.Window (0, windowRect1, listGUI, "Join a game via the list");
windowRect2 = GUILayout.Window (1, windowRect2, directConnectGUIWindow, "Directly join a game via an IP");
windowRect3 = GUILayout.Window (2, windowRect3, hostGUI, "Host a game");
}
}else{
GUI.Box (Rect (90, 180, 260, 105), "Playername");
GUI.Label (Rect (100, 195, 250, 100), "Please enter your name:");
myPlayerName = GUI.TextField (Rect (178, 215, 147, 27), myPlayerName);
if(GUI.changed){
//Save the name changes
PlayerPrefs.SetString("playerName", myPlayerName);
}
if(myPlayerName==""){
GUI.Label (Rect (100, 240, 260, 100), "After entering your name you can start playing!");
return;
}
GUI.Label (Rect (100, 240, 260, 100), "Click on quickplay to start playing right away!");
if(GUI.Button(Rect(400,150,150,30), "Quickplay") ){
currentMenu="playnow";
playNowMode=true;
playNowModeStarted=Time.time;
}
if(GUI.Button(Rect(400,245,150,30), "Advanced") ){
currentMenu="advanced";
advancedMode=true;
}
}
}
function playNowFunction(){
if(GUI.Button(Rect(490,185,75,20), "Cancel")){
Network.Disconnect();
currentMenu="";
playNowMode=false;
}
GUI.Box(Rect(Screen.width/4+0,Screen.height/2-50,420,50), "");
if(multiplayerScript.tryingToConnectPlayNowNumber>=10){
//If players get fed up waiting they can choose to start a host right away
if(GUI.Button(Rect(400,185,75,20), "Just host")){
multiplayerScript.StartHost(hostPlayers, multiplayerScript.serverPort);
}
}
var connectStatus = multiplayerScript.PlayNow(playNowModeStarted);
if(connectStatus=="failed"){
//Couldn't find a proper host; host ourselves
Debug.Log("PlayNow: No games hosted, so hosting one ourselves");
multiplayerScript.StartHost(7, multiplayerScript.serverPort);
}else{
//Still trying to connect to the first hit
GUI.Label(Rect(Screen.width/4+10,Screen.height/2-45,385,50), connectStatus);
}
}
function hostGUI(id : int){
GUILayout.BeginVertical();
GUILayout.Space(10);
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
GUILayout.Space(10);
GUILayout.Label("Use port: ");
hostPort = parseInt(GUILayout.TextField(hostPort.ToString(), GUILayout.MaxWidth(75)));
GUILayout.Space(10);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Space(10);
GUILayout.Label("Players: ");
hostPlayers = parseInt(GUILayout.TextField(hostPlayers.ToString(), GUILayout.MaxWidth(75)));
GUILayout.Space(10);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
// Start a new server
if (GUILayout.Button ("Start hosting a server")){
multiplayerScript.StartHost(hostPlayers, hostPort);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
function directConnectGUIWindow(id : int){
GUILayout.BeginVertical();
GUILayout.Space(5);
GUILayout.EndVertical();
GUILayout.Label(multiplayerScript.connectionInfo);
if(multiplayerScript.nowConnecting){
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
GUILayout.Label("Trying to connect to "+connectIP+":"+connectPort);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
} else {
GUILayout.BeginHorizontal();
GUILayout.Space(10);
connectIP = GUILayout.TextField(connectIP, GUILayout.MinWidth(70));
connectPort = parseInt(GUILayout.TextField(connectPort+""));
GUILayout.Space(10);
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.Space(10);
GUILayout.FlexibleSpace();
if (GUILayout.Button ("Connect"))
{
multiplayerScript.Connect(connectIP, connectPort);
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
}
private var scrollPosition : Vector2;
function listGUI (id : int) {
GUILayout.BeginVertical();
GUILayout.Space(6);
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
GUILayout.Space(200);
// Refresh hosts
if (GUILayout.Button ("Refresh available Servers"))
{
multiplayerScript.FetchHostList(true);
}
multiplayerScript.FetchHostList(false);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
//scrollPosition = GUI.BeginScrollView (Rect (0,60,385,200), scrollPosition, Rect (0, 100, 350, 3000));
scrollPosition = GUILayout.BeginScrollView( scrollPosition );
var aHost : int = 0;
if( connection.sortedList connection.sortedList.length >= 1 )
{
for( var myElement in connection.sortedList )
{
element = connection.hostData[myElement];
GUILayout.BeginHorizontal();
// Do not display NAT enabled games if we cannot do NAT punchthrough
if ( !( connection.filterNATHosts element.useNat ) )
{
aHost=1;
var buttonText : String = element.gameName + " (" + element.connectedPlayers + "/" + element.playerLimit + ")";
GUI.color = Color( 0.8, 0.8,0.2, 1 );
if( GUILayout.Button( buttonText ) )
{
// Connect to the server.
connection.Connect( element );
// Read the gameScene info, load that level.
gameScene = parseInt( element.comment );
Debug.Log( "gameScene is: " + gameScene );
//Application.LoadLevel( gameScene );
phase = 5;
}
GUILayout.Space( 1 );
}
GUILayout.EndHorizontal();
}
}
GUILayout.EndScrollView ();
if(aHost==0){
GUILayout.Label("No games hosted at the moment..");
}
}
And these are the errors I am getting.
Assets/Example4/MenuAssets/Menu_multiplayerCode.js(265,14): BCE0044: expecting :, found ‘=’.
Assets/Example4/MenuAssets/Menu_multiplayerCode.js(263,34): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Example4/MenuAssets/Menu_multiplayerCode.js(263,29): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Assets/Example4/MenuAssets/Menu_multiplayerCode.js(263,28): BCE0043: Unexpected token: :.
Assets/Example4/MenuAssets/Menu_multiplayerCode.js(263,10): UCE0001: ‘;’ expected. Insert a semicolon at the end.
Thanks for your time!
Hello,
I did a small space combat game a few months ago, that what running well on Unity2.6 + my own MasterServer/Facilitator/ConnectionTester dedicater server… All was working really fine, Nat Punchthrough was ok too.
I did move to Unity 3 , and started to update the servers but … the ConnectionTest requires now 4 public IP addresses ! , I don’t
have 4 public addresses, and running out of time as I am registering the Kongregate Contest …
I don’ta have much time to go back in what was working, I have to focus on the game code, but , how can I do to run a ConnectionTester !?
I built every thing , I moved it on my dedicated server , I see I am creating sessions , enumeration etc … ok , but with the
ConnectionTester I am having problems with Nat punchthrough… and that is normal in fact.
What can I do to complete the game net code , can I use Unity Servers until the End of the Contest ?
if yes, what shall I put here :
MasterServer.ipAddress = ??? ;
MasterServer.port = ??? ;
Network.natFacilitatorIP = ???;
Network.natFacilitatorPort = ???;
Network.connectionTesterIP = ???;
Network.connectionTesterIP =???;
Network.connectionTesterPort = ???;
Thanks for your feedback !
MasterServer ipAddress and port, Network.natFacilitatorIP and natFacilitatorPort, and the connectionTester addresses should all be provided by Unity - by default, they point to Unity Tech’s Master Server.