Added some of the configuration options. (not all yet)

This commit is contained in:
FrozenCow 2011-01-16 21:44:03 +01:00
parent 3aa48f2215
commit 9b8a90bf9f
6 changed files with 39 additions and 31 deletions

13
configuration.txt Normal file
View File

@ -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 }

View File

@ -21,9 +21,12 @@ public class DynmapPlugin extends JavaPlugin {
private MapManager mgr = null; private MapManager mgr = null;
private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this); private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this);
public static File dataRoot;
public DynmapPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) { public DynmapPlugin(PluginLoader pluginLoader, Server instance, PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
super(pluginLoader, instance, desc, folder, plugin, cLoader); super(pluginLoader, instance, desc, folder, plugin, cLoader);
dataRoot = folder;
} }
public World getWorld() { public World getWorld() {
@ -31,8 +34,6 @@ public class DynmapPlugin extends JavaPlugin {
} }
public void onEnable() { public void onEnable() {
if (!this.getDataFolder().isDirectory())
this.getDataFolder().mkdirs();
Configuration configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt")); Configuration configuration = new Configuration(new File(this.getDataFolder(), "configuration.txt"));
configuration.load(); configuration.load();
@ -41,7 +42,7 @@ public class DynmapPlugin extends JavaPlugin {
mgr.startManager(); mgr.startManager();
try { try {
server = new WebServer(mgr.serverport, mgr, getServer(), debugger, configuration); server = new WebServer(mgr, getServer(), debugger, configuration);
} catch(IOException e) { } catch(IOException e) {
log.info("position failed to start WebServer (IOException)"); log.info("position failed to start WebServer (IOException)");
} }

View File

@ -24,10 +24,10 @@ public class MapManager extends Thread {
private boolean running = false; private boolean running = false;
/* path to image tile directory */ /* path to image tile directory */
public String tilepath = "tiles/"; public File tileDirectory;
/* web files location */ /* web files location */
public String webPath; public File webDirectory;
/* bind web server to ip-address */ /* bind web server to ip-address */
public String bindaddress = "0.0.0.0"; public String bindaddress = "0.0.0.0";
@ -48,24 +48,19 @@ public class MapManager extends Thread {
this.world = world; this.world = world;
this.debugger = debugger; this.debugger = debugger;
this.staleQueue = new StaleQueue(); this.staleQueue = new StaleQueue();
File tilepathFile = new File(tilepath); tileDirectory = new File(DynmapPlugin.dataRoot, configuration.getString("tilespath", "web/tiles"));
if (!tilepathFile.isDirectory()) webDirectory = new File(DynmapPlugin.dataRoot, configuration.getString("webpath", "web"));
tilepathFile.mkdirs(); renderWait = (int)(configuration.getDouble("renderinterval", 0.5) * 1000);
serverport = 8123;
bindaddress = "0.0.0.0";
//webPath = "/srv/http/dynmap/";
webPath = "[JAR]";
if (!tileDirectory.isDirectory())
tileDirectory.mkdirs();
map = new KzedMap(this, world, debugger, configuration); map = new KzedMap(this, world, debugger, configuration);
} }
/* initialize and start map manager */ /* initialize and start map manager */
public void startManager() public void startManager()
{ {
synchronized(lock) { synchronized(lock) {
running = true; running = true;
this.start(); this.start();

View File

@ -23,15 +23,19 @@ public class WebServer extends Thread {
private MapManager mgr; private MapManager mgr;
private Server server; 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.mgr = mgr;
this.server = server; this.server = server;
this.debugger = debugger; 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; running = true;
start(); start();
log.info("map WebServer started on port " + port); debugger.debug("WebServer started on " + bindAddress + ":" + port);
} }
public void run() public void run()

View File

@ -74,13 +74,9 @@ public class WebServerRequest extends Thread {
if (path.startsWith("/up/")) { if (path.startsWith("/up/")) {
handleUp(out, path.substring(3)); handleUp(out, path.substring(3));
} else if (path.startsWith("/tiles/")) { } else if (path.startsWith("/tiles/")) {
handleMapToDirectory(out, path.substring(6), mgr.tilepath); handleMapToDirectory(out, path.substring(6), mgr.tileDirectory);
} else if (path.startsWith("/")) { } else if (path.startsWith("/")) {
if(mgr.webPath.equals("[JAR]")) { handleMapToDirectory(out, path, mgr.webDirectory);
handleMapToJar(out, path);
} else if(mgr.webPath.length() > 0) {
handleMapToDirectory(out, path, mgr.webPath);
}
} }
out.flush(); out.flush();
out.close(); out.close();
@ -188,13 +184,12 @@ public class WebServerRequest extends Thread {
writeEndOfHeaders(out); 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); path = getFilePath(path);
if (path != null) { if (path != null) {
File tilesDirectory = new File(directoryPath); File tileFile = new File(directory, path);
File tileFile = new File(tilesDirectory, path);
if (tileFile.getAbsolutePath().startsWith(tilesDirectory.getAbsolutePath()) && tileFile.isFile()) { if (tileFile.getAbsolutePath().startsWith(directory.getAbsolutePath()) && tileFile.isFile()) {
FileInputStream s = new FileInputStream(tileFile); FileInputStream s = new FileInputStream(tileFile);
writeFile(out, path, s); writeFile(out, path, s);
return; return;

View File

@ -88,9 +88,9 @@ public class KzedMap extends MapType {
@Override @Override
public void render(MapTile tile) { public void render(MapTile tile) {
if (tile instanceof KzedZoomedMapTile) { if (tile instanceof KzedZoomedMapTile) {
zoomrenderer.render((KzedZoomedMapTile)tile, getMapManager().tilepath); zoomrenderer.render((KzedZoomedMapTile)tile, getMapManager().tileDirectory.getAbsolutePath());
} else if (tile instanceof KzedMapTile) { } else if (tile instanceof KzedMapTile) {
((KzedMapTile)tile).renderer.render((KzedMapTile)tile, getMapManager().tilepath); ((KzedMapTile)tile).renderer.render((KzedMapTile)tile, getMapManager().tileDirectory.getAbsolutePath());
} }
} }