-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make reconnects possible #113
Open
1-alex98
wants to merge
2
commits into
develop
Choose a base branch
from
bugfix/#112-dont-close-peers-on-no-con
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,7 +238,7 @@ public CompletableFuture<Game> createGame(String title, String featuredModName, | |
is to let the game time out, but as usual, that's not a good solution since no matter what timeout one chooses, | ||
there is always some drawback. Therefore, we don't timeout games but reset a player's game state when he tries | ||
to create a new game. Or when he logs out. */ | ||
removePlayer(currentGame, player); | ||
removePlayer(currentGame, player, false); | ||
} | ||
|
||
Requests.verify(currentGame == null, ErrorCode.ALREADY_IN_GAME); | ||
|
@@ -581,8 +581,14 @@ public void onPlayerOfflineEvent(PlayerOfflineEvent event) { | |
playerGameStateCounters.get(event.getPlayer().getGameState()).decrementAndGet(); | ||
} | ||
|
||
/** | ||
* Removes player from his current game. It removes player completely by default, if running it does leave the | ||
* possibility to reconnect. | ||
* | ||
* @param player the player to remove from his game | ||
*/ | ||
public void removePlayer(Player player) { | ||
Optional.ofNullable(player.getCurrentGame()).ifPresent(game -> removePlayer(game, player)); | ||
Optional.ofNullable(player.getCurrentGame()).ifPresent(game -> removePlayer(game, player, game.getState() == GameState.PLAYING)); | ||
} | ||
|
||
/** | ||
|
@@ -710,7 +716,7 @@ private void addPlayer(Game game, Player player) { | |
markDirty(game, DEFAULT_MIN_DELAY, DEFAULT_MAX_DELAY); | ||
} | ||
|
||
private void removePlayer(Game game, Player player) { | ||
private void removePlayer(Game game, Player player, boolean reconnectPossible) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. allowReconnect? |
||
log.debug("Removing player '{}' from game '{}'", player, game); | ||
|
||
int playerId = player.getId(); | ||
|
@@ -721,12 +727,15 @@ private void removePlayer(Game game, Player player) { | |
Map<Integer, Player> connectedPlayers = game.getConnectedPlayers(); | ||
connectedPlayers.remove(playerId); | ||
|
||
clientService.disconnectPlayerFromGame(player.getId(), connectedPlayers.values()); | ||
if (!reconnectPossible) { | ||
//Doing this makes all players drop the connection to the player which makes reconnects impossible | ||
clientService.disconnectPlayerFromGame(player.getId(), connectedPlayers.values()); | ||
} | ||
|
||
// Checking for GameState.INITIALIZING isn't necessary since in this case, connectedPlayers will already be empty | ||
if (game.getState() == GameState.OPEN && game.getHost().equals(player)) { | ||
// A copy of the connected players is required as otherwise we run into a ConcurrentModificationException | ||
new ArrayList<>(connectedPlayers.values()).forEach(connectedPlayer -> removePlayer(game, connectedPlayer)); | ||
new ArrayList<>(connectedPlayers.values()).forEach(connectedPlayer -> removePlayer(game, connectedPlayer, false)); | ||
} | ||
|
||
if (connectedPlayers.isEmpty()) { | ||
|
@@ -757,7 +766,7 @@ private void onPlayerGameEnded(Player player, Game game) { | |
|
||
private void onPlayerGameClosed(Player player, Game game) { | ||
log.debug("Player '{}' closed game: {}", player, game); | ||
removePlayer(game, player); | ||
removePlayer(game, player, false); | ||
} | ||
|
||
private void onGameCancelled(Game game) { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removes player from their current game ;)