Skip to content

Commit 83fcace

Browse files
committed
update to com.github.AlexProgrammerDE:MCProtocolLib:576b311
1 parent f9edd60 commit 83fcace

File tree

2 files changed

+33
-51
lines changed

2 files changed

+33
-51
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ dependencies {
4141
compileOnly "org.jetbrains:annotations:24.1.0"
4242
compileOnly "org.projectlombok:lombok:1.18.32"
4343
annotationProcessor "org.projectlombok:lombok:1.18.32"
44-
implementation "com.github.AlexProgrammerDE:MCProtocolLib:f2d67ef"
44+
implementation "com.github.AlexProgrammerDE:MCProtocolLib:576b311"
4545
}

src/main/java/me/marlester/mcbotlib/clientlisteners/BaseListener.java

Lines changed: 32 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import org.geysermc.mcprotocollib.protocol.data.handshake.HandshakeIntent;
4545
import org.geysermc.mcprotocollib.protocol.data.status.ServerStatusInfo;
4646
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerInfoHandler;
47+
import org.geysermc.mcprotocollib.protocol.data.status.handler.ServerPingTimeHandler;
4748
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundDisconnectPacket;
4849
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundKeepAlivePacket;
4950
import org.geysermc.mcprotocollib.protocol.packet.common.clientbound.ClientboundPingPacket;
@@ -100,30 +101,26 @@ public void packetReceived(Session session, Packet packet) {
100101
throw new IllegalStateException("Failed to generate shared key.", e);
101102
}
102103

103-
SessionService sessionService = session.getFlag(MinecraftConstants.SESSION_SERVICE_KEY,
104-
new SessionService());
105-
String serverId = SessionService.getServerId(helloPacket.getServerId(),
106-
helloPacket.getPublicKey(), key);
104+
SessionService sessionService = session.getFlag(MinecraftConstants.SESSION_SERVICE_KEY, new SessionService());
105+
String serverId = SessionService.getServerId(helloPacket.getServerId(), helloPacket.getPublicKey(), key);
107106

108-
// ODOT: Add generic error, disabled multiplayer and banned from playing online errors
107+
// TODO: Add generic error, disabled multiplayer and banned from playing online errors
109108
try {
110109
sessionService.joinServer(profile, accessToken, serverId);
111110
} catch (IOException e) {
112-
session.disconnect(Component.translatable("disconnect.loginFailedInfo",
113-
Component.text(e.getMessage())), e);
111+
session.disconnect(Component.translatable("disconnect.loginFailedInfo", Component.text(e.getMessage())), e);
114112
return;
115113
}
116114

117-
// MCBotLib start
115+
// mcbotlib start
118116
var keyPacket = new ServerboundKeyPacket(helloPacket.getPublicKey(), key,
119117
helloPacket.getChallenge());
120118
var encryption = new AESEncryption(key);
121119
session.send(keyPacket, () -> session.enableEncryption(encryption));
122-
// MCBotLib end
120+
// mcbotlib end
123121
} else if (packet instanceof ClientboundGameProfilePacket) {
124-
session.switchInboundProtocol(() -> protocol.setInboundState(ProtocolState.CONFIGURATION));
125-
session.send(new ServerboundLoginAcknowledgedPacket(),
126-
() -> protocol.setOutboundState(ProtocolState.CONFIGURATION));
122+
session.switchInboundState(() -> protocol.setInboundState(ProtocolState.CONFIGURATION));
123+
session.send(new ServerboundLoginAcknowledgedPacket(), () -> protocol.setOutboundState(ProtocolState.CONFIGURATION));
127124
} else if (packet instanceof ClientboundLoginDisconnectPacket loginDisconnectPacket) {
128125
session.disconnect(loginDisconnectPacket.getReason());
129126
} else if (packet instanceof ClientboundLoginCompressionPacket loginCompressionPacket) {
@@ -140,60 +137,51 @@ public void packetReceived(Session session, Packet packet) {
140137
session.send(new ServerboundPingRequestPacket(System.currentTimeMillis()));
141138
} else if (packet instanceof ClientboundPongResponsePacket pongResponsePacket) {
142139
long time = System.currentTimeMillis() - pongResponsePacket.getPingTime();
143-
var handler = session.getFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY);
140+
ServerPingTimeHandler handler = session.getFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY);
144141
if (handler != null) {
145142
handler.handle(session, time);
146143
}
147144

148145
session.disconnect(Component.translatable("multiplayer.status.finished"));
149146
}
150147
} else if (protocol.getInboundState() == ProtocolState.GAME) {
151-
if (packet instanceof ClientboundKeepAlivePacket keepAlivePacket &&
152-
session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
148+
if (packet instanceof ClientboundKeepAlivePacket keepAlivePacket && session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
153149
session.send(new ServerboundKeepAlivePacket(keepAlivePacket.getPingId()));
154-
} else if (packet instanceof ClientboundPingPacket pingPacket &&
155-
session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
156-
session.send(new ServerboundPongPacket(pingPacket.getId()));
157150
} else if (packet instanceof ClientboundDisconnectPacket disconnectPacket) {
158151
session.disconnect(disconnectPacket.getReason());
159152
} else if (packet instanceof ClientboundStartConfigurationPacket) {
160-
session.switchInboundProtocol(() -> protocol.setInboundState(ProtocolState.CONFIGURATION));
161-
session.send(new ServerboundConfigurationAcknowledgedPacket(),
162-
() -> protocol.setOutboundState(ProtocolState.CONFIGURATION));
153+
session.switchInboundState(() -> protocol.setInboundState(ProtocolState.CONFIGURATION));
154+
session.send(new ServerboundConfigurationAcknowledgedPacket(), () -> protocol.setOutboundState(ProtocolState.CONFIGURATION));
163155
} else if (packet instanceof ClientboundTransferPacket transferPacket) {
164156
if (session.getFlag(MinecraftConstants.FOLLOW_TRANSFERS, true)) {
165-
TcpClientSession newSession = new TcpClientSession(transferPacket.getHost(),
166-
transferPacket.getPort(), session.getPacketProtocol());
157+
TcpClientSession newSession = new TcpClientSession(transferPacket.getHost(), transferPacket.getPort(), session.getPacketProtocol());
167158
newSession.setFlags(session.getFlags());
168159
session.disconnect(Component.translatable("disconnect.transfer"));
169160
newSession.connect(true, true);
170161
}
162+
// mcbotlib start
163+
} else if (packet instanceof ClientboundPingPacket pingPacket) {
164+
session.send(new ServerboundPongPacket(pingPacket.getId()));
171165
}
166+
// mcbotlib end
172167
} else if (protocol.getInboundState() == ProtocolState.CONFIGURATION) {
173-
if (packet instanceof ClientboundKeepAlivePacket keepAlivePacket &&
174-
session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
168+
if (packet instanceof ClientboundKeepAlivePacket keepAlivePacket && session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
175169
session.send(new ServerboundKeepAlivePacket(keepAlivePacket.getPingId()));
176-
} else if (packet instanceof ClientboundPingPacket pingPacket &&
177-
session.getFlag(MinecraftConstants.AUTOMATIC_KEEP_ALIVE_MANAGEMENT, true)) {
178-
session.send(new ServerboundPongPacket(pingPacket.getId()));
179170
} else if (packet instanceof ClientboundFinishConfigurationPacket) {
180-
session.switchInboundProtocol(() -> protocol.setInboundState(ProtocolState.GAME));
181-
session.send(new ServerboundFinishConfigurationPacket(),
182-
() -> protocol.setOutboundState(ProtocolState.GAME));
171+
session.switchInboundState(() -> protocol.setInboundState(ProtocolState.GAME));
172+
session.send(new ServerboundFinishConfigurationPacket(), () -> protocol.setOutboundState(ProtocolState.GAME));
183173
} else if (packet instanceof ClientboundSelectKnownPacks selectKnownPacks) {
184-
/* MCBotLib start */
174+
// mcbotlib start
185175
if (session.getFlag(MinecraftConstants.SEND_BLANK_KNOWN_PACKS_RESPONSE, true)) {
186176
session.send(new ServerboundSelectKnownPacks(Collections.emptyList()));
187177
} else {
188178
session.send(new ServerboundSelectKnownPacks(BuiltInKnownPackRegistry.INSTANCE
189179
.getMatchingPacks(selectKnownPacks.getKnownPacks())));
190180
}
191-
/* MCBotLib end */
181+
// mcbotlib end
192182
} else if (packet instanceof ClientboundTransferPacket transferPacket) {
193183
if (session.getFlag(MinecraftConstants.FOLLOW_TRANSFERS, true)) {
194-
TcpClientSession newSession =
195-
new TcpClientSession(transferPacket.getHost(), transferPacket.getPort(),
196-
session.getPacketProtocol());
184+
TcpClientSession newSession = new TcpClientSession(transferPacket.getHost(), transferPacket.getPort(), session.getPacketProtocol());
197185
newSession.setFlags(session.getFlags());
198186
session.disconnect(Component.translatable("disconnect.transfer"));
199187
newSession.connect(true, true);
@@ -206,26 +194,20 @@ public void packetReceived(Session session, Packet packet) {
206194
public void connected(ConnectedEvent event) {
207195
Session session = event.getSession();
208196
MinecraftProtocol protocol = (MinecraftProtocol) session.getPacketProtocol();
209-
ClientIntentionPacket intention =
210-
new ClientIntentionPacket(protocol.getCodec().getProtocolVersion(), session.getHost(),
211-
session.getPort(), switch (targetState) {
212-
case LOGIN -> transferring ? HandshakeIntent.TRANSFER : HandshakeIntent.LOGIN;
213-
case STATUS -> HandshakeIntent.STATUS;
214-
default -> throw new IllegalStateException("Unexpected value: " + targetState);
215-
});
197+
ClientIntentionPacket intention = new ClientIntentionPacket(protocol.getCodec().getProtocolVersion(), session.getHost(), session.getPort(), switch (targetState) {
198+
case LOGIN -> transferring ? HandshakeIntent.TRANSFER : HandshakeIntent.LOGIN;
199+
case STATUS -> HandshakeIntent.STATUS;
200+
default -> throw new IllegalStateException("Unexpected value: " + targetState);
201+
});
216202

203+
session.switchInboundState(() -> protocol.setInboundState(this.targetState));
204+
session.send(intention, () -> protocol.setOutboundState(this.targetState));
217205
switch (this.targetState) {
218206
case LOGIN -> {
219-
session.switchInboundProtocol(() -> protocol.setInboundState(ProtocolState.LOGIN));
220-
session.send(intention, () -> protocol.setOutboundState(ProtocolState.LOGIN));
221207
GameProfile profile = session.getFlag(MinecraftConstants.PROFILE_KEY);
222208
session.send(new ServerboundHelloPacket(profile.getName(), profile.getId()));
223209
}
224-
case STATUS -> {
225-
session.switchInboundProtocol(() -> protocol.setInboundState(ProtocolState.STATUS));
226-
session.send(intention, () -> protocol.setOutboundState(ProtocolState.STATUS));
227-
session.send(new ServerboundStatusRequestPacket());
228-
}
210+
case STATUS -> session.send(new ServerboundStatusRequestPacket());
229211
default -> throw new IllegalStateException("Unexpected value: " + targetState);
230212
}
231213
}

0 commit comments

Comments
 (0)