waitFor

abstract void waitFor(Future<? extends Object> future)

Allows blocking client log-in until the {@code future} is done.

Since packet reception happens on netty's event loops, this allows handlers toperform logic on the Server Thread, etc. For instance, a handler can prepare anupcoming query request or check necessary login data on the server thread.

Here is an example where the player log-in is blocked so that a credential check andbuilding of a followup query request can be performed properly on the logical serverthread before the player successfully logs in:

{@code * ServerLoginNetworking.registerGlobalReceiver(CHECK_CHANNEL, (server, handler, understood, buf, synchronizer, responseSender) -> { * if (!understood) { * handler.disconnect(new LiteralText("Only accept clients that can check!")); * return; * } * * String checkMessage = buf.readString(32767); * * // Just send the CompletableFuture returned by the server's submit method * synchronizer.waitFor(server.submit(() -> { * LoginInfoChecker checker = LoginInfoChecker.get(server); * * if (!checker.check(handler.getConnectionInfo(), checkMessage)) { * handler.disconnect(new LiteralText("Invalid credentials!")); * return; * } * * responseSender.send(UPCOMING_CHECK, checker.buildSecondQueryPacket(handler, checkMessage)); * })); * }); * }
Usually it is enough to pass the return value for submit for {@code future}.

Parameters

future

the future that must be done before the player can log in

Sources

jvm source
Link copied to clipboard