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

Started by
3 comments, last by wazoo69 19 years, 4 months ago
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.
Advertisement
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.
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?
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.
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..;)

Learn about game programming!Games Programming in C++: Start to Finish

This topic is closed to new replies.

Advertisement