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?
That's what I wrote. Note that the 'host' has 5 F's and 3 0's in my example.
In the example I cited above, for a 4 player game (one host, 3 players), you don't get to the 4 player minimum without also getting an FFFFFFFF:
host - FFFFF000
player1 0000000F
player 2 000000F0
player 3 00000F00
> I believe as long as the number of players is satisified and the attributes do not overlap then the match will start.
I do not know if this is correct or not. If it is, you would need different masks based on the number of players you accept as a minimum. In my example, for a three player game (host and 2 others) you would add one more F to the Host and the system would reject a 'player3' in such an invite.