Search in sources :

Example 6 with ServerSideConnection

use of org.spongepowered.api.network.ServerSideConnection 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

ServerSideConnectionEvent (org.spongepowered.api.event.network.ServerSideConnectionEvent)6 ServerSideConnection (org.spongepowered.api.network.ServerSideConnection)6 Cause (org.spongepowered.api.event.Cause)4 CompletionException (java.util.concurrent.CompletionException)3 Component (net.kyori.adventure.text.Component)3 TextComponent (net.minecraft.network.chat.TextComponent)3 EngineConnection (org.spongepowered.api.network.EngineConnection)3 Inject (org.spongepowered.asm.mixin.injection.Inject)3 Inject (com.google.inject.Inject)2 MutableComponent (net.minecraft.network.chat.MutableComponent)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 ServerLoginPacketListenerImpl (net.minecraft.server.network.ServerLoginPacketListenerImpl)2 ResourceKey (org.spongepowered.api.ResourceKey)2 Sponge (org.spongepowered.api.Sponge)2 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)2 EventContext (org.spongepowered.api.event.EventContext)2 Listener (org.spongepowered.api.event.Listener)2 SpongeEventFactory (org.spongepowered.api.event.SpongeEventFactory)2 RegisterChannelEvent (org.spongepowered.api.event.lifecycle.RegisterChannelEvent)2