Sign in to a game
How to sign in a player to Vivox services.
阅读时间2 分钟最后更新于 12 天前
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. For the account name:
- 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.
The following criteria applies to account names:
- Maximum of 127 bytes
- Must start and end with a period (.)
- No adjacent spaces
- 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
The game uses the
vx_req_account_anonymous_loginvx_resp_account_anonymous_login
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)
vx_evt_buddy_presencevx_evt_participant_added- The display name is only valid for the current session and does not persist in the Vivox network.
- The maximum display name length is 127 bytes, plus a null terminator.
- The display name is set in the field of the
displaynamerequest.vx_req_account_anonymous_login
The following code is an example of how to initiate the sign in process:
The following code is an example of how to handle the sign in response:. . .vx_req_account_anonymous_login_t *req;vx_req_account_anonymous_login_create(&req);req->connector_handle = vx_strdup("c1");req->acct_name = vx_strdup(".issuer-w-dev.mytestaccountname.");req->displayname = vx_strdup("John Doe");req->account_handle = vx_strdup(req->acct_name);req->access_token = vx_strdup(_the_access_token_generated_by_the_game_server);vx_issue_request3(&req->base, &request_count);. . .
In addition to handling thevoid HandleLoginResponse(vx_resp_account_anonymous_login *resp){ if (resp->base.return_code == 1) { printf(U, resp->base.status_code, vx_get_error_string(resp->base.status_code)); return; } vx_req_account_anonymous_login *req = reinterpret_cast<vx_req_account_anonymous_login *>(req->base.request); printf("login succeeded for account %s\n", req->acct_name);}
vx_resp_account_anonymous_loginvx_evt_account_login_state_changelogin_state_logged_outAfter the game receives thevoid HandleLoginStateChange(vx_evt_account_login_state_change *evt){ if (evt->state == login_state_logged_in) { printf("%s is logged in\n", evt->account_handle); } else if (evt->state == login_state_logged_out) { if (evt->status_code !=0) { printf("%s logged out with status %d:%s\n", evt->status_code, vx_get_error_string(evt->status_code)); } else { printf("%s is logged out\n", evt->acct_name); } }}
vx_resp_connector_create