Search in sources :

Example 1 with SpongeChannelManager

use of org.spongepowered.common.network.channel.SpongeChannelManager in project SpongeCommon by SpongePowered.

the class SpongeCommonModule method configure.

@Override
protected void configure() {
    this.bind(Game.class).to(SpongeGame.class);
    this.bind(MinecraftVersion.class).toInstance(SpongeCommon.minecraftVersion());
    this.bind(ChannelManager.class).toInstance(new SpongeChannelManager(ChannelBufferAllocator.POOLED));
    this.bind(PluginManager.class).toInstance(Launch.instance().pluginManager());
    this.bind(DataManager.class).to(SpongeDataManager.class);
    this.bind(ConfigManager.class).to(PluginConfigManager.class);
    this.bind(MetricsConfigManager.class).to(SpongeMetricsConfigManager.class);
    this.bind(SqlManager.class).to(SpongeSqlManager.class);
    this.bind(ServiceProvider.GameScoped.class).to(SpongeGameScopedServiceProvider.class);
    this.bind(FactoryProvider.class).to(SpongeFactoryProvider.class);
    this.bind(BuilderProvider.class).to(SpongeBuilderProvider.class);
    this.requestStaticInjection(SpongeCommon.class);
    this.requestStaticInjection(Sponge.class);
}
Also used : PluginManager(org.spongepowered.api.plugin.PluginManager) MetricsConfigManager(org.spongepowered.api.util.metric.MetricsConfigManager) SpongeMetricsConfigManager(org.spongepowered.common.util.metric.SpongeMetricsConfigManager) Game(org.spongepowered.api.Game) SpongeGame(org.spongepowered.common.SpongeGame) ChannelManager(org.spongepowered.api.network.channel.ChannelManager) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) SpongeBuilderProvider(org.spongepowered.common.registry.SpongeBuilderProvider) BuilderProvider(org.spongepowered.api.registry.BuilderProvider) DataManager(org.spongepowered.api.data.DataManager) SpongeDataManager(org.spongepowered.common.data.SpongeDataManager) SpongeSqlManager(org.spongepowered.common.sql.SpongeSqlManager) SqlManager(org.spongepowered.api.sql.SqlManager) SpongeFactoryProvider(org.spongepowered.common.registry.SpongeFactoryProvider) FactoryProvider(org.spongepowered.api.registry.FactoryProvider) MinecraftVersion(org.spongepowered.api.MinecraftVersion) MetricsConfigManager(org.spongepowered.api.util.metric.MetricsConfigManager) ConfigManager(org.spongepowered.api.config.ConfigManager) PluginConfigManager(org.spongepowered.common.config.PluginConfigManager) SpongeMetricsConfigManager(org.spongepowered.common.util.metric.SpongeMetricsConfigManager)

Example 2 with SpongeChannelManager

use of org.spongepowered.common.network.channel.SpongeChannelManager in project SpongeCommon by SpongePowered.

the class ClientHandshakePacketListenerImplMixin_Vanilla method vanilla$handleRequestPayload.

// @formatter:on
@Inject(method = "handleCustomQuery", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;send(Lnet/minecraft/network/protocol/Packet;)V"), cancellable = true)
private void vanilla$handleRequestPayload(final ClientboundCustomQueryPacket packet, final CallbackInfo ci) {
    ci.cancel();
    final SpongeChannelManager channelRegistry = (SpongeChannelManager) Sponge.channelManager();
    this.minecraft.execute(() -> {
        final EngineConnection connection = (EngineConnection) this;
        if (!channelRegistry.handleLoginRequestPayload(connection, packet)) {
            PacketSender.sendTo(connection, PacketUtil.createLoginPayloadResponse(null, packet.getTransactionId()));
        }
    });
}
Also used : SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) EngineConnection(org.spongepowered.api.network.EngineConnection) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with SpongeChannelManager

use of org.spongepowered.common.network.channel.SpongeChannelManager in project SpongeCommon by SpongePowered.

the class ServerLoginPacketListenerImplMixin method handleAcceptedLogin.

/**
 * @author morph - April 27th, 2021
 * @author dualspiral - July 17th, 2021
 *
 * @reason support async ban/whitelist service and user->player syncing.
 */
@Overwrite
public void handleAcceptedLogin() {
    if (!this.gameProfile.isComplete()) {
        this.gameProfile = this.shadow$createFakeProfile(this.gameProfile);
    }
    // Sponge start - avoid #tick calling handleAcceptedLogin more than once.
    if (this.impl$accepted) {
        return;
    }
    this.impl$accepted = true;
    final PlayerList playerList = this.server.getPlayerList();
    // Sponge end
    // Sponge start - completable future
    ((PlayerListBridge) playerList).bridge$canPlayerLogin(this.connection.getRemoteAddress(), this.gameProfile).handle((componentOpt, throwable) -> {
        if (throwable != null) {
            // An error occurred during login checks so we ask to abort.
            ((ConnectionBridge) this.connection).bridge$setKickReason(new TextComponent("An error occurred checking ban/whitelist status."));
            SpongeCommon.logger().error("An error occurred when checking the ban/whitelist status of {}.", this.gameProfile.getId().toString());
            SpongeCommon.logger().error(throwable);
        } else if (componentOpt != null) {
            // We handle this later
            ((ConnectionBridge) this.connection).bridge$setKickReason(componentOpt);
        }
        try {
            ((SpongeServer) SpongeCommon.server()).userManager().handlePlayerLogin(this.gameProfile);
        } catch (final IOException e) {
            throw new CompletionException(e);
        }
        return null;
    }).handleAsync((ignored, throwable) -> {
        if (throwable != null) {
            // We're just going to disconnect here, because something went horribly wrong.
            if (throwable instanceof CompletionException) {
                throw (CompletionException) throwable;
            } else {
                throw new CompletionException(throwable);
            }
        }
        // Sponge end
        this.state = ServerLoginPacketListenerImpl.State.ACCEPTED;
        if (this.server.getCompressionThreshold() >= 0 && !this.connection.isMemoryConnection()) {
            this.connection.send(new ClientboundLoginCompressionPacket(this.server.getCompressionThreshold()), (param0) -> this.connection.setupCompression(this.server.getCompressionThreshold()));
        }
        this.connection.send(new ClientboundGameProfilePacket(this.gameProfile));
        final ServerPlayer var1 = this.server.getPlayerList().getPlayer(this.gameProfile.getId());
        if (var1 != null) {
            this.state = ServerLoginPacketListenerImpl.State.DELAY_ACCEPT;
            this.delayedAcceptPlayer = this.server.getPlayerList().getPlayerForLogin(this.gameProfile);
        } else {
            // Sponge start - Also send the channel registrations using the minecraft channel, for compatibility
            final ServerSideConnection connection = (ServerSideConnection) this;
            ((SpongeChannelManager) Sponge.channelManager()).sendChannelRegistrations(connection);
            try {
                this.server.getPlayerList().placeNewPlayer(this.connection, this.server.getPlayerList().getPlayerForLogin(this.gameProfile));
                // invalidate just to be sure there is no user cached for the online player anymore
                Sponge.server().userManager().removeFromCache(this.gameProfile.getId());
            } catch (final Exception e) {
                throw new RuntimeException(e);
            }
        }
        return null;
    }, SpongeCommon.server()).exceptionally(throwable -> {
        // If a throwable exists, we're just going to disconnect the user, better than leaving them in limbo.
        if (throwable != null) {
            this.impl$disconnectError(throwable, this.state == ServerLoginPacketListenerImpl.State.ACCEPTED || this.state == ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT);
        }
        return null;
    // Sponge End
    });
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) ConnectionBridge(org.spongepowered.common.bridge.network.ConnectionBridge) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) Inject(org.spongepowered.asm.mixin.injection.Inject) SpongeServer(org.spongepowered.common.SpongeServer) Connection(net.minecraft.network.Connection) Overwrite(org.spongepowered.asm.mixin.Overwrite) SpongeAdventure(org.spongepowered.common.adventure.SpongeAdventure) EventContext(org.spongepowered.api.event.EventContext) PlayerList(net.minecraft.server.players.PlayerList) ClientboundLoginCompressionPacket(net.minecraft.network.protocol.login.ClientboundLoginCompressionPacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) Component(net.kyori.adventure.text.Component) ConnectionHolderBridge(org.spongepowered.common.bridge.network.ConnectionHolderBridge) PlayerListBridge(org.spongepowered.common.bridge.server.players.PlayerListBridge) At(org.spongepowered.asm.mixin.injection.At) Opcodes(org.objectweb.asm.Opcodes) ServerLoginPacketListenerImplBridge(org.spongepowered.common.bridge.server.network.ServerLoginPacketListenerImplBridge) ClientboundGameProfilePacket(net.minecraft.network.protocol.login.ClientboundGameProfilePacket) ServerLoginPacketListenerImpl(net.minecraft.server.network.ServerLoginPacketListenerImpl) Redirect(org.spongepowered.asm.mixin.injection.Redirect) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Sponge(org.spongepowered.api.Sponge) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) SpongeCommon(org.spongepowered.common.SpongeCommon) Final(org.spongepowered.asm.mixin.Final) ClientboundDisconnectPacket(net.minecraft.network.protocol.game.ClientboundDisconnectPacket) Cause(org.spongepowered.api.event.Cause) TextComponent(net.minecraft.network.chat.TextComponent) Shadow(org.spongepowered.asm.mixin.Shadow) ClientboundLoginCompressionPacket(net.minecraft.network.protocol.login.ClientboundLoginCompressionPacket) PlayerList(net.minecraft.server.players.PlayerList) ConnectionBridge(org.spongepowered.common.bridge.network.ConnectionBridge) CompletionException(java.util.concurrent.CompletionException) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) IOException(java.io.IOException) IOException(java.io.IOException) CompletionException(java.util.concurrent.CompletionException) ClientboundGameProfilePacket(net.minecraft.network.protocol.login.ClientboundGameProfilePacket) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with SpongeChannelManager

use of org.spongepowered.common.network.channel.SpongeChannelManager in project SpongeCommon by SpongePowered.

the class ServerGamePacketListenerImplMixin_Vanilla method vanilla$onHandleCustomPayload.

@Inject(method = "handleCustomPayload", at = @At(value = "HEAD"))
private void vanilla$onHandleCustomPayload(final ServerboundCustomPayloadPacket packet, final CallbackInfo ci) {
    // For some reason, "ServerboundCustomPayloadPacket" is released in the processPacket
    // method of its class, only applicable to this packet, so just retain here.
    ((ServerboundCustomPayloadPacketAccessor) packet).accessor$data().retain();
    final SpongeChannelManager channelRegistry = (SpongeChannelManager) Sponge.channelManager();
    this.server.execute(() -> channelRegistry.handlePlayPayload((EngineConnection) this, packet));
}
Also used : SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) EngineConnection(org.spongepowered.api.network.EngineConnection) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 5 with SpongeChannelManager

use of org.spongepowered.common.network.channel.SpongeChannelManager in project SpongeCommon by SpongePowered.

the class ServerLoginPacketListenerImplMixin_Vanilla method onResponsePayload.

@Inject(method = "handleCustomQueryPacket", at = @At("HEAD"), cancellable = true)
private void onResponsePayload(final ServerboundCustomQueryPacket packet, final CallbackInfo ci) {
    ci.cancel();
    final SpongeChannelManager channelRegistry = (SpongeChannelManager) Sponge.channelManager();
    this.server.execute(() -> channelRegistry.handleLoginResponsePayload((EngineConnection) this, packet));
}
Also used : SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) EngineConnection(org.spongepowered.api.network.EngineConnection) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SpongeChannelManager (org.spongepowered.common.network.channel.SpongeChannelManager)6 Inject (org.spongepowered.asm.mixin.injection.Inject)5 EngineConnection (org.spongepowered.api.network.EngineConnection)4 MinecraftServer (net.minecraft.server.MinecraftServer)2 ServerLoginPacketListenerImpl (net.minecraft.server.network.ServerLoginPacketListenerImpl)2 Sponge (org.spongepowered.api.Sponge)2 Cause (org.spongepowered.api.event.Cause)2 EventContext (org.spongepowered.api.event.EventContext)2 SpongeEventFactory (org.spongepowered.api.event.SpongeEventFactory)2 ServerSideConnectionEvent (org.spongepowered.api.event.network.ServerSideConnectionEvent)2 ServerSideConnection (org.spongepowered.api.network.ServerSideConnection)2 Final (org.spongepowered.asm.mixin.Final)2 Mixin (org.spongepowered.asm.mixin.Mixin)2 Shadow (org.spongepowered.asm.mixin.Shadow)2 At (org.spongepowered.asm.mixin.injection.At)2 CallbackInfo (org.spongepowered.asm.mixin.injection.callback.CallbackInfo)2 SpongeCommon (org.spongepowered.common.SpongeCommon)2 IOException (java.io.IOException)1 CompletionException (java.util.concurrent.CompletionException)1 Component (net.kyori.adventure.text.Component)1