-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
75717fa
commit 8689f2c
Showing
67 changed files
with
8,989 additions
and
3,007 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
// Copyright (c) 2020 AccelByte Inc. All Rights Reserved. | ||
// This is licensed software from AccelByte Inc, for limitations | ||
// and restrictions contact your company contract manager. | ||
|
||
using System; | ||
using System.Net; | ||
using System.Net.Security; | ||
using System.Security.Cryptography.X509Certificates; | ||
using AccelByte.Core; | ||
using AccelByte.Api; | ||
using AccelByte.Models; | ||
using HybridWebSocket; | ||
using UnityEngine; | ||
|
||
namespace AccelByte.Server | ||
{ | ||
public static class AccelByteServerPlugin | ||
{ | ||
private static readonly ServerOauthLoginSession session; | ||
private static readonly ServerConfig config; | ||
private static readonly CoroutineRunner coroutineRunner; | ||
private static readonly UnityHttpWorker httpWorker; | ||
private static TokenData accessToken; | ||
private static DedicatedServer server; | ||
private static DedicatedServerManager dedicatedServerManager; | ||
private static ServerEcommerce ecommerce; | ||
private static ServerStatistic statistic; | ||
|
||
public static ServerConfig Config { get { return AccelByteServerPlugin.config; } } | ||
|
||
static AccelByteServerPlugin() | ||
{ | ||
#if UNITY_WEBGL && !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.Expand(); | ||
AccelByteServerPlugin.coroutineRunner = new CoroutineRunner(); | ||
AccelByteServerPlugin.httpWorker = new UnityHttpWorker(); | ||
|
||
AccelByteServerPlugin.session = new ServerOauthLoginSession( | ||
AccelByteServerPlugin.config.IamServerUrl, | ||
AccelByteServerPlugin.config.ClientId, | ||
AccelByteServerPlugin.config.ClientSecret, | ||
AccelByteServerPlugin.httpWorker, | ||
AccelByteServerPlugin.coroutineRunner); | ||
|
||
AccelByteServerPlugin.server = new DedicatedServer(AccelByteServerPlugin.session, | ||
AccelByteServerPlugin.coroutineRunner); | ||
} | ||
|
||
public static DedicatedServer GetDedicatedServer() | ||
{ | ||
return AccelByteServerPlugin.server; | ||
} | ||
|
||
public static DedicatedServerManager GetDedicatedServerManager() | ||
{ | ||
if (AccelByteServerPlugin.dedicatedServerManager == null) | ||
{ | ||
AccelByteServerPlugin.dedicatedServerManager = new DedicatedServerManager( | ||
new DedicatedServerManagerApi( | ||
AccelByteServerPlugin.config.DSMServerUrl, | ||
AccelByteServerPlugin.config.Namespace, | ||
AccelByteServerPlugin.httpWorker), | ||
AccelByteServerPlugin.session, | ||
AccelByteServerPlugin.coroutineRunner); | ||
} | ||
|
||
return AccelByteServerPlugin.dedicatedServerManager; | ||
} | ||
|
||
public static ServerEcommerce GetEcommerce() | ||
{ | ||
if (AccelByteServerPlugin.ecommerce == null) | ||
{ | ||
AccelByteServerPlugin.ecommerce = new ServerEcommerce( | ||
new ServerEcommerceApi( | ||
AccelByteServerPlugin.config.PlatformServerUrl, | ||
AccelByteServerPlugin.httpWorker), | ||
AccelByteServerPlugin.session, | ||
AccelByteServerPlugin.config.Namespace, | ||
AccelByteServerPlugin.coroutineRunner); | ||
} | ||
|
||
return AccelByteServerPlugin.ecommerce; | ||
} | ||
|
||
public static ServerStatistic GetStatistic() | ||
{ | ||
if (AccelByteServerPlugin.statistic == null) | ||
{ | ||
AccelByteServerPlugin.statistic = new ServerStatistic( | ||
new ServerStatisticApi( | ||
AccelByteServerPlugin.config.StatisticServerUrl, | ||
AccelByteServerPlugin.httpWorker), | ||
AccelByteServerPlugin.session, | ||
AccelByteServerPlugin.config.Namespace, | ||
AccelByteServerPlugin.coroutineRunner); | ||
} | ||
|
||
return AccelByteServerPlugin.statistic; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright (c) 2019 - 2020 AccelByte Inc. All Rights Reserved. | ||
// This is licensed software from AccelByte Inc, for limitations | ||
// and restrictions contact your company contract manager. | ||
|
||
using AccelByte.Models; | ||
using AccelByte.Core; | ||
using UnityEngine.Assertions; | ||
|
||
namespace AccelByte.Api | ||
{ | ||
/// <summary> | ||
/// Provide information of entitlements owned by the user | ||
/// </summary> | ||
public class Entitlement | ||
{ | ||
private readonly string @namespace; | ||
private readonly EntitlementApi api; | ||
private readonly ISession session; | ||
private readonly CoroutineRunner coroutineRunner; | ||
|
||
internal Entitlement(EntitlementApi api, ISession session, string ns, CoroutineRunner coroutineRunner) | ||
{ | ||
Assert.IsNotNull(api, "api parameter can not be null."); | ||
Assert.IsNotNull(session, "session parameter can not be null"); | ||
Assert.IsFalse(string.IsNullOrEmpty(ns), "ns paramater couldn't be empty"); | ||
Assert.IsNotNull(coroutineRunner, "coroutineRunner parameter can not be null. Construction failed"); | ||
|
||
this.api = api; | ||
this.session = session; | ||
this.@namespace = ns; | ||
this.coroutineRunner = coroutineRunner; | ||
} | ||
|
||
/// <summary> | ||
/// Query user entitlements. | ||
/// </summary> | ||
/// <param name="entitlementName">The name of the entitlement (optional)</param> | ||
/// <param name="itemId">Item's id (optional)</param> | ||
/// <param name="offset">Offset of the list that has been sliced based on Limit parameter (optional, default = 0)</param> | ||
/// <param name="limit">The limit of item on page (optional)</param> | ||
/// <param name="callback">Returns a Result that contains EntitlementPagingSlicedResult via callback when completed</param> | ||
/// <param name="entitlementClazz">Class of the entitlement (optional)</param> | ||
/// <param name="entitlementAppType">This is the type of application that entitled (optional)</param> | ||
public void QueryUserEntitlements(string entitlementName, string itemId, int offset, int limit, ResultCallback<EntitlementPagingSlicedResult> callback, | ||
EntitlementClazz entitlementClazz = EntitlementClazz.NONE, EntitlementAppType entitlementAppType = EntitlementAppType.NONE) | ||
{ | ||
Report.GetFunctionLog(this.GetType().Name); | ||
Assert.IsNotNull(entitlementName, "Can't query user entitlements! EntitlementName parameter is null!"); | ||
Assert.IsNotNull(itemId, "Can't query user entitlements! ItemId parameter is null!"); | ||
|
||
if (!this.session.IsValid()) | ||
{ | ||
callback.TryError(ErrorCode.IsNotLoggedIn); | ||
|
||
return; | ||
} | ||
|
||
this.coroutineRunner.Run( | ||
this.api.QueryUserEntitlements( | ||
this.@namespace, | ||
this.session.UserId, | ||
this.session.AuthorizationToken, | ||
entitlementName, | ||
itemId, | ||
offset, | ||
limit, | ||
entitlementClazz, | ||
entitlementAppType, | ||
callback)); | ||
} | ||
|
||
/// <summary> | ||
/// Get user's entitlement by the entitlementId. | ||
/// </summary> | ||
/// <param name="entitlementId">The id of the entitlement</param> | ||
/// <param name="callback">Returns a Result that contains EntitlementInfo via callback when completed</param> | ||
public void GetUserEntitlementById(string entitlementId, ResultCallback<EntitlementInfo> callback) | ||
{ | ||
Report.GetFunctionLog(this.GetType().Name); | ||
Assert.IsNotNull(entitlementId, "Can't get user entitlement by id! entitlementId parameter is null!"); | ||
|
||
if (!this.session.IsValid()) | ||
{ | ||
callback.TryError(ErrorCode.IsNotLoggedIn); | ||
|
||
return; | ||
} | ||
|
||
this.coroutineRunner.Run( | ||
this.api.GetUserEntitlementById( | ||
this.@namespace, | ||
this.session.UserId, | ||
this.session.AuthorizationToken, | ||
entitlementId, | ||
callback)); | ||
} | ||
|
||
/// <summary> | ||
/// Consume a user entitlement. | ||
/// </summary> | ||
/// <param name="entitlementId">The id of the user entitlement.</param> | ||
/// <param name="useCount">Number of consumed entitlement</param> | ||
/// <param name="callback">Returns a Result that contains EntitlementInfo via callback when completed</param> | ||
public void ConsumeUserEntitlement(string entitlementId, int useCount, ResultCallback<EntitlementInfo> callback) | ||
{ | ||
Report.GetFunctionLog(this.GetType().Name); | ||
Assert.IsNotNull(entitlementId, "Can't consume user entitlement! entitlementId parameter is null!"); | ||
|
||
if (!this.session.IsValid()) | ||
{ | ||
callback.TryError(ErrorCode.IsNotLoggedIn); | ||
|
||
return; | ||
} | ||
|
||
this.coroutineRunner.Run( | ||
this.api.ConsumeUserEntitlement( | ||
this.@namespace, | ||
this.session.UserId, | ||
this.session.AuthorizationToken, | ||
entitlementId, | ||
useCount, | ||
callback)); | ||
} | ||
} | ||
} |
Oops, something went wrong.