support 1.7 servers

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

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

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

@ -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.JavaMinecraftServer;
import cc.fascinated.model.server.MinecraftServer; import cc.fascinated.model.server.MinecraftServer;

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