void Start () {
Data_Manager.CreateInstance();
if(TNServerInstance.isActive){
TNServerInstance.Stop ();
}
...
}
public void ButtonPressedServerAccept(){
loading.SetActive (true);
netGameName = field_servername.text;
netGamePassword = field_serverpassword.text;
if(netGamePassword == "none"){
netGamePassword = "";
}
field_servername.GetComponent<UIInput>().RemoveFocus ();
field_serverpassword.GetComponent<UIInput>().RemoveFocus ();
StartCoroutine ("StartServer");
}
IEnumerator StartServer(){
Tools.ResolveIPs(null);
yield return new WaitForSeconds
(0
.25f
); // allow loading image to be displayed if(!TNServerInstance.isActive){
serverUdpPort = Random.Range(10000, 50000);
if(TNServerInstance.Start(5127, serverUdpPort, lobby.remotePort, "server.dat", TNServerInstance.Type.Udp)){
lbl_NetMessage.enabled = false;
}
while(!TNServerInstance.isListening) yield return null; // wait for TNServerInstance to finalise
print ("Set server name "+netGameName);
TNServerInstance.serverName = netGameName;
TNManager.Connect("127.0.0.1:5127"); // connect to local server
}else{
print ("Server already running");
}
}
void OnNetworkConnect(bool success, string message){
bool home = Random.value < 0.5f;
GameDetails.instance.SetDifficulty (1);
string myClubKey = "CLUB_001";
if(PlayerPrefs.GetInt (GLOBALS.PREFS_CLUB_CREATED, 0) != 0){
myClubKey = "CLUB_900";
}
GameDetails.instance.SetGameDetails (MATCHTYPE.NETWORKED, true, home, home, !home, home ? myClubKey : "CLUB_001", !home ? myClubKey : "CLUB_001");
if(TNServerInstance.isActive){
print ("OnNetworkConnect "+TNServerInstance.listeningPort+" "+netGameName+" password "+netGamePassword);
TNManager.JoinChannel (1,"MatchLauncher", false, 2, netGamePassword);
}else{
print ("Channels stuff "+success+" "+message);
TNManager.GetChannelList(OnChannelListRefresh);
}
}