support 1.7 servers
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m26s

This commit is contained in:
Lee 2024-04-10 14:32:19 +01:00
parent 795c97401c
commit b26d5aa67f
4 changed files with 20 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package cc.fascinated.common;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.ToString;
import lombok.extern.log4j.Log4j2;
@ -65,6 +66,8 @@ public enum JavaMinecraftVersion {
V1_8(47, "v1_8_R3"), // 1.8.x
V1_7_6(5, "v1_7_R4"), // 1.7.6 - 1.7.10
UNKNOWN(-1, "Unknown");
// Game Updates
@ -82,6 +85,8 @@ public enum JavaMinecraftVersion {
public static final JavaMinecraftVersion THE_COMBAT_UPDATE = JavaMinecraftVersion.V1_9;
public static final JavaMinecraftVersion BOUNTIFUL_UPDATE = JavaMinecraftVersion.V1_8;
private static final JavaMinecraftVersion[] VALUES = JavaMinecraftVersion.values();
/**
* The protocol number of this version.
*/
@ -170,6 +175,16 @@ public enum JavaMinecraftVersion {
return this.protocol <= other.getProtocol();
}
/**
* Get the minimum Minecraft version.
*
* @return the minimum version
*/
@NonNull
public static JavaMinecraftVersion getMinimumVersion() {
return VALUES[VALUES.length - 2];
}
/**
* Get the version from the given protocol.
*

View File

@ -4,7 +4,7 @@ import cc.fascinated.Main;
import cc.fascinated.common.JavaMinecraftVersion;
import cc.fascinated.common.ServerUtils;
import cc.fascinated.config.Config;
import cc.fascinated.model.mojang.JavaServerStatusToken;
import cc.fascinated.model.token.JavaServerStatusToken;
import com.google.gson.annotations.SerializedName;
import lombok.*;
import net.md_5.bungee.api.chat.TextComponent;

View File

@ -1,4 +1,4 @@
package cc.fascinated.model.mojang;
package cc.fascinated.model.token;
import cc.fascinated.model.server.JavaMinecraftServer;
import cc.fascinated.model.server.MinecraftServer;

View File

@ -2,12 +2,13 @@ package cc.fascinated.service.pinger.impl;
import cc.fascinated.Main;
import cc.fascinated.common.DNSUtils;
import cc.fascinated.common.JavaMinecraftVersion;
import cc.fascinated.common.ServerUtils;
import cc.fascinated.common.packet.impl.java.JavaPacketHandshakingInSetProtocol;
import cc.fascinated.common.packet.impl.java.JavaPacketStatusInStart;
import cc.fascinated.exception.impl.BadRequestException;
import cc.fascinated.exception.impl.ResourceNotFoundException;
import cc.fascinated.model.mojang.JavaServerStatusToken;
import cc.fascinated.model.token.JavaServerStatusToken;
import cc.fascinated.model.server.JavaMinecraftServer;
import cc.fascinated.service.pinger.MinecraftServerPinger;
import lombok.extern.log4j.Log4j2;
@ -42,12 +43,11 @@ public final class JavaMinecraftServerPinger implements MinecraftServerPinger<Ja
try (DataInputStream inputStream = new DataInputStream(socket.getInputStream());
DataOutputStream outputStream = new DataOutputStream(socket.getOutputStream())) {
// Begin handshaking with the server
new JavaPacketHandshakingInSetProtocol(hostname, port, 47).process(inputStream, outputStream);
new JavaPacketHandshakingInSetProtocol(hostname, port, JavaMinecraftVersion.getMinimumVersion().getProtocol()).process(inputStream, outputStream);
// Send the status request to the server, and await back the response
JavaPacketStatusInStart packetStatusInStart = new JavaPacketStatusInStart();
packetStatusInStart.process(inputStream, outputStream);
System.out.println(packetStatusInStart.getResponse());
JavaServerStatusToken token = Main.GSON.fromJson(packetStatusInStart.getResponse(), JavaServerStatusToken.class);
return JavaMinecraftServer.create(hostname, ip, port, token);
}