-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix game running with patched lwjgl in offline mode even with xvfb, #208
- Loading branch information
1 parent
b9ef404
commit 5be1025
Showing
4 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
headlessmc-launcher/src/main/java/me/earth/headlessmc/launcher/launch/XvfbService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package me.earth.headlessmc.launcher.launch; | ||
|
||
import lombok.Cleanup; | ||
import lombok.CustomLog; | ||
import lombok.RequiredArgsConstructor; | ||
import me.earth.headlessmc.launcher.LauncherProperties; | ||
import me.earth.headlessmc.launcher.files.ConfigService; | ||
import me.earth.headlessmc.launcher.os.OS; | ||
import me.earth.headlessmc.launcher.util.IOUtil; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
@CustomLog | ||
@RequiredArgsConstructor | ||
public class XvfbService { | ||
private final ConfigService configService; | ||
private final OS os; | ||
|
||
private boolean checked; | ||
private boolean runningWithXvfb; | ||
|
||
public boolean isRunningWithXvfb() { | ||
if (!checked) { | ||
try { | ||
runningWithXvfb = checkRunningWithXvfb(); | ||
} catch (IOException e) { | ||
log.error(e); | ||
} finally { | ||
checked = true; | ||
} | ||
} | ||
|
||
return runningWithXvfb; | ||
} | ||
|
||
private boolean checkRunningWithXvfb() throws IOException { | ||
if (os.getType() != OS.Type.LINUX || !configService.getConfig().get(LauncherProperties.CHECK_XVFB, false)) { | ||
return false; | ||
} | ||
|
||
Process process = new ProcessBuilder().command("ps", "aux").start(); | ||
@Cleanup | ||
BufferedReader reader = IOUtil.reader(process.getInputStream()); | ||
String output = IOUtil.read(reader); | ||
boolean result = output.toLowerCase(Locale.ENGLISH).contains("xvfb"); | ||
log.info(result ? "Running with xvfb" : "Not running with xvfb"); | ||
return result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters