3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-26 00:00:41 +01:00

Automatically add loopback exemption to Windows

Dieser Commit ist enthalten in:
Ender 2020-03-24 02:56:04 -05:00
Ursprung bbf6683bd8
Commit ac8d1bf295
2 geänderte Dateien mit 52 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -25,16 +25,16 @@
package org.geysermc.platform.standalone;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
import org.geysermc.common.PlatformType;
import org.geysermc.common.bootstrap.IGeyserBootstrap;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.utils.FileUtils;
import org.geysermc.platform.standalone.console.GeyserLogger;
import java.io.File;
import java.io.IOException;
import java.util.UUID;
public class GeyserBootstrap implements IGeyserBootstrap {
private GeyserConfiguration geyserConfig;
@ -50,6 +50,8 @@ public class GeyserBootstrap implements IGeyserBootstrap {
public void onEnable() {
geyserLogger = new GeyserLogger();
Util.checkLoopback(geyserLogger);
try {
File configFile = FileUtils.fileOrCopiedFromResource("config.yml", (x) -> x.replaceAll("generateduuid", UUID.randomUUID().toString()));
geyserConfig = FileUtils.loadConfig(configFile, GeyserConfiguration.class);

Datei anzeigen

@ -0,0 +1,44 @@
package org.geysermc.platform.standalone;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.OpenOption;
import java.nio.file.Paths;
import org.geysermc.platform.standalone.console.GeyserLogger;
public class Util {
private static final String checkExemption = "powershell -Command \"CheckNetIsolation LoopbackExempt -s\""; // Java's Exec feature runs as CMD, NetIsolation is only accessible from PowerShell.
private static final String loopbackCommand = "powershell -Command \"CheckNetIsolation LoopbackExempt -a -n='Microsoft.MinecraftUWP_8wekyb3d8bbwe'\"";
private static final String startScript = "powershell -Command \"Start-Process 'cmd' -ArgumentList /c,%temp%/loopback_minecraft.bat -Verb runAs\"";
public static void checkLoopback(GeyserLogger geyserLogger) {
if (System.getProperty("os.name").equalsIgnoreCase("Windows 10")) {
try {
Process process = Runtime.getRuntime().exec(checkExemption);
InputStream is = process.getInputStream();
StringBuilder sb = new StringBuilder();
while (process.isAlive()) {
if (is.available() != 0) {
sb.append((char) is.read());
}
}
String result = sb.toString();
if (!result.contains("minecraftuwp")) {
Files.write(Paths.get(System.getenv("temp") + "/loopback_minecraft.bat"), loopbackCommand.getBytes(), new OpenOption[0]);
process = Runtime.getRuntime().exec(startScript);
geyserLogger.warning("Added loopback exemption to Windows!");
}
} catch (Exception e) {
e.printStackTrace();
geyserLogger.error("Couldn't auto add loopback exemption to Windows!");
}
}
}
}