Fix issue in previous builds and create ClientDebug client mod
This commit is contained in:
parent
e7dbec0a77
commit
0dd79c29f3
|
@ -0,0 +1,10 @@
|
||||||
|
package io.gitlab.jfronny.dynres;
|
||||||
|
|
||||||
|
import net.fabricmc.api.ClientModInitializer;
|
||||||
|
|
||||||
|
public class DebugClient implements ClientModInitializer {
|
||||||
|
@Override
|
||||||
|
public void onInitializeClient() {
|
||||||
|
Logger.l.info("[DynRes DebugClient] This mod is not needed on clients. All it does here is log additional info");
|
||||||
|
}
|
||||||
|
}
|
|
@ -14,8 +14,6 @@ import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.gui.FabricGuiEntry;
|
import net.fabricmc.loader.gui.FabricGuiEntry;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -26,7 +24,6 @@ public class DynRes implements DedicatedServerModInitializer {
|
||||||
static WebServer server;
|
static WebServer server;
|
||||||
public static File resFile;
|
public static File resFile;
|
||||||
public static Cfg cfg;
|
public static Cfg cfg;
|
||||||
public static Logger logger = LogManager.getLogger("DynRes");
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
|
AutoConfig.register(Cfg.class, JanksonConfigSerializer::new);
|
||||||
|
@ -44,7 +41,7 @@ public class DynRes implements DedicatedServerModInitializer {
|
||||||
server.close();
|
server.close();
|
||||||
server.join();
|
server.join();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
logger.error("Failed to stop web server", e);
|
Logger.l.error("Failed to stop web server", e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -64,14 +61,14 @@ public class DynRes implements DedicatedServerModInitializer {
|
||||||
restartServer();
|
restartServer();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
logger.error("Failed to run restart command", e);
|
Logger.l.error("Failed to run restart command", e);
|
||||||
context.getSource().sendError(new LiteralText(e.getMessage()));
|
context.getSource().sendError(new LiteralText(e.getMessage()));
|
||||||
}
|
}
|
||||||
return Command.SINGLE_SUCCESS;
|
return Command.SINGLE_SUCCESS;
|
||||||
})));
|
})));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DynRes.logger.error("DYNRES SHOULD NOT BE RUN ON INTERNAL SERVERS!");
|
Logger.l.error("DYNRES SHOULD NOT BE RUN ON INTERNAL SERVERS!");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package io.gitlab.jfronny.dynres;
|
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager;
|
||||||
|
|
||||||
|
public class Logger {
|
||||||
|
public static final org.apache.logging.log4j.Logger l = LogManager.getLogger("DynRes");
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package io.gitlab.jfronny.dynres.mixin;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.dynres.DynRes;
|
||||||
|
import io.gitlab.jfronny.dynres.Logger;
|
||||||
|
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||||
|
import net.minecraft.network.packet.c2s.play.ResourcePackStatusC2SPacket;
|
||||||
|
import net.minecraft.network.packet.s2c.play.ResourcePackSendS2CPacket;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(ClientPlayNetworkHandler.class)
|
||||||
|
public class ClientPlayNetworkHandlerMixin {
|
||||||
|
@Inject(at = @At("HEAD"), method = "sendResourcePackStatus(Lnet/minecraft/network/packet/c2s/play/ResourcePackStatusC2SPacket$Status;)V")
|
||||||
|
public void logSentResourcePackStatus(ResourcePackStatusC2SPacket.Status packStatus, CallbackInfo info) {
|
||||||
|
Logger.l.info("[SEND] ResourcePackStatus=" + packStatus);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("HEAD"), method = "onResourcePackSend(Lnet/minecraft/network/packet/s2c/play/ResourcePackSendS2CPacket;)V")
|
||||||
|
public void logResourcePackStatus(ResourcePackSendS2CPacket status, CallbackInfo info) {
|
||||||
|
Logger.l.info("[RECEIVE] ResourcePackUrl=" + status.getURL());
|
||||||
|
Logger.l.info("[RECEIVE] ResourcePackSha1=" + status.getSHA1());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(at = @At("RETURN"), method = "validateResourcePackUrl(Ljava/lang/String;)Z")
|
||||||
|
public void logUrlValid(String url, CallbackInfoReturnable<Boolean> info) {
|
||||||
|
Logger.l.info("[CHECK] ResourcePackUrlValid=" + info.getReturnValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,20 @@
|
||||||
|
package io.gitlab.jfronny.dynres.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Overwrite;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(MinecraftServer.class)
|
||||||
|
public class MinecraftServerMixin {
|
||||||
|
/**
|
||||||
|
* @author JFronny
|
||||||
|
* @reason loadWorldResourcePack overrides the custom resource pack link which would cause this mod to break
|
||||||
|
*/
|
||||||
|
@Overwrite
|
||||||
|
public void loadWorldResourcePack() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package io.gitlab.jfronny.dynres.mixin;
|
||||||
|
|
||||||
|
import io.gitlab.jfronny.dynres.Logger;
|
||||||
|
import net.minecraft.client.network.ServerInfo;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@Mixin(ServerInfo.class)
|
||||||
|
public class ServerInfoMixin {
|
||||||
|
@Inject(at = @At("RETURN"), method = "getResourcePack()Lnet/minecraft/client/network/ServerInfo$ResourcePackState;")
|
||||||
|
public void getResPackState(CallbackInfoReturnable<ServerInfo.ResourcePackState> info) {
|
||||||
|
Logger.l.info("[RECEIVE] ResourcePackStatus=" + info.getReturnValue());
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
package io.gitlab.jfronny.dynres.mixin;
|
package io.gitlab.jfronny.dynres.mixin;
|
||||||
|
|
||||||
import io.gitlab.jfronny.dynres.DynRes;
|
import io.gitlab.jfronny.dynres.DynRes;
|
||||||
|
import io.gitlab.jfronny.dynres.Logger;
|
||||||
import io.gitlab.jfronny.dynres.ServerPropertiesHandlerExt;
|
import io.gitlab.jfronny.dynres.ServerPropertiesHandlerExt;
|
||||||
import net.minecraft.server.dedicated.ServerPropertiesHandler;
|
import net.minecraft.server.dedicated.ServerPropertiesHandler;
|
||||||
import net.minecraft.util.registry.DynamicRegistryManager;
|
import net.minecraft.util.registry.DynamicRegistryManager;
|
||||||
|
@ -24,9 +25,6 @@ public class ServerPropertiesHandlerMixin implements ServerPropertiesHandlerExt
|
||||||
|
|
||||||
@Shadow public String resourcePackSha1;
|
@Shadow public String resourcePackSha1;
|
||||||
|
|
||||||
private String resourcePackSha1Temp;
|
|
||||||
private String resourcePackTemp;
|
|
||||||
|
|
||||||
@Inject(at = @At("RETURN"), method = "<init>(Ljava/util/Properties;Lnet/minecraft/util/registry/DynamicRegistryManager;)V")
|
@Inject(at = @At("RETURN"), method = "<init>(Ljava/util/Properties;Lnet/minecraft/util/registry/DynamicRegistryManager;)V")
|
||||||
public void init(Properties properties, DynamicRegistryManager dynamicRegistryManager, CallbackInfo info) {
|
public void init(Properties properties, DynamicRegistryManager dynamicRegistryManager, CallbackInfo info) {
|
||||||
applyChanges(true);
|
applyChanges(true);
|
||||||
|
@ -36,25 +34,18 @@ public class ServerPropertiesHandlerMixin implements ServerPropertiesHandlerExt
|
||||||
public void applyChanges(boolean print) {
|
public void applyChanges(boolean print) {
|
||||||
resourcePack = DynRes.removePort(DynRes.simplifyElement(DynRes.cfg.baseLink)) + ":" + DynRes.getPort() + "/resources.zip";
|
resourcePack = DynRes.removePort(DynRes.simplifyElement(DynRes.cfg.baseLink)) + ":" + DynRes.getPort() + "/resources.zip";
|
||||||
if (print)
|
if (print)
|
||||||
DynRes.logger.info("Pack link: " + resourcePack);
|
Logger.l.info("Pack link: " + resourcePack);
|
||||||
if (!Objects.equals(resourcePackTemp, resourcePack)) {
|
resourcePackSha1 = "";
|
||||||
resourcePackTemp = resourcePack;
|
if (DynRes.cfg.hashResources) {
|
||||||
resourcePackSha1 = "";
|
try {
|
||||||
if (DynRes.cfg.hashResources) {
|
FileInputStream fs = new FileInputStream(DynRes.resFile);
|
||||||
try {
|
resourcePackSha1 = DigestUtils.sha1Hex(fs);
|
||||||
FileInputStream fs = new FileInputStream(DynRes.resFile);
|
if (print)
|
||||||
resourcePackSha1 = DigestUtils.sha1Hex(fs);
|
Logger.l.info("Set hash to " + resourcePackSha1);
|
||||||
if (print)
|
fs.close();
|
||||||
DynRes.logger.info("Set hash to " + resourcePackSha1);
|
} catch (IOException e) {
|
||||||
fs.close();
|
Logger.l.error("Failed to get hash, continuing with empty", e);
|
||||||
} catch (IOException e) {
|
|
||||||
DynRes.logger.error("Failed to get hash, continuing with empty", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
resourcePackSha1Temp = resourcePackSha1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
resourcePackSha1 = resourcePackSha1Temp;
|
|
||||||
}
|
}
|
||||||
resourcePackHash = resourcePackSha1;
|
resourcePackHash = resourcePackSha1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package io.gitlab.jfronny.dynres.web;
|
package io.gitlab.jfronny.dynres.web;
|
||||||
|
|
||||||
import io.gitlab.jfronny.dynres.DynRes;
|
import io.gitlab.jfronny.dynres.DynRes;
|
||||||
|
import io.gitlab.jfronny.dynres.Logger;
|
||||||
import io.gitlab.jfronny.dynres.web.bluemapcore.HttpRequest;
|
import io.gitlab.jfronny.dynres.web.bluemapcore.HttpRequest;
|
||||||
import io.gitlab.jfronny.dynres.web.bluemapcore.HttpRequestHandler;
|
import io.gitlab.jfronny.dynres.web.bluemapcore.HttpRequestHandler;
|
||||||
import io.gitlab.jfronny.dynres.web.bluemapcore.HttpResponse;
|
import io.gitlab.jfronny.dynres.web.bluemapcore.HttpResponse;
|
||||||
|
@ -17,10 +18,10 @@ public class RequestHandler implements HttpRequestHandler {
|
||||||
public HttpResponse handle(HttpRequest request) {
|
public HttpResponse handle(HttpRequest request) {
|
||||||
try {
|
try {
|
||||||
//TODO remove debug statement
|
//TODO remove debug statement
|
||||||
DynRes.logger.info("Got connection");
|
Logger.l.info("Got connection");
|
||||||
String method = request.getMethod().toUpperCase();
|
String method = request.getMethod().toUpperCase();
|
||||||
if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
|
if (!method.equals("GET") && !method.equals("HEAD") && !method.equals("POST")) {
|
||||||
DynRes.logger.error("Invalid method: " + method);
|
Logger.l.error("Invalid method: " + method);
|
||||||
HttpResponse resp = new HttpResponse(HttpStatusCode.BAD_REQUEST);
|
HttpResponse resp = new HttpResponse(HttpStatusCode.BAD_REQUEST);
|
||||||
resp.setData(method + " method not supported");
|
resp.setData(method + " method not supported");
|
||||||
return resp;
|
return resp;
|
||||||
|
@ -38,10 +39,10 @@ public class RequestHandler implements HttpRequestHandler {
|
||||||
resp.setData(fs);
|
resp.setData(fs);
|
||||||
return resp;
|
return resp;
|
||||||
}
|
}
|
||||||
DynRes.logger.error("An invalid file was requested: " + path);
|
Logger.l.error("An invalid file was requested: " + path);
|
||||||
return new HttpResponse(HttpStatusCode.NOT_FOUND);
|
return new HttpResponse(HttpStatusCode.NOT_FOUND);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
DynRes.logger.error("Cough error while sending", e);
|
Logger.l.error("Cough error while sending", e);
|
||||||
return new HttpResponse(HttpStatusCode.INTERNAL_SERVER_ERROR);
|
return new HttpResponse(HttpStatusCode.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
package io.gitlab.jfronny.dynres.web.bluemapcore;
|
package io.gitlab.jfronny.dynres.web.bluemapcore;
|
||||||
|
|
||||||
import io.gitlab.jfronny.dynres.DynRes;
|
import io.gitlab.jfronny.dynres.DynRes;
|
||||||
|
import io.gitlab.jfronny.dynres.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -78,7 +79,7 @@ public class HttpConnection implements Runnable {
|
||||||
} catch (ConnectionClosedException e){
|
} catch (ConnectionClosedException e){
|
||||||
break;
|
break;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
DynRes.logger.error("Unexpected error while processing a HttpRequest!", e);
|
Logger.l.error("Unexpected error while processing a HttpRequest!", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +87,7 @@ public class HttpConnection implements Runnable {
|
||||||
try {
|
try {
|
||||||
close();
|
close();
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
DynRes.logger.error("Error while closing HttpConnection!", e);
|
Logger.l.error("Error while closing HttpConnection!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
package io.gitlab.jfronny.dynres.web.bluemapcore;
|
package io.gitlab.jfronny.dynres.web.bluemapcore;
|
||||||
|
|
||||||
import io.gitlab.jfronny.dynres.DynRes;
|
import io.gitlab.jfronny.dynres.DynRes;
|
||||||
|
import io.gitlab.jfronny.dynres.Logger;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
@ -69,11 +70,11 @@ public class WebServer extends Thread {
|
||||||
server = new ServerSocket(port, maxConnections, bindAdress);
|
server = new ServerSocket(port, maxConnections, bindAdress);
|
||||||
server.setSoTimeout(0);
|
server.setSoTimeout(0);
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
DynRes.logger.error("Error while starting the WebServer!", e);
|
Logger.l.error("Error while starting the WebServer!", e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DynRes.logger.info("WebServer started.");
|
Logger.l.info("WebServer started.");
|
||||||
|
|
||||||
while (!server.isClosed() && server.isBound()){
|
while (!server.isClosed() && server.isBound()){
|
||||||
|
|
||||||
|
@ -84,18 +85,18 @@ public class WebServer extends Thread {
|
||||||
connectionThreads.execute(new HttpConnection(server, connection, handler, 10, TimeUnit.SECONDS));
|
connectionThreads.execute(new HttpConnection(server, connection, handler, 10, TimeUnit.SECONDS));
|
||||||
} catch (RejectedExecutionException e){
|
} catch (RejectedExecutionException e){
|
||||||
connection.close();
|
connection.close();
|
||||||
DynRes.logger.error("Dropped an incoming HttpConnection! (Too many connections?)");
|
Logger.l.error("Dropped an incoming HttpConnection! (Too many connections?)");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (SocketException e){
|
} catch (SocketException e){
|
||||||
// this mainly occurs if the socket got closed, so we ignore this error
|
// this mainly occurs if the socket got closed, so we ignore this error
|
||||||
} catch (IOException e){
|
} catch (IOException e){
|
||||||
DynRes.logger.error("Error while creating a new HttpConnection!", e);
|
Logger.l.error("Error while creating a new HttpConnection!", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DynRes.logger.info("WebServer closed.");
|
Logger.l.info("WebServer closed.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
|
@ -118,7 +119,7 @@ public class WebServer extends Thread {
|
||||||
server.close();
|
server.close();
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
DynRes.logger.error("Error while closing WebServer!", e);
|
Logger.l.error("Error while closing WebServer!", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,17 @@
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "io.gitlab.jfronny.dynres.mixin",
|
"package": "io.gitlab.jfronny.dynres.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"client": [
|
||||||
|
"ClientPlayNetworkHandlerMixin",
|
||||||
|
"ServerInfoMixin"
|
||||||
],
|
],
|
||||||
"server": [
|
"server": [
|
||||||
"ServerPropertiesHandlerMixin"
|
"ServerPropertiesHandlerMixin",
|
||||||
|
"MinecraftServerMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
}
|
},
|
||||||
|
"mixins": [
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,13 @@
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"icon": "assets/dynres/icon.png",
|
"icon": "assets/dynres/icon.png",
|
||||||
"environment": "server",
|
"environment": "*",
|
||||||
"entrypoints": {
|
"entrypoints": {
|
||||||
"server": [
|
"server": [
|
||||||
"io.gitlab.jfronny.dynres.DynRes"
|
"io.gitlab.jfronny.dynres.DynRes"
|
||||||
|
],
|
||||||
|
"client": [
|
||||||
|
"io.gitlab.jfronny.dynres.DebugClient"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
|
Loading…
Reference in New Issue