I am using PHP + JS to create a game. Every game is person vs person, so only 2 users. It works, but I have trouble with "double bookings". Like this:
- User1 creates Game #10 (PHP)
- Game shows up in the lobby (JS)
- User2 joins Game #10 (PHP)
- User3 joins Game #10 (PHP)
- Game disappears from lobby (JS)
The steps 3 and 4 happen with only milliseconds between. When a user joins a game, I first check if the "seat" is taken. If not - i parse all essential data, etc, and then i set the seat as taken. During the parsing, it seems as users can join the same game. This is a matter of milliseconds, as I stated earlier. But how do i prevent this?