I have created a website with a 1v1 matchmaking system.
Here's how it works:
If I click find an opponent it changes matchmaking=1 in a database.
But there is a problem, if a user clicks the find an opponent button and then quits before the site actually found the opponent matchmaking doesn't reset to 0. So if another user then comes he might be paired with an inactive user.
So I think (but im not sure) I need a system that detects when a user clicks the go back button. The goal is to get a fail-proof system that pairs two and two users without flaw. Any help is appreciated.
index.html
<div class="menuItem" onclick="location.href='matchmaker.php';">find an opponent</div>
matchmaker.php (in a nutshell)
connect_to_server();
set_matchmaking_to_one();
$opponent = NULL;
while ($opponent == NULL) {
$player = look_for_player_with_matchmaking_on();
$opponent = mysqli_fetch_array($player)[0]; //this gets the id if exists
}
echo "your opponent: " . $opponent;
// after while loop an opponent should be found.
or