Seven is the number.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

193 lines
8.4 KiB

4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
4 years ago
3 years ago
  1. // -----------------------------------------------------------------------
  2. // <copyright file="AppSettings.cs" company="Exit Games GmbH">
  3. // Loadbalancing Framework for Photon - Copyright (C) 2018 Exit Games GmbH
  4. // </copyright>
  5. // <summary>Settings for Photon application(s) and the server to connect to.</summary>
  6. // <author>developer@photonengine.com</author>
  7. // ----------------------------------------------------------------------------
  8. #if UNITY_2017_4_OR_NEWER
  9. #define SUPPORTED_UNITY
  10. #endif
  11. namespace Photon.Realtime
  12. {
  13. using System;
  14. using ExitGames.Client.Photon;
  15. #if SUPPORTED_UNITY || NETFX_CORE
  16. using Hashtable = ExitGames.Client.Photon.Hashtable;
  17. using SupportClass = ExitGames.Client.Photon.SupportClass;
  18. #endif
  19. /// <summary>
  20. /// Settings for Photon application(s) and the server to connect to.
  21. /// </summary>
  22. /// <remarks>
  23. /// This is Serializable for Unity, so it can be included in ScriptableObject instances.
  24. /// </remarks>
  25. #if !NETFX_CORE || SUPPORTED_UNITY
  26. [Serializable]
  27. #endif
  28. public class AppSettings
  29. {
  30. /// <summary>AppId for Realtime or PUN.</summary>
  31. public string AppIdRealtime;
  32. /// <summary>AppId for the Chat Api.</summary>
  33. public string AppIdChat;
  34. /// <summary>AppId for use in the Voice Api.</summary>
  35. public string AppIdVoice;
  36. /// <summary>The AppVersion can be used to identify builds and will split the AppId distinct "Virtual AppIds" (important for matchmaking).</summary>
  37. public string AppVersion;
  38. /// <summary>If false, the app will attempt to connect to a Master Server (which is obsolete but sometimes still necessary).</summary>
  39. /// <remarks>if true, Server points to a NameServer (or is null, using the default), else it points to a MasterServer.</remarks>
  40. public bool UseNameServer = true;
  41. /// <summary>Can be set to any of the Photon Cloud's region names to directly connect to that region.</summary>
  42. /// <remarks>if this IsNullOrEmpty() AND UseNameServer == true, use BestRegion. else, use a server</remarks>
  43. public string FixedRegion;
  44. /// <summary>Set to a previous BestRegionSummary value before connecting.</summary>
  45. /// <remarks>
  46. /// This is a value used when the client connects to the "Best Region".</br>
  47. /// If this is null or empty, all regions gets pinged. Providing a previous summary on connect,
  48. /// speeds up best region selection and makes the previously selected region "sticky".</br>
  49. ///
  50. /// Unity clients should store the BestRegionSummary in the PlayerPrefs.
  51. /// You can store the new result by implementing <see cref="IConnectionCallbacks.OnConnectedToMaster"/>.
  52. /// If <see cref="LoadBalancingClient.SummaryToCache"/> is not null, store this string.
  53. /// To avoid storing the value multiple times, you could set SummaryToCache to null.
  54. /// </remarks>
  55. #if SUPPORTED_UNITY
  56. [NonSerialized]
  57. #endif
  58. public string BestRegionSummaryFromStorage;
  59. /// <summary>The address (hostname or IP) of the server to connect to.</summary>
  60. public string Server;
  61. /// <summary>If not null, this sets the port of the first Photon server to connect to (that will "forward" the client as needed).</summary>
  62. public int Port;
  63. /// <summary>The address (hostname or IP and port) of the proxy server.</summary>
  64. public string ProxyServer;
  65. /// <summary>The network level protocol to use.</summary>
  66. public ConnectionProtocol Protocol = ConnectionProtocol.Udp;
  67. /// <summary>Enables a fallback to another protocol in case a connect to the Name Server fails.</summary>
  68. /// <remarks>See: LoadBalancingClient.EnableProtocolFallback.</remarks>
  69. public bool EnableProtocolFallback = true;
  70. /// <summary>Defines how authentication is done. On each system, once or once via a WSS connection (safe).</summary>
  71. public AuthModeOption AuthMode = AuthModeOption.Auth;
  72. /// <summary>If true, the client will request the list of currently available lobbies.</summary>
  73. public bool EnableLobbyStatistics;
  74. /// <summary>Log level for the network lib.</summary>
  75. public DebugLevel NetworkLogging = DebugLevel.ERROR;
  76. /// <summary>If true, the Server field contains a Master Server address (if any address at all).</summary>
  77. public bool IsMasterServerAddress
  78. {
  79. get { return !this.UseNameServer; }
  80. }
  81. /// <summary>If true, the client should fetch the region list from the Name Server and find the one with best ping.</summary>
  82. /// <remarks>See "Best Region" in the online docs.</remarks>
  83. public bool IsBestRegion
  84. {
  85. get { return this.UseNameServer && string.IsNullOrEmpty(this.FixedRegion); }
  86. }
  87. /// <summary>If true, the default nameserver address for the Photon Cloud should be used.</summary>
  88. public bool IsDefaultNameServer
  89. {
  90. get { return this.UseNameServer && string.IsNullOrEmpty(this.Server); }
  91. }
  92. /// <summary>If true, the default ports for a protocol will be used.</summary>
  93. public bool IsDefaultPort
  94. {
  95. get { return this.Port <= 0; }
  96. }
  97. /// <summary>ToString but with more details.</summary>
  98. public string ToStringFull()
  99. {
  100. return string.Format(
  101. "appId {0}{1}{2}{3}" +
  102. "use ns: {4}, reg: {5}, {9}, " +
  103. "{6}{7}{8}" +
  104. "auth: {10}",
  105. String.IsNullOrEmpty(this.AppIdRealtime) ? string.Empty : "rt: " + this.HideAppId(this.AppIdRealtime) + ", ",
  106. String.IsNullOrEmpty(this.AppIdChat) ? string.Empty : "chat: " + this.HideAppId(this.AppIdChat) + ", ",
  107. String.IsNullOrEmpty(this.AppIdVoice) ? string.Empty : "voice: " + this.HideAppId(this.AppIdVoice) + ", ",
  108. String.IsNullOrEmpty(this.AppVersion) ? string.Empty : "appV: " + this.AppVersion + ", ",
  109. this.UseNameServer,
  110. this.IsBestRegion ? "/best/" : this.FixedRegion,
  111. //this.BestRegionSummaryFromStorage,
  112. String.IsNullOrEmpty(this.Server) ? string.Empty : "server: " + this.Server + ", ",
  113. this.IsDefaultPort ? string.Empty : "port: " + this.Port + ", ",
  114. String.IsNullOrEmpty(ProxyServer) ? string.Empty : "proxy: " + this.ProxyServer + ", ",
  115. this.Protocol,
  116. this.AuthMode
  117. //this.EnableLobbyStatistics,
  118. //this.NetworkLogging,
  119. );
  120. }
  121. /// <summary>Checks if a string is a Guid by attempting to create one.</summary>
  122. /// <param name="val">The potential guid to check.</param>
  123. /// <returns>True if new Guid(val) did not fail.</returns>
  124. public static bool IsAppId(string val)
  125. {
  126. try
  127. {
  128. new Guid(val);
  129. }
  130. catch
  131. {
  132. return false;
  133. }
  134. return true;
  135. }
  136. private string HideAppId(string appId)
  137. {
  138. return string.IsNullOrEmpty(appId) || appId.Length < 8
  139. ? appId
  140. : string.Concat(appId.Substring(0, 8), "***");
  141. }
  142. public AppSettings CopyTo(AppSettings d)
  143. {
  144. d.AppIdRealtime = this.AppIdRealtime;
  145. d.AppIdChat = this.AppIdChat;
  146. d.AppIdVoice = this.AppIdVoice;
  147. d.AppVersion = this.AppVersion;
  148. d.UseNameServer = this.UseNameServer;
  149. d.FixedRegion = this.FixedRegion;
  150. d.BestRegionSummaryFromStorage = this.BestRegionSummaryFromStorage;
  151. d.Server = this.Server;
  152. d.Port = this.Port;
  153. d.ProxyServer = this.ProxyServer;
  154. d.Protocol = this.Protocol;
  155. d.AuthMode = this.AuthMode;
  156. d.EnableLobbyStatistics = this.EnableLobbyStatistics;
  157. d.NetworkLogging = this.NetworkLogging;
  158. d.EnableProtocolFallback = this.EnableProtocolFallback;
  159. return d;
  160. }
  161. }
  162. }