Only print handshake errors when debug is enabled

The exceptions only now showed up with the new print handling, but 100% of the printed cases have just been invalid packets, which we can (and should) just ignore.
Fixes #1854
This commit is contained in:
KennyTV 2020-07-01 09:11:46 +02:00
parent 3ba2191829
commit b99b79f44a
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 19 additions and 8 deletions

View File

@ -88,7 +88,7 @@ public class TagRewriter {
}
// Send new tags if present
if (newTags != null) {
if (newTags != null && !newTags.isEmpty()) {
for (TagData tag : newTags) {
wrapper.write(Type.STRING, tag.identifier);
wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries);

View File

@ -27,16 +27,27 @@ public class BaseProtocol extends SimpleProtocol {
registerIncoming(State.HANDSHAKE, 0x00, 0x00, new PacketRemapper() {
@Override
public void registerMap() {
// select right protocol
map(Type.VAR_INT); // 0 - Client Protocol Version
map(Type.STRING); // 1 - Server Address
map(Type.UNSIGNED_SHORT); // 2 - Server Port
map(Type.VAR_INT); // 3 - Next State
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int protVer = wrapper.get(Type.VAR_INT, 0);
int state = wrapper.get(Type.VAR_INT, 1);
try {
handleWithException(wrapper);
} catch (Exception e) {
// Only throw exceptions here when debug is enabled
// The handling has proven to be correct, but often receives invalid packets as the first packet of a connection
if (Via.getManager().isDebug()) {
throw e;
} else {
wrapper.cancel();
}
}
}
private void handleWithException(PacketWrapper wrapper) throws Exception {
int protVer = wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.STRING); // Server Address
wrapper.passthrough(Type.UNSIGNED_SHORT); // Server Port
int state = wrapper.passthrough(Type.VAR_INT);
ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setProtocolVersion(protVer);