Yatopia/patches/server/0029-Use-offline-uuids-if-we-need-to.patch

106 lines
5.1 KiB
Diff
Raw Normal View History

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Mon, 17 Aug 2020 19:16:39 +0300
Subject: [PATCH] Use offline uuids if we need to
By default, the user cache falls back to requests to mojang if it wasn't able to find a player.
This is completely fine if we're running an online mode server, however proxies require the
server to run in offline mode, which makes mojang's default commands to not work properly
( say if we want to ban a player which has never joined the server, he wouldn't get banned )
What our change does is make use of already existing options in paper.yml and spigot.yml to check
if the server is running behind a proxy and if the proxy is running online mode. If admins fail to
configure it properly, their mistake!
Furthermore, my research on the issue shows that this behavior also can be seen if we're not running
behind a proxy at all! I try to whitelist any of my staff, and they get whitelisted with online mode
UUIDs, while they should get whitelisted with offline mode ones.
Thanks to Gabriele C <sgdc3.mail@gmail.com> for pointing this issue to us, as he said paper doesn't
have any interest fixing this.
diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
index caaa01b20e5b7430b809477022f8ab35f3c5bf20..dfa719716efdb93b2f4440916bef70971a2a404d 100644
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
@@ -1914,7 +1914,7 @@ public abstract class EntityHuman extends EntityLiving {
public static UUID a(GameProfile gameprofile) {
UUID uuid = gameprofile.getId();
- if (uuid == null) {
+ if (org.yatopiamc.yatopia.server.YatopiaConfig.shouldUseOfflineUUID() || uuid == null) { // Yatopia
uuid = getOfflineUUID(gameprofile.getName());
}
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
index 1496c43fc9487caf6ddb3782a9d1c79ef6ca1e94..d3ffbd5247b3a9b2a046d6696c959e834dff7ef4 100644
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
@@ -82,6 +82,11 @@ public class UserCache {
@Nullable
private static GameProfile a(GameProfileRepository gameprofilerepository, String s) {
+ // Yatopia start
+ if (org.yatopiamc.yatopia.server.YatopiaConfig.shouldUseOfflineUUID() && org.yatopiamc.yatopia.server.YatopiaConfig.isProxy()) {
+ return new GameProfile(EntityHuman.getOfflineUUID(s), s);
+ }
+ // Yatopia end
final AtomicReference<GameProfile> atomicreference = new AtomicReference();
ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() {
public void onProfileLookupSucceeded(GameProfile gameprofile) {
@@ -102,6 +107,15 @@ public class UserCache {
gameprofile = new GameProfile(uuid, s);
}
+ // Yatopia start
+ if (org.yatopiamc.yatopia.server.YatopiaConfig.shouldUseOfflineUUID() && !org.yatopiamc.yatopia.server.YatopiaConfig.isProxy()) {
+ GameProfile newProfile = new GameProfile(EntityHuman.getOfflineUUID(s), s);
+ if (gameprofile == null || gameprofile.getProperties().isEmpty()) return newProfile;
+ newProfile.getProperties().putAll(gameprofile.getProperties());
+ return newProfile;
+ }
+ // Yatopia end
+
return gameprofile;
}
diff --git a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
index 003a024da8ab877895244ff9e4e4ff62288622ff..eb5f7172829037862c20bb7527badaa589f50cc7 100644
--- a/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
+++ b/src/main/java/org/yatopiamc/yatopia/server/YatopiaConfig.java
@@ -10,6 +10,7 @@ import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.regex.Pattern;
+import net.minecraft.server.MinecraftServer;
import org.bukkit.Bukkit;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -211,4 +212,26 @@ public class YatopiaConfig {
private static void fixFallDistance() {
fixFallDistance = getBoolean("settings.fixFallDistance", false);
}
+
+ public static boolean shouldUseOfflineUUID() {
+ if (org.spigotmc.SpigotConfig.bungee && com.destroystokyo.paper.PaperConfig.bungeeOnlineMode) {
+ return false;
+ }
+ if (org.spigotmc.SpigotConfig.bungee) {
+ return true;
+ }
+ if (com.destroystokyo.paper.PaperConfig.velocitySupport &&
+ com.destroystokyo.paper.PaperConfig.velocityOnlineMode) {
+ return false;
+ }
+ if (com.destroystokyo.paper.PaperConfig.velocitySupport) {
+ return true;
+ }
+
+ return !MinecraftServer.getServer().getOnlineMode();
+ }
+
+ public static boolean isProxy() {
+ return org.spigotmc.SpigotConfig.bungee || com.destroystokyo.paper.PaperConfig.velocitySupport;
+ }
}