Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Moresteck committed Jan 6, 2024
2 parents acc3208 + 794a4f9 commit 8165834
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,14 @@ private void write() {
generateConfigOption("settings.fetch-uuids-from", "https://api.mojang.com/profiles/minecraft");
generateConfigOption("settings.remove-join-leave-debug", true);
generateConfigOption("settings.enable-tpc-nodelay", false);
generateConfigOption("settings.use-get-for-uuids.enabled", false);

generateConfigOption("settings.use-get-for-uuids.enabled", true);
generateConfigOption("settings.use-get-for-uuids.info", "This setting causes the server to use the GET method for Username to UUID conversion. This is useful incase the POST method goes offline.");

generateConfigOption("settings.faster-packets.enabled", false);
generateConfigOption("settings.use-get-for-uuids.case-sensitive.enabled", true);
generateConfigOption("settings.use-get-for-uuids.case-sensitive.info", "This setting will verify sensitivity of the username as the GET method is case-insensitive.");

generateConfigOption("settings.faster-packets.enabled", true);
generateConfigOption("settings.faster-packets.info", "This setting increases the speed of packets, a fix from newer Minecraft versions.");

generateConfigOption("settings.fix-drowning-push-down.enabled", true);
Expand Down
48 changes: 36 additions & 12 deletions src/main/java/com/legacyminecraft/poseidon/util/GetUUIDFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,55 @@

public class GetUUIDFetcher {

public static class UUIDAndUsernameResult {
private UUIDResult uuidResult;
private String returnedUsername;

public static UUIDResult getUUID(String username) {
public UUIDAndUsernameResult(UUIDResult uuidResult, String returnedUsername) {
this.uuidResult = uuidResult;
this.returnedUsername = returnedUsername;
}

public UUIDResult getUuidResult() {
return uuidResult;
}

public String getReturnedUsername() {
return returnedUsername;
}
}


public static UUIDAndUsernameResult getUUID(String username) {
try {
JSONObject jsonObject = readJsonFromUrl("https://api.mojang.com/users/profiles/minecraft/" + encode(username));
UUIDResult uuidResult;
String returnedUsername = null;

if (!jsonObject.containsKey("id")) {
return new UUIDResult(generateOfflineUUID(username), UUIDResult.ReturnType.OFFLINE);
}
UUID uuid = toUUIDWithDashes(String.valueOf(jsonObject.get("id")));
if (uuid == null) {
return new UUIDResult(null, UUIDResult.ReturnType.API_OFFLINE);
uuidResult = new UUIDResult(generateOfflineUUID(username), UUIDResult.ReturnType.OFFLINE);
} else {
UUID uuid = toUUIDWithDashes(String.valueOf(jsonObject.get("id")));
if (uuid == null) {
uuidResult = new UUIDResult(null, UUIDResult.ReturnType.API_OFFLINE);
} else {
returnedUsername = String.valueOf(jsonObject.get("name"));
uuidResult = new UUIDResult(uuid, UUIDResult.ReturnType.ONLINE);
}
}

return new UUIDResult(uuid, UUIDResult.ReturnType.ONLINE);

return new UUIDAndUsernameResult(uuidResult, returnedUsername);

} catch (Exception exception) {
UUIDResult uuidResult;
UUIDResult uuidResult = null;
if (exception == null || exception.getMessage() == null) {
//This is a hacky solution to tell if the API is offline, or the user is cracked.
// This is a hacky solution to tell if the API is offline, or the user is cracked.
uuidResult = new UUIDResult(generateOfflineUUID(username), UUIDResult.ReturnType.OFFLINE);
} else {
uuidResult = new UUIDResult(null, UUIDResult.ReturnType.API_OFFLINE);
uuidResult.setException(exception);
}
uuidResult.setException(exception);
return uuidResult;
return new UUIDAndUsernameResult(uuidResult, null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@ public void run() {

public void getMethod() {
UUIDResult uuidResult;
uuidResult = GetUUIDFetcher.getUUID(loginPacket.name);
if (uuidResult.getReturnType().equals(UUIDResult.ReturnType.ONLINE)) {
GetUUIDFetcher.UUIDAndUsernameResult uuidAndUsernameResult = GetUUIDFetcher.getUUID(loginPacket.name);
uuidResult = uuidAndUsernameResult.getUuidResult();

if (uuidResult.getReturnType().equals(UUIDResult.ReturnType.ONLINE) && uuidAndUsernameResult.getReturnedUsername().equals(loginPacket.name)) {
System.out.println("Fetched UUID from Mojang for " + loginPacket.name + " - " + uuidResult.getUuid().toString());
loginProcessHandler.userUUIDReceived(uuidResult.getUuid(), true);
return;
} else if (uuidResult.getReturnType().equals(UUIDResult.ReturnType.ONLINE)) {
if(PoseidonConfig.getInstance().getConfigBoolean("settings.use-get-for-uuids.case-sensitive.enabled")) {
System.out.println("Fetched UUID from Mojang for " + loginPacket.name + " - " + uuidResult.getUuid().toString() + " however, the username returned was " + uuidAndUsernameResult.getReturnedUsername() + ". The user has been kicked as the server is configured to use case sensitive usernames");
loginProcessHandler.cancelLoginProcess(ChatColor.RED + "Sorry, that username has invalid casing");
return;
} else {
System.out.println("Fetched UUID from Mojang for " + loginPacket.name + " - " + uuidResult.getUuid().toString());
loginProcessHandler.userUUIDReceived(uuidResult.getUuid(), true);
return;
}
} else if (uuidResult.getReturnType().equals(UUIDResult.ReturnType.OFFLINE)) {
if ((boolean) PoseidonConfig.getInstance().getProperty("settings.allow-graceful-uuids")) {
System.out.println(loginPacket.name + " does not have a Mojang UUID associated with their name");
Expand Down Expand Up @@ -82,6 +94,7 @@ public void postMethod() {
}
} catch (Exception e) {
System.out.println("Mojang failed contact for user " + loginPacket.name + ":");
System.out.println("If this issue persists, please utilize the GET method by setting settings.use-get-for-uuids.enabled to true in the config");
e.printStackTrace();
loginProcessHandler.cancelLoginProcess(ChatColor.RED + "Sorry, we can't connect to Mojang currently, please try again later");
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/org/bukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,10 @@ public interface Entity {
* @return the last known {@link EntityDamageEvent} or null if hitherto unharmed
*/
public EntityDamageEvent getLastDamageCause();

/**
* Returns a unique and persistent id for this entity
* @return unique id
*/
public UUID getUniqueId();
}

0 comments on commit 8165834

Please sign in to comment.