Photon Cloud Using other Servers

Options
I received an email stating that Photon Cloud games would automatically start using Photon's servers from other country areas.
But my game Rogue Underworld is only using the European server. I assumed My game would use the US server during my testing, since I'm in the US. How do I make sure that my game is using the closest server?

Comments

  • Tobias
    Options
    Currently, you have to pick the region servers manually. We want to provide a location-based service but that's not implemented yet.
    Check out the regions here:
    http://doc.exitgames.com/photon-cloud/Regions
  • grfxman
    Options
    "You can for instance a) let the game client ping the different Photon Cloud regions and pre-select the one with the best ping"

    How would I add the code to do this? And Where would I add it in my Unity build?

    Thanks;
    Christian
  • Good day,

    I had to do the same so I wrote the following code:
    public class ConnectionManager : Photon.MonoBehaviour
    {	
    // ...
    	public string[] servers;
    	public string appID;
    	public string appVersion = "1.0";
    	public int port = 5055;
    	
    	private int PingComparison(Ping x, Ping y)
    	{
    		if (x.isDone && !y.isDone)
    			return -1;
    		if (!x.isDone && y.isDone)
    			return 1;
    		if (!x.isDone && y.isDone)
    			return 0;
    		return x.time.CompareTo(y.time);
    		
    	}
    	
    	System.Collections.IEnumerator ConnectRoutine(string[] servers, int port, string appID, string version)
    	{
    /*		Assert.Test(gameObject, servers.Length > 0, "servers.Length > 0");
    		Assert.Test(gameObject, port > 0, "port > 0");
    		Assert.Test(gameObject, !string.IsNullOrEmpty(appID), "!string.IsNullOrEmpty(appID)");
    		Assert.Test(gameObject, !string.IsNullOrEmpty(version), "!string.IsNullOrEmpty(version)");*/
    		
    		string[] ips = new string[servers.Length];
    		for (int i = 0; i < ips.Length; ++i)
    		{
    			System.Net.IPAddress[] ipAdresses = System.Net.Dns.GetHostAddresses(servers[i]);
    			//Assert.Test(gameObject, ipAdresses.Length > 0, "ipAdresses.Length > 0");
    			ips[i] = ipAdresses[0].ToString();
    		}
    			
    		Ping[] pings = new Ping[ips.Length];
    		for (int i = 0; i < ips.Length; ++i)
    			pings[i] = new Ping(ips[i]);
    
    		do
    		{
    			yield return new WaitForEndOfFrame();
    			System.Array.Sort(pings, PingComparison);
    		} while (!pings[0].isDone);
    			
    		for (int i = 0; i < pings.Length; ++i)
    		{
    			//Logger.Info(gameObject, "Server {0}: ip={1}, ping={2}, done={3}", servers[i], pings[i].ip, pings[i].time, pings[i].isDone);
    			if (i > 0)
    				pings[i].DestroyPing();
    		}
    				
    		PhotonNetwork.Connect(pings[0].ip, port, appID, version);
    		pings[0].DestroyPing();
    	}
    
    	System.Collections.IEnumerator Start()
    	{
    		//Assert.Test(gameObject, levelRoot != null, "levelRoot != null");
    		yield return StartCoroutine(ConnectRoutine(servers, port, appID, appVersion));
    	}
    
    //...
    }
    
  • grfxman
    Options
    Thank You for that :)