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 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)");
}

View File

@ -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();

View File

@ -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()

View File

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

View File

@ -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());
}
}