mirror of
https://github.com/JonasunderscoreJones/McWebserver.git
synced 2025-10-23 11:29:19 +02:00
fixed conflicts
This commit is contained in:
commit
00e872f8aa
4 changed files with 64 additions and 1 deletions
|
@ -19,6 +19,8 @@ public class ModConfigs {
|
||||||
public static Boolean ADV_API_ENABLED;
|
public static Boolean ADV_API_ENABLED;
|
||||||
public static Boolean API_INGAME_COMMAND_ENABLED;
|
public static Boolean API_INGAME_COMMAND_ENABLED;
|
||||||
public static String WEB_FILE_NOSUPPORT;
|
public static String WEB_FILE_NOSUPPORT;
|
||||||
|
|
||||||
|
public static Boolean PHP_ENABLED;
|
||||||
public static Boolean VERBOSE = false; //needs to be set to false since the verbose logger is called before config file is fully loaded
|
public static Boolean VERBOSE = false; //needs to be set to false since the verbose logger is called before config file is fully loaded
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +50,7 @@ public class ModConfigs {
|
||||||
config.addKeyValuePair(new Pair<>("web.api.cmd", true), "whether or not the ingame command to manage tokens should be enabled or not");
|
config.addKeyValuePair(new Pair<>("web.api.cmd", true), "whether or not the ingame command to manage tokens should be enabled or not");
|
||||||
config.addKeyValuePair(new Pair<>("web.file.notSupported", "not_supported.html"), "the name of the html file for 'not supported' page");
|
config.addKeyValuePair(new Pair<>("web.file.notSupported", "not_supported.html"), "the name of the html file for 'not supported' page");
|
||||||
config.addKeyValuePair(new Pair<>("logger.verbose", false), "whether or not to log verbose output");
|
config.addKeyValuePair(new Pair<>("logger.verbose", false), "whether or not to log verbose output");
|
||||||
|
config.addKeyValuePair(new Pair<>("web.php", false), "enable php");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void assignConfigs() {
|
private static void assignConfigs() {
|
||||||
|
@ -61,5 +64,6 @@ public class ModConfigs {
|
||||||
API_INGAME_COMMAND_ENABLED = CONFIG.getOrDefault("web.api.cmd", true);
|
API_INGAME_COMMAND_ENABLED = CONFIG.getOrDefault("web.api.cmd", true);
|
||||||
WEB_FILE_NOSUPPORT = CONFIG.getOrDefault("web.file.notSupported", "not_supported.html");
|
WEB_FILE_NOSUPPORT = CONFIG.getOrDefault("web.file.notSupported", "not_supported.html");
|
||||||
VERBOSE = CONFIG.getOrDefault("logger.verbose", true);
|
VERBOSE = CONFIG.getOrDefault("logger.verbose", true);
|
||||||
|
PHP_ENABLED = CONFIG.getOrDefault("web.php", false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package me.jonasjones.mcwebserver.mixin;
|
||||||
import me.jonasjones.mcwebserver.McWebserver;
|
import me.jonasjones.mcwebserver.McWebserver;
|
||||||
import me.jonasjones.mcwebserver.config.ModConfigs;
|
import me.jonasjones.mcwebserver.config.ModConfigs;
|
||||||
import me.jonasjones.mcwebserver.web.ServerHandler;
|
import me.jonasjones.mcwebserver.web.ServerHandler;
|
||||||
|
import me.jonasjones.mcwebserver.web.php.PhpServer;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
@ -16,5 +17,6 @@ public class WebserverStopMixin {
|
||||||
McWebserver.LOGGER.info("Stopping Webserver...");
|
McWebserver.LOGGER.info("Stopping Webserver...");
|
||||||
ModConfigs.VERBOSE = false;
|
ModConfigs.VERBOSE = false;
|
||||||
ServerHandler.mcserveractive = false;
|
ServerHandler.mcserveractive = false;
|
||||||
|
PhpServer.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package me.jonasjones.mcwebserver.web;
|
package me.jonasjones.mcwebserver.web;
|
||||||
|
|
||||||
import me.jonasjones.mcwebserver.config.ModConfigs;
|
import me.jonasjones.mcwebserver.config.ModConfigs;
|
||||||
|
import me.jonasjones.mcwebserver.web.php.PhpServer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
|
@ -75,11 +76,14 @@ public class ServerHandler implements Runnable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
if (ModConfigs.IS_ENABLED) {
|
if ((ModConfigs.IS_ENABLED && !ModConfigs.PHP_ENABLED)) {
|
||||||
LOGGER.info("Starting Webserver...");
|
LOGGER.info("Starting Webserver...");
|
||||||
|
|
||||||
new HttpServer(socket);
|
new HttpServer(socket);
|
||||||
HttpServer.main();
|
HttpServer.main();
|
||||||
|
} else if (ModConfigs.PHP_ENABLED) {
|
||||||
|
LOGGER.info("Starting php Webserver...");
|
||||||
|
PhpServer.main();
|
||||||
} else {
|
} else {
|
||||||
LOGGER.info("Webserver disabled in the config file.");
|
LOGGER.info("Webserver disabled in the config file.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
package me.jonasjones.mcwebserver.web.php;
|
||||||
|
|
||||||
|
import me.jonasjones.mcwebserver.McWebserver;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
import static me.jonasjones.mcwebserver.config.ModConfigs.WEB_PORT;
|
||||||
|
import static me.jonasjones.mcwebserver.config.ModConfigs.WEB_ROOT;
|
||||||
|
|
||||||
|
public class PhpServer {
|
||||||
|
private static Process process;
|
||||||
|
|
||||||
|
public static void main() {
|
||||||
|
try {
|
||||||
|
|
||||||
|
process = getProcess();
|
||||||
|
|
||||||
|
// Read the output
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null) {
|
||||||
|
McWebserver.VERBOSELOGGER.info(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
McWebserver.LOGGER.info("PHP server started!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
McWebserver.LOGGER.error("Error with PHP server: ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static Process getProcess() throws IOException {
|
||||||
|
|
||||||
|
// Build the command to start the PHP built-in web server
|
||||||
|
String command = String.format("php -S localhost:%d -t %s", WEB_PORT, WEB_ROOT);
|
||||||
|
|
||||||
|
// Start the process
|
||||||
|
ProcessBuilder processBuilder = new ProcessBuilder(command.split("\\s+"));
|
||||||
|
processBuilder.redirectErrorStream(true);
|
||||||
|
return processBuilder.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void stop() {
|
||||||
|
if (process == null || !process.isAlive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
process.destroy();
|
||||||
|
McWebserver.LOGGER.info("PHP server stopped!");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue