Sign in to a game
How to sign in a player to Vivox services.
Read time 2 minutesLast updated 2 days ago
After you initialize the Vivox SDK, you can sign a user in to the Vivox instance assigned to your game by using an account name that is selected by the game.
- Create a one-to-one mapping between an account name and a player.
- Use the same account name for the same player every time they play the game.
- Player account names must be unique for each play and be anonymous.
If you do not want to use a unique account name per player, or if you do not want to expose the username to the network, then use one of the following options:
- A hash of the unique username
- A universally unique identifier (UUID)
- The total length of the issuer + account name cannot exceed 124 characters.
- Can use only the following characters:
-
Alphanumerics
0-9, A-Z, a-z
0x30-0x39, 0x41-0x5A, 0x61-0x7A
Exclamation mark ' ! ' 0x21 Open parenthesis ' ( ' 0x28 Close parenthesis ' ) ' 0x29 Plus ' + ' 0x2B Minus ' - ' 0x2D Period ' . ' 0x2E Equals ' = ' 0x3D Underscore ' _ ' 0x5F Tilde ' ~ ' 0x7E Percent ' % ' 0x7F
In addition to registering an ILoginSession::FOnBeginLoginCompletedDelegate callback, the game must handle ILoginSession::EventStateChanged events that have the state value set to LoginState::LoggedOut. The Vivox SDK sends this message when whenever a sign out occurs. When a sign out is initiated by a user, LoginState will transition through LoginState::LoggedIn to LoginState::LoggingOut to LoginState::LoggedOut. In the event of a sign out initiated by the server, or due to network loss, the LoggingOut state is skipped and the LoggedIn state changes directly to LoggedOut. The following code displays an example of this message:/* . . . */AccountId Account = AccountId(kDefaultIssuer, "example_user", kDefaultDomain);ILoginSession &MyLoginSession(MyVoiceClient->GetLoginSession(Account));bool IsLoggedIn = false;// Setup the delegate to execute when login completesILoginSession::FOnBeginLoginCompletedDelegate OnBeginLoginCompleted;OnBeginLoginCompleted.BindLambda([this, &IsLoggedIn, &MyLoginSession](VivoxCoreError Error){ if (VxErrorSuccess == Error) { IsLoggedIn = true; // This bool is only illustrative. The user is now logged in. }});// Request the user to login to VivoxMyLoginSession.BeginLogin(kDefaultServer, MyLoginSession.GetLoginToken(kDefaultKey, kDefaultExpiration), OnBeginLoginCompleted);/* . . . */
void UMyGameClass::OnLoginSessionStateChanged(LoginState State){ if (LoginState::LoggedOut == State) { UE_LOG(MyLog, Error, TEXT("LoginSession Logged Out Unexpectedly\n")); // Optionally handle other cases }}