Authentication
Updating Player Account
The Noctua SDK provides a simple way to update player accounts, ensuring that your game and our services always have the most up-to-date information.
Player Account Structure
The player account data is structured as follows:
{
"ingame_username": "string", // In-game username
"ingame_server_id": "string", // Identifier for the in-game server
"ingame_role_id": "string", // In-game account id
"extra": { // Flexible object for additional account details
"field1": "value1",
"field2": "value2"
// Additional fields as needed
}
}
Note
The extra field allows you to include additional game-specific information that might be relevant for your player accounts.
When to Update
To ensure data consistency, update player account data at these key integration points:
- Onboarding / Start Play: You need to make sure these two parts are done before calling
Noctua.Auth.UpdatePlayerAccountAsync
:Noctua.Auth.AuthenticateAsync()
- The in-game UID (RoleID) is generated/available
- Login and Logout: Whenever a player logs in or logs out their account.
- Server Changes: When a player switches between in-game servers.
- Profile Updates: Any time a player updates their in-game nickname.
- Before In-App Purchases: Update account data before initiating an in-app purchase to ensure accurate item delivery.
Warning
Don't use this function to maintain your in-game states, this function is only for updating the player account data that will be used for identifying the player in our system.
How to Update
Use the Noctua.Auth.UpdatePlayerAccountAsync
function provided by the Noctua SDK to update player data:
Noctua.Auth.UpdatePlayerAccountAsync(data)
Here's an example of how to use this function in your game:
private async UniTask UpdatePlayerAccountAsync()
{
var playerData = new PlayerAccountData
{
IngameUsername = "CoolGamer123",
IngameServerId = "Server001",
IngameRoleId = "Role789",
Extra = new Dictionary<string, string>
{
{ "level", "42" },
{ "xp", "9876" }
}
};
try
{
await Noctua.Auth.UpdatePlayerAccountAsync(playerData);
Debug.Log($"Player account updated successfully");
}
catch (Exception e)
{
if (e is NoctuaException noctuaEx)
{
Debug.Log("NoctuaException: " + noctuaEx.ErrorCode + " : " + noctuaEx.Message);
}
else
{
Debug.Log("Exception: " + e);
}
}
}
Tip
Always handle potential errors when updating data to ensure your game remains responsive even if the update fails.
Best Practices
- Regular Updates: Implement updates at all key points mentioned above to maintain data consistency.
- Error Handling: Always include proper error handling to manage cases where updates might fail.
- Minimal Data: Only include necessary data in the extra field to optimize performance.