With NEX, the process of connecting to a game server is split into the following three phases.
When first connecting to the friend server, it issues a principal ID to the CTR console. This principal ID is saved as a backup on the CTR console to which it was issued.
Use the NgsFacade::Login
function to log in to a game server. This function takes a pointer to a ProtocolCallContext
object, the game server ID, and the access key as arguments. There are also options that can specify the principal ID (default value, INVALID_PRINCIPALID
), and timeout period (in milliseconds) for asynchronous processing. This function cannot specify a timeout for the ProtocolCallContext
object. If the principal ID is something other than INVALID_PRINCIPALID
, it is compared with the principal ID saved on the console. When it does not match, QERROR(Fpd, InvalidPrincipalId)
is returned.
If the asynchronous processing result is a login failure, get the network error code with the NgsFacade::GetLastLoginErrorCode
function.
Starting with NEX 2.5, specifications were changed so that the server version is checked when logging in. It is not possible to log in to the game server if the version is earlier than the version requested by the library. Send a request to update the game server through OMAS.
The library checks the server version when a user logs in, and if the server version is earlier than the one required by the library, it is not possible to log in to the game server. Send a request to update the game server through OMAS.
Code 3.1 Connecting to the Game Server
static const qUnsignedInt32 GAME_SERVER_ID = 0xXXXXXXXX;
static const qChar16 ACCESS_KEY[] = "xxxxxxxx";
void LoginGameServer(NgsFacade* pNgsFacade)
{
ProtocolCallContext oContext;
qResult result = pNgsFacade->Login(&oContext, GAME_SERVER_ID, ACCESS_KEY);
if(!result)
{
return;
}
// Wait for the asynchronous processing result.
oContext.Wait();
if (!oContext.GetOutcome())
{
NN_LOG("Network Error Code \u\n", pNgsFacade->GetLastLoginNetworkErrorCode());
return;
}
}
Note
A development server is automatically used for development hardware and a production server for production hardware, so users of the library do not need to be aware of which server they are connecting to.
Use the NgsFacade::Logout
function to disconnect from a game server. This function takes a pointer to a ProtocolCallContext
class object as an argument. If a client logs out while it is still in a matchmaking session, the game server automatically removes that user from the matchmaking session.
If you do not need to be logged in to the friend server after you have logged out from the game server, log out from the friend server and disconnect from the access point at the same time.
In the absence of explicit requests from clients, the NEX library sends a keep-alive to the game server once every five seconds while it is logged in. If communication with the game server is not possible for 30 seconds or longer, because the connection with the access point was lost, the system was turned off, or for another reason, the game server concludes that the client has logged out and automatically changes the user's status to offline.
Note
When attempting to destroy an NgsFacade
class object when the status is logging in, logged in, or logging out, NgsFacade::Terminate
is called by the NgsFacade
destructor and blocks until the status transitions to offline. We recommend calling the NgsFacade::Terminate
function before destroying the NgsFacade
class object.
CONFIDENTIAL