Archived
0

fix PLAY:KeepAlive

This commit is contained in:
2021-05-03 17:10:26 +03:00
parent 7d4c6e383e
commit 87dc18f009
3 changed files with 15 additions and 1 deletions

View File

@@ -50,12 +50,14 @@ public enum State {
0x00, TeleportConfirmPacket.class, 0x00, TeleportConfirmPacket.class,
0x04, ClientSettingsPacket.class, 0x04, ClientSettingsPacket.class,
0x09, PluginMessagePacket.class, 0x09, PluginMessagePacket.class,
0x0B, PingPacket.class,
0x0D, PlayerPositionPacket.class, 0x0D, PlayerPositionPacket.class,
0x0E, CPlayerPositionAndLookPacket.class, 0x0E, CPlayerPositionAndLookPacket.class,
0x0F, PlayerLookPacket.class 0x0F, PlayerLookPacket.class
), ),
// client bound // client bound
Map.of( Map.of(
PingPacket.class, 0x1F,
JoinGamePacket.class, 0x23, JoinGamePacket.class, 0x23,
SpawnPositionPacket.class, 0x46, SpawnPositionPacket.class, 0x46,
ChunkDataPacket.class, 0x20, ChunkDataPacket.class, 0x20,

View File

@@ -53,6 +53,7 @@ public class Main {
State.STATUS.packetFlux(PingPacket.class).subscribe(packetHandler::onKeepAlive); State.STATUS.packetFlux(PingPacket.class).subscribe(packetHandler::onKeepAlive);
State.STATUS.packetFlux(StatusServerRequestPacket.class).subscribe(packetHandler::onServerStatus); State.STATUS.packetFlux(StatusServerRequestPacket.class).subscribe(packetHandler::onServerStatus);
State.LOGIN.packetFlux(LoginStartPacket.class).subscribe(packetHandler::onLoginStart); State.LOGIN.packetFlux(LoginStartPacket.class).subscribe(packetHandler::onLoginStart);
State.PLAY.packetFlux(PingPacket.class).subscribe(packetHandler::onKeepAlivePlay);
server.bind(config.server().host(), config.server().port()); server.bind(config.server().host(), config.server().port());
} }

View File

@@ -38,6 +38,10 @@ public class PacketHandler {
channel.getCtx().writeAndFlush(channel.getPacket()).channel().disconnect(); channel.getCtx().writeAndFlush(channel.getPacket()).channel().disconnect();
} }
public void onKeepAlivePlay(ChannelContext<PingPacket> channel) {
channel.getCtx().writeAndFlush(channel.getPacket());
}
public void onServerStatus(ChannelContext<StatusServerRequestPacket> channel) { public void onServerStatus(ChannelContext<StatusServerRequestPacket> channel) {
ServerInfo serverInfo = new ServerInfo(); ServerInfo serverInfo = new ServerInfo();
serverInfo.version().name(ProtocolConstant.PROTOCOL_NAME); serverInfo.version().name(ProtocolConstant.PROTOCOL_NAME);
@@ -106,7 +110,14 @@ public class PacketHandler {
playerPositionAndLookPacket.setLook(new Look(0f, 0f)); playerPositionAndLookPacket.setLook(new Look(0f, 0f));
playerPositionAndLookPacket.setTeleportId(random.nextInt()); playerPositionAndLookPacket.setTeleportId(random.nextInt());
channel.getCtx().writeAndFlush(playerPositionAndLookPacket); channel.getCtx().write(playerPositionAndLookPacket);
PingPacket pingPacket = new PingPacket();
pingPacket.setPayload(System.currentTimeMillis());
channel.getCtx().write(pingPacket);
channel.getCtx().flush();
} }
private static String faviconToBase64(Path iconPath) { private static String faviconToBase64(Path iconPath) {