Leaderboards
Overview
AccelByte Cloud's Leaderboard service enables you to keep track of players' scores and ranking in the game by collecting data from the Cloud Statistics service such as the number of matches played, the player's matchmaking rating, and their experience points. The Leaderboard service will use this data to calculate each player's rank. This service supports multiple leaderboards in one game, including a daily leaderboard for day to day player activities, weekly leaderboard for a weekly player recap, a monthly leaderboard to record player activities every month, a seasonal leaderboard for seasonal player activities such as holiday events, and also an all-time leaderboard to record and player activities for all time. Each cycle of the leaderboard is explained in greater detail below.
Leaderboard Cycles
- The Daily Leaderboard collects players' daily scores and rankings once the leaderboard has been created. When the leaderboard has been generated, players can start playing the game and the leaderboard service will collect their score and ranking until the daily reset time. Players have to keep playing to maintain their position on the daily leaderboard.
- The Weekly Leaderboard is similar to the Daily Leaderboard, but player scores and rankings will be updated every week. Players have to keep playing to maintain their position on the weekly leaderboard.
- The Monthly Leaderboard is also similar to the Daily and Weekly Leaderboards. The player's score and ranking will be updated every month.
- The All-Time Leaderboard doesn't have any time constraint; it will record the player's score and ranking as long as the leaderboard exists in-game. As player scores continue to accumulate this leaderboard will be updated.
- The Seasonal Leaderboard runs for a specific period of time that is set when the leaderboard is created. For example, if an event is running on the 1st of May between 00:30 AM and 2:30 AM, the seasonal leaderboard will only record the rank and score of players who took part in that particular event. Once the event is over, the leaderboard will be reset.
Prerequisites
Before you create a leaderboard config, make sure you have created a statistic configuration in the same game namespace. Statistics configs are used to update a player's leaderboard rank.
Permissions
Permissions are used to grant access to specific resources within our services. Make sure your account has the following permissions before you attempt to manage the leaderboard in the Admin Portal. For a full list of permissions that impact leaderboards management, see the Leaderboards tab of the permissions reference.
Usage | Resource | Action |
---|---|---|
List All Leaderboards By Given Namespace | ADMIN:NAMESPACE:{namespace}:LEADERBOARD | Read |
Create New Leaderboard | ADMIN:NAMESPACE:{namespace}:LEADERBOARD | Create |
Get Leaderboard By Leaderboardcode | ADMIN:NAMESPACE:{namespace}:LEADERBOARD | Read |
Get User Ranking | ADMIN:NAMESPACE:{namespace}:LEADERBOARD | Read |
Delete User Ranking | ADMIN:NAMESPACE:{namespace}:LEADERBOARD:USER | Update |
Permissions work slightly differently depending on whether they are assigned to IAM Clients or Roles assigned to users. For more information, read the Authentication and Authorization documentation.
Manage Leaderboards in the Admin Portal
Create a New Leaderboard
In the Leaderboard menu of the Admin Portal, click the Create Leaderboard button.
Fill in the required fields.
- Input the Leaderboard Code with the appropriate format. Note that you can't use the same leaderboard code multiple times even if the previous leaderboard has been deleted.
- Input the StatCode with the related statistic code that you've created. This will be the statistic that the leaderboard draws from.
- Input the Start Date with RFC3339 standard format, e.g. 2020-10-02T15:00:00.05Z.
- Input the Daily reset time for a daily leaderboard.
- Input a day and time for the Weekly reset time for a weekly leaderboard.
- Input the day and time for the Monthly reset time for a monthly leaderboard. For example, if you input 1st in the date field and 12:00 AM in the time field, the reset time will be the first day of the month at 12:00 AM.
- If you select the Seasonal option, you must input the number of days it will take for the leaderboard to reset in the Season Period Days field.
- Choose the Order of the Leaderboard.
- Select an Icon for your leaderboard.
When you're done, click the Add button to create your new leaderboard and the new leaderboard will appear in the Leaderboard List.
NOTE
After creating the leaderboard, make sure that the configuration is correct as you will not be able to edit the leaderboard once it starts.
Get Leaderboard Rankings
In the Leaderboard List of the Admin Portal, choose the leaderboard you want to see ranking data for by clicking on the Action column and selecting View.
In this example, we choose to see the all-time leaderboard rankings. You can view the rankings for all cycles of leaderboards.
Delete or Archive a Leaderboard
In the Leaderboard List tab, choose the leaderboard that you want to delete. Then click Delete in the Action menu next to that leaderboard.
The Delete Leaderboard form appears. Select the Take a Snapshot Before Deletion box if you want to archive the first 1,000 records of the leaderboard and type DELETE in the available fields.
Click the Delete button to delete the leaderboard.
View Archived Leaderboard Data
Go to the Leaderboard page and open the Snapshots tab.
In the Snapshot tab, you can see all of the archived leaderboards. To open a leaderboard, click View in the leaderboard's Action menu.
Here you can check and see the list of the leaderboard that you already deleted before.
Implement Leaderboards using the Client SDKs
Retrieve Rankings
Retrieve all player rankings using a specific leaderboard code. The data is presented in descending order.
- Unreal Engine
- Unity
FString LeaderboardCode = FString("SomeLeaderboardCode");
EAccelByteLeaderboardTimeFrame TimeFrame = EAccelByteLeaderboardTimeFrame::ALL_TIME;
int32 Offset = 0;
int32 Limit = 99;
FRegistry::Leaderboard.GetRankings(LeaderboardCode, TimeFrame, Offset, Limit, THandler<FAccelByteModelsLeaderboardRankingResult>::CreateLambda([](const FAccelByteModelsLeaderboardRankingResult& Result)
{
// Do something if GetRankings has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetRankings has an error
UE_LOG(LogTemp, Log, TEXT("Error GetRankings, Error Code: %d Error Message: %s"), ErrorCode, *ErrorMessage);
}));
string leaderboardCode = "SomeLeaderboardCode";
LeaderboardTimeFrame timeFrame= LeaderboardTimeFrame.ALL_TIME;
int offset = 0;
int limit = 99;
AccelBytePlugin.GetLeaderboard().GetRankings(leaderboardCode, timeFrame, offset, limit, result =>
{
if (result.IsError)
{
// Do something if GetRankings has an error
Debug.Log($"Error GetRankings, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetRankings has been successful
}
});
Retrieve User Ranking
Retreive a specific player's ranking using their User ID and the desired leaderboard code.
- Unreal Engine
- Unity
FString UserId = FString("SomeUserId");
FString LeaderboardCode = FString("SomeLeaderboardCode");
FRegistry::Leaderboard.GetUserRanking(UserId, LeaderboardCode, THandler<FAccelByteModelsUserRankingData>::CreateLambda([](const FAccelByteModelsUserRankingData& Result)
{
// Do something if GetUserRanking has been successful
}), FErrorHandler::CreateLambda([](int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserRanking has an error
UE_LOG(LogTemp, Log, TEXT("Error GetUserRanking, Error Code: %d Error Meessage: %s"), ErrorCode, *ErrorMessage);
}));
string userId = "SomeUserId";
string leaderboardCode = "SomeLeaderboardCode";
AccelBytePlugin.GetLeaderboard().GetUserRanking(userId, leaderboardCode, result =>
{
if (result.IsError)
{
// Do something if GetUserRanking has an error
Debug.Log($"Error GetUserRanking, Error Code: {result.Error.Code} Error Message: {result.Error.Message}");
}
else
{
// Do something if GetUserRanking has been successful
}
});
Connect Custom Services to Leaderboards using the Server SDKs
SDK Initialization
Before using the Leaderboard service from the SDK, you will need to initialize your server-side SDK to make you authorized and able to perform create, read, update, and delete actions.
Golang SDK Initialization
Before using the Leaderboard service from the Golang SDK, you will need to initialize the SDK by following the steps below:
- Create your OAuth Client and assign the necessary permissions to access the IAM service.
- Log in as a Client using the SDK.
- Initialize the OAuth 2.0 service using the following function:
- Golang
leaderboardConfigurationService := &leaderboard.LeaderboardConfigurationService{
Client: factory.NewLeaderboardClient(&repository.ConfigRepositoryImpl{}),
TokenRepository: &repository.TokenRepositoryImpl{},
}
Once completed, you can use the Golang SDK to create, read, update, or delete the Leaderboard service from your serverless app.
Python SDK Initialization
Before using the Leaderboard service from the Python SDK, you will need to initialize the SDK by following the steps below:
- Create your OAuth Client and assign the necessary permissions to access the Matchmaking service.
- Log in as a Client using the SDK.
Once completed, you can use the Python SDK to create, read, update, or delete the Leaderboard service from your serverless app.
.NET (C#) SDK Initialization
Before using the Leaderboard service, you will need to set some permissions. Use the following .NET namespaces:
using AccelByte.Sdk.Api.Leaderboard.Model;
using AccelByte.Sdk.Api.Leaderboard.Operation;
using AccelByte.Sdk.Api.Leaderboard.Wrapper;
Java SDK Initialization
Before using the Leaderboard service, you will need to set some permissions. Initialize the LeaderboardConfiguration wrapper from the Leaderboard service using the following code:
LeaderboardConfiguration wLeaderboard = new LeaderboardConfiguration(sdk);
Once completed, you can use the SDK to create, read, update, or delete leaderboards.
Create a Leaderboard
Use the following function to create a leaderboard:
- Golang
- Python
- C#
- Java
ok, err := leaderboardConfigurationService.CreateLeaderboardConfigurationAdminV1(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.leaderboard import create_leaderboard_configuration_admin_v1
from accelbyte_py_sdk.api.leaderboard.models import ModelsLeaderboardConfigReq
from accelbyte_py_sdk.api.leaderboard.models import ModelsDailyConfig
from accelbyte_py_sdk.api.leaderboard.models import ModelsMonthlyConfig
from accelbyte_py_sdk.api.leaderboard.models import ModelsWeeklyConfig
result, error = create_leaderboard_configuration_admin_v1(
body=ModelsLeaderboardConfigReq.create(
daily=ModelsDailyConfig.create(
reset_time="<reset-time>"
),
descending=True,
icon_url="<icon-url>",
leaderboard_code="<leaderboard_code>",
monthly=ModelsMonthlyConfig.create(
reset_date=1,
reset_time="<reset-time>"
),
name="<name>",
season_period=1,
start_time="<start-time>",
stat_code="<stat-code>",
weekly=ModelsWeeklyConfig.create(
reset_day=1,
reset_time="<reset-time>"
)
)
)
if error:
print(error)
LeaderboardConfiguration wLeaderboard = new LeaderboardConfiguration(sdk);
ModelsLeaderboardConfigReq newLeaderboard = new ModelsLeaderboardConfigReq()
{
LeaderboardCode = "<leaderboard_code>",
Name = "<leaderboard_name>",
StatCode = "1",
SeasonPeriod = 36,
Descending = false,
StartTime = DateTime.Now.AddMonths(1).ToString("yyyy-MM-dd'T'HH:mm:ss.ffK");,
Daily = new ModelsDailyConfig()
{
ResetTime = "00:00:00"
},
Weekly = new ModelsWeeklyConfig()
{
ResetDay = 0,
ResetTime = "00:00:00"
},
Monthly = new ModelsMonthlyConfig()
{
ResetDate = 1,
ResetTime = "00:00:00"
}
};
ModelsLeaderboardConfigReq? cLeaderboard = wLeaderboard.CreateLeaderboardConfigurationAdminV1(
CreateLeaderboardConfigurationAdminV1.Builder
.Build(newLeaderboard, sdk.Namespace));
ModelsLeaderboardConfigReq newLeaderboard = ModelsLeaderboardConfigReq.builder()
.leaderboardCode(leaderboardCode)
.name(leaderboardName)
.statCode("1")
.seasonPeriod(36)
.descending(false)
.startTime(startTime)
.daily(ModelsDailyConfig.builder().resetTime("00:00:00").build())
.weekly(ModelsWeeklyConfig.builder().resetDay(0).resetTime("00:00:00").build())
.monthly(ModelsMonthlyConfig.builder().resetDate(1).resetTime("00:00:00").build())
.build();
ModelsLeaderboardConfigReq cLeaderboard = wLeaderboard
.createLeaderboardConfigurationAdminV1(CreateLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.body(newLeaderboard)
.build());
Delete a Leaderboard
Use the following function to delete a leaderboard:
- Golang
- Python
- C#
- Java
err := leaderboardConfigurationService.CreateLeaderboardConfigurationAdminV1(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.leaderboard import delete_leaderboard_configuration_admin_v1
result, error = delete_leaderboard_configuration_admin_v1(
leaderboard_code="<leaderboard_code>"
)
if error:
print(error)
LeaderboardConfiguration wLeaderboard = new LeaderboardConfiguration(sdk);
wLeaderboard.DeleteLeaderboardConfigurationAdminV1(
DeleteLeaderboardConfigurationAdminV1.Builder
.Build("<leaderboard_code>", sdk.Namespace));
wLeaderboard.deleteLeaderboardConfigurationAdminV1(DeleteLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.leaderboardCode(leaderboardCode)
.build());
Retrieve a Leaderboard
Use the following function to retrieve a leaderboard:
- Golang
- Python
- C#
- Java
ok, err := leaderboardConfigurationService.GetLeaderboardConfigurationAdminV1(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.leaderboard import get_leaderboard_configuration_admin_v1
result, error = get_leaderboard_configuration_admin_v1(
leaderboard_code="<leaderboard_code>"
)
if error:
print(error)
LeaderboardConfiguration wLeaderboard = new LeaderboardConfiguration(sdk);
ModelsGetLeaderboardConfigResp? gLeaderboard = wLeaderboard.GetLeaderboardConfigurationAdminV1(
GetLeaderboardConfigurationAdminV1.Builder
.Build("<leaderboard_code>", sdk.Namespace));
ModelsGetLeaderboardConfigResp gLeaderboard = wLeaderboard
.getLeaderboardConfigurationAdminV1(GetLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.leaderboardCode(leaderboardCode)
.build());
Update a Leaderboard
Use the following function to update a leaderboard:
- Golang
- Python
- C#
- Java
ok, err := leaderboardConfigurationService.GetLeaderboardConfigurationAdminV1(input)
if err != nil {
return err
}
return nil
from accelbyte_py_sdk.api.leaderboard import update_leaderboard_configuration_admin_v1
from accelbyte_py_sdk.api.leaderboard.models import ModelsUpdateLeaderboardConfigReq
from accelbyte_py_sdk.api.leaderboard.models import ModelsDailyConfig
from accelbyte_py_sdk.api.leaderboard.models import ModelsMonthlyConfig
from accelbyte_py_sdk.api.leaderboard.models import ModelsWeeklyConfig
result, error = update_leaderboard_configuration_admin_v1(
body=ModelsUpdateLeaderboardConfigReq.create(
daily=ModelsDailyConfig.create(
reset_time="<reset-time>"
),
descending=True,
icon_url="<icon-url>",
monthly=ModelsMonthlyConfig.create(
reset_date=1,
reset_time="<reset-time>"
),
name="<name>",
season_period=1,
start_time="<start-time>",
stat_code="<stat-code>",
weekly=ModelsWeeklyConfig.create(
reset_day=1,
reset_time="<reset-time>"
)
),
leaderboard_code="<leaderboard_code>"
)
if error:
print(error)
LeaderboardConfiguration wLeaderboard = new LeaderboardConfiguration(sdk);
ModelsUpdateLeaderboardConfigReq updateLeaderboard = new ModelsUpdateLeaderboardConfigReq()
{
Name = "CSharp SDK Leaderboard Test",
StatCode = "1",
StartTime = start_time,
SeasonPeriod = 40
};
ModelsGetLeaderboardConfigResp? uLeaderboard = wLeaderboard.UpdateLeaderboardConfigurationAdminV1(
UpdateLeaderboardConfigurationAdminV1.Builder
.Build(updateLeaderboard, "<leaderboard_code>", sdk.Namespace));
ModelsUpdateLeaderboardConfigReq updateLeaderboard = ModelsUpdateLeaderboardConfigReq.builder()
.name(leaderboardName)
.statCode("1")
.startTime(startTime)
.seasonPeriod(40)
.build();
ModelsGetLeaderboardConfigResp uLeaderboard = wLeaderboard
.updateLeaderboardConfigurationAdminV1(UpdateLeaderboardConfigurationAdminV1.builder()
.namespace(namespace)
.leaderboardCode(leaderboardCode)
.body(updateLeaderboard)
.build());
Related Concepts
- Leaderboards rely on player statistics to work, so check out our guide on our Statistics service.
- In addition to Leaderboards, Achievements can also be a great way to increase player engagement.
- Golang test case files
- Python test case files
- .NET (C#) test case files
- Java test case files