// -----------------------------------------------------------------------
//
// Loadbalancing Framework for Photon - Copyright (C) 2018 Exit Games GmbH
//
// Settings for Photon application(s) and the server to connect to.
// developer@photonengine.com
// ----------------------------------------------------------------------------
#if UNITY_2017_4_OR_NEWER
#define SUPPORTED_UNITY
#endif
namespace Photon.Realtime
{
using System;
using ExitGames.Client.Photon;
#if SUPPORTED_UNITY || NETFX_CORE
using Hashtable = ExitGames.Client.Photon.Hashtable;
using SupportClass = ExitGames.Client.Photon.SupportClass;
#endif
///
/// Settings for Photon application(s) and the server to connect to.
///
///
/// This is Serializable for Unity, so it can be included in ScriptableObject instances.
///
#if !NETFX_CORE || SUPPORTED_UNITY
[Serializable]
#endif
public class AppSettings
{
/// AppId for Realtime or PUN.
public string AppIdRealtime;
/// AppId for Photon Fusion.
public string AppIdFusion;
/// AppId for Photon Chat.
public string AppIdChat;
/// AppId for Photon Voice.
public string AppIdVoice;
/// The AppVersion can be used to identify builds and will split the AppId distinct "Virtual AppIds" (important for matchmaking).
public string AppVersion;
/// If false, the app will attempt to connect to a Master Server (which is obsolete but sometimes still necessary).
/// if true, Server points to a NameServer (or is null, using the default), else it points to a MasterServer.
public bool UseNameServer = true;
/// Can be set to any of the Photon Cloud's region names to directly connect to that region.
/// if this IsNullOrEmpty() AND UseNameServer == true, use BestRegion. else, use a server
public string FixedRegion;
/// Set to a previous BestRegionSummary value before connecting.
///
/// This is a value used when the client connects to the "Best Region".
/// If this is null or empty, all regions gets pinged. Providing a previous summary on connect,
/// speeds up best region selection and makes the previously selected region "sticky".
///
/// Unity clients should store the BestRegionSummary in the PlayerPrefs.
/// You can store the new result by implementing .
/// If is not null, store this string.
/// To avoid storing the value multiple times, you could set SummaryToCache to null.
///
#if SUPPORTED_UNITY
[NonSerialized]
#endif
public string BestRegionSummaryFromStorage;
/// The address (hostname or IP) of the server to connect to.
public string Server;
/// If not null, this sets the port of the first Photon server to connect to (that will "forward" the client as needed).
public int Port;
/// The address (hostname or IP and port) of the proxy server.
public string ProxyServer;
/// The network level protocol to use.
public ConnectionProtocol Protocol = ConnectionProtocol.Udp;
/// Enables a fallback to another protocol in case a connect to the Name Server fails.
/// See: LoadBalancingClient.EnableProtocolFallback.
public bool EnableProtocolFallback = true;
/// Defines how authentication is done. On each system, once or once via a WSS connection (safe).
public AuthModeOption AuthMode = AuthModeOption.Auth;
/// If true, the client will request the list of currently available lobbies.
public bool EnableLobbyStatistics;
/// Log level for the network lib.
public DebugLevel NetworkLogging = DebugLevel.ERROR;
/// If true, the Server field contains a Master Server address (if any address at all).
public bool IsMasterServerAddress
{
get { return !this.UseNameServer; }
}
/// If true, the client should fetch the region list from the Name Server and find the one with best ping.
/// See "Best Region" in the online docs.
public bool IsBestRegion
{
get { return this.UseNameServer && string.IsNullOrEmpty(this.FixedRegion); }
}
/// If true, the default nameserver address for the Photon Cloud should be used.
public bool IsDefaultNameServer
{
get { return this.UseNameServer && string.IsNullOrEmpty(this.Server); }
}
/// If true, the default ports for a protocol will be used.
public bool IsDefaultPort
{
get { return this.Port <= 0; }
}
/// ToString but with more details.
public string ToStringFull()
{
return string.Format(
"appId {0}{1}{2}{3}" +
"use ns: {4}, reg: {5}, {9}, " +
"{6}{7}{8}" +
"auth: {10}",
String.IsNullOrEmpty(this.AppIdRealtime) ? string.Empty : "Realtime/PUN: " + this.HideAppId(this.AppIdRealtime) + ", ",
String.IsNullOrEmpty(this.AppIdFusion) ? string.Empty : "Fusion: " + this.HideAppId(this.AppIdFusion) + ", ",
String.IsNullOrEmpty(this.AppIdChat) ? string.Empty : "Chat: " + this.HideAppId(this.AppIdChat) + ", ",
String.IsNullOrEmpty(this.AppIdVoice) ? string.Empty : "Voice: " + this.HideAppId(this.AppIdVoice) + ", ",
String.IsNullOrEmpty(this.AppVersion) ? string.Empty : "AppVersion: " + this.AppVersion + ", ",
"UseNameServer: " + this.UseNameServer + ", ",
"Fixed Region: " + this.FixedRegion + ", ",
//this.BestRegionSummaryFromStorage,
String.IsNullOrEmpty(this.Server) ? string.Empty : "Server: " + this.Server + ", ",
this.IsDefaultPort ? string.Empty : "Port: " + this.Port + ", ",
String.IsNullOrEmpty(ProxyServer) ? string.Empty : "Proxy: " + this.ProxyServer + ", ",
this.Protocol,
this.AuthMode
//this.EnableLobbyStatistics,
//this.NetworkLogging,
);
}
/// 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;
}
private string HideAppId(string appId)
{
return string.IsNullOrEmpty(appId) || appId.Length < 8
? appId
: string.Concat(appId.Substring(0, 8), "***");
}
public AppSettings CopyTo(AppSettings d)
{
d.AppIdRealtime = this.AppIdRealtime;
d.AppIdFusion = this.AppIdFusion;
d.AppIdChat = this.AppIdChat;
d.AppIdVoice = this.AppIdVoice;
d.AppVersion = this.AppVersion;
d.UseNameServer = this.UseNameServer;
d.FixedRegion = this.FixedRegion;
d.BestRegionSummaryFromStorage = this.BestRegionSummaryFromStorage;
d.Server = this.Server;
d.Port = this.Port;
d.ProxyServer = this.ProxyServer;
d.Protocol = this.Protocol;
d.AuthMode = this.AuthMode;
d.EnableLobbyStatistics = this.EnableLobbyStatistics;
d.NetworkLogging = this.NetworkLogging;
d.EnableProtocolFallback = this.EnableProtocolFallback;
return d;
}
}
}