Sign in to follow this  

DirectPlay peer to peer: how to detect if player is host?

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When connecting to a DirectPlay peer-to-peer session, I get a DPN_MSGID_CREATE_PLAYER message for each machine in the session, including my own machine, the hosting machine, and any other machines connected. I need to know which of these is the host. What's the best way to determine this? Do I need to have the host explicitly send a special "I am host" message to each peer after it connects? I would prefer not to have to do this, since I'd like to determine which player is the host before my messaging flow starts.

Share this post


Link to post
Share on other sites
When you recieve any message from a host computer when using DirectPlay it will have attached to the packet the senderID -- this should be the ID of the host computer (in a peer-peer session you will run into situations where you send data DIRECTLY between two players without going through the host, however). This is useful for identification purposes, but if you need to know the specific address of the host then you'll have to record that in a variable when you find or join the host -- problem with this second method is that if you are using Host Migration then the IP won't be automatically switched if the host is changed. Using the SenderID should be more effective.

Share this post


Link to post
Share on other sites
Yes, it's the ID of the host I'm interested in, not the address. And I understand that each message I receive comes with the ID of the sender. But how do I know which of these ID's belongs to the host?

For example, let's say my machine and your machine both connect to a session on a host machine. Now there's a total of three machines in the session, so I will receive three DPN_MSGID_CREATE_PLAYER messages: one for my machine, one for yours, and one for the host. Each of these DPN_MSGID_CREATE_PLAYER messages contains the unique ID of the player being created. And all messages I receive in the future will come with the sender's ID, which will be one of these three unique ID's. But how can I determine which of these three ID's represents the host?

Share this post


Link to post
Share on other sites
Okay, after more extensive trawling through the docs, I found what I'm looking for. IDirectPlay8Peer::GetPeerInfo() fills a DPN_PLAYER_INFO struct with a dwPlayerFlags member that has the DPNPLAYER_HOST flag set if that player is the host. Problem solved.

Share this post


Link to post
Share on other sites
Silly me for bringing it up Martoon, but don't forget to check the samples of DPlay (you'll need them from the original DX9 SDK as they've removed them from the Dec.2004 version)..

I believe it covers how to do the "small-but-important" crap like this..;)

Share this post


Link to post
Share on other sites

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this