GeyserMC / MCProtocolLib

A library for communication with a Minecraft client/server.
MIT License
721 stars 201 forks source link

"Disconnected" while trying to join a server #654

Closed ponktacology closed 3 years ago

ponktacology commented 3 years ago

I'm trying to create a simple limbo server.

    Server server = new TcpServer(settings.getHost(), settings.getPort(), MinecraftProtocol.class);
    server.setGlobalFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
    server.setGlobalFlag(MinecraftConstants.VERIFY_USERS_KEY, settings.isVerifyUsers());
    server.setGlobalFlag(
        MinecraftConstants.SERVER_INFO_BUILDER_KEY,
        (ServerInfoBuilder)
            session ->
                new ServerStatusInfo(
                    new VersionInfo(
                        MinecraftServerStressTest.SERVER_VERSION,
                        MinecraftServerStressTest.PROTOCOL_VERSION),
                    new PlayerInfo(100, 0, new GameProfile[0]),
                    Component.text("Hello world!"),
                    null));
    server.setGlobalFlag(
        MinecraftConstants.SERVER_LOGIN_HANDLER_KEY,
        (ServerLoginHandler)
            session -> {
              session.send(
                  new ServerJoinGamePacket(
                      0,
                      false,
                      GameMode.SURVIVAL,
                      GameMode.SURVIVAL,
                      1,
                      new String[] {"minecraft:world"},
                      CompoundTagUtil.getDimensionTag(),
                      CompoundTagUtil.getOverworldTag(),
                      "minecraft:world",
                      100,
                      0,
                      16,
                      false,
                      false,
                      false,
                      false));
              session.send(new ServerSpawnPositionPacket(new Position(0, 0, 0), 0.0F));
              session.send(new ServerPlayerAbilitiesPacket(false, false, false, false, 0.1f, 0.1f));
              session.send(new ServerPlayerChangeHeldItemPacket(0));
              session.send(new ServerUpdateTimePacket(1, 0L));
              session.send(
                  new ServerPlayerPositionRotationPacket(0, 0, 0, 0.0F, 0.0F, 1, false));
                session.send(new ServerSetBorderSizePacket(15));
                session.send(new ServerSetTitleTextPacket(Component.text("Hi!")));
                session.send(new ServerSwitchCameraPacket(2));
            });

    server.bind();

While trying to connect to the server I'm getting "Disconnected" message.

ponktacology commented 3 years ago

there should be a notice that you need to use specific version for specific minecraft protocol...