Skip to content

Commit

Permalink
Only wait 5 seconds for PlayerEnterConfigurationEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrygames committed Jul 6, 2024
1 parent cfdbbb0 commit 5b1f5b2
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
/**
* This event is executed when a player is about to enter the configuration state.
* It is <b>not</b> called for the initial configuration of a player after login.
* <p>Velocity will wait for this event before asking the client to enter configuration state.</p>
* <p>Velocity will wait for this event before asking the client to enter configuration state.
* However due to backend server being unable to keep the connection alive during state changes,
* Velocity will only wait for a maximum of 5 seconds.</p>
*
* @param player The player who is about to enter configuration state.
* @param server The server that wants to reconfigure the player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
/**
* This event is executed when a player is about to finish the configuration state.
* <p>Velocity will wait for this event before asking the client to finish the configuration state.
* However due to backend server being unable to keep the connection alive for more than 15 seconds,
* However due to backend server being unable to keep the connection alive during state changes,
* Velocity will only wait for a maximum of 5 seconds. If you need to hold a player in configuration
* state it is recommended to use the {@link PlayerConfigurationEvent}.</p>
* state, use the {@link PlayerConfigurationEvent}.</p>
*
* @param player The player who is about to finish the configuration phase.
* @param server The server that has (re-)configured the player.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,14 @@ public CompletableFuture<Void> handleBackendFinishUpdate(VelocityServerConnectio
smc.write(brandPacket);
}

callConfigurationEvent().thenRun(() -> {
server.getEventManager().fire(new PlayerFinishConfigurationEvent(player, serverConn))
.completeOnTimeout(null, 5, TimeUnit.SECONDS).thenRunAsync(() -> {
player.getConnection().write(FinishedUpdatePacket.INSTANCE);
player.getConnection().getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.PLAY);
server.getEventManager().fireAndForget(new PlayerFinishedConfigurationEvent(player, serverConn));
}, player.getConnection().eventLoop());
}).exceptionally(ex -> {
callConfigurationEvent().thenCompose(v -> {
return server.getEventManager().fire(new PlayerFinishConfigurationEvent(player, serverConn))
.completeOnTimeout(null, 5, TimeUnit.SECONDS);
}).thenRunAsync(() -> {
player.getConnection().write(FinishedUpdatePacket.INSTANCE);
player.getConnection().getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.PLAY);
server.getEventManager().fireAndForget(new PlayerFinishedConfigurationEvent(player, serverConn));
}, player.getConnection().eventLoop()).exceptionally(ex -> {
logger.error("Error finishing configuration state:", ex);
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,15 +1274,16 @@ private boolean sendKeepAliveToBackend(final @Nullable VelocityServerConnection
* Switches the connection to the client into config state.
*/
public void switchToConfigState() {
server.getEventManager().fire(new PlayerEnterConfigurationEvent(this, getConnectionInFlightOrConnectedServer())).thenRunAsync(() -> {
connection.write(StartUpdatePacket.INSTANCE);
connection.getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.CONFIG);
// Make sure we don't send any play packets to the player after update start
connection.addPlayPacketQueueHandler();
}, connection.eventLoop()).exceptionally((ex) -> {
logger.error("Error switching player connection to config state", ex);
return null;
});
server.getEventManager().fire(new PlayerEnterConfigurationEvent(this, getConnectionInFlightOrConnectedServer()))
.completeOnTimeout(null, 5, TimeUnit.SECONDS).thenRunAsync(() -> {
connection.write(StartUpdatePacket.INSTANCE);
connection.getChannel().pipeline().get(MinecraftEncoder.class).setState(StateRegistry.CONFIG);
// Make sure we don't send any play packets to the player after update start
connection.addPlayPacketQueueHandler();
}, connection.eventLoop()).exceptionally((ex) -> {
logger.error("Error switching player connection to config state", ex);
return null;
});
}
/**
Expand Down

0 comments on commit 5b1f5b2

Please sign in to comment.