Search in sources :

Example 6 with SpongeChannelManager

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

the class ServerLoginPacketListenerImplMixin_Vanilla method impl$onTick.

@Inject(method = "tick", at = @At("HEAD"))
private void impl$onTick(final CallbackInfo ci) {
    if (this.state == ServerLoginPacketListenerImpl.State.NEGOTIATING) {
        final ServerSideConnection connection = (ServerSideConnection) this;
        if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_NOT_STARTED) {
            this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_CLIENT_TYPE;
            ((SpongeChannelManager) Sponge.channelManager()).requestClientType(connection).thenAccept(result -> {
                this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS;
            });
        } else if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_CHANNEL_REGISTRATIONS) {
            ((SpongeChannelManager) Sponge.channelManager()).sendLoginChannelRegistry(connection).thenAccept(result -> {
                final Cause cause = Cause.of(EventContext.empty(), this);
                final ServerSideConnectionEvent.Handshake event = SpongeEventFactory.createServerSideConnectionEventHandshake(cause, connection);
                SpongeCommon.post(event);
                this.impl$handshakeState = ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_PLUGIN_DATA;
            });
        } else if (this.impl$handshakeState == ServerLoginPacketListenerImplMixin_Vanilla.HANDSHAKE_SYNC_PLUGIN_DATA) {
            final TransactionStore store = ConnectionUtil.getTransactionStore(connection);
            if (store.isEmpty()) {
                this.state = ServerLoginPacketListenerImpl.State.READY_TO_ACCEPT;
            }
        }
    }
}
Also used : ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) ServerLoginPacketListener(net.minecraft.network.protocol.login.ServerLoginPacketListener) ServerLoginPacketListenerImpl(net.minecraft.server.network.ServerLoginPacketListenerImpl) ServerSideConnectionEvent(org.spongepowered.api.event.network.ServerSideConnectionEvent) TransactionStore(org.spongepowered.common.network.channel.TransactionStore) ServerboundCustomQueryPacket(net.minecraft.network.protocol.login.ServerboundCustomQueryPacket) Inject(org.spongepowered.asm.mixin.injection.Inject) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) EngineConnection(org.spongepowered.api.network.EngineConnection) Sponge(org.spongepowered.api.Sponge) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) SpongeCommon(org.spongepowered.common.SpongeCommon) Final(org.spongepowered.asm.mixin.Final) EventContext(org.spongepowered.api.event.EventContext) Cause(org.spongepowered.api.event.Cause) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) MinecraftServer(net.minecraft.server.MinecraftServer) Mixin(org.spongepowered.asm.mixin.Mixin) ConnectionUtil(org.spongepowered.common.network.channel.ConnectionUtil) ServerboundHelloPacket(net.minecraft.network.protocol.login.ServerboundHelloPacket) Shadow(org.spongepowered.asm.mixin.Shadow) At(org.spongepowered.asm.mixin.injection.At) TransactionStore(org.spongepowered.common.network.channel.TransactionStore) Cause(org.spongepowered.api.event.Cause) SpongeChannelManager(org.spongepowered.common.network.channel.SpongeChannelManager) ServerSideConnection(org.spongepowered.api.network.ServerSideConnection) 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