GS2-Ranking2 Deploy/CDK Reference

The template format used when creating stacks with GS2-Deploy, and implementation examples of template output in various languages using CDK

Entities

Resources managed by the Deploy operation

Namespace

Namespace

A Namespace allows multiple independent instances of the same service within a single project by separating data spaces and usage contexts. Each GS2 service is managed on a per-namespace basis. Even when using the same service, if the Namespace differs, the data is treated as a completely independent data space.

Therefore, you must create a Namespace before you can start using each service.

Request

Resource creation and update requests

Type Condition Required Default Value Limits Description
name string
✓
~ 128 chars Namespace name
Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
description string ~ 1024 chars Description
transactionSettingV2 TransactionSettingV2 Transaction Setting (V2)
Decides how the transactions this Namespace issues are executed. There are only two things to set: the GS2-Distributor Namespace that executes them, and whether the actions in a transaction run one at a time – so that a later action can build on what an earlier one wrote – or all at once for a shorter response time.
Set this on a new Namespace. transactionSetting, the obsolete setting it replaces, is used only while this is unset.
logSetting LogSetting Log Output Setting
Specifies the GS2-Log Namespace for outputting API request and response logs. Used for tracking score submissions and ranking reward distributions.

GetAttr

Resource creation results that can be retrieved using the !GetAttr tag

Type Description
Item Namespace Namespace created

Implementation Example

Type: GS2::Ranking2::Namespace
Properties:
  Name: namespace-0001
  Description: null
  TransactionSettingV2: null
  LogSetting: 
    LoggingNamespaceId: grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/ranking2"
)


SampleStack := core.NewStack()
ranking2.NewNamespace(
    &SampleStack,
    "namespace-0001",
    ranking2.NamespaceOptions{
        LogSetting: &core.LogSetting{
            LoggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001",
        },
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        new \Gs2Cdk\Ranking2\Model\Namespace_(
            stack: $this,
            name: "namespace-0001",
            options: new \Gs2Cdk\Ranking2\Model\Options\NamespaceOptions(
                logSetting: new \Gs2Cdk\Core\Model\LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            )
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.ranking2.model.Namespace(
                this,
                "namespace-0001",
                new io.gs2.cdk.ranking2.model.options.NamespaceOptions()
                        .withLogSetting(new io.gs2.cdk.core.model.LogSetting(
                            "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                        ))
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Ranking2.Model.Namespace(
            stack: this,
            name: "namespace-0001",
            options: new Gs2Cdk.Gs2Ranking2.Model.Options.NamespaceOptions
            {
                logSetting = new Gs2Cdk.Core.Model.LogSetting(
                    loggingNamespaceId: "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import ranking2 from "@/gs2cdk/ranking2";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new ranking2.model.Namespace(
            this,
            "namespace-0001",
            {
                logSetting: new core.LogSetting(
                    "grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001"
                )
            }
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, ranking2

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        ranking2.Namespace(
            stack=self,
            name='namespace-0001',
            options=ranking2.NamespaceOptions(
                log_setting=core.LogSetting(
                    logging_namespace_id='grn:gs2:ap-northeast-1:YourOwnerId:log:namespace-0001',
                ),
            ),
        )

print(SampleStack().yaml())  # Generate Template

TransactionSettingV2

Transaction Setting (V2)

Transaction Setting (V2) decides how the transactions issued by a Namespace are executed.

There are only two things to set:

  • distributorNamespaceId: the GS2-Distributor Namespace used to execute the transaction
  • enableParallelExecution: whether the actions in a transaction run one at a time or all at once

Whichever you choose, the transaction is executed by the server the moment it is issued, and it succeeds or fails as a whole: when an action fails, the actions that already ran are undone with it and nothing is left applied. Everything else about how a transaction runs is fixed to the recommended configuration, so there is nothing else to set.

Running the actions one at a time (the default, enableParallelExecution is false) lets each action work on top of what the actions before it wrote. The actions run in verify, consume, acquire order, and this is what lets you:

  • update the same row from more than one action in a single transaction, which fails when they run all at once
  • read what an earlier action wrote, including from List and Query and from inside a nested transaction
  • use %{Gs2Xxx:ActionName.path[0].field} to feed the result of an earlier verify or consume action into the parameters of a later verify, consume or acquire action

In exchange, the response time is the sum of the time taken by each action, and a transaction may contain at most 20 actions. The order within each phase is decided by the action name and then by the target resource, so you cannot choose the execution order by rearranging the actions in the request, and execution stops at the first action that fails.

Running the actions all at once (enableParallelExecution is true) executes them in parallel against a single snapshot of the data, so the response time is that of the slowest single action and there is no limit on the number of actions.

In exchange, an action cannot see what the other actions wrote, and two actions that write the same row fail the transaction with database:transaction:same.resource (400), so choose this only when you can guarantee that no two actions in the same transaction write the same data. %{...} may reference only the results of an earlier phase (verify, then consume, then acquire); a reference to an action in the same phase is left unresolved, and a phase that contains %{...} waits for the earlier phases to complete, which lengthens the response time by that amount.

Transaction Setting is the obsolete setting that Transaction Setting (V2) replaces, kept for Namespaces created before Transaction Setting (V2) existed. It applies only while Transaction Setting (V2) is unset, and setting Transaction Setting (V2) supersedes it. Three behaviours it allowed are deliberately not offered here: executing a transaction as a client-run stamp sheet, running AutoRun asynchronously via GS2-Distributor, and folding acquire actions into GS2-JobQueue.

Type Condition Required Default Value Limits Description
distributorNamespaceId string “grn:gs2:{region}:{ownerId}:distributor:default” ~ 1024 chars GS2-Distributor Namespace GRN used to execute transactions
enableParallelExecution bool false Whether to execute the actions in parallel instead of sequentially

LogSetting

Log Output Setting

Log Output Setting defines how log data is exported. This type holds the GS2-Log Namespace identifier (Namespace ID), which is used to export log data. Specify the GS2-Log Namespace where log data is collected and stored in the GRN format for the Log Namespace ID (loggingNamespaceId). Configuring this setting ensures that log data for API requests and responses occurring within the specified Namespace is output to the target GS2-Log Namespace. GS2-Log provides real-time logs that can be used for system monitoring, analysis, debugging, and other operational purposes.

Type Condition Required Default Value Limits Description
loggingNamespaceId string
✓
~ 1024 chars GS2-Log Namespace GRN to output logs
Must be specified in GRN format starting with “grn:gs2:”.

TransactionSetting

Transaction Setting

Transaction Setting is obsolete: Transaction Setting (V2) replaces it. It is kept for Namespaces created before Transaction Setting (V2) existed, applies only while Transaction Setting (V2) is unset, and should not be chosen for a new Namespace.

It exposes each part of transaction execution as a separate field – AutoRun, AtomicCommit, asynchronous execution using GS2-Distributor, batch application of script results, asynchronous processing of acquire actions via GS2-JobQueue, and sequential execution – so combinations other than the recommended one can be built. Transaction Setting (V2) is that recommended combination expressed as a single setting. Keep using Transaction Setting only on a Namespace that already depends on a behaviour Transaction Setting (V2) does not offer: executing a transaction as a client-run stamp sheet, running AutoRun asynchronously via GS2-Distributor, or folding acquire actions into GS2-JobQueue.

Type Condition Required Default Value Limits Description
enableAutoRun bool false Whether to automatically execute issued transactions on the server side
enableAtomicCommit bool {enableAutoRun} == true false Whether to commit transactions atomically
* Enabled only if enableAutoRun is true
transactionUseDistributor bool {enableAtomicCommit} == true false Whether to execute transactions asynchronously
* Enabled only if enableAtomicCommit is true
commitScriptResultInUseDistributor bool {transactionUseDistributor} == true false Whether to execute the commit processing of the script result asynchronously
* Enabled only if transactionUseDistributor is true
acquireActionUseJobQueue bool {enableAtomicCommit} == true false Whether to use GS2-JobQueue to execute the acquire action
* Enabled only if enableAtomicCommit is true
enableSequentialExecution bool {enableAtomicCommit} == true false Whether to execute the actions of an atomic commit sequentially so that multiple actions may update the same row
* Enabled only if enableAtomicCommit is true
distributorNamespaceId string “grn:gs2:{region}:{ownerId}:distributor:default” ~ 1024 chars GS2-Distributor Namespace GRN used to execute transactions
queueNamespaceId string “grn:gs2:{region}:{ownerId}:queue:default” ~ 1024 chars GS2-JobQueue Namespace GRN used to execute transactions

CurrentRankingMaster

Currently active Ranking Model master data

This master data defines the Ranking Models currently active within the Namespace. GS2 uses JSON format files for managing master data. By uploading these files, you can apply the master data to the server.

To create JSON files, GS2 provides a master data editor within the management console. Additionally, you can create tools better suited for game operations and export JSON files in the appropriate format.

Request

Resource creation and update requests

Type Condition Required Default Value Limits Description
namespaceName string
✓
~ 128 chars Namespace name
Unique Namespace name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
mode string (enum)
enum {
  “direct”,
  “preUpload”
}
“direct” Update mode
DefinitionDescription
directDirectly update master data
preUploadUpload master data and then update
settings string {mode} == “direct”
✓*
~ 5242880 bytes (5MB) Master Data
* Required if mode is “direct”
uploadToken string {mode} == “preUpload”
✓*
~ 1024 chars Token obtained by pre-upload
Used to apply the uploaded master data.
* Required if mode is “preUpload”

GetAttr

Resource creation results that can be retrieved using the !GetAttr tag

Type Description
Item CurrentRankingMaster Updated master data of the currently active Ranking Models

Implementation Example

Type: GS2::Ranking2::CurrentRankingMaster
Properties:
  NamespaceName: namespace-0001
  Mode: direct
  Settings: {
    "version": "2024-05-30",
    "globalRankingModels": [
      {
        "name": "ranking-0001",
        "orderDirection": "asc"
      },
      {
        "name": "ranking-0002",
        "orderDirection": "desc"
      }
    ],
    "clusterRankingModels": [
      {
        "name": "ranking-0001",
        "clusterType": "Raw",
        "orderDirection": "asc"
      },
      {
        "name": "ranking-0002",
        "clusterType": "Gs2Guild::Guild",
        "orderDirection": "desc"
      }
    ],
    "subscribeRankingModels": [
      {
        "name": "ranking-0001",
        "orderDirection": "asc"
      },
      {
        "name": "ranking-0002",
        "orderDirection": "desc"
      }
    ]
  }
  UploadToken: null
import (
    "github.com/gs2io/gs2-golang-cdk/core"
    "github.com/gs2io/gs2-golang-cdk/ranking2"
)


SampleStack := core.NewStack()
ranking2.NewNamespace(
    &SampleStack,
    "namespace-0001",
    ranking2.NamespaceOptions{},
).MasterData(
    []ranking2.GlobalRankingModel{
        ranking2.NewGlobalRankingModel(
            "ranking-0001",
            false,
            ranking2.GlobalRankingModelOrderDirectionAsc,
            ranking2.GlobalRankingModelRewardCalculationIndexRank,
            ranking2.GlobalRankingModelOptions{
            },
        ),
        ranking2.NewGlobalRankingModel(
            "ranking-0002",
            false,
            ranking2.GlobalRankingModelOrderDirectionDesc,
            ranking2.GlobalRankingModelRewardCalculationIndexRank,
            ranking2.GlobalRankingModelOptions{
            },
        ),
    },
    []ranking2.ClusterRankingModel{
        ranking2.NewClusterRankingModel(
            "ranking-0001",
            ranking2.ClusterRankingModelClusterTypeRaw,
            false,
            ranking2.ClusterRankingModelOrderDirectionAsc,
            ranking2.ClusterRankingModelRewardCalculationIndexRank,
            ranking2.ClusterRankingModelOptions{
            },
        ),
        ranking2.NewClusterRankingModel(
            "ranking-0002",
            ranking2.ClusterRankingModelClusterTypeGs2Guild_guild,
            false,
            ranking2.ClusterRankingModelOrderDirectionDesc,
            ranking2.ClusterRankingModelRewardCalculationIndexRank,
            ranking2.ClusterRankingModelOptions{
            },
        ),
    },
    []ranking2.SubscribeRankingModel{
        ranking2.NewSubscribeRankingModel(
            "ranking-0001",
            false,
            ranking2.SubscribeRankingModelOrderDirectionAsc,
            ranking2.SubscribeRankingModelOptions{
            },
        ),
        ranking2.NewSubscribeRankingModel(
            "ranking-0002",
            false,
            ranking2.SubscribeRankingModelOrderDirectionDesc,
            ranking2.SubscribeRankingModelOptions{
            },
        ),
    },
)

println(SampleStack.Yaml())  // Generate Template
class SampleStack extends \Gs2Cdk\Core\Model\Stack
{
    function __construct() {
        parent::__construct();
        (new \Gs2Cdk\Ranking2\Model\Namespace_(
            stack: $this,
            name: "namespace-0001"
        ))->masterData(
            [
                new \Gs2Cdk\Ranking2\Model\GlobalRankingModel(
                    name:"ranking-0001",
                    sum: false,
                    orderDirection: \Gs2Cdk\Ranking2\Model\Enums\GlobalRankingModelOrderDirection::ASC,
                    rewardCalculationIndex: \Gs2Cdk\Ranking2\Model\Enums\GlobalRankingModelRewardCalculationIndex::RANK
                ),
                new \Gs2Cdk\Ranking2\Model\GlobalRankingModel(
                    name:"ranking-0002",
                    sum: false,
                    orderDirection: \Gs2Cdk\Ranking2\Model\Enums\GlobalRankingModelOrderDirection::DESC,
                    rewardCalculationIndex: \Gs2Cdk\Ranking2\Model\Enums\GlobalRankingModelRewardCalculationIndex::RANK
                )
            ],
            [
                new \Gs2Cdk\Ranking2\Model\ClusterRankingModel(
                    name:"ranking-0001",
                    clusterType: \Gs2Cdk\Ranking2\Model\Enums\ClusterRankingModelClusterType::RAW,
                    sum: false,
                    orderDirection: \Gs2Cdk\Ranking2\Model\Enums\ClusterRankingModelOrderDirection::ASC,
                    rewardCalculationIndex: \Gs2Cdk\Ranking2\Model\Enums\ClusterRankingModelRewardCalculationIndex::RANK
                ),
                new \Gs2Cdk\Ranking2\Model\ClusterRankingModel(
                    name:"ranking-0002",
                    clusterType: \Gs2Cdk\Ranking2\Model\Enums\ClusterRankingModelClusterType::GS2_GUILD__GUILD,
                    sum: false,
                    orderDirection: \Gs2Cdk\Ranking2\Model\Enums\ClusterRankingModelOrderDirection::DESC,
                    rewardCalculationIndex: \Gs2Cdk\Ranking2\Model\Enums\ClusterRankingModelRewardCalculationIndex::RANK
                )
            ],
            [
                new \Gs2Cdk\Ranking2\Model\SubscribeRankingModel(
                    name:"ranking-0001",
                    sum: false,
                    orderDirection: \Gs2Cdk\Ranking2\Model\Enums\SubscribeRankingModelOrderDirection::ASC
                ),
                new \Gs2Cdk\Ranking2\Model\SubscribeRankingModel(
                    name:"ranking-0002",
                    sum: false,
                    orderDirection: \Gs2Cdk\Ranking2\Model\Enums\SubscribeRankingModelOrderDirection::DESC
                )
            ]
        );
    }
}

print((new SampleStack())->yaml());  // Generate Template
class SampleStack extends io.gs2.cdk.core.model.Stack
{
    public SampleStack() {
        super();
        new io.gs2.cdk.ranking2.model.Namespace(
            this,
            "namespace-0001"
        ).masterData(
            Arrays.asList(
                new io.gs2.cdk.ranking2.model.GlobalRankingModel(
                    "ranking-0001",
                    false,
                    io.gs2.cdk.ranking2.model.enums.GlobalRankingModelOrderDirection.ASC,
                    io.gs2.cdk.ranking2.model.enums.GlobalRankingModelRewardCalculationIndex.RANK
                ),
                new io.gs2.cdk.ranking2.model.GlobalRankingModel(
                    "ranking-0002",
                    false,
                    io.gs2.cdk.ranking2.model.enums.GlobalRankingModelOrderDirection.DESC,
                    io.gs2.cdk.ranking2.model.enums.GlobalRankingModelRewardCalculationIndex.RANK
                )
            ),
            Arrays.asList(
                new io.gs2.cdk.ranking2.model.ClusterRankingModel(
                    "ranking-0001",
                    io.gs2.cdk.ranking2.model.enums.ClusterRankingModelClusterType.RAW,
                    false,
                    io.gs2.cdk.ranking2.model.enums.ClusterRankingModelOrderDirection.ASC,
                    io.gs2.cdk.ranking2.model.enums.ClusterRankingModelRewardCalculationIndex.RANK
                ),
                new io.gs2.cdk.ranking2.model.ClusterRankingModel(
                    "ranking-0002",
                    io.gs2.cdk.ranking2.model.enums.ClusterRankingModelClusterType.GS2_GUILD__GUILD,
                    false,
                    io.gs2.cdk.ranking2.model.enums.ClusterRankingModelOrderDirection.DESC,
                    io.gs2.cdk.ranking2.model.enums.ClusterRankingModelRewardCalculationIndex.RANK
                )
            ),
            Arrays.asList(
                new io.gs2.cdk.ranking2.model.SubscribeRankingModel(
                    "ranking-0001",
                    false,
                    io.gs2.cdk.ranking2.model.enums.SubscribeRankingModelOrderDirection.ASC
                ),
                new io.gs2.cdk.ranking2.model.SubscribeRankingModel(
                    "ranking-0002",
                    false,
                    io.gs2.cdk.ranking2.model.enums.SubscribeRankingModelOrderDirection.DESC
                )
            )
        );
    }
}

System.out.println(new SampleStack().yaml());  // Generate Template
public class SampleStack : Gs2Cdk.Core.Model.Stack
{
    public SampleStack() {
        new Gs2Cdk.Gs2Ranking2.Model.Namespace(
            stack: this,
            name: "namespace-0001"
        ).MasterData(
            new Gs2Cdk.Gs2Ranking2.Model.GlobalRankingModel[] {
                new Gs2Cdk.Gs2Ranking2.Model.GlobalRankingModel(
                    name: "ranking-0001",
                    sum: false,
                    orderDirection: Gs2Cdk.Gs2Ranking2.Model.Enums.GlobalRankingModelOrderDirection.Asc,
                    rewardCalculationIndex: Gs2Cdk.Gs2Ranking2.Model.Enums.GlobalRankingModelRewardCalculationIndex.Rank
                ),
                new Gs2Cdk.Gs2Ranking2.Model.GlobalRankingModel(
                    name: "ranking-0002",
                    sum: false,
                    orderDirection: Gs2Cdk.Gs2Ranking2.Model.Enums.GlobalRankingModelOrderDirection.Desc,
                    rewardCalculationIndex: Gs2Cdk.Gs2Ranking2.Model.Enums.GlobalRankingModelRewardCalculationIndex.Rank
                )
            },
            new Gs2Cdk.Gs2Ranking2.Model.ClusterRankingModel[] {
                new Gs2Cdk.Gs2Ranking2.Model.ClusterRankingModel(
                    name: "ranking-0001",
                    clusterType: Gs2Cdk.Gs2Ranking2.Model.Enums.ClusterRankingModelClusterType.Raw,
                    sum: false,
                    orderDirection: Gs2Cdk.Gs2Ranking2.Model.Enums.ClusterRankingModelOrderDirection.Asc,
                    rewardCalculationIndex: Gs2Cdk.Gs2Ranking2.Model.Enums.ClusterRankingModelRewardCalculationIndex.Rank
                ),
                new Gs2Cdk.Gs2Ranking2.Model.ClusterRankingModel(
                    name: "ranking-0002",
                    clusterType: Gs2Cdk.Gs2Ranking2.Model.Enums.ClusterRankingModelClusterType.Gs2Guild_guild,
                    sum: false,
                    orderDirection: Gs2Cdk.Gs2Ranking2.Model.Enums.ClusterRankingModelOrderDirection.Desc,
                    rewardCalculationIndex: Gs2Cdk.Gs2Ranking2.Model.Enums.ClusterRankingModelRewardCalculationIndex.Rank
                )
            },
            new Gs2Cdk.Gs2Ranking2.Model.SubscribeRankingModel[] {
                new Gs2Cdk.Gs2Ranking2.Model.SubscribeRankingModel(
                    name: "ranking-0001",
                    sum: false,
                    orderDirection: Gs2Cdk.Gs2Ranking2.Model.Enums.SubscribeRankingModelOrderDirection.Asc
                ),
                new Gs2Cdk.Gs2Ranking2.Model.SubscribeRankingModel(
                    name: "ranking-0002",
                    sum: false,
                    orderDirection: Gs2Cdk.Gs2Ranking2.Model.Enums.SubscribeRankingModelOrderDirection.Desc
                )
            }
        );
    }
}

Debug.Log(new SampleStack().Yaml());  // Generate Template
import core from "@/gs2cdk/core";
import ranking2 from "@/gs2cdk/ranking2";

class SampleStack extends core.Stack
{
    public constructor() {
        super();
        new ranking2.model.Namespace(
            this,
            "namespace-0001",
        ).masterData(
            [
                new ranking2.model.GlobalRankingModel(
                    "ranking-0001",
                    false,
                    ranking2.model.GlobalRankingModelOrderDirection.ASC,
                    ranking2.model.GlobalRankingModelRewardCalculationIndex.RANK
                ),
                new ranking2.model.GlobalRankingModel(
                    "ranking-0002",
                    false,
                    ranking2.model.GlobalRankingModelOrderDirection.DESC,
                    ranking2.model.GlobalRankingModelRewardCalculationIndex.RANK
                )
            ],
            [
                new ranking2.model.ClusterRankingModel(
                    "ranking-0001",
                    ranking2.model.ClusterRankingModelClusterType.RAW,
                    false,
                    ranking2.model.ClusterRankingModelOrderDirection.ASC,
                    ranking2.model.ClusterRankingModelRewardCalculationIndex.RANK
                ),
                new ranking2.model.ClusterRankingModel(
                    "ranking-0002",
                    ranking2.model.ClusterRankingModelClusterType.GS2_GUILD__GUILD,
                    false,
                    ranking2.model.ClusterRankingModelOrderDirection.DESC,
                    ranking2.model.ClusterRankingModelRewardCalculationIndex.RANK
                )
            ],
            [
                new ranking2.model.SubscribeRankingModel(
                    "ranking-0001",
                    false,
                    ranking2.model.SubscribeRankingModelOrderDirection.ASC
                ),
                new ranking2.model.SubscribeRankingModel(
                    "ranking-0002",
                    false,
                    ranking2.model.SubscribeRankingModelOrderDirection.DESC
                )
            ]
        );
    }
}

console.log(new SampleStack().yaml());  // Generate Template
from gs2_cdk import Stack, core, ranking2

class SampleStack(Stack):

    def __init__(self):
        super().__init__()
        ranking2.Namespace(
            stack=self,
            name="namespace-0001",
        ).master_data(
            global_ranking_models=[
                ranking2.GlobalRankingModel(
                    name='ranking-0001',
                    sum=False,
                    order_direction=ranking2.GlobalRankingModelOrderDirection.ASC,
                    reward_calculation_index=ranking2.GlobalRankingModelRewardCalculationIndex.RANK
                ),
                ranking2.GlobalRankingModel(
                    name='ranking-0002',
                    sum=False,
                    order_direction=ranking2.GlobalRankingModelOrderDirection.DESC,
                    reward_calculation_index=ranking2.GlobalRankingModelRewardCalculationIndex.RANK
                ),
            ],
            cluster_ranking_models=[
                ranking2.ClusterRankingModel(
                    name='ranking-0001',
                    cluster_type=ranking2.ClusterRankingModelClusterType.RAW,
                    sum=False,
                    order_direction=ranking2.ClusterRankingModelOrderDirection.ASC,
                    reward_calculation_index=ranking2.ClusterRankingModelRewardCalculationIndex.RANK
                ),
                ranking2.ClusterRankingModel(
                    name='ranking-0002',
                    cluster_type=ranking2.ClusterRankingModelClusterType.GS2_GUILD__GUILD,
                    sum=False,
                    order_direction=ranking2.ClusterRankingModelOrderDirection.DESC,
                    reward_calculation_index=ranking2.ClusterRankingModelRewardCalculationIndex.RANK
                ),
            ],
            subscribe_ranking_models=[
                ranking2.SubscribeRankingModel(
                    name='ranking-0001',
                    sum=False,
                    order_direction=ranking2.SubscribeRankingModelOrderDirection.ASC
                ),
                ranking2.SubscribeRankingModel(
                    name='ranking-0002',
                    sum=False,
                    order_direction=ranking2.SubscribeRankingModelOrderDirection.DESC
                ),
            ],
        )

print(SampleStack().yaml())  # Generate Template

GlobalRankingModel

Global Ranking Model

The global ranking is a model that allows you to create a ranking that targets all players. You can display the top 1000 rankings.

By associating it with the repeat event of GS2-Schedule, you can reset the ranking according to the number of repetitions.

Type Condition Required Default Value Limits Description
globalRankingModelId string
*
~ 1024 chars Global Ranking GRN
* Set automatically by the server
name string
✓
~ 128 chars Global Ranking Model name
Unique Global Ranking Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadata string ~ 1024 chars Metadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
minimumValue long 0 ~ 9223372036854775805 Minimum Score
The minimum allowed score value. Scores below this value will be rejected when submitted. Used to filter out invalid or unintended score values.
maximumValue long 0 ~ 9223372036854775805 Maximum Score
The maximum allowed score value. Scores above this value will be rejected when submitted. Used to prevent abnormally high scores from being registered.
sum bool false Sum Scores
When enabled, all submitted scores are accumulated and the ranking is determined by the total value. When disabled, only the best score (highest or lowest depending on sort direction) is used for ranking.
orderDirection string (enum)
enum {
  “asc”,
  “desc”
}
✓
Order Direction
The sort direction for ranking scores. Use asc for rankings where lower scores are better (e.g., time trials), or desc for rankings where higher scores are better (e.g., high scores).
DefinitionDescription
ascascending-order
descdescending-order
entryPeriodEventId string ~ 1024 chars Entry Period Event GRN
GS2-Schedule event GRN that defines the period during which scores can be submitted. When linked to a repeating event, the ranking resets with each repeat cycle, enabling seasonal rankings.
rankingRewards List<RankingReward> {entryPeriodEventId} != null [] 0 ~ 100 items Ranking Rewards
List of rewards granted based on ranking position at the end of each season. Only available when an entry period event is configured. Each reward defines a rank threshold and the acquire actions to execute.
accessPeriodEventId string ~ 1024 chars Access Period Event GRN
GS2-Schedule event GRN that defines the period during which ranking results can be viewed and rewards can be claimed. Typically set to the interval between score entry periods.
rewardCalculationIndex string (enum)
enum {
  “rank”,
  “index”
}
“rank” Reward Calculation Index
Determines how rewards are matched to players. rank uses the 1-based ranking position (players with tied scores share the same rank), while index uses the 0-based unique sorted position (no ties). Choose rank for most typical use cases.
DefinitionDescription
rankDetermine rewards based on rank
indexDetermine rewards based on index

RankingReward

Ranking Reward

Set the rewards that can be received during the reference period when the score registration period is set in the ranking. If the repeat setting is enabled, the most recently ended period ranking will be the target for receiving rewards.

Type Condition Required Default Value Limits Description
thresholdRank int
✓
1 ~ 1001 Rank Threshold
The rank threshold for this reward tier. Players whose rank (or index, depending on rewardCalculationIndex setting) is at or above this threshold receive this reward. Set to 1001 to define rewards for unranked players (those outside the top 1000).
metadata string ~ 1024 chars Metadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
acquireActions List<AcquireAction> [] 0 ~ 100 items List of Acquire Actions
List of acquire actions executed when the player claims this ranking reward. These define the actual items, currency, or other resources granted as the reward for achieving this rank threshold.

ClusterRankingModel

Cluster Ranking Model

The cluster ranking model enables rankings for players within guilds or gatherings. You can display the top 1000 rankings.

By associating it with the repeat event of GS2-Schedule, you can reset the ranking according to the number of repetitions.

Type Condition Required Default Value Limits Description
clusterRankingModelId string
*
~ 1024 chars Cluster Ranking GRN
* Set automatically by the server
name string
✓
~ 128 chars Cluster Ranking Model name
Unique Cluster Ranking Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadata string ~ 1024 chars Metadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
clusterType string (enum)
enum {
  “Raw”,
  “Gs2Guild::Guild”,
  “Gs2Matchmaking::SeasonGathering”
}
✓
Cluster Type
Defines the type of group (cluster) used for ranking segmentation. “Raw” allows arbitrary cluster names without membership verification, “Gs2Guild::Guild” verifies the user belongs to a GS2-Guild guild, and “Gs2Matchmaking::SeasonGathering” verifies membership in a GS2-Matchmaking season gathering.
DefinitionDescription
RawNo verification
Gs2Guild::GuildGS2-Guild Guild
Gs2Matchmaking::SeasonGatheringGS2-Matchmaking Season Gathering
minimumValue long 0 ~ 9223372036854775805 Minimum Score
The minimum allowed score value. Scores below this value will be rejected when submitted.
maximumValue long 0 ~ 9223372036854775805 Maximum Score
The maximum allowed score value. Scores above this value will be rejected when submitted.
sum bool false Sum Scores
When enabled, all submitted scores are accumulated and the ranking is determined by the total value. When disabled, only the best score is used for ranking.
orderDirection string (enum)
enum {
  “asc”,
  “desc”
}
✓
Order Direction
The sort direction for ranking scores. Use asc for lower-is-better rankings, or desc for higher-is-better rankings.
DefinitionDescription
ascascending-order
descdescending-order
entryPeriodEventId string ~ 1024 chars Entry Period Event GRN
GS2-Schedule event GRN that defines the period during which scores can be submitted. When linked to a repeating event, the ranking resets with each repeat cycle, enabling seasonal rankings.
rankingRewards List<RankingReward> {entryPeriodEventId} != null [] 0 ~ 100 items Ranking Rewards
List of rewards granted based on ranking position at the end of each season. Only available when an entry period event is configured.
accessPeriodEventId string ~ 1024 chars Access Period Event GRN
GS2-Schedule event GRN that defines the period during which ranking results can be viewed and rewards can be claimed.
rewardCalculationIndex string (enum)
enum {
  “rank”,
  “index”
}
“rank” Reward Calculation Index
Determines how rewards are matched to players. rank uses the 1-based ranking position (tied scores share same rank), index uses the 0-based unique sorted position (no ties).
DefinitionDescription
rankDetermine rewards based on rank
indexDetermine rewards based on index

SubscribeRankingModel

Subscribe Ranking Model

A model that aggregates scores of other players that the user has subscribed to and creates a ranking.

Type Condition Required Default Value Limits Description
subscribeRankingModelId string
*
~ 1024 chars Subscribe Ranking GRN
* Set automatically by the server
name string
✓
~ 128 chars Subscribe Ranking Model name
Unique Subscribe Ranking Model name. Specified using alphanumeric characters, hyphens (-), underscores (_), and periods (.).
metadata string ~ 1024 chars Metadata
Arbitrary values can be set in the metadata.
Since they do not affect GS2’s behavior, they can be used to store information used in the game.
minimumValue long 0 ~ 9223372036854775805 Minimum Score
The minimum allowed score value. Scores below this value will be rejected when submitted.
maximumValue long 0 ~ 9223372036854775805 Maximum Score
The maximum allowed score value. Scores above this value will be rejected when submitted.
sum bool false Sum Scores
When enabled, all submitted scores are accumulated and the ranking is determined by the total value. When disabled, only the best score is used for ranking.
orderDirection string (enum)
enum {
  “asc”,
  “desc”
}
✓
Order Direction
The sort direction for ranking scores. Use asc for lower-is-better rankings, or desc for higher-is-better rankings.
DefinitionDescription
ascascending-order
descdescending-order
entryPeriodEventId string ~ 1024 chars Entry Period Event GRN
GS2-Schedule event GRN that defines the period during which scores can be submitted. When linked to a repeating event, the ranking resets with each repeat cycle, enabling seasonal rankings.
accessPeriodEventId string ~ 1024 chars Access Period Event GRN
GS2-Schedule event GRN that defines the period during which ranking results can be viewed.

AcquireAction

Acquire Action

Type Condition Required Default Value Limits Description
action string (enum)
enum {
"Gs2AdReward:AcquirePointByUserId",
"Gs2Dictionary:AddEntriesByUserId",
"Gs2Enchant:ReDrawBalanceParameterStatusByUserId",
"Gs2Enchant:SetBalanceParameterStatusByUserId",
"Gs2Enchant:ReDrawRarityParameterStatusByUserId",
"Gs2Enchant:AddRarityParameterStatusByUserId",
"Gs2Enchant:SetRarityParameterStatusByUserId",
"Gs2Enhance:DirectEnhanceByUserId",
"Gs2Enhance:UnleashByUserId",
"Gs2Enhance:CreateProgressByUserId",
"Gs2Exchange:ExchangeByUserId",
"Gs2Exchange:IncrementalExchangeByUserId",
"Gs2Exchange:CreateAwaitByUserId",
"Gs2Exchange:AcquireForceByUserId",
"Gs2Exchange:SkipByUserId",
"Gs2Experience:AddExperienceByUserId",
"Gs2Experience:SetExperienceByUserId",
"Gs2Experience:AddRankCapByUserId",
"Gs2Experience:SetRankCapByUserId",
"Gs2Experience:MultiplyAcquireActionsByUserId",
"Gs2Formation:AddMoldCapacityByUserId",
"Gs2Formation:SetMoldCapacityByUserId",
"Gs2Formation:AcquireActionsToFormProperties",
"Gs2Formation:SetFormByUserId",
"Gs2Formation:AcquireActionsToPropertyFormProperties",
"Gs2Friend:UpdateProfileByUserId",
"Gs2Grade:AddGradeByUserId",
"Gs2Grade:ApplyRankCapByUserId",
"Gs2Grade:MultiplyAcquireActionsByUserId",
"Gs2Guild:IncreaseMaximumCurrentMaximumMemberCountByGuildName",
"Gs2Guild:SetMaximumCurrentMaximumMemberCountByGuildName",
"Gs2Idle:IncreaseMaximumIdleMinutesByUserId",
"Gs2Idle:SetMaximumIdleMinutesByUserId",
"Gs2Idle:ReceiveByUserId",
"Gs2Inbox:SendMessageByUserId",
"Gs2Inventory:AddCapacityByUserId",
"Gs2Inventory:SetCapacityByUserId",
"Gs2Inventory:AcquireItemSetByUserId",
"Gs2Inventory:AcquireItemSetWithGradeByUserId",
"Gs2Inventory:AddReferenceOfByUserId",
"Gs2Inventory:DeleteReferenceOfByUserId",
"Gs2Inventory:AcquireSimpleItemsByUserId",
"Gs2Inventory:SetSimpleItemsByUserId",
"Gs2Inventory:AcquireBigItemByUserId",
"Gs2Inventory:SetBigItemByUserId",
"Gs2JobQueue:PushByUserId",
"Gs2Limit:CountDownByUserId",
"Gs2Limit:DeleteCounterByUserId",
"Gs2LoginReward:DeleteReceiveStatusByUserId",
"Gs2LoginReward:UnmarkReceivedByUserId",
"Gs2Lottery:DrawByUserId",
"Gs2Lottery:ResetBoxByUserId",
"Gs2Mission:RevertReceiveByUserId",
"Gs2Mission:IncreaseCounterByUserId",
"Gs2Mission:SetCounterByUserId",
"Gs2Money:DepositByUserId",
"Gs2Money:RevertRecordReceipt",
"Gs2Money2:DepositByUserId",
"Gs2Quest:CreateProgressByUserId",
"Gs2Schedule:TriggerByUserId",
"Gs2Schedule:ExtendTriggerByUserId",
"Gs2Script:InvokeScript",
"Gs2SerialKey:RevertUseByUserId",
"Gs2SerialKey:IssueOnce",
"Gs2Showcase:DecrementPurchaseCountByUserId",
"Gs2Showcase:ForceReDrawByUserId",
"Gs2SkillTree:MarkReleaseByUserId",
"Gs2Stamina:RecoverStaminaByUserId",
"Gs2Stamina:RaiseMaxValueByUserId",
"Gs2Stamina:SetMaxValueByUserId",
"Gs2Stamina:SetRecoverIntervalByUserId",
"Gs2Stamina:SetRecoverValueByUserId",
"Gs2StateMachine:StartStateMachineByUserId",
}
✓
Type of Acquire Action
request string
✓
~ 524288 chars JSON string of the request used when executing the action