Force-join players to a game if they haven't joined after 5 seconds.

This check has always occurred for disconnected players; expand it to all players.
This commit is contained in:
Patrick Hulin 2020-01-06 17:39:34 -05:00
parent 7f0d793544
commit dda8c904b6

View file

@ -50,7 +50,7 @@ import java.util.zip.GZIPOutputStream;
*/ */
public class GameController implements GameCallback { public class GameController implements GameCallback {
private static final int GAME_TIMEOUTS_CHECK_JOINING_STATUS_EVERY_SECS = 15; // checks and inform players about joining status private static final int GAME_TIMEOUTS_CHECK_JOINING_STATUS_EVERY_SECS = 5; // checks and inform players about joining status
private static final int GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS = 2 * 60; // leave player from game if it don't join and inactive on server private static final int GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS = 2 * 60; // leave player from game if it don't join and inactive on server
private static final ExecutorService gameExecutor = ThreadExecutor.instance.getGameExecutor(); private static final ExecutorService gameExecutor = ThreadExecutor.instance.getGameExecutor();
@ -324,25 +324,22 @@ public class GameController implements GameCallback {
} }
private void sendInfoAboutPlayersNotJoinedYet() { private void sendInfoAboutPlayersNotJoinedYet() {
// runs every 15 secs untill all players join // runs every 5 secs untill all players join
for (Player player : game.getPlayers().values()) { for (Player player : game.getPlayers().values()) {
if (!player.hasLeft() && player.isHuman()) { if (!player.hasLeft() && player.isHuman()) {
Optional<User> requestedUser = getUserByPlayerId(player.getId()); Optional<User> requestedUser = getUserByPlayerId(player.getId());
if (requestedUser.isPresent()) { if (requestedUser.isPresent()) {
User user = requestedUser.get(); User user = requestedUser.get();
if (!user.isConnected()) {
if (gameSessions.get(player.getId()) == null) { if (gameSessions.get(player.getId()) == null) {
// join the game because player has not joined are was removed because of disconnect // join the game because player has not joined are was removed because of disconnect
user.removeConstructing(player.getId()); user.removeConstructing(player.getId());
GameManager.instance.joinGame(game.getId(), user.getId()); GameManager.instance.joinGame(game.getId(), user.getId());
logger.debug("Player " + player.getName() + " (disconnected) has joined gameId: " + game.getId()); logger.debug("Player " + player.getName() + " (disconnected) has joined gameId: " + game.getId());
}
ChatManager.instance.broadcast(chatId, player.getName(), user.getPingInfo() ChatManager.instance.broadcast(chatId, player.getName(), user.getPingInfo()
+ " is pending to join the game (waiting " + user.getSecondsDisconnected() + " of " + " is pending to join the game (waiting only for "
+ GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS + " secs)", + GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS + " secs)",
MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null); MessageColor.BLUE, true, ChatMessage.MessageType.STATUS, null);
if (user.getSecondsDisconnected() > GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS) { if (!user.isConnected() && user.getSecondsDisconnected() > GAME_TIMEOUTS_CANCEL_PLAYER_GAME_JOINING_AFTER_INACTIVE_SECS) {
// TODO: 2019.04.22 - if user playing another game on server but not joining (that's the reason?), then that's check will never trigger
// Cancel player join possibility lately after 4 minutes // Cancel player join possibility lately after 4 minutes
logger.debug("Player " + player.getName() + " - canceled game (after 240 seconds) gameId: " + game.getId()); logger.debug("Player " + player.getName() + " - canceled game (after 240 seconds) gameId: " + game.getId());
player.leave(); player.leave();