Supporting External Lobby Launching
Once the application has been registered, the DirectPlay application must be able to recognize whether a lobby launched it or not. If a lobby launched it, it must follow a slightly different code path to set up the network connection. Consult the DUEL (Lobby.c) and DPCHAT (Lobby.cpp) samples in the SDK for the code necessary to support external lobby launching. See Tutorial 1: Connecting by Using the Lobby for a demonstation on how to connect an application by using a DirectPlay lobby.
Here are the basic steps necessary:
1At startup, create an IDirectPlayLobby2 interface using the CoCreateInstance API.
2The application can examine the connection information that was passed in by the lobby and modify some of the connection settings if necessary. The IDirectPlayLobby2::GetConnectionSettings method returns a DPLCONNECTION structure with the connection settings. This method returns DPERR_NOTLOBBIED if a lobby did not launch the application. New settings can be set with IDirectPlayLobby2::SetConnectionSettings.
3IDirectPlayLobby2::Connect creates or joins the specified application session using the specified service provider, and returns an IDirectPlay2 interface. Connect returns an error if the session could not be created/joined, or if a lobby didn't launch the application.
4Use QueryInterface to obtain an IDirectPlay3 interface and then call Release on the IDirectPlay2 interface.
5Create a player using the name information supplied in the DPLCONNECTION structure obtained in step 2.
At this point, the application can continue on the same code path as if the user had manually selected a connection, joined or created a session, and entered the name of the player to create.
The IDirectPlayLobby2 interface can be saved if the game will pass information back to the lobby (see Lobby Messaging), or it can be discarded by using the Release method if no messages will be sent.
Many lobbies will launch the application and then go into a suspend mode waiting for the application to terminate. DirectPlay will notify the lobby when the application that it launched has terminated. For this reason it is very important that the application launched by the lobby not launch another application.