GS2-Account
The account system provided by Game Server Services is an “anonymous account” type of account system. This is a major system in Japan, but may be unfamiliar in other regions.
However, this account system makes a lot of sense for games.
What is an anonymous account?
When you think of account management, you usually think of having a login ID and a password. Anonymous accounts are no different.
However, the most important feature is that both the login ID and password are randomly generated by the system.
The login ID and password issued by the system can be saved to the local storage of the device, and the game can be resumed by logging in with this information for the second and subsequent times.
graph TD
Startup --> LoadSave{"Load Anonymous Account<br/>from Device Storage"}
LoadSave -- Not Exists --> CreateAccount["Create Anonymous Account"]
CreateAccount --> SaveAccount["Save Anonymous Account"]
SaveAccount --> Login
LoadSave -- Exists --> Login
Login --> InGameAdvantages of Anonymous Account
- Easy registration: Users can start playing games immediately without going through a complicated registration process. Especially in free-to-play (F2P) style games, reducing the registration process is important for encouraging more users to try the game.
- Protection of player information: Since users do not need to set their own login IDs or passwords, personal information and privacy are protected. In addition, there is no need to reset or change passwords.
- Easy transfer of game data: Users can use various platform IDs or social media accounts as transfer information, making it easy to transfer data between different devices or applications.
- Anonymous gameplay experience: Players can enjoy a more free gameplay experience by playing games anonymously without using their real names or nicknames.
TakeOver
There is no place less reliable than your device’s local storage. You could drop your device or destroy it. If you lose all your game data, you are in a no-win situation.
Players can experience the game with an anonymous account, and if they really like it, they can register “Takeover Information”. You can use information from various game publishers’ ID bases for the Takeover Information, or you can set up a social networking account. Game publishers’ ID bases can also be a good choice.
The Takeover Information will include user IDs and other information obtained as a result of authentication with the various ID platforms. Then perform the takeover on an entirely new device. Log in to the various ID platforms and perform the takeover using the user ID you received. Information can be obtained to log in with an anonymous account created in the past with the Takeover Information.
This information is stored in the local storage of the device and will be used for future logins.
graph TD InGame -- Loved the game very much! --> AddTakeOverSetting["Add Takeover Information"] AddTakeOverSetting --> BrokenDevice["Broken Device"] NewDevice["New Device"] --> DoTakeOver["Execute TakeOver<br/>(Enter Takeover Information)"] DoTakeOver -- Restore Anonymous Account --> SaveAccount["Save Anonymous Account"] SaveAccount --> Login
Before performing a takeover, you can also show the destination account’s data and let the player confirm it. See Confirming before takeover for details.
Instead of having the player decide the takeover user ID and password, GS2 can also issue them with an expiration. See Expiring takeover codes issued by GS2 for details.
OpenID Connect Connectivity
Support is available to use OpenID Connect compliant authentication systems for registering takeover information and executing the takeover process.
Registering Authentication Services
To use the OpenID Connect integration feature, master data configuration is required. You can specify the integration destination for each transfer slot, supporting up to 1,025 different authentication methods. The configuration items are as follows:
- OpenID Connect Discovery Endpoint URL
- Authentication service client ID
- Authentication service client secret
- Redirect URL after authentication completion
- Additional scope values to request
- Additional return values to obtain from the authentication result
Sign in with Apple must calculate the client secret dynamically, but it also provides this calculation functionality. If you specify a Sign in with Apple URL in the Spec URL based on OpenID Connect Discovery, then instead of the client secret, the
- Apple Developer team ID
- ID of the private key issued by Apple
- Payload (PEM) of the private key issued by Apple
The client secret is calculated by GS2 as needed.
Authentication Process
GS2 also provides support for authentication processing.
An API for obtaining the URL of the authentication page of an authentication service and a callback handling endpoint after authentication from the authentication service are provided.
The callback URL for the authentication service should be set according to the following format:
https://account.{region}.gen2.gs2io.com/{ownerId}/{namespaceName}/type/{type}/callback
https://account.ap-northeast-1.gen2.gs2io.com/aAbBcCdD-project/namespace-0001/type/0/callbackUpon receiving the authentication callback, the user will be redirected to the following URL
https://account.{region}.gen2.gs2io.com/{ownerId}/{namespaceName}/type/{type}/done?id_token={idToken}The ID token obtained by authenticating to the URL query string is passed across.
Using non-GS2 authenticators such as Firebase Authentication
Once the ID token is obtained, the method does not have to be the above procedure.
Deny registration from non-Authentication services
Slots with OpenID Connect integration in the master data will not be able to register transfer information using any user identifier and password, nor will they be able to perform transfers.
Example Implementation
Creating an Anonymous Account
GS2-Account has a hierarchy of namespaces that allows multiple pools of accounts within a single project. There is no specific purpose for namespaces, and they can be used as needed, for example to separate namespaces for different deployment regions.
var result = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).CreateAsync();
var item = await result.ModelAsync();
var userId = item.UserId;
var password = item.Password; const auto NamespaceName = "namespace-0001";
const auto Future = Gs2->Account->Namespace(
NamespaceName
)->Create();
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
const auto Result = Future->GetTask().Result();
const auto Future2 = Result->Model();
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;
const auto Result2 = Future2->GetTask().Result();
const auto UserId = Result2->UserId;
const auto Password = Result2->Password;var domain = ez.account.namespace_(
"namespace-0001"
)
var async_result = await domain.create(
)
if async_result.error != null:
push_error(str(async_result.error))
return
var result = async_result.resultLogging in using an anonymous account
The GS2-Account authentication process must be redone at regular intervals. Here is an example of a login using Gs2AccountAuthenticator, a utility class that automatically performs such processing.
By specifying Gs2AccountAuthenticator and the user ID and password of the anonymous account you created to the GS2 API client, you can obtain a GameSession instance that represents the session information during login. From now on, this GameSession instance will be used to access the information of the logged-in player.
var gameSession = await gs2.LoginAsync(
new Gs2AccountAuthenticator(
accountSetting: new AccountSetting {
accountNamespaceName = this.accountNamespaceName,
}
),
account.UserId,
account.Password
); const auto NamespaceName = "namespace-0001";
const auto KeyId = "grn:gs2:{region}:{yourOwnerId}:key:namespace-0001:key:key-0001";
const auto Future = Profile->Login(
MakeShareable<Gs2::UE5::Util::IAuthenticator>(
new Gs2::UE5::Util::FGs2AccountAuthenticator(
NamespaceName,
KeyId
)
),
UserId,
Password
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
const auto Result = Future->GetTask().Result();var authenticator = Gs2AccountAuthenticator.new(
"namespace-0001",
"grn:gs2:{region}:{ownerId}:key:namespace-0001:key:key-0001"
)
var game_session = Gs2GameSession.new(
authenticator, connection, account.user_id, account.password
)
var async_result = await game_session.login()
if async_result.error != null:
push_error(str(async_result.error))
returnSpecial Exceptions During Authentication
The following special exceptions may occur during authentication processing:
| Exception Type | Base Type | Description |
|---|---|---|
PasswordIncorrectException | UnauthorizedException | Password does not match |
BannedInfinityException | UnauthorizedException | Account has been suspended |
It is recommended that the game properly handles these exceptions and displays appropriate error messages to the user.
How these exceptions are surfaced when logging in via Gs2AccountAuthenticator / FGs2AccountAuthenticator depends on the SDK wrapper implementation. See the API Reference for details.
Registering takeover setting
You can maintain multiple takeover settings for an account by specifying different values for the slot number. Slot numbers range from 0 to 1024, allowing up to 1,025 takeover settings per account.
For example, you can store an email address/password in Slot Number:0 and social media ID information in Slot Number:1, allowing players to choose their preferred takeover method.
Password Handling in Takeover Settings
The password registered in takeover information is hashed and stored on the server side. Once a password is set, it cannot be retrieved via API. If forgotten, a new takeover setting must be issued. This mechanism ensures secure retention of player authentication information while preventing unauthorized use.
var result = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).TakeOver(
type: 0
).AddTakeOverSettingAsync(
userIdentifier: "user-0001@gs2.io",
password: "password-0001"
); const auto NamespaceName = "namespace-0001";
const auto Type = 0;
const auto UserIdentifier = "user-0001@gs2.io";
const auto Password = "password-0001";
const auto Future = Gs2->Account->Namespace(
NamespaceName
)->Me(
AccessToken
)->TakeOver(
Type
)->AddTakeOverSetting(
UserIdentifier,
Password
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
const auto Result = Future->GetTask().Result();var domain = ez.account.namespace_(
"namespace-0001"
).me(game_session).take_over(0)
var async_result = await domain.add_take_over_setting(
"user-0001@gs2.io", "password-0001"
)
if async_result.error != null:
push_error(str(async_result.error))
returnGet a List of Registered Takeover Settings
var items = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).TakeOversAsync(
).ToListAsync(); const auto NamespaceName = "namespace-0001";
const auto It = Gs2->Account->Namespace(
NamespaceName
)->Me(
AccessToken
)->TakeOvers();
TArray<Gs2::UE5::Account::Model::FEzTakeOverPtr> Result;
for (auto Item : *It)
{
if (Item.IsError())
{
return false;
}
Result.Add(Item.Current());
}var iterator = ez.account.namespace_(
"namespace-0001"
).me(
game_session
).take_overs(
)
var async_result = await iterator.load()
if async_result.error != null:
# Handle the error
push_error(str(async_result.error))
return
var items = async_result.resultPerform takeover
string userId;
string password;
try {
var result = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).DoTakeOverAsync(
type: 0,
userIdentifier: "user-0001@gs2.io",
password: "password-0001"
);
var item = await result.ModelAsync();
userId = item.UserId;
password = item.Password;
} catch(Gs2.Gs2Account.Exception.PasswordIncorrectException e) {
// Incorrect password specified.
} const auto NamespaceName = "namespace-0001";
const auto Type = 0;
const auto UserIdentifier = "user-0001@gs2.io";
const auto Password = "password-0001";
const auto Future = Gs2->Account->Namespace(
NamespaceName
)->DoTakeOver(
Type,
UserIdentifier,
Password
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
auto e = Future->GetTask().Error();
if (e->IsChildOf(Gs2::Account::Error::FPasswordIncorrectError::Class))
{
// Incorrect password specified.
}
return false;
}
// obtain changed values / result values
const auto Future2 = Future->GetTask().Result()->Model();
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;
const auto Result = Future2->GetTask().Result();var domain = ez.account.namespace_(
"namespace-0001"
)
var async_result = await domain.do_take_over(
null, # type
"user-0001@gs2.io", # user_identifier
"password-0001" # password
)
if async_result.error != null:
if async_result.error.type == "PasswordIncorrectException":
# Incorrect password specified.
pass
push_error(str(async_result.error))
return
var result = async_result.resultOpenID Connect Authentication Process
The Unity sample uses unity-webview for the in-app browser. For Godot, replace the URL change signal and URL-opening method with those provided by the WebView plugin you use.
public static async UniTask<string> OpenAuthentication(
WebViewObject webView,
Gs2Domain gs2,
string namespaceName,
IGameSession gameSession,
int type
) {
string idToken = null;
webView.Init(
separated: true,
ld: url =>
{
if (new Uri(url).LocalPath.EndsWith("/done")) {
var codeField = new Uri(url).Query.Replace("?", "").Split("&").Select(v => new KeyValuePair<string,string>(v[..v.IndexOf("=", StringComparison.Ordinal)], v[(v.IndexOf("=", StringComparison.Ordinal)+1)..])).FirstOrDefault(v => v.Key == "id_token");
idToken = Uri.UnescapeDataString(codeField.Value);
webView.SetVisibility(false);
}
}
);
webView.LoadURL(
(await gs2.Account.Namespace(
namespaceName
).Me(
gameSession
).GetAuthorizationUrlAsync(
type
)).AuthorizationUrl
);
webView.SetInteractionEnabled(true);
webView.SetVisibility(true);
await UniTask.WaitWhile(() => idToken == null);
return idToken;
}func open_authentication(web_view, ez, namespace_name: String, type: int) -> String:
var state = {"id_token": ""}
web_view.url_changed.connect(func(url):
var url_text = str(url)
if not url_text.get_slice("?", 0).ends_with("/done"):
return
for field in url_text.get_slice("?", 1).split("&"):
var pair = field.split("=", true, 1)
if pair.size() == 2 and pair[0] == "id_token":
state.id_token = pair[1].uri_decode()
web_view.hide()
)
var async_result = await ez.account.namespace_(
namespace_name
).get_authorization_url(type)
if async_result.error != null:
push_error(str(async_result.error))
return ""
# Replace this with the URL-opening method of the WebView plugin you use.
web_view.open_url(async_result.result.authorization_url)
while state.id_token.is_empty():
await Engine.get_main_loop().process_frame
return state.id_tokenRegistering takeover information using OpenID Connect
var result = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).TakeOver(
type: 0
).AddTakeOverSettingOpenIdConnectAsync(
idToken: "id-token"
); const auto NamespaceName = "namespace-0001";
const auto Type = 0;
const auto Future = Gs2->Account->Namespace(
NamespaceName
)->Me(
AccessToken
)->TakeOver(
Type
)->AddTakeOverSettingOpenIdConnect(
"id-token"
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
const auto Result = Future->GetTask().Result();var domain = ez.account.namespace_(
"namespace-0001"
).me(game_session).take_over(
0
)
var async_result = await domain.add_take_over_setting_open_id_connect(
"0123456789" # id_token
)
if async_result.error != null:
push_error(str(async_result.error))
return
var result = async_result.resultExecuting a takeover using OpenID Connect
var result = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).DoTakeOverOpenIdConnectAsync(
type: 0,
idToken: "id-token"
);
var item = await result.ModelAsync();
var userId = item.UserId;
var password = item.Password; const auto NamespaceName = "namespace-0001";
const auto Type = 0;
const auto Future = Gs2->Account->Namespace(
NamespaceName
)->DoTakeOverOpenIdConnect(
Type,
"id-token"
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError())
{
return false;
}
// obtain changed values / result values
const auto Future2 = Future->GetTask().Result()->Model();
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;
const auto Result = Future2->GetTask().Result();var domain = ez.account.namespace_(
"namespace-0001"
)
var async_result = await domain.do_take_over_open_id_connect(
null, # type
"0123456789" # id_token
)
if async_result.error != null:
push_error(str(async_result.error))
return
var result = async_result.resultConfirming before takeover
Once a takeover is performed, the device plays as the destination account. To prevent taking over the wrong account, you can use PreviewTakeOver / PreviewTakeOverOpenIdConnect to show the destination account’s data and let the player confirm it before performing the takeover.
PreviewTakeOver performs the same verification as DoTakeOver, and PreviewTakeOverOpenIdConnect the same as DoTakeOverOpenIdConnect, and returns the following values.
| Value | Description |
|---|---|
| item | The destination account. The password is not included |
| banStatuses | The suspensions currently applied to the destination account |
| token | An access token for reading the destination account’s data |
| expire | The expiration time of the access token |
- Nothing is written.
doTakeOverScriptis not executed, and the password does not change even if Automatic Password Change is enabled. After the player confirms, call DoTakeOver / DoTakeOverOpenIdConnect to perform the takeover. However, in a slot of Expiring takeover codes issued by GS2 withmaxFailedAttemptsspecified, failed verifications are counted - The access token can only call the Describe* and Get* APIs of each microservice. GetBallot of GS2-Matchmaking and GS2-SeasonRating, and the *WithSignature APIs, cannot be called even though their names start with Get
- The access token expires in 10 minutes and is not refreshed
- If the destination account is suspended, no access token is returned. Show the contents of banStatuses to the player. An account suspended indefinitely results in a BannedInfinity error
- If differentUserIdForLoginAndDataRetention is enabled and the destination account has never logged in, no access token is returned because there is no data to read yet. The access token reads the data of the data owner ID
- PreviewTakeOverOpenIdConnect does not mark the ID Token as used. You can pass the same ID Token to DoTakeOverOpenIdConnect after the confirmation, so the player does not need to authenticate with the ID provider again. However, if the ID Token’s expiration set by the ID provider passes, DoTakeOverOpenIdConnect fails; in that case, start over from authentication
PreviewGameSession() (preview_game_session() in Godot) on the result of PreviewTakeOver creates a GameSession for reading the destination account’s data.
This GameSession does not log in again when the access token expires.
It returns null if no access token was returned.
var account = gs2.Account.Namespace(
namespaceName: "namespace-0001"
);
// Only verify the credentials and receive the destination account
var preview = await account.PreviewTakeOverAsync(
type: 0,
userIdentifier: "user-0001@gs2.io",
password: "password-0001"
);
var previewSession = preview.PreviewGameSession();
if (previewSession == null) {
// The account is suspended, or has never logged in
foreach (var banStatus in preview.BanStatuses) {
Debug.Log($"{banStatus.Reason} {banStatus.ReleaseTimestamp}");
}
return;
}
// Read the destination account's data
var profile = await gs2.Friend.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: previewSession
).Profile(
).ModelAsync();
// Once the player agrees in the confirmation dialog, perform the takeover
var result = await account.DoTakeOverAsync(
type: 0,
userIdentifier: "user-0001@gs2.io",
password: "password-0001"
); const auto Domain = Gs2->Account->Namespace(
"namespace-0001" // namespaceName
);
// Only verify the credentials and receive the destination account
const auto Future = Domain->PreviewTakeOver(
0, // type
"user-0001@gs2.io", // userIdentifier
"password-0001" // password
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
const auto Preview = Future->GetTask().Result();
const auto PreviewSession = Preview->PreviewGameSession();
if (!PreviewSession.IsValid())
{
// The account is suspended, or has never logged in. BanStatuses contains the suspensions
return false;
}
// Read the destination account's data
const auto Future2 = Gs2->Friend->Namespace(
"namespace-0001" // namespaceName
)->Me(
PreviewSession
)->Profile(
)->Model();
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;
const auto Profile = Future2->GetTask().Result();
// Once the player agrees in the confirmation dialog, perform the takeover
const auto Future3 = Domain->DoTakeOver(
0, // type
"user-0001@gs2.io", // userIdentifier
"password-0001" // password
);
Future3->StartSynchronousTask();
if (Future3->GetTask().IsError()) return false;var domain = ez.account.namespace_(
"namespace-0001"
)
# Only verify the credentials and receive the destination account
var async_result = await domain.preview_take_over(
0, # type
"user-0001@gs2.io", # user_identifier
"password-0001" # password
)
if async_result.error != null:
push_error(str(async_result.error))
return
var preview = async_result.result
var preview_session = preview.preview_game_session()
if preview_session == null:
# The account is suspended, or has never logged in. ban_statuses contains the suspensions
return
# Read the destination account's data
var profile_result = await ez.friend.namespace_(
"namespace-0001"
).me(preview_session).profile(
).model()
if profile_result.error != null:
push_error(str(profile_result.error))
return
var profile = profile_result.result
# Once the player agrees in the confirmation dialog, perform the takeover
var take_over_result = await domain.do_take_over(
0, # type
"user-0001@gs2.io", # user_identifier
"password-0001" # password
)
if take_over_result.error != null:
push_error(str(take_over_result.error))
returnFor OpenID Connect, pass the same ID Token to PreviewTakeOverOpenIdConnect and DoTakeOverOpenIdConnect.
var preview = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).PreviewTakeOverOpenIdConnectAsync(
type: 0,
idToken: idToken
);
// Once the player agrees in the confirmation dialog, perform the takeover with the same ID Token
var result = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).DoTakeOverOpenIdConnectAsync(
type: 0,
idToken: idToken
); const auto Domain = Gs2->Account->Namespace(
"namespace-0001" // namespaceName
);
const auto Future = Domain->PreviewTakeOverOpenIdConnect(
0, // type
IdToken
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
const auto Preview = Future->GetTask().Result();
// Once the player agrees in the confirmation dialog, perform the takeover with the same ID Token
const auto Future2 = Domain->DoTakeOverOpenIdConnect(
0, // type
IdToken
);
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;var domain = ez.account.namespace_(
"namespace-0001"
)
var async_result = await domain.preview_take_over_open_id_connect(
0, # type
id_token
)
if async_result.error != null:
push_error(str(async_result.error))
return
var preview = async_result.result
# Once the player agrees in the confirmation dialog, perform the takeover with the same ID Token
var take_over_result = await domain.do_take_over_open_id_connect(
0, # type
id_token
)
if take_over_result.error != null:
push_error(str(take_over_result.error))
returnExpiring takeover codes issued by GS2
You can offer a takeover in the form “We issue a takeover ID and password. They are valid for N days and expire once used”, leaving both issuing and expiring the code to GS2. The player does not have to decide either the takeover ID or the password.
Takeover type model settings
For a slot that issues codes, set takeOverMethod to issuedCode and specify issuedCodeSetting in the takeover type model of the master data.
| Field | Description |
|---|---|
| expiresDays | Required. The number of days from issuance until the code expires (1-365) |
| maxFailedAttempts | Optional. The code expires when the password is entered incorrectly this many times (1-100). The count is reset to 0 when a takeover succeeds. If omitted, the code does not expire no matter how many times the password is entered incorrectly |
| deleteOnUse | Whether the code expires when a takeover with it succeeds. Defaults to true. If false, the code can be used any number of times until it expires |
The default value of takeOverMethod is openIdConnect. Existing master data that does not specify takeOverMethod keeps working as OpenID Connect slots.
If you switch a slot that already has registered takeover information (a slot without a takeover type model, or an OpenID Connect slot) to issuedCode, the takeover information registered before the switch can no longer be used (DoTakeOver / PreviewTakeOver return NotFound). We recommend assigning a new slot number to issued codes.
{
"version": "2024-07-30",
"takeOverTypeModels": [
{
"type": 1,
"metadata": "IssuedCode",
"takeOverMethod": "issuedCode",
"issuedCodeSetting": {
"expiresDays": 30,
"maxFailedAttempts": 10,
"deleteOnUse": true
}
}
]
}Issuing a takeover code
Calling IssueTakeOverCode makes GS2 issue a user ID and password for taking over the logged-in player’s account, and registers them as the takeover information of the specified slot. To issue from the server, use IssueTakeOverCodeByUserId.
| Value | Description |
|---|---|
| item | The issued takeover information. userIdentifier is the issued user ID (12 characters in the form XXXX-XXXX-XXXX), and expiresAt is when the code expires |
| password | The issued password (8 characters) |
- The user ID and password consist of uppercase letters (A-Z) and digits (2-7)
- Only the hash of the password is stored, so it can be obtained only from this response. Show the user ID and password to the player
- Issuing again expires the previous code. Only one code is valid per slot
- If issuing conflicts with a concurrent update to the same account, it may fail with a 409 (Conflict) error. In that case, retry
var takeOver = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).IssueTakeOverCodeAsync(
type: 1
);
// The password can be obtained only from this response
var password = takeOver.Password;
var item = await takeOver.ModelAsync();
var userIdentifier = item.UserIdentifier;
var expiresAt = item.ExpiresAt; // When the code expires (Unix time, milliseconds) const auto Future = Gs2->Account->Namespace(
"namespace-0001" // namespaceName
)->Me(
GameSession
)->IssueTakeOverCode(
1 // type
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
const auto TakeOver = Future->GetTask().Result();
// The password can be obtained only from this response
const auto Password = TakeOver->Password();
const auto Future2 = TakeOver->Model();
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;
const auto UserIdentifier = Future2->GetTask().Result()->GetUserIdentifier();
const auto ExpiresAt = Future2->GetTask().Result()->GetExpiresAt(); // When the code expires (Unix time, milliseconds)
Taking over with an issued code
As in Perform takeover, call DoTakeOver and pass the slot’s type together with the issued user ID and password. PreviewTakeOver in Confirming before takeover can be used in the same way.
- A code that has expired, has been used, or has reached the limit of failed password attempts results in a NotFound error. Whether the code existed is not revealed
- If the password is wrong, a PasswordIncorrect error is returned, as with other takeover information
- PreviewTakeOver normally writes nothing, but in a slot with
maxFailedAttemptsspecified, it counts failed verifications in the same way as DoTakeOver
In a slot that issues codes, CreateTakeOver, UpdateTakeOver, and the OpenID Connect APIs cannot be used.
Other functions
Platform ID management
GS2-Account can store user IDs used on platforms such as X and Instagram. Other players can search for these IDs and invite friends from social networks. Platform IDs are managed in slot numbers 0–1024, and multiple IDs can be registered per account.
Registering a Platform ID
var domain = gs2.Account.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).PlatformId(
type: 0,
userIdentifier: "123456"
);
var result = await domain.AddPlatformIdSettingAsync(
);
var item = await result.ModelAsync(); const auto Domain = Gs2->Account->Namespace(
"namespace-0001" // namespaceName
)->Me(
GameSession
)->PlatformId(
0, // type
"123456" // userIdentifier
);
const auto Future = Domain->AddPlatformIdSetting(
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
// obtain changed values / result values
const auto Future2 = Future->GetTask().Result()->Model();
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;
const auto Result = Future2->GetTask().Result();var domain = ez.account.namespace_(
"namespace-0001"
).me(game_session).platform_id(0)
var async_result = await domain.add_platform_id_setting("123456")
if async_result.error != null:
push_error(str(async_result.error))
return
var item = async_result.resultSearching Users by Platform ID
var domain = gs2.Account.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).PlatformId(
type: 0,
userIdentifier: "123456"
);
var result = await domain.FindPlatformUserAsync(
);
var item = await result.ModelAsync(); const auto Domain = Gs2->Account->Namespace(
"namespace-0001" // namespaceName
)->Me(
GameSession
)->PlatformId(
0, // type
"123456" // userIdentifier
);
const auto Future = Domain->FindPlatformUser(
);
Future->StartSynchronousTask();
if (Future->GetTask().IsError()) return false;
// obtain changed values / result values
const auto Future2 = Future->GetTask().Result()->Model();
Future2->StartSynchronousTask();
if (Future2->GetTask().IsError()) return false;
const auto Result = Future2->GetTask().Result();var domain = ez.account.namespace_(
"namespace-0001"
).me(game_session).platform_id(0)
var async_result = await domain.find_platform_user("123456")
if async_result.error != null:
push_error(str(async_result.error))
return
var item = async_result.resultListing Registered Platform IDs
var items = await gs2.Account.Namespace(
namespaceName: "namespace-0001"
).Me(
gameSession: GameSession
).PlatformIdsAsync(
).ToListAsync(); const auto It = Gs2->Account->Namespace(
"namespace-0001" // namespaceName
)->Me(
GameSession
)->PlatformIds();
TArray<Gs2::UE5::Account::Model::FEzPlatformIdPtr> Result;
for (auto Item : *It)
{
if (Item.IsError())
{
return false;
}
Result.Add(Item.Current());
}var iterator = ez.account.namespace_(
"namespace-0001"
).me(
game_session
).platform_ids(
)
var async_result = await iterator.load()
if async_result.error != null:
# Handle the error
push_error(str(async_result.error))
return
var items = async_result.resultCustom script triggers
Event triggers can invoke GS2-Script before and after processing such as account creation, authentication, handovers, and bans. Triggers support synchronous or asynchronous execution; asynchronous processing can integrate with GS2-Script or Amazon EventBridge.
Main event triggers and script setting names are:
createAccountScript(completion notification:createAccountDone): before and after account creationauthenticationScript(completion notification:authenticationDone): before and after logincreateTakeOverScript(completion notification:createTakeOverDone): before and after registering takeover informationdoTakeOverScript(completion notification:doTakeOverDone): before and after executing a takeoverbanScript(completion notification:banDone): before and after applying a banunBanScript(completion notification:unBanDone): before and after lifting a ban
Automatic Password Change
Namespace settings allow for automatically changing the password when performing a takeover. By using this feature, you can prevent logging in from the previous device after a takeover is executed.
However, this feature does not completely prevent simultaneous logins from multiple devices. GS2-Gateway provides functionality to reject simultaneous logins by the same user, which offers more robust protection against concurrent logins.
User Data Anonymization
When differentUserIdForLoginAndDataRetention is enabled in the Namespace settings, separate User IDs for login and Data Owner IDs for data retention are issued. Applications continue to use the User ID for authentication, while server-side user data uses the Data Owner ID, enabling separation between personal information and in-game data. This feature allows data analysis to be performed on anonymized user data, achieving both privacy protection and operational data collection.
Master data management
Registering master data allows you to configure data and behavior that can be used by the microservice.
Available master data types:
TakeOverTypeModel: takeover settings and OpenID Connect information for each slot number. For the settings of codes issued by GS2, see Expiring takeover codes issued by GS2
Below is a JSON example of master data that configures an OpenID Connect integration:
{
"version": "2024-07-30",
"takeOverTypeModels": [
{
"type": 0,
"metadata": "Google",
"openIdConnectSetting": {
"configurationPath": "https://accounts.google.com/.well-known/openid-configuration",
"clientId": "your-client-id",
"clientSecret": "your-client-secret"
}
}
]
}For Sign in with Apple, specify appleTeamId / appleKeyId / applePrivateKeyPem instead of clientSecret. See Registering Authentication Services for details.
Master data can be registered via the management console, imported from GitHub, or registered from CI using GS2-Deploy or various language CDKs.
Setting per-player time offsets
Game Server Services account information can have a time offset. This offset can be set to how many minutes into the future the player will behave as a state.
This feature can be used to let QA staff play the game in a state one hour into the future, even within the production environment. This way, problems such as an event not being opened when it is time to start the event can be quickly noticed.
Account Suspension
It is possible to suspend a player for bad behavior in the game. Ban states are recorded as multiple BanStatus entries containing reasons and planned release times, and the account retains a flag indicating whether it is banned. Event triggers can be configured before and after adding or removing bans to coordinate with external systems.