Search in sources :

Example 1 with SpongeLegacyMinecraftVersion

use of org.spongepowered.common.network.status.SpongeLegacyMinecraftVersion in project SpongeCommon by SpongePowered.

the class MixinLegacyPingHandler method readLegacy.

private boolean readLegacy(ChannelHandlerContext ctx, ByteBuf buf) {
    if (buf.readUnsignedByte() != 0xFE) {
        return false;
    }
    MinecraftServer server = this.networkSystem.getServer();
    InetSocketAddress client = (InetSocketAddress) ctx.channel().remoteAddress();
    ServerStatusResponse response;
    int i = buf.readableBytes();
    switch(i) {
        case 0:
            LOGGER.debug("Ping: (<=1.3) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_3, null);
            if (response != null) {
                this.writeResponse(ctx, String.format("%s§%d§%d", SpongeStatusResponse.getUnformattedMotd(response), response.getPlayers().getOnlinePlayerCount(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
        case 1:
            if (buf.readUnsignedByte() != 0x01) {
                return false;
            }
            LOGGER.debug("Ping: (1.4-1.5) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_5, null);
            if (response != null) {
                this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getOnlinePlayerCount(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
        default:
            if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) {
                return false;
            }
            if (!buf.isReadable(2)) {
                break;
            }
            short length = buf.readShort();
            if (!buf.isReadable(length * 2)) {
                break;
            }
            if (!buf.readBytes(length * 2).toString(Charsets.UTF_16BE).equals("MC|PingHost")) {
                return false;
            }
            if (!buf.isReadable(2)) {
                break;
            }
            length = buf.readShort();
            if (!buf.isReadable(length)) {
                break;
            }
            int protocol = buf.readUnsignedByte();
            length = buf.readShort();
            String host = buf.readBytes(length * 2).toString(Charsets.UTF_16BE);
            int port = buf.readInt();
            LOGGER.debug("Ping: (1.6) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, new SpongeLegacyMinecraftVersion(SpongeLegacyMinecraftVersion.V1_6, protocol), InetSocketAddress.createUnresolved(NetworkUtil.cleanVirtualHost(host), port));
            if (response != null) {
                this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getOnlinePlayerCount(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
    }
    return true;
}
Also used : SpongeLegacyMinecraftVersion(org.spongepowered.common.network.status.SpongeLegacyMinecraftVersion) InetSocketAddress(java.net.InetSocketAddress) ServerStatusResponse(net.minecraft.network.ServerStatusResponse) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 2 with SpongeLegacyMinecraftVersion

use of org.spongepowered.common.network.status.SpongeLegacyMinecraftVersion in project Sponge by SpongePowered.

the class LegacyQueryHandlerMixin method impl$readLegacy.

private boolean impl$readLegacy(final ChannelHandlerContext ctx, final ByteBuf buf) {
    if (buf.readUnsignedByte() != 0xFE) {
        return false;
    }
    final MinecraftServer server = this.serverConnectionListener.getServer();
    final InetSocketAddress client = (InetSocketAddress) ctx.channel().remoteAddress();
    final ServerStatus response;
    final int i = buf.readableBytes();
    switch(i) {
        case 0:
            LegacyQueryHandlerMixin.LOGGER.debug("Ping: (<=1.3) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_3, null);
            if (response != null) {
                this.writeResponse(ctx, String.format("%s§%d§%d", SpongeStatusResponse.getUnformattedMotd(response), response.getPlayers().getNumPlayers(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
        case 1:
            if (buf.readUnsignedByte() != 0x01) {
                return false;
            }
            LegacyQueryHandlerMixin.LOGGER.debug("Ping: (1.4-1.5) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_5, null);
            if (response != null) {
                this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getNumPlayers(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
        default:
            if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) {
                return false;
            }
            if (!buf.isReadable(2)) {
                break;
            }
            short length = buf.readShort();
            if (!buf.isReadable(length * 2)) {
                break;
            }
            if (!buf.readBytes(length * 2).toString(Charsets.UTF_16BE).equals("MC|PingHost")) {
                return false;
            }
            if (!buf.isReadable(2)) {
                break;
            }
            length = buf.readShort();
            if (!buf.isReadable(length)) {
                break;
            }
            final int protocol = buf.readUnsignedByte();
            length = buf.readShort();
            final String host = buf.readBytes(length * 2).toString(Charsets.UTF_16BE);
            final int port = buf.readInt();
            LegacyQueryHandlerMixin.LOGGER.debug("Ping: (1.6) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, new SpongeLegacyMinecraftVersion(SpongeLegacyMinecraftVersion.V1_6, protocol), InetSocketAddress.createUnresolved(NetworkUtil.cleanVirtualHost(host), port));
            if (response != null) {
                this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getNumPlayers(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
    }
    return true;
}
Also used : SpongeLegacyMinecraftVersion(org.spongepowered.common.network.status.SpongeLegacyMinecraftVersion) InetSocketAddress(java.net.InetSocketAddress) ServerStatus(net.minecraft.network.protocol.status.ServerStatus) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 3 with SpongeLegacyMinecraftVersion

use of org.spongepowered.common.network.status.SpongeLegacyMinecraftVersion in project SpongeCommon by SpongePowered.

the class LegacyQueryHandlerMixin method impl$readLegacy.

private boolean impl$readLegacy(final ChannelHandlerContext ctx, final ByteBuf buf) {
    if (buf.readUnsignedByte() != 0xFE) {
        return false;
    }
    final MinecraftServer server = this.serverConnectionListener.getServer();
    final InetSocketAddress client = (InetSocketAddress) ctx.channel().remoteAddress();
    final ServerStatus response;
    final int i = buf.readableBytes();
    switch(i) {
        case 0:
            LegacyQueryHandlerMixin.LOGGER.debug("Ping: (<=1.3) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_3, null);
            if (response != null) {
                this.writeResponse(ctx, String.format("%s§%d§%d", SpongeStatusResponse.getUnformattedMotd(response), response.getPlayers().getNumPlayers(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
        case 1:
            if (buf.readUnsignedByte() != 0x01) {
                return false;
            }
            LegacyQueryHandlerMixin.LOGGER.debug("Ping: (1.4-1.5) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, SpongeLegacyMinecraftVersion.V1_5, null);
            if (response != null) {
                this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getNumPlayers(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
        default:
            if (buf.readUnsignedByte() != 0x01 || buf.readUnsignedByte() != 0xFA) {
                return false;
            }
            if (!buf.isReadable(2)) {
                break;
            }
            short length = buf.readShort();
            if (!buf.isReadable(length * 2)) {
                break;
            }
            if (!buf.readBytes(length * 2).toString(Charsets.UTF_16BE).equals("MC|PingHost")) {
                return false;
            }
            if (!buf.isReadable(2)) {
                break;
            }
            length = buf.readShort();
            if (!buf.isReadable(length)) {
                break;
            }
            final int protocol = buf.readUnsignedByte();
            length = buf.readShort();
            final String host = buf.readBytes(length * 2).toString(Charsets.UTF_16BE);
            final int port = buf.readInt();
            LegacyQueryHandlerMixin.LOGGER.debug("Ping: (1.6) from {}:{}", client.getAddress(), client.getPort());
            response = SpongeStatusResponse.postLegacy(server, client, new SpongeLegacyMinecraftVersion(SpongeLegacyMinecraftVersion.V1_6, protocol), InetSocketAddress.createUnresolved(NetworkUtil.cleanVirtualHost(host), port));
            if (response != null) {
                this.writeResponse(ctx, String.format("§1\u0000%d\u0000%s\u0000%s\u0000%d\u0000%d", response.getVersion().getProtocol(), response.getVersion().getName(), SpongeStatusResponse.getMotd(response), response.getPlayers().getNumPlayers(), response.getPlayers().getMaxPlayers()));
            } else {
                ctx.close();
            }
            break;
    }
    return true;
}
Also used : SpongeLegacyMinecraftVersion(org.spongepowered.common.network.status.SpongeLegacyMinecraftVersion) InetSocketAddress(java.net.InetSocketAddress) ServerStatus(net.minecraft.network.protocol.status.ServerStatus) MinecraftServer(net.minecraft.server.MinecraftServer)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 SpongeLegacyMinecraftVersion (org.spongepowered.common.network.status.SpongeLegacyMinecraftVersion)3 ServerStatus (net.minecraft.network.protocol.status.ServerStatus)2 ServerStatusResponse (net.minecraft.network.ServerStatusResponse)1