Search in sources :

Example 1 with ClientType

use of org.spongepowered.common.entity.player.ClientType in project SpongeCommon by SpongePowered.

the class SpongeChannelManager method handleClientType.

private void handleClientType(final EngineConnection connection, final ChannelBuf payload) {
    final ClientType clientType = ClientType.from(payload.readString());
    if (clientType == null) {
        // TODO This shouldn't happen...what do? Terminate them?
        return;
    }
    ((ConnectionBridge) ((ServerLoginPacketListenerImpl) connection).connection).bridge$setClientType(clientType);
}
Also used : ClientType(org.spongepowered.common.entity.player.ClientType) ConnectionBridge(org.spongepowered.common.bridge.network.ConnectionBridge)

Example 2 with ClientType

use of org.spongepowered.common.entity.player.ClientType in project SpongeCommon by SpongePowered.

the class SpongeChannelManager method handleLoginRequestPayload.

private boolean handleLoginRequestPayload(final EngineConnection connection, final ResourceKey channelKey, final int transactionId, final ChannelBuf payload) {
    if (channelKey.equals(Constants.Channels.SPONGE_CLIENT_TYPE)) {
        final ClientType clientType = ((MinecraftBridge) Sponge.client()).bridge$getClientType();
        final ChannelBuf responsePayload = this.bufferAllocator.buffer();
        responsePayload.writeString(clientType.getName());
        final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
        PacketSender.sendTo(connection, mcPacket);
        return true;
    }
    if (channelKey.equals(Constants.Channels.SPONGE_CHANNEL_REGISTRY)) {
        this.handleChannelRegistry(connection, payload);
        // Respond with registered channels
        final ChannelBuf responsePayload = this.encodeChannelRegistry();
        final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
        PacketSender.sendTo(connection, mcPacket);
        return true;
    }
    ResourceKey actualChannelKey = channelKey;
    ChannelBuf actualPayload = payload;
    if (channelKey.equals(Constants.Channels.FML_LOGIN_WRAPPER_CHANNEL)) {
        actualChannelKey = ResourceKey.resolve(payload.readString());
        final int length = payload.readVarInt();
        actualPayload = payload.readSlice(length);
    }
    final SpongeChannel channel = this.channels.get(actualChannelKey);
    if (channel != null) {
        channel.handleLoginRequestPayload(connection, transactionId, actualPayload);
        return true;
    }
    return false;
}
Also used : ClientType(org.spongepowered.common.entity.player.ClientType) MinecraftBridge(org.spongepowered.common.bridge.client.MinecraftBridge) ChannelBuf(org.spongepowered.api.network.channel.ChannelBuf) ResourceKey(org.spongepowered.api.ResourceKey)

Aggregations

ClientType (org.spongepowered.common.entity.player.ClientType)2 ResourceKey (org.spongepowered.api.ResourceKey)1 ChannelBuf (org.spongepowered.api.network.channel.ChannelBuf)1 MinecraftBridge (org.spongepowered.common.bridge.client.MinecraftBridge)1 ConnectionBridge (org.spongepowered.common.bridge.network.ConnectionBridge)1