Question by
matti3 · Mar 29, 2016 at 04:14 PM ·
networkconnectionmasterservernetwork.connect
Failed to connect master server
I've had a problem for day. I've been trying to make a system where the user acts as a host for a game. Is It true that I can't make it without buying the Pro-license? The only thing I've been able to make is a LAN-game.
Error: Failed to connect master server
var playerPrefab : GameObject;
var spawnObject : Transform;
var gameName : String = "level1";
private var refreshing : boolean = false;
private var hostData : HostData[];
var DatabaseObject : GameObject;
static var LuodaanHahmo : boolean = false;
var connected : boolean;
var ipAddress : String;
var ownIP : String;
var gameIP : String;
var port : int;
function OnGUI () {
if(!Network.isClient && !Network.isServer) {
if (GUI.Button(Rect(Screen.width/2,Screen.height/2,100,20),"Start Server")) {
startServer();
}
if (GUI.Button(Rect(Screen.width/2,Screen.height/2 + 30,100,20),"Refresh Hosts")) {
Debug.Log("Refresh");
refreshHostList();
}
if(hostData) {
for(var i:int = 0; i<hostData.length; i++) {
if(GUI.Button(Rect(Screen.width/2,Screen.height/2 + 60,100,20),hostData[i].gameName)) {
Network.Connect(hostData[i]);
}
}
}
}
}
function Update () {
if(refreshing) {
if(MasterServer.PollHostList().Length > 0) {
refreshing = false;
Debug.Log(MasterServer.PollHostList().Length);
hostData = MasterServer.PollHostList();
}
}
if(LuodaanHahmo) {
Database.charactersInGame[0] = new Character(PersonalData.AnnettuNimi, PersonalData.AloitusRaha, 4, 0, true, 0, 999999, 0, 10, 10, 10, 10, 10, 18);
LuodaanHahmo = false;
}
ipAddress = MasterServer.ipAddress;
}
function startServer () {
var useNat = !Network.HavePublicAddress();
Network.InitializeServer(1,port, useNat);
MasterServer.RegisterHost(gameName, "Tutorial Game", " this is a tutorial");
}
function OnServerInitialized () {
Debug.Log("server initialized");
spawnPlayer();
DatabaseObject.active = true;
}
function OnConnectedToServer () {
connected = true;
spawnPlayer();
}
function OnDisconnectedFromServer() {
connected = false;
}
function spawnPlayer () {
Network.Instantiate(playerPrefab, spawnObject.position, Quaternion.identity, 0);
}
function OnMasterServerEvent(mse:MasterServerEvent) {
if(mse == MasterServerEvent.RegistrationSucceeded) {
Debug.Log("Registered Server");
}
}
function refreshHostList () {
MasterServer.RequestHostList(gameName);
refreshing = true;
}
Comment