我已经创建了一个带有1v1相亲系统的网站。
下面是它的工作原理:
如果我单击查找对手,它会更改数据库中的matchmaking=1。
但是有一个问题,如果用户点击了查找对手按钮,然后在站点实际找到对手之前退出,那么对手匹配不会重置为0。因此,如果另一个用户随后到来,他可能会与非活动用户配对。
因此,我认为(但我不确定)我需要一个系统来检测用户何时单击返回按钮。我们的目标是获得一个防故障的系统,使两个和两个用户配对,没有缺陷。任何帮助都是非常感谢的。
index.html
<div class="menuItem" onclick="location.href='matchmaker.php';">find an opponent</div>
matchmaker.php (简而言之)
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.
发布于 2020-03-15 07:08:20
或
https://stackoverflow.com/questions/60687805
复制相似问题