DirectX:DirectPlay:Tutorials:VB:DX7:Commencing Gameplay
When a session has been started, we need to be able to monitor how many people have joined that session. In other words, we need to enumerate the players.
Dim i As Integer
Dim intPlayersWaiting As Integer
Dim objEnumPlayers As DirectPlayEnumPlayers
Set objEnumPlayers = dp.GetDPEnumPlayers("", 0)
intPlayersWaiting = objEnumPlayers.GetCount
For i = 1 To intPlayersWaiting
LstBox.AddItem objEnumPlayers.GetShortName(i)
Next
This code will list the short names of every player connected to the current session (again, LstBox refers to a valid listbox object). The user (usually the host) can use this information to decide when to commence the game. For example, a game may allow 4 players to join, but the host could start the game when there were only two or three if desired. Once the game starts, the host should disable the "join" ability to keep new players from joining the session late.
Dim objSessionData As DirectPlaySessionData
Set objSessionData = dp.CreateSessionData dp.GetSessionDesc objSessionData objSessionData.SetFlags objSessionData.GetFlags Or DPSESSION_JOINDISABLED dp.SetSessionDesc objSessionData
Fill a DirectPlaySessionData object with session data. Use the current flags in conjunction with the DPSESSION_JOINDISABLED flag to disable joining. Once the flags are defined, set the session data using the same object and the DirectPlay4.SetSessionDesc method.
Continue with the In-Game Messaging tutorial; we're almost there! (Click here to download this tutorial's source code.)