Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-25 15:50:14 +01:00
Automatically add loopback exemption to Windows
Dieser Commit ist enthalten in:
Ursprung
bbf6683bd8
Commit
ac8d1bf295
@ -25,18 +25,18 @@
|
||||
|
||||
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;
|
||||
private GeyserLogger geyserLogger;
|
||||
|
||||
@ -49,7 +49,9 @@ public class GeyserBootstrap implements IGeyserBootstrap {
|
||||
@Override
|
||||
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);
|
||||
|
@ -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!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren