use of org.spongepowered.common.accessor.server.network.ServerLoginPacketListenerImplAccessor in project SpongeCommon by SpongePowered.
the class VelocityForwardingInfo method sendQuery.
public static void sendQuery(final ServerLoginPacketListenerImpl mcConn) {
final EngineConnection conn = (EngineConnection) mcConn;
VelocityChannel.CHANNEL.sendTo(conn, cbuf -> {
}).whenComplete((response, error) -> {
if (error != null) {
if (error instanceof NoResponseException) {
conn.close(Component.text("This server requires you to connect with Velocity."));
}
return;
}
if (!VelocityForwardingInfo.checkIntegrity(response)) {
conn.close(Component.text("Unable to verify player details. Is your forwarding secret correct?"));
return;
}
final ConnectionAccessor connectionAccessor = (ConnectionAccessor) mcConn.getConnection();
connectionAccessor.accessor$address(new InetSocketAddress(VelocityForwardingInfo.readAddress(response), ((InetSocketAddress) mcConn.getConnection().getRemoteAddress()).getPort()));
((ServerLoginPacketListenerImplAccessor) mcConn).accessor$gameProfile(VelocityForwardingInfo.createProfile(response));
}).exceptionally(err -> {
if (!(err instanceof NoResponseException)) {
// Handled above
VelocityForwardingInfo.LOGGER.error("Failed to process velocity forwarding info", err);
conn.close(Component.text("Invalid forwarding information received!"));
}
return null;
});
}
Aggregations