Archived

This topic is now archived and is closed to further replies.

sunbeam60

GetClientInfo() fails on host player?

Recommended Posts

sunbeam60    114
Hi, For some reason DirectPlay chooses to create a player for the server itself. I wish to catch the host player and prevent it from being created as a player in my system. From my own code, it seems GetClientInfo() always fails when trying to call it on the DPNID representing the host player. Also, as seen from the DirectPlay sample code (simpleserver.cpp)
            // Determine the required size of the buffer

            DWORD dwSize = 0;
            DPN_PLAYER_INFO* pdpPlayerInfo = NULL;
            hr = g_pDPServer->GetClientInfo( pCreatePlayerMsg->dpnidPlayer, 
                                             pdpPlayerInfo, &dwSize, 0 );
            if( FAILED(hr) && hr != DPNERR_BUFFERTOOSMALL )
            {
                // Ignore this message if this is for the host

                if( hr != DPNERR_INVALIDPLAYER )
                    DXTRACE_ERR_MSGBOX( TEXT("GetClientInfo"), hr );

                break;
            } 
It seems like the host player is expected to fail when trying to determine if a DPNID represents the host itself. But in that case, why is the DPNPLAYER_HOST flag specified as being possible in the DPN_PLAYER_INFO::dwPlayerFlags member? If the host always fails, how can that flag ever be of use? Is there a reliable (i.e. one that does not rely on catching a specific succession of errors and interpreting it as indicative of the host) way to determine if the DPNID being examined represents the host player? TIA Bjorn

Share this post


Link to post
Share on other sites
AI_the_rapman    122
My way of doing that:

...
pDirectPlayer8Server->Host(..., 0, ...); // preset the host player context to be 0
...

switch (dwMessage) {
case DPN_MSGID_INDICATE_CONNECT:
// create your game player object here, and
// preset the player context value to the pointer
// to the object;
break;

case DPN_MSGID_INDICATED_CONNECT_ABORTED:
// the connection has been aborted before it
// is accepted, so cleanup the previously created
// player object by the preset player context value
break;

case DPN_MSGID_ACCEPT_PLAYER:
// for the host player, the player context value
// has been preset to zero via Host() method; for
// real connection clients, the player context
// values are pointers to the corresponding player
// object (non zero); so if player context is zero
// at this stage, then it must be host player, you
// can safely ignore it; and if player context is
// nonzero, it must be one of the previous real client
// inside DPN_MSGID_INDICATE_CONNECT, so now you can
// do further work on the player object, etc.
break;

case ...:
break;
}

hope it helps

cheers

Share this post


Link to post
Share on other sites