PLEASE HELP. I found a big problem :>(
I just discovered a real big problem with my game logic involving how players are joined together into a match and I am hoping someone can help me resolve it
Requirements for my application
A player can either HOST a match or FIND a match to join.
(Note: The HOST player sets all of the game options such as number of players, number of rounds, number of cards, etc..)
- Every match created must have only "one" HOST player only
- All players who request to FIND a match (ie: non-host players) must ONLY join a match which is being hosted and not have a match created between themselves, which does not include a host.
Example:
Player1 is hosting a 2-player match and is actively searching for one more player to join the match. At this time, two separate players (non-host players) each make separate requests to FIND a random match to join. Sometimes, I see a match is created between the two non-host players, while the HOST player keeps spinning looking for a player to join.
Question:
How can I ensure all non-host players only join a match which is being hosted, instead of creating a match between themselves?
My existing application match logic:
1) When a player requests to HOST a match (eg: 2-player match) then the following match request is made, which will result in the GKMatchmakerViewController window being displayed so players can be located to fill the match slots:
let request = GKMatchRequest.init( )
request.minPlayers = 2
request.maxPlayers = 2
request.playerAttributes = 0xFFFF0000 <-- represents HOST player (see note below)
let mmvc = GKMatchmakerViewController.init(matchRequest: request)
Note: The 0xFFFF0000 playerAttribute value ensures multiple HOST players, who are actively searching for players for their match, are not joined together into the same match. Basically, if the match already has a player with attribute 0xFFFF0000, then another player with attirbute 0xFFFF0000 cannot also join the same match.
2) When a player requests to FIND a match (eg: 2-player match) to join then following the match request is made to programmatically find a match:
let matchRequest = GKMatchRequest.init( )
matchRequest.minPlayers = 2
matchRequest.maxPlayers = 2
matchRequest.playerAttributes = 0 <---indicates player is NOT A HOST and can join any match available
GKMatchmaker.shared().findMatch(for: matchRequest, withCompletionHandler: ...)
In my 2-player non-host "Problem" described above, I understand why the two non-host players create a match between themselves. They are both requesting to find a 2-player match while both have player attributes set to "0". Is there a way to make non-host players only join a game with a HOST player?