API Reference of GS2-SerialKey SDK for Game Engine
Model
EzCampaignModel
Campaign Model
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
name | string | ✓ | ~ 128 chars | Campaign name | |
metadata | string | ~ 2048 chars | metadata | ||
enableCampaignCode | bool | ✓ | false | Allow redemption with campaign code |
EzSerialKey
Serial Code
The serial code issued can be used only once. Serial codes are issued in the format “RPCLP-FP7N-NCDMJ-FLVA-IRI4” and the data length cannot be changed. Information on the type of campaign is also included within the serial code. When using the serial code, simply specify the namespace in which the serial code is to be used.
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
campaignModelName | string | ✓ | ~ 128 chars | Campaign name | |
metadata | string | ~ 2048 chars | metadata | ||
code | string | ✓ | ~ 48 chars | Serial Code | |
status | enum [‘ACTIVE’, ‘USED’, ‘INACTIVE’] | ✓ | “ACTIVE” | ~ 128 chars | Status |
Methods
getCampaignModel
Get campaign model
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
campaignModelName | string | ✓ | ~ 128 chars | Campaign name |
Result
Type | Description | |
---|---|---|
item | EzCampaignModel | Campaign Model |
Implementation Example
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).CampaignModel(
campaignModelName: "campaign-0001"
);
var item = await domain.ModelAsync();
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).CampaignModel(
campaignModelName: "campaign-0001"
);
var future = domain.Model();
yield return future;
var item = future.Result;
const auto Domain = Gs2->SerialKey->Namespace(
"namespace-0001" // namespaceName
)->CampaignModel(
"campaign-0001" // campaignModelName
);
const auto Future = Domain.Model();
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
Value change event handling
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).CampaignModel(
campaignModelName: "campaign-0001"
);
// Start event handling
var callbackId = domain.Subscribe(
value => {
// Called when the value changes
// The "value" is passed the value after the change.
}
);
// Stop event handling
domain.Unsubscribe(callbackId);
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).CampaignModel(
campaignModelName: "campaign-0001"
);
var future = domain.Model();
yield return future;
var item = future.Result;
const auto Domain = Gs2->SerialKey->Namespace(
"namespace-0001" // namespaceName
)->CampaignModel(
"campaign-0001" // campaignModelName
);
// Start event handling
const auto CallbackId = Domain->Subscribe(
[](TSharedPtr<Gs2::SerialKey::Model::FCampaignModel> value) {
// Called when the value changes
// The "value" is passed the value after the change.
}
);
// Stop event handling
Domain->Unsubscribe(CallbackId);
Warning
This event is called when the value in the local cache that the SDK has is changed.
The local cache will only be changed by executing the SDK’s API, or by executing a stamp sheet via GS2-Distributor with GS2-Gateway notification enabled, or by executing a GS2-JobQueue with GS2-Gateway notification enabled. GS2-Gateway notification enabled.
Therefore, callbacks will not be invoked if the value is changed in any other way.
get
Get Serial Code
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
code | string | ✓ | ~ 48 chars | Serial Code |
Result
Type | Description | |
---|---|---|
item | EzSerialKey | Serial Key |
campaignModel | EzCampaignModel | Campaign Model |
Implementation Example
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).User(
userId: null
);
var result = await domain.GetAsync(
code: "code-0001"
);
var item = await result.ModelAsync();
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).User(
userId: null
);
var future = domain.GetFuture(
code: "code-0001"
);
yield return future;
if (future.Error != null)
{
onError.Invoke(future.Error, null);
yield break;
}
var future2 = future.Result.Model();
yield return future2;
if (future2.Error != null)
{
onError.Invoke(future2.Error, null);
yield break;
}
var result = future2.Result;
const auto Domain = Gs2->SerialKey->Namespace(
"namespace-0001" // namespaceName
)->User(
nullptr // userId
);
const auto Future = Domain->Get(
"code-0001"
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
// obtain changed values / result values
const auto Future2 = Future->GetTask().Result()->Model();
Future2->StartSynchronousTask();
if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
const auto Result = Future2->GetTask().Result();
useSerialCode
Consume Serial Code
Request
Type | Require | Default | Limitation | Description | |
---|---|---|---|---|---|
namespaceName | string | ✓ | ~ 32 chars | Namespace name | |
accessToken | string | ✓ | ~ 128 chars | User Id | |
code | string | ✓ | ~ 48 chars | Serial Code |
Result
Type | Description | |
---|---|---|
item | EzSerialKey | Serial Key |
campaignModel | EzCampaignModel | Campaign Model |
Error
Special exceptions are defined in this API. GS2-SDK for GameEngine provides specialized exceptions derived from general exceptions to facilitate handling of errors that may need to be handled in games. Please refer to the documentation here for more information on common error types and handling methods.
Type | Base Type | Description |
---|---|---|
AlreadyUsedException | BadRequestException | The specified serial code has already been used. |
CodeNotFoundException | NotFoundException | The specified serial code does not exist. |
Implementation Example
try {
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).SerialKey(
serialKeyCode: null
);
var result = await domain.UseSerialCodeAsync(
code: "code-0001"
);
var item = await result.ModelAsync();
} catch(Gs2.Gs2SerialKey.Exception.AlreadyUsed e) {
// The specified serial code has already been used.
} catch(Gs2.Gs2SerialKey.Exception.CodeNotFound e) {
// The specified serial code does not exist.
}
var domain = gs2.SerialKey.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).SerialKey(
serialKeyCode: null
);
var future = domain.UseSerialCodeFuture(
code: "code-0001"
);
yield return future;
if (future.Error != null)
{
if (future.Error is Gs2.Gs2SerialKey.Exception.AlreadyUsedException)
{
// The specified serial code has already been used.
}
if (future.Error is Gs2.Gs2SerialKey.Exception.CodeNotFoundException)
{
// The specified serial code does not exist.
}
onError.Invoke(future.Error, null);
yield break;
}
var future2 = future.Result.Model();
yield return future2;
if (future2.Error != null)
{
onError.Invoke(future2.Error, null);
yield break;
}
var result = future2.Result;
const auto Domain = Gs2->SerialKey->Namespace(
"namespace-0001" // namespaceName
)->Me(
AccessToken
)->SerialKey(
nullptr // serialKeyCode
);
const auto Future = Domain->UseSerialCode(
"code-0001"
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
if (Gs2::SerialKey::Error::FAlreadyUsedError::TypeString == Task->GetTask().Error()->Type())
{
// The specified serial code has already been used.
}
if (Gs2::SerialKey::Error::FCodeNotFoundError::TypeString == Task->GetTask().Error()->Type())
{
// The specified serial code does not exist.
}
return false;
}
// obtain changed values / result values
const auto Future2 = Future->GetTask().Result()->Model();
Future2->StartSynchronousTask();
if (!TestFalse(WHAT, Future2->GetTask().IsError())) return false;
const auto Result = Future2->GetTask().Result();