execute SQL query before a user aborts matchmaking

93 Views Asked by At

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.
1

There are 1 best solutions below

1
shelly On
  1. If you have a button/link to quit the quque you could remove the user from that match, if he clicks it.

or

  1. Before you really start the match you could create a dialog to confirm that the user is still there. If the user doesnt confirms after time x you cancel that match. You could use some ajax code for that.