Additional improves to #6150

This commit is contained in:
Oleg Agafonov 2020-01-07 12:01:34 +04:00
parent 339c419d4b
commit 6ce1e973f3

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 = 5; // checks and inform players about joining status private static final int GAME_TIMEOUTS_CHECK_JOINING_STATUS_EVERY_SECS = 10; // 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();
@ -330,18 +330,20 @@ public class GameController implements GameCallback {
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();
// TODO: workaround to fix not started games in tourneys, need to find out real reason
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.warn("Forced join of player " + player.getName() + " (" + user.getUserState() + ") to 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 only for " + " is forced to join the game (waiting ends after "
+ 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.isConnected() && 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) {
// Cancel player join possibility lately after 4 minutes // Cancel player join possibility lately
logger.debug("Player " + player.getName() + " - canceled game (after 240 seconds) gameId: " + game.getId()); logger.debug("Player " + player.getName() + " - canceled joining game (after "
+ user.getSecondsDisconnected() + " secs of inactivity) gameId: " + game.getId());
player.leave(); player.leave();
} }
} }