Skip to content

Commit

Permalink
feat(sdk): update to release 2.6.0
Browse files Browse the repository at this point in the history
  • Loading branch information
satrioaccelbyte committed Mar 3, 2020
1 parent 75717fa commit 8689f2c
Show file tree
Hide file tree
Showing 67 changed files with 8,989 additions and 3,007 deletions.
22 changes: 18 additions & 4 deletions Assets/AccelByte/AccelBytePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018 AccelByte Inc. All Rights Reserved.
// Copyright (c) 2018 - 2020 AccelByte Inc. All Rights Reserved.
// This is licensed software from AccelByte Inc, for limitations
// and restrictions contact your company contract manager.

Expand All @@ -8,6 +8,7 @@
using System.Security.Cryptography.X509Certificates;
using AccelByte.Core;
using AccelByte.Models;
using AccelByte.Server;
using HybridWebSocket;
using UnityEngine;

Expand All @@ -29,8 +30,9 @@ public static class AccelBytePlugin
private static Lobby lobby;
private static CloudStorage cloudStorage;
private static GameProfiles gameProfiles;
private static Entitlements entitlements;
private static Entitlement entitlements;
private static Statistic statistic;
private static Qos qos;

public static Config Config { get { return AccelBytePlugin.config; } }

Expand Down Expand Up @@ -263,11 +265,11 @@ public static GameProfiles GetGameProfiles()
return AccelBytePlugin.gameProfiles;
}

public static Entitlements GetEntitlements()
public static Entitlement GetEntitlements()
{
if (AccelBytePlugin.entitlements == null)
{
AccelBytePlugin.entitlements = new Entitlements(
AccelBytePlugin.entitlements = new Entitlement(
new EntitlementApi(AccelBytePlugin.config.PlatformServerUrl, AccelBytePlugin.httpWorker),
AccelBytePlugin.user.Session,
AccelBytePlugin.config.Namespace,
Expand All @@ -290,5 +292,17 @@ public static Statistic GetStatistic()

return AccelBytePlugin.statistic;
}

public static Qos GetQos()
{
if (AccelBytePlugin.qos == null)
{
AccelBytePlugin.qos = new Qos(
new QosManagerApi(AccelBytePlugin.config.QosManagerServerUrl, AccelBytePlugin.httpWorker),
AccelBytePlugin.coroutineRunner);
}

return AccelBytePlugin.qos;
}
}
}
127 changes: 127 additions & 0 deletions Assets/AccelByte/AccelByteServerPlugin.cs
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;
}
}
}
126 changes: 126 additions & 0 deletions Assets/AccelByte/Api/Entitlement.cs
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));
}
}
}
Loading

0 comments on commit 8689f2c

Please sign in to comment.