diff --git a/README.md b/README.md index 069c4a0..062148f 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,13 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex ### TODO * French translations * Change mod name to WD2 -* Put a limit on screen resolution * Auto-find rotation for BOTTOM & TOP screens ### Config elements -* Site blacklist -* minePad resolution -* Homepage * RPMP (Real pixels per Minecraft pixels) -* Browser language * Screen load/unload distance (max distance = 60.0) * Disable ownership thief item -* Disable hard recipes +* Put a limit on screen resolution ### Delayed things * Plugin API @@ -26,5 +21,6 @@ This is the unfinished port of the WebDisplays mod for Minecraft 1.12.2. The tex * CC Interface, if CC gets updated... * Center camera to screen when using keyboard * minePad management: check GuiContainer.draggedStack for minePad +* In-game command to add/remove blacklisted domains diff --git a/src/main/java/net/montoyo/wd/WebDisplays.java b/src/main/java/net/montoyo/wd/WebDisplays.java index 557ba73..91b2ac9 100644 --- a/src/main/java/net/montoyo/wd/WebDisplays.java +++ b/src/main/java/net/montoyo/wd/WebDisplays.java @@ -17,6 +17,8 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundCategory; import net.minecraft.util.SoundEvent; import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.world.WorldEvent; @@ -44,6 +46,8 @@ import net.montoyo.wd.utilities.Util; import java.io.*; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.net.MalformedURLException; +import java.net.URL; import java.util.Arrays; import java.util.Optional; import java.util.UUID; @@ -62,6 +66,7 @@ public class WebDisplays { public static SimpleNetworkWrapper NET_HANDLER; public static WDCreativeTab CREATIVE_TAB; public static final ResourceLocation ADV_PAD_BREAK = new ResourceLocation("webdisplays", "webdisplays/pad_break"); + public static final String BLACKLIST_URL = "mod://webdisplays/blacklisted.html"; //Blocks public BlockScreen blockScreen; @@ -93,15 +98,34 @@ public class WebDisplays { //Config public static final double PAD_RATIO = 59.0 / 30.0; - public String homePage = "mod://webdisplays/main.html"; //TODO: Read from config + public String homePage; public double padResX; public double padResY; private int lastPadId = 0; public boolean doHardRecipe = true; private boolean hasOC; + private String[] blacklist; @Mod.EventHandler public void onPreInit(FMLPreInitializationEvent ev) { + //Load config + Configuration cfg = new Configuration(ev.getSuggestedConfigurationFile()); + cfg.load(); + Property blacklist = cfg.get("main", "blacklist", new String[0]); + Property padHeight = cfg.get("main", "padHeight", 480); + Property hardRecipe = cfg.get("main", "hardRecipes", true); + Property homePage = cfg.get("main", "homepage", "mod://webdisplays/main.html"); + + blacklist.setComment("An array of domain names you don't want to load."); + padHeight.setComment("The minePad Y resolution in pixels. padWidth = padHeight * " + PAD_RATIO); + hardRecipe.setComment("If true, breaking the minePad is required to craft upgrades."); + homePage.setComment("The URL that will be loaded each time you create a screen"); + cfg.save(); + + this.blacklist = blacklist.getStringList(); + this.doHardRecipe = hardRecipe.getBoolean(); + this.homePage = homePage.getString(); + CREATIVE_TAB = new WDCreativeTab(); //Criterions @@ -111,9 +135,8 @@ public class WebDisplays { criterionKeyboardCat = new Criterion("keyboard_cat"); registerTrigger(criterionPadBreak, criterionUpgradeScreen, criterionLinkPeripheral, criterionKeyboardCat); - //Read configuration TODO - final int padHeight = 480; - padResY = (double) padHeight; + //Read configuration + padResY = (double) padHeight.getInt(); padResX = padResY * PAD_RATIO; //Init blocks @@ -324,5 +347,18 @@ public class WebDisplays { return INSTANCE.hasOC; } + public static boolean isSiteBlacklisted(String url) { + try { + URL url2 = new URL(Util.addProtocol(url)); + return Arrays.stream(INSTANCE.blacklist).anyMatch(str -> str.equalsIgnoreCase(url2.getHost())); + } catch(MalformedURLException ex) { + return false; + } + } + + public static String applyBlacklist(String url) { + return isSiteBlacklisted(url) ? BLACKLIST_URL : url; + } + } diff --git a/src/main/java/net/montoyo/wd/client/ClientProxy.java b/src/main/java/net/montoyo/wd/client/ClientProxy.java index 8816342..13e7b61 100644 --- a/src/main/java/net/montoyo/wd/client/ClientProxy.java +++ b/src/main/java/net/montoyo/wd/client/ClientProxy.java @@ -74,7 +74,7 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi private long lastURLSent; private PadData(String url, int id) { - view = mcef.createBrowser(url); + view = mcef.createBrowser(WebDisplays.applyBlacklist(url)); view.resize((int) WebDisplays.INSTANCE.padResX, (int) WebDisplays.INSTANCE.padResY); isInHotbar = true; this.id = id; @@ -356,8 +356,13 @@ public class ClientProxy extends SharedProxy implements IResourceManagerReloadLi for(PadData pd: padList) { if(pd.view == browser && t - pd.lastURLSent >= 1000) { - pd.lastURLSent = t; //Avoid spamming the server with porn URLs - WebDisplays.NET_HANDLER.sendToServer(new SMessagePadCtrl(pd.id, url)); + if(WebDisplays.isSiteBlacklisted(url)) + pd.view.loadURL(WebDisplays.BLACKLIST_URL); + else { + pd.lastURLSent = t; //Avoid spamming the server with porn URLs + WebDisplays.NET_HANDLER.sendToServer(new SMessagePadCtrl(pd.id, url)); + } + break; } } diff --git a/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java b/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java index 0830aeb..ddbd2cc 100644 --- a/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java +++ b/src/main/java/net/montoyo/wd/client/gui/GuiSetURL2.java @@ -103,7 +103,7 @@ public class GuiSetURL2 extends WDScreen { ClientProxy.PadData pd = ((ClientProxy) WebDisplays.PROXY).getPadByID(held.getTagCompound().getInteger("PadID")); if(pd != null && pd.view != null) - pd.view.loadURL(url); + pd.view.loadURL(WebDisplays.applyBlacklist(url)); } } else WebDisplays.NET_HANDLER.sendToServer(SMessageScreenCtrl.setURL(tileEntity, screenSide, url, remoteLocation)); diff --git a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java index 1364133..a21bdb7 100644 --- a/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java +++ b/src/main/java/net/montoyo/wd/client/renderers/ScreenRenderer.java @@ -41,7 +41,7 @@ public class ScreenRenderer extends TileEntitySpecialRenderer for(int i = 0; i < te.screenCount(); i++) { TileEntityScreen.Screen scr = te.getScreen(i); if(scr.browser == null) { - scr.browser = ((ClientProxy) WebDisplays.PROXY).getMCEF().createBrowser(scr.url); + scr.browser = ((ClientProxy) WebDisplays.PROXY).getMCEF().createBrowser(WebDisplays.applyBlacklist(scr.url)); if(scr.rotation.isVertical) scr.browser.resize(scr.resolution.y, scr.resolution.x); diff --git a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java index 5c4d0d8..f245627 100644 --- a/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java +++ b/src/main/java/net/montoyo/wd/entity/TileEntityScreen.java @@ -322,6 +322,7 @@ public class TileEntityScreen extends TileEntity { return; } + url = WebDisplays.applyBlacklist(url); scr.url = url; scr.videoType = VideoType.getTypeFromURL(url); @@ -639,9 +640,14 @@ public class TileEntityScreen extends TileEntity { public void updateClientSideURL(IBrowser target, String url) { for(Screen scr: screens) { if(scr.browser == target) { - scr.url = url; //FIXME: This is an invalid fix for something that CANNOT be fixed - scr.videoType = VideoType.getTypeFromURL(url); + boolean blacklisted = WebDisplays.isSiteBlacklisted(url); + scr.url = blacklisted ? WebDisplays.BLACKLIST_URL : url; //FIXME: This is an invalid fix for something that CANNOT be fixed + scr.videoType = VideoType.getTypeFromURL(scr.url); ytVolume = Float.POSITIVE_INFINITY; //Force volume update + + if(blacklisted && scr.browser != null) + scr.browser.loadURL(WebDisplays.BLACKLIST_URL); + break; } } diff --git a/src/main/java/net/montoyo/wd/net/server/SMessagePadCtrl.java b/src/main/java/net/montoyo/wd/net/server/SMessagePadCtrl.java index 11ecc09..aac9333 100644 --- a/src/main/java/net/montoyo/wd/net/server/SMessagePadCtrl.java +++ b/src/main/java/net/montoyo/wd/net/server/SMessagePadCtrl.java @@ -52,14 +52,13 @@ public class SMessagePadCtrl implements IMessage, Runnable { if(url.isEmpty()) is.setTagCompound(null); //Shutdown else { - //TODO: Check if site is not blacklisted if(is.getTagCompound() == null) is.setTagCompound(new NBTTagCompound()); if(!is.getTagCompound().hasKey("PadID")) is.getTagCompound().setInteger("PadID", WebDisplays.getNextAvailablePadID()); - is.getTagCompound().setString("PadURL", url); + is.getTagCompound().setString("PadURL", WebDisplays.applyBlacklist(url)); } } } else { @@ -77,7 +76,7 @@ public class SMessagePadCtrl implements IMessage, Runnable { target = player.inventory.offHandInventory.get(0); if(target != null) - target.getTagCompound().setString("PadURL", url); + target.getTagCompound().setString("PadURL", WebDisplays.applyBlacklist(url)); } } diff --git a/src/main/resources/assets/webdisplays/html/blacklisted.html b/src/main/resources/assets/webdisplays/html/blacklisted.html new file mode 100644 index 0000000..55a130e --- /dev/null +++ b/src/main/resources/assets/webdisplays/html/blacklisted.html @@ -0,0 +1,11 @@ + + + + + +

Blacklisted

+

+ This website has been blacklisted by either you or the server owner. +

+ +