private IEnumerator MaintainAccessToken() { TimeSpan refreshBackoff = TimeSpan.FromSeconds(10); var rand = new Random(); while (true) { if (refreshBackoff >= ServerOauthLoginSession.MaxBackoffInterval) { yield break; } if (this.tokenData == null || DateTime.UtcNow < this.nextRefreshTime) { yield return(new WaitForSeconds(ServerOauthLoginSession.WaitExpiryDelay / 1000f)); continue; } Result refreshResult = null; yield return(LoginWithClientCredentials(result => refreshResult = result)); if (!refreshResult.IsError) { this.nextRefreshTime = ServerOauthLoginSession.ScheduleNormalRefresh(this.tokenData.expires_in); } else { refreshBackoff = ServerOauthLoginSession.CalculateBackoffInterval(refreshBackoff, rand.Next(1, 60)); this.nextRefreshTime = DateTime.UtcNow + refreshBackoff; } } }
private static void Init() { #endif #if (UNITY_WEBGL || ENABLE_IL2CPP) && !UNITY_EDITOR Utf8Json.Resolvers.CompositeResolver.RegisterAndSetAsDefault( new [] { Utf8Json.Formatters.PrimitiveObjectFormatter.Default }, new[] { Utf8Json.Resolvers.GeneratedResolver.Instance, Utf8Json.Resolvers.BuiltinResolver.Instance, Utf8Json.Resolvers.EnumResolver.Default, // for unity Utf8Json.Unity.UnityResolver.Instance } ); #endif var configFile = Resources.Load("AccelByteServerSDKConfig"); if (configFile == null) { throw new Exception( "'AccelByteServerSDKConfig.json' isn't found in the Project/Assets/Resources directory"); } string wholeJsonText = ((TextAsset)configFile).text; AccelByteServerPlugin.config = wholeJsonText.ToObject <ServerConfig>(); AccelByteServerPlugin.config.CheckRequiredField(); AccelByteServerPlugin.config.Expand(); AccelByteServerPlugin.coroutineRunner = new CoroutineRunner(); AccelByteServerPlugin.httpClient = new AccelByteHttpClient(); AccelByteServerPlugin.session = new ServerOauthLoginSession( AccelByteServerPlugin.config.IamServerUrl, AccelByteServerPlugin.config.ClientId, AccelByteServerPlugin.config.ClientSecret, AccelByteServerPlugin.httpClient, AccelByteServerPlugin.coroutineRunner); AccelByteServerPlugin.server = new DedicatedServer( AccelByteServerPlugin.session, AccelByteServerPlugin.coroutineRunner); }
public DedicatedServer(ServerOauthLoginSession session, CoroutineRunner coroutineRunner) { this.session = session; this.coroutineRunner = coroutineRunner; }