#pragma warning disable 1587
/// \file
/// ScriptableObject defining a server setup. An instance is created as PhotonServerSettings.
#pragma warning restore 1587
using System;
using System.Collections.Generic;
using ExitGames.Client.Photon;
using UnityEngine;
public class Region
{
public CloudRegionCode Code;
public string HostAndPort;
public int Ping;
public static CloudRegionCode Parse(string codeAsString)
{
codeAsString = codeAsString.ToLower();
CloudRegionCode code = CloudRegionCode.none;
if (Enum.IsDefined(typeof(CloudRegionCode), codeAsString))
{
code = (CloudRegionCode)Enum.Parse(typeof(CloudRegionCode), codeAsString);
}
return code;
}
internal static CloudRegionFlag ParseFlag(string codeAsString)
{
codeAsString = codeAsString.ToLower();
CloudRegionFlag code = 0;
if (Enum.IsDefined(typeof(CloudRegionFlag), codeAsString))
{
code = (CloudRegionFlag)Enum.Parse(typeof(CloudRegionFlag), codeAsString);
}
return code;
}
public override string ToString()
{
return string.Format("'{0}' \t{1}ms \t{2}", this.Code, this.Ping, this.HostAndPort);
}
}
///
/// Collection of connection-relevant settings, used internally by PhotonNetwork.ConnectUsingSettings.
///
[Serializable]
public class ServerSettings : ScriptableObject
{
public enum HostingOption { NotSet = 0, PhotonCloud = 1, SelfHosted = 2, OfflineMode = 3, BestRegion = 4 }
public string AppID = "";
public string VoiceAppID = "";
public string ChatAppID = "";
public HostingOption HostType = HostingOption.NotSet;
public CloudRegionCode PreferredRegion;
public CloudRegionFlag EnabledRegions = (CloudRegionFlag)(-1);
public ConnectionProtocol Protocol = ConnectionProtocol.Udp;
public string ServerAddress = "";
public int ServerPort = 5055;
public int VoiceServerPort = 5055; // Voice only uses UDP
public bool JoinLobby;
public bool EnableLobbyStatistics;
public PhotonLogLevel PunLogging = PhotonLogLevel.ErrorsOnly;
public DebugLevel NetworkLogging = DebugLevel.ERROR;
public bool RunInBackground = true;
public List RpcList = new List(); // set by scripts and or via Inspector
[HideInInspector]
public bool DisableAutoOpenWizard;
public void UseCloudBestRegion(string cloudAppid)
{
this.HostType = HostingOption.BestRegion;
this.AppID = cloudAppid;
}
public void UseCloud(string cloudAppid)
{
this.HostType = HostingOption.PhotonCloud;
this.AppID = cloudAppid;
}
public void UseCloud(string cloudAppid, CloudRegionCode code)
{
this.HostType = HostingOption.PhotonCloud;
this.AppID = cloudAppid;
this.PreferredRegion = code;
}
public void UseMyServer(string serverAddress, int serverPort, string application)
{
this.HostType = HostingOption.SelfHosted;
this.AppID = (application != null) ? application : "master";
this.ServerAddress = serverAddress;
this.ServerPort = serverPort;
}
/// Checks if a string is a Guid by attempting to create one.
/// The potential guid to check.
/// True if new Guid(val) did not fail.
public static bool IsAppId(string val)
{
try
{
new Guid(val);
}
catch
{
return false;
}
return true;
}
public override string ToString()
{
return "ServerSettings: " + HostType + " " + ServerAddress;
}
}