DRM

The Viveport DRM API provides a function to verify if the content should be launched for the current user.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
/** Language: C# for Unity*/
namespace Viveport
{
   public abstract class LicenseChecker
   {
      public abstract void OnSuccess(long issueTime,
                                     long expirationTime,
                                     int latestVersion,
                                     bool updateRequired);
      public abstract void OnFailure(int errorCode,
                                     string errorMessage);
   }

   class Api
   {
      public static void GetLicense(LicenseChecker checker, string appId, string appKey);
   }
}

How to Use DRM

Note

Remember that you should call Init() and IsReady() to setup the SDK library and client runtime before you call GetLicense()

The API GetLicense() is used to get the user’s content license, which is issued from Viveport to verify if the current user has permission to launch the content. The verification should be done with 3 parameters - an App ID, an App Key, and a LicenseChecker.

You need to implement a subclass of LicenseChecker to decide what to do if user’s license verification is successful or failed.

Detailed Example in Unity

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
using System;
using Viveport;

public class ViveportDemo : MonoBehaviour
{
   static string APP_ID = "bd67b286-aafc-449d-8896-bb7e9b351876";
   static string APP_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFypCg0OHf"
                         + "BC+VZLSWPbNSgDo9qg/yQORDwGy1rKIboMj3IXn4Zy6h6bgn"
                         + "8kiMY7VI0lPwIj9lijT3ZxkzuTsI5GsK//Y1bqeTol4OUFR+"
                         + "47gj+TUuekAS2WMtglKox+/7mO6CA1gV+jZrAKo6YSVmPd+o"
                         + "FsgisRcqEgNh5MIURQIDAQAB";


   // Use this for initialization
   void Start ()
   {
       Api.Init(InitStatusHandler, APP_ID);
   }

   private static void InitStatusHandler(int nResult)
   {
       Viveport.Core.Logger.Log("Init(): " + nResult);
       if (nResult != 0)
       {
          Viveport.Core.Logger.Log("Init setup error ...");
          // Handle error
       }
       UserStats.IsReady(IsReadyHandler);
   }

   private static void IsReadyHandler(int nResult)
   {
       if (nResult != 0)
       {
          Viveport.Core.Logger.Log("Platform setup error ...");
          // Handle error
       }
       Api.GetLicense(new MyLicenseChecker(), APP_ID, APP_KEY);
   }

   class MyLicenseChecker : Api.LicenseChecker
   {
       public override void OnSuccess(long issueTime, long expirationTime, int latestVersion, bool updateRequired)
       {
           Viveport.Core.Logger.Log("[MyLicenseChecker] issueTime: " + issueTime);
           Viveport.Core.Logger.Log("[MyLicenseChecker] expirationTime: " + expirationTime);
           Viveport.Core.Logger.Log("[MyLicenseChecker] latestVersion: " + latestVersion);
           Viveport.Core.Logger.Log("[MyLicenseChecker] updateRequired: " + updateRequired);
           // Do more things
       }

       public override void OnFailure(int errorCode, string errorMessage)
       {
           Viveport.Core.Logger.Log("[MyLicenseChecker] errorCode: " + errorCode);
           Viveport.Core.Logger.Log("[MyLicenseChecker] errorMessage: " + errorMessage);
       }
   }
}

Detailed Example in Unreal

ViveportApiDemo.h

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "Components/ActorComponent.h"
#include "ViveportApiDemo.generated.h"
#include "ViveportApi.h"


UCLASS( ClassGroup=(Viveport), meta=(BlueprintSpawnableComponent) )
class VIVEPORTSDK_API UViveportApiDemo : public UActorComponent
{
    GENERATED_BODY()

 public:
    // Sets default values for this component's properties
    UViveportApiDemo();

    // Called when the game starts
    void BeginPlay() override;

    // Called every frame
    void TickComponent(
                        float DeltaTime,
                        ELevelTick TickType,
                        FActorComponentTickFunction* ThisTickFunction
                      ) override;

    /** The APP ID for auth verify */
    FString APP_ID = "bd67b286-aafc-449d-8896-bb7e9b351876";

    /** Public key for auth verify */
    FString APP_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFypCg0OHf"
                       + "BC+VZLSWPbNSgDo9qg/yQORDwGy1rKIboMj3IXn4Zy6h6bgn"
                       + "8kiMY7VI0lPwIj9lijT3ZxkzuTsI5GsK//Y1bqeTol4OUFR+"
                       + "47gj+TUuekAS2WMtglKox+/7mO6CA1gV+jZrAKo6YSVmPd+o"
                       + "FsgisRcqEgNh5MIURQIDAQAB";
 private:
    // callback interface
    class MyLicenseChecker : public UViveportApi::LicenseChecker
    {
    public:
        void OnSuccess(
                        long long issue_time,
                        long long expiration_time,
                        int latest_version,
                        bool update_required
                      ) override;
        void OnFailure(
                        int errorCode,
                        const FString& errorMessage
                      ) override;
    };

    MyLicenseChecker myLicenseChecker;
};

ViveportApiDemo.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include "ViveportSDKPrivatePCH.h"
#include "ViveportApiDemo.h"

UViveportApiDemo::UViveportApiDemo()
{
    // Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
    // off to improve performance if you don't need them.
    bWantsBeginPlay = true;
    PrimaryComponentTick.bCanEverTick = true;
}

// Called when the game starts
void UViveportApiDemo::BeginPlay()
{
    Super::BeginPlay();
    FString fstring = UViveportApi::Version();
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);

    UViveportApi::GetLicense(&myLicenseChecker, APP_ID, APP_KEY);
}

// Called every frame
void UViveportApiDemo::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
    Super::TickComponent( DeltaTime, TickType, ThisTickFunction );
}

void UViveportApiDemo::MyLicenseChecker::OnSuccess(long long issue_time, long long expiration_time, int latest_version, bool update_required)
{
    char result[256] = { '\0' };
    sprintf_s(result, "Verify OK!\n issue_time=%lld,\n expiration_time=%lld,\n latest_version=%d,\n update_required=%d", issue_time, expiration_time, latest_version, update_required);
    FString fstring(result);
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
}

void UViveportApiDemo::MyLicenseChecker::OnFailure(int error_code, const FString& error_message)
{
    char result[256] = { '\0' };
    sprintf_s(result, "Verify failed!\n error_code=%d,\n error_message=%s", error_code, TCHAR_TO_UTF8(*error_message));
    FString fstring(result);
    GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::White, fstring);
}