use of org.spongepowered.common.accessor.network.ConnectionAccessor 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;
});
}
use of org.spongepowered.common.accessor.network.ConnectionAccessor in project SpongeCommon by SpongePowered.
the class ServerHandshakePacketListenerImplMixin_IpForward method bungee$patchHandshake.
@Inject(method = "handleIntention", at = @At("HEAD"), cancellable = true)
private void bungee$patchHandshake(final ClientIntentionPacket packet, final CallbackInfo ci) {
if (SpongeConfigs.getCommon().get().ipForwarding.mode == IpForwardingCategory.Mode.LEGACY && packet.getIntention() == ConnectionProtocol.LOGIN) {
final String ip = ((ClientIntentionPacketAccessor) packet).accessor$hostName();
// ignore any extra data
final String[] split = ip.split("\00\\|", 2)[0].split("\00");
if (split.length == 3 || split.length == 4) {
((ClientIntentionPacketAccessor) packet).accessor$hostName(split[0]);
((ConnectionAccessor) this.connection).accessor$address(new InetSocketAddress(split[1], ((InetSocketAddress) this.connection.getRemoteAddress()).getPort()));
((ConnectionBridge_IpForward) this.connection).bungeeBridge$setSpoofedUUID(UUIDTypeAdapter.fromString(split[2]));
if (split.length == 4) {
((ConnectionBridge_IpForward) this.connection).bungeeBridge$setSpoofedProfile(ServerHandshakePacketListenerImplMixin_IpForward.ipForward$GSON.fromJson(split[3], Property[].class));
}
} else {
this.connection.setProtocol(ConnectionProtocol.LOGIN);
final Component error = new TextComponent("If you wish to use IP forwarding, please enable it in your BungeeCord config as well!").withStyle(ChatFormatting.RED);
this.connection.send(new ClientboundLoginDisconnectPacket(error));
this.connection.disconnect(error);
}
}
}
use of org.spongepowered.common.accessor.network.ConnectionAccessor in project SpongeCommon by SpongePowered.
the class ServerPlayerMixin method bridge$setLanguage.
@Override
public void bridge$setLanguage(final Locale language) {
// Update locale on Channel, used for sending localized messages
if (this.connection != null) {
final Channel channel = ((ConnectionAccessor) this.connection.connection).accessor$channel();
channel.attr(SpongeAdventure.CHANNEL_LOCALE).set(language);
SpongeAdventure.forEachBossBar(bar -> {
if (bar.getPlayers().contains(this)) {
this.connection.send(new ClientboundBossEventPacket(ClientboundBossEventPacket.Operation.UPDATE_NAME, bar));
}
});
}
this.impl$language = language;
}
Aggregations