From 9b8a90bf9f66435d0c20889a6edeaa84769608bf Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Sun, 16 Jan 2011 21:44:03 +0100 Subject: [PATCH] Added some of the configuration options. (not all yet) --- configuration.txt | 13 ++++++++++++ src/main/java/org/dynmap/DynmapPlugin.java | 7 ++++--- src/main/java/org/dynmap/MapManager.java | 21 +++++++------------ src/main/java/org/dynmap/WebServer.java | 10 ++++++--- .../java/org/dynmap/WebServerRequest.java | 15 +++++-------- src/main/java/org/dynmap/kzedmap/KzedMap.java | 4 ++-- 6 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 configuration.txt diff --git a/configuration.txt b/configuration.txt new file mode 100644 index 00000000..85f98e2b --- /dev/null +++ b/configuration.txt @@ -0,0 +1,13 @@ +renderinterval: 30 # How often a tile gets rendered (in seconds). +tilepath: web/tiles # The path where the tile-files are placed. +webpath: web # The path where the web-files are located. [JAR] to use the internal web-files supplied in the .jar-file. + +webserver: + address: 0.0.0.0 # The interface the webserver will bind to (0.0.0.0 is all interfaces). + port: 8123 # The port the webserver will listen on. +maps: + org.dynmap.kzedmap.KzedMap: + colorpath: [JAR] + renderers: + org.dynmap.kzedmap.DefaultTileRenderer: { prefix: t } + org.dynmap.kzedmap.CaveTileRenderer: { prefix: ct } \ No newline at end of file diff --git a/src/main/java/org/dynmap/DynmapPlugin.java b/src/main/java/org/dynmap/DynmapPlugin.java index e557c45c..cea07f50 100644 --- a/src/main/java/org/dynmap/DynmapPlugin.java +++ b/src/main/java/org/dynmap/DynmapPlugin.java @@ -21,9 +21,12 @@ public class DynmapPlugin extends JavaPlugin { private MapManager mgr = null; private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this); + + public static File dataRoot; public DynmapPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { super(pluginLoader, instance, desc, folder, plugin, cLoader); + dataRoot = folder; } public World getWorld() { @@ -31,8 +34,6 @@ public class DynmapPlugin extends JavaPlugin { } public void onEnable() { - if (!this.getDataFolder().isDirectory()) - this.getDataFolder().mkdirs(); Configuration configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt")); configuration.load(); @@ -41,7 +42,7 @@ public class DynmapPlugin extends JavaPlugin { mgr.startManager(); try { - server = new WebServer(mgr.serverport, mgr, getServer(), debugger, configuration); + server = new WebServer(mgr, getServer(), debugger, configuration); } catch(IOException e) { log.info("position failed to start WebServer (IOException)"); } diff --git a/src/main/java/org/dynmap/MapManager.java b/src/main/java/org/dynmap/MapManager.java index 2c67f0d8..2419c95d 100644 --- a/src/main/java/org/dynmap/MapManager.java +++ b/src/main/java/org/dynmap/MapManager.java @@ -24,10 +24,10 @@ public class MapManager extends Thread { private boolean running = false; /* path to image tile directory */ - public String tilepath = "tiles/"; + public File tileDirectory; /* web files location */ - public String webPath; + public File webDirectory; /* bind web server to ip-address */ public String bindaddress = "0.0.0.0"; @@ -48,24 +48,19 @@ public class MapManager extends Thread { this.world = world; this.debugger = debugger; this.staleQueue = new StaleQueue(); - - File tilepathFile = new File(tilepath); - if (!tilepathFile.isDirectory()) - tilepathFile.mkdirs(); - - - serverport = 8123; - bindaddress = "0.0.0.0"; - //webPath = "/srv/http/dynmap/"; - webPath = "[JAR]"; + tileDirectory = new File(DynmapPlugin.dataRoot, configuration.getString("tilespath", "web/tiles")); + webDirectory = new File(DynmapPlugin.dataRoot, configuration.getString("webpath", "web")); + renderWait = (int)(configuration.getDouble("renderinterval", 0.5) * 1000); + if (!tileDirectory.isDirectory()) + tileDirectory.mkdirs(); map = new KzedMap(this, world, debugger, configuration); } /* initialize and start map manager */ public void startManager() - { + { synchronized(lock) { running = true; this.start(); diff --git a/src/main/java/org/dynmap/WebServer.java b/src/main/java/org/dynmap/WebServer.java index 07e08df6..bb3b3abd 100644 --- a/src/main/java/org/dynmap/WebServer.java +++ b/src/main/java/org/dynmap/WebServer.java @@ -23,15 +23,19 @@ public class WebServer extends Thread { private MapManager mgr; private Server server; - public WebServer(int port, MapManager mgr, Server server, Debugger debugger, ConfigurationNode configuration) throws IOException + public WebServer(MapManager mgr, Server server, Debugger debugger, ConfigurationNode configuration) throws IOException { this.mgr = mgr; this.server = server; this.debugger = debugger; - sock = new ServerSocket(port, 5, mgr.bindaddress.equals("0.0.0.0") ? null : InetAddress.getByName(mgr.bindaddress)); + + String bindAddress = configuration.getString("webserver/bindaddress", "0.0.0.0"); + int port = configuration.getInt("webserver/port", 8123); + + sock = new ServerSocket(port, 5, bindAddress.equals("0.0.0.0") ? null : InetAddress.getByName(bindAddress)); running = true; start(); - log.info("map WebServer started on port " + port); + debugger.debug("WebServer started on " + bindAddress + ":" + port); } public void run() diff --git a/src/main/java/org/dynmap/WebServerRequest.java b/src/main/java/org/dynmap/WebServerRequest.java index 63bbbd08..a632e37d 100644 --- a/src/main/java/org/dynmap/WebServerRequest.java +++ b/src/main/java/org/dynmap/WebServerRequest.java @@ -74,13 +74,9 @@ public class WebServerRequest extends Thread { if (path.startsWith("/up/")) { handleUp(out, path.substring(3)); } else if (path.startsWith("/tiles/")) { - handleMapToDirectory(out, path.substring(6), mgr.tilepath); + handleMapToDirectory(out, path.substring(6), mgr.tileDirectory); } else if (path.startsWith("/")) { - if(mgr.webPath.equals("[JAR]")) { - handleMapToJar(out, path); - } else if(mgr.webPath.length() > 0) { - handleMapToDirectory(out, path, mgr.webPath); - } + handleMapToDirectory(out, path, mgr.webDirectory); } out.flush(); out.close(); @@ -188,13 +184,12 @@ public class WebServerRequest extends Thread { writeEndOfHeaders(out); } - public void handleMapToDirectory(BufferedOutputStream out, String path, String directoryPath) throws IOException { + public void handleMapToDirectory(BufferedOutputStream out, String path, File directory) throws IOException { path = getFilePath(path); if (path != null) { - File tilesDirectory = new File(directoryPath); - File tileFile = new File(tilesDirectory, path); + File tileFile = new File(directory, path); - if (tileFile.getAbsolutePath().startsWith(tilesDirectory.getAbsolutePath()) && tileFile.isFile()) { + if (tileFile.getAbsolutePath().startsWith(directory.getAbsolutePath()) && tileFile.isFile()) { FileInputStream s = new FileInputStream(tileFile); writeFile(out, path, s); return; diff --git a/src/main/java/org/dynmap/kzedmap/KzedMap.java b/src/main/java/org/dynmap/kzedmap/KzedMap.java index 2bb202dc..f925df6f 100644 --- a/src/main/java/org/dynmap/kzedmap/KzedMap.java +++ b/src/main/java/org/dynmap/kzedmap/KzedMap.java @@ -88,9 +88,9 @@ public class KzedMap extends MapType { @Override public void render(MapTile tile) { if (tile instanceof KzedZoomedMapTile) { - zoomrenderer.render((KzedZoomedMapTile)tile, getMapManager().tilepath); + zoomrenderer.render((KzedZoomedMapTile)tile, getMapManager().tileDirectory.getAbsolutePath()); } else if (tile instanceof KzedMapTile) { - ((KzedMapTile)tile).renderer.render((KzedMapTile)tile, getMapManager().tilepath); + ((KzedMapTile)tile).renderer.render((KzedMapTile)tile, getMapManager().tileDirectory.getAbsolutePath()); } }