DirectX SDK

Supporting Dynamic Lobby Connection

One drawback of external lobby launching is that the lobby server always tells the lobby client to launch a new instance of the application, even if one is already running. You can avoid a redundant launch by supporting dynamic lobby connection.

The instructions in this section assume the application is already running and has a connection to a lobby server that will return connection settings.

[C++]
  1. At startup, create an IDirectPlayLobby3 interface by using the CoCreateInstance function.
  2. Allow the user to select "Wait for lobby connection", or words to that effect, rather than making a manual connection. Take the following steps only if that selection has been made. (See the Duel sample for one implementation.)
  3. Call IDirectPlayLobby3::WaitForConnectionSettings to put your application in wait mode. This does not block execution, it simply tells DirectPlay that the application is active and waiting for a connection, so that the lobby client's call to DirectPlayLobby3::RunApplication will not launch another instance.
  4. Wait for a lobby message to come in by using IDirectPlayLobby3::ReceiveLobbyMessage. The message type to expect is the DPLSYS_NEWCONNECTIONSETTINGS system message. Note that you can call WaitForConnectionSettings again to cancel wait mode in response to a user cancel.
  5. After you receive the system message, examine the connection information that was passed in by the lobby and modify settings as necessary. The IDirectPlayLobby3::GetConnectionSettings method returns a DPLCONNECTION structure with the connection settings. New settings can be set by using IDirectPlayLobby3::SetConnectionSettings.
  6. Call IDirectPlayLobby3::ConnectEx to create or join the application session. (The application knows whether it is to create or join a session by examining DPLCONNECTION.dwFlags.)
  7. Create a player using the name information supplied in the DPLCONNECTION structure obtained in step 5.
[Visual Basic]
  1. At startup, create an DirectPlayLobby3 object by using the DirectX7.DirectPlayLobbyCreate method.
  2. Allow the user to select "Wait for lobby connection", or words to that effect, rather than making a manual connection. Take the following steps only if that selection has been made.
  3. Call DirectPlayLobby3.WaitForConnectionSettings to put your application in wait mode. This does not block execution, it simply tells DirectPlay that the application is active and waiting for a connection, so that the lobby client's call to DirectPlayLobby3.RunApplication will not launch another instance.
  4. Wait for a lobby message to come in by using DirectPlayLobby3.ReceiveLobbyMessage. The message type to expect is the DPLSYS_NEWCONNECTIONSETTINGS system message. Note that you can call WaitForConnectionSettings again to cancel wait mode in response to a user cancel.
  5. After you receive the system message, examine the connection information that was passed in by the lobby and modify settings as necessary. The DirectPlayLobby3.GetConnectionSettings method returns a DirectPlayLobbyConnection object containing the connection settings. New settings can be set by using DirectPlayLobby3.SetConnectionSettings.
  6. Call DirectPlayLobby3.Connect to create or join the application session. (The application knows whether it is to create or join a session by examining the value returned by DirectPlayLobbyConnection.GetFlags.)
  7. Create a player using the name information supplied in the DirectPlayLobbyConnection object obtained in step 5.