mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-26 10:37:44 +01:00
Expanded internal webserver to also handle web and tiles, where web-files can be retrieved from filesystem or jar. Also some debugging changes.
This commit is contained in:
parent
b4fca31cd5
commit
6a7559f3ad
@ -11,7 +11,7 @@
|
|||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="compile" depends="init">
|
<target name="compile" depends="init">
|
||||||
<javac srcdir="${src}/main/java" destdir="${bin}" classpath="${bukkit.jar}" includeantruntime="false" />
|
<javac srcdir="${src}/main/java" destdir="${bin}" classpath="${bukkit.jar}" debug="on" includeantruntime="false" />
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="dist" depends="compile">
|
<target name="dist" depends="compile">
|
||||||
@ -19,6 +19,7 @@
|
|||||||
<jar jarfile="${dist}/${pluginname}.jar">
|
<jar jarfile="${dist}/${pluginname}.jar">
|
||||||
<fileset dir="${bin}"/>
|
<fileset dir="${bin}"/>
|
||||||
<fileset file="${src}/main/resources/plugin.yml"/>
|
<fileset file="${src}/main/resources/plugin.yml"/>
|
||||||
|
<zipfileset dir="web" prefix="web/"/>
|
||||||
</jar>
|
</jar>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
private WebServer server = null;
|
private WebServer server = null;
|
||||||
private MapManager mgr = null;
|
private MapManager mgr = null;
|
||||||
private DynmapBlockListener listener = null;
|
|
||||||
|
|
||||||
private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this);
|
private BukkitPlayerDebugger debugger = new BukkitPlayerDebugger(this);
|
||||||
|
|
||||||
@ -31,36 +30,33 @@ public class DynmapPlugin extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
log.info("Map INIT");
|
debugger.enable();
|
||||||
|
|
||||||
mgr = new MapManager(getWorld(), debugger);
|
mgr = new MapManager(getWorld(), debugger);
|
||||||
mgr.startManager();
|
mgr.startManager();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
server = new WebServer(mgr.serverport, mgr);
|
server = new WebServer(mgr.serverport, mgr, getServer(), debugger);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
log.info("position failed to start WebServer (IOException)");
|
log.info("position failed to start WebServer (IOException)");
|
||||||
}
|
}
|
||||||
|
|
||||||
listener = new DynmapBlockListener(mgr);
|
|
||||||
|
|
||||||
registerEvents();
|
registerEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
log.info("Map UNINIT");
|
|
||||||
|
|
||||||
mgr.stopManager();
|
mgr.stopManager();
|
||||||
|
|
||||||
if(server != null) {
|
if(server != null) {
|
||||||
server.shutdown();
|
server.shutdown();
|
||||||
server = null;
|
server = null;
|
||||||
}
|
}
|
||||||
|
debugger.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerEvents() {
|
public void registerEvents() {
|
||||||
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, listener, Priority.Normal, this);
|
getServer().getPluginManager().registerEvent(Event.Type.BLOCK_PLACED, new DynmapBlockListener(mgr), Priority.Normal, this);
|
||||||
|
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, new DynmapPlayerListener(mgr), Priority.Normal, this);
|
||||||
//getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DESTROYED, listener, Priority.Normal, this);
|
//getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DESTROYED, listener, Priority.Normal, this);
|
||||||
/* etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
|
/* etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.MEDIUM);
|
||||||
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this, PluginListener.Priority.MEDIUM);
|
etc.getLoader().addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this, PluginListener.Priority.MEDIUM);
|
||||||
|
@ -87,12 +87,12 @@ public class MapManager extends Thread {
|
|||||||
/* path to signs file */
|
/* path to signs file */
|
||||||
public String signspath = "signs.txt";
|
public String signspath = "signs.txt";
|
||||||
|
|
||||||
/* port to run web server on */
|
|
||||||
public int serverport = 8123;
|
|
||||||
|
|
||||||
/* 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";
|
||||||
|
|
||||||
|
/* port to run web server on */
|
||||||
|
public int serverport = 8123;
|
||||||
|
|
||||||
/* time to pause between rendering tiles (ms) */
|
/* time to pause between rendering tiles (ms) */
|
||||||
public int renderWait = 500;
|
public int renderWait = 500;
|
||||||
|
|
||||||
@ -114,6 +114,9 @@ public class MapManager extends Thread {
|
|||||||
/* zoomed-out tile cache */
|
/* zoomed-out tile cache */
|
||||||
public Cache<String, BufferedImage> zoomCache;
|
public Cache<String, BufferedImage> zoomCache;
|
||||||
|
|
||||||
|
/* web files location */
|
||||||
|
public String webPath;
|
||||||
|
|
||||||
public void debug(String msg)
|
public void debug(String msg)
|
||||||
{
|
{
|
||||||
debugger.debug(msg);
|
debugger.debug(msg);
|
||||||
@ -129,6 +132,8 @@ public class MapManager extends Thread {
|
|||||||
signspath = "signs.txt";
|
signspath = "signs.txt";
|
||||||
serverport = 8123;
|
serverport = 8123;
|
||||||
bindaddress = "0.0.0.0";
|
bindaddress = "0.0.0.0";
|
||||||
|
//webPath = "/srv/http/dynmap/";
|
||||||
|
webPath = "[JAR]";
|
||||||
|
|
||||||
tileStore = new HashMap<Long, MapTile>();
|
tileStore = new HashMap<Long, MapTile>();
|
||||||
staleTiles = new LinkedList<MapTile>();
|
staleTiles = new LinkedList<MapTile>();
|
||||||
@ -138,8 +143,8 @@ public class MapManager extends Thread {
|
|||||||
colors = loadColorSet(colorsetpath);
|
colors = loadColorSet(colorsetpath);
|
||||||
|
|
||||||
renderer = new CombinedTileRenderer(new MapTileRenderer[] {
|
renderer = new CombinedTileRenderer(new MapTileRenderer[] {
|
||||||
new DayTileRenderer(colors, tilepath + "t_{X}_{Y}.png"),
|
new DayTileRenderer(debugger, colors, tilepath + "t_{X}_{Y}.png"),
|
||||||
new CaveTileRenderer(colors, tilepath + "ct_{X}_{Y}.png")
|
new CaveTileRenderer(debugger, colors, tilepath + "ct_{X}_{Y}.png")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,6 +241,7 @@ public class MapManager extends Thread {
|
|||||||
|
|
||||||
MapTile t = this.popStaleTile();
|
MapTile t = this.popStaleTile();
|
||||||
if(t != null) {
|
if(t != null) {
|
||||||
|
debugger.debug("rendering tile " + t + "...");
|
||||||
renderer.render(t);
|
renderer.render(t);
|
||||||
|
|
||||||
updateUpdates(t, tileUpdates);
|
updateUpdates(t, tileUpdates);
|
||||||
@ -262,6 +268,8 @@ public class MapManager extends Thread {
|
|||||||
/* "touch" a block - its map tile will be regenerated */
|
/* "touch" a block - its map tile will be regenerated */
|
||||||
public boolean touch(int x, int y, int z)
|
public boolean touch(int x, int y, int z)
|
||||||
{
|
{
|
||||||
|
debugger.debug("touched: " + x + "," + y + "," + z);
|
||||||
|
|
||||||
int dx = x - anchorx;
|
int dx = x - anchorx;
|
||||||
int dy = y - anchory;
|
int dy = y - anchory;
|
||||||
int dz = z - anchorz;
|
int dz = z - anchorz;
|
||||||
|
@ -81,7 +81,7 @@ public class MapTile {
|
|||||||
/* check if all relevant chunks are loaded */
|
/* check if all relevant chunks are loaded */
|
||||||
public boolean isMapLoaded()
|
public boolean isMapLoaded()
|
||||||
{
|
{
|
||||||
int x1 = mx - 64;
|
int x1 = mx - MapManager.tileHeight / 2;
|
||||||
int x2 = mx + MapManager.tileWidth / 2 + MapManager.tileHeight / 2;
|
int x2 = mx + MapManager.tileWidth / 2 + MapManager.tileHeight / 2;
|
||||||
|
|
||||||
int z1 = mz - MapManager.tileHeight / 2;
|
int z1 = mz - MapManager.tileHeight / 2;
|
||||||
|
@ -4,6 +4,7 @@ import java.io.*;
|
|||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
import org.dynmap.debug.Debugger;
|
||||||
|
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -12,14 +13,19 @@ public class WebServer extends Thread {
|
|||||||
public static final String VERSION = "Huncraft";
|
public static final String VERSION = "Huncraft";
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
|
private Debugger debugger;
|
||||||
|
|
||||||
private ServerSocket sock = null;
|
private ServerSocket sock = null;
|
||||||
private boolean running = false;
|
private boolean running = false;
|
||||||
|
|
||||||
private MapManager mgr;
|
private MapManager mgr;
|
||||||
|
private Server server;
|
||||||
|
|
||||||
public WebServer(int port, MapManager mgr) throws IOException
|
public WebServer(int port, MapManager mgr, Server server, Debugger debugger) throws IOException
|
||||||
{
|
{
|
||||||
this.mgr = mgr;
|
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));
|
sock = new ServerSocket(port, 5, mgr.bindaddress.equals("0.0.0.0") ? null : InetAddress.getByName(mgr.bindaddress));
|
||||||
running = true;
|
running = true;
|
||||||
start();
|
start();
|
||||||
@ -31,7 +37,7 @@ public class WebServer extends Thread {
|
|||||||
while (running) {
|
while (running) {
|
||||||
try {
|
try {
|
||||||
Socket socket = sock.accept();
|
Socket socket = sock.accept();
|
||||||
WebServerRequest requestThread = new WebServerRequest(socket, mgr);
|
WebServerRequest requestThread = new WebServerRequest(socket, mgr, server, debugger);
|
||||||
requestThread.start();
|
requestThread.start();
|
||||||
}
|
}
|
||||||
catch (IOException e) {
|
catch (IOException e) {
|
||||||
|
@ -2,97 +2,85 @@ package org.dynmap;
|
|||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.*;
|
import org.bukkit.*;
|
||||||
|
import org.dynmap.debug.Debugger;
|
||||||
|
|
||||||
public class WebServerRequest extends Thread {
|
public class WebServerRequest extends Thread {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
private Socket sock;
|
private Debugger debugger;
|
||||||
|
private Socket socket;
|
||||||
private MapManager mgr;
|
private MapManager mgr;
|
||||||
private DynmapPlugin etc;
|
private Server server;
|
||||||
|
|
||||||
public WebServerRequest(Socket socket, MapManager mgr)
|
public WebServerRequest(Socket socket, MapManager mgr, Server server, Debugger debugger)
|
||||||
{
|
{
|
||||||
sock = socket;
|
this.debugger = debugger;
|
||||||
|
this.socket = socket;
|
||||||
this.mgr = mgr;
|
this.mgr = mgr;
|
||||||
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendHeader(BufferedOutputStream out, int code, String contentType, long contentLength, long lastModified) throws IOException
|
private static void writeHttpHeader(BufferedOutputStream out, int statusCode, String statusText) throws IOException {
|
||||||
{
|
out.write("HTTP/1.0 ".getBytes());
|
||||||
out.write(("HTTP/1.0 " + code + " OK\r\n" +
|
out.write(Integer.toString(statusCode).getBytes());
|
||||||
"Date: " + new Date().toString() + "\r\n" +
|
out.write((" " + statusText + "\r\n").getBytes());
|
||||||
"Server: JibbleWebServer/1.0\r\n" +
|
|
||||||
"Content-Type: " + contentType + "\r\n" +
|
|
||||||
"Expires: Thu, 01 Dec 1994 16:00:00 GMT\r\n" +
|
|
||||||
((contentLength != -1) ? "Content-Length: " + contentLength + "\r\n" : "") +
|
|
||||||
"Last-modified: " + new Date(lastModified).toString() + "\r\n" +
|
|
||||||
"\r\n").getBytes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendError(BufferedOutputStream out, int code, String message) throws IOException
|
private static void writeHeaderField(BufferedOutputStream out, String name, String value) throws IOException {
|
||||||
{
|
out.write(name.getBytes());
|
||||||
message = message + "<hr>" + WebServer.VERSION;
|
out.write((int)':');
|
||||||
sendHeader(out, code, "text/html", message.length(), System.currentTimeMillis());
|
out.write((int)' ');
|
||||||
out.write(message.getBytes());
|
out.write(value.getBytes());
|
||||||
out.flush();
|
out.write(13);
|
||||||
out.close();
|
out.write(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void writeEndOfHeaders(BufferedOutputStream out) throws IOException {
|
||||||
|
out.write(13);
|
||||||
|
out.write(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
InputStream reader = null;
|
InputStream reader = null;
|
||||||
try {
|
try {
|
||||||
sock.setSoTimeout(30000);
|
socket.setSoTimeout(30000);
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
|
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
|
||||||
BufferedOutputStream out = new BufferedOutputStream(sock.getOutputStream());
|
BufferedOutputStream out = new BufferedOutputStream(socket.getOutputStream());
|
||||||
|
|
||||||
String request = in.readLine();
|
String request = in.readLine();
|
||||||
if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) {
|
if (request == null || !request.startsWith("GET ") || !(request.endsWith(" HTTP/1.0") || request.endsWith("HTTP/1.1"))) {
|
||||||
// Invalid request type (no "GET")
|
// Invalid request type (no "GET")
|
||||||
sendError(out, 500, "Invalid Method.");
|
writeHttpHeader(out, 500, "Invalid Method.");
|
||||||
|
writeEndOfHeaders(out);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String path = request.substring(4, request.length() - 9);
|
String path = request.substring(4, request.length() - 9);
|
||||||
|
debugger.debug("request: " + path);
|
||||||
int current = (int) (System.currentTimeMillis() / 1000);
|
if (path.startsWith("/up/")) {
|
||||||
long cutoff = 0;
|
handleUp(out, path.substring(3));
|
||||||
|
} else if (path.startsWith("/tiles/")) {
|
||||||
if(path.charAt(0) == '/') {
|
handleMapToDirectory(out, path.substring(6), "/srv/http/dynmap/tiles/");
|
||||||
try {
|
} else if (path.startsWith("/")) {
|
||||||
cutoff = ((long) Integer.parseInt(path.substring(1))) * 1000;
|
if(mgr.webPath.equals("[JAR]")) {
|
||||||
} catch(NumberFormatException e) {
|
handleMapToJar(out, path);
|
||||||
|
} else if(mgr.webPath.length() > 0) {
|
||||||
|
handleMapToDirectory(out, path, mgr.webPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sendHeader(out, 200, "text/plain", -1, System.currentTimeMillis());
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
|
|
||||||
long relativeTime = etc.getServer().getTime() % 24000;
|
|
||||||
sb.append(current + " " + relativeTime + "\n");
|
|
||||||
|
|
||||||
for(Player player : etc.getServer().getOnlinePlayers()) {
|
|
||||||
sb.append(player.getName() + " player " + player.getLocation().getX() + " " + player.getLocation().getY() + " " + player.getLocation().getZ() + "\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
synchronized(mgr.lock) {
|
|
||||||
for(TileUpdate tu : mgr.tileUpdates) {
|
|
||||||
if(tu.at >= cutoff) {
|
|
||||||
sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " t\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out.write(sb.toString().getBytes());
|
|
||||||
|
|
||||||
out.flush();
|
out.flush();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
@ -107,4 +95,123 @@ public class WebServerRequest extends Thread {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleUp(BufferedOutputStream out, String path) throws IOException {
|
||||||
|
int current = (int) (System.currentTimeMillis() / 1000);
|
||||||
|
long cutoff = 0;
|
||||||
|
|
||||||
|
if(path.charAt(0) == '/') {
|
||||||
|
try {
|
||||||
|
cutoff = ((long) Integer.parseInt(path.substring(1))) * 1000;
|
||||||
|
} catch(NumberFormatException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
long relativeTime = server.getTime() % 24000;
|
||||||
|
sb.append(current + " " + relativeTime + "\n");
|
||||||
|
|
||||||
|
for(Player player : server.getOnlinePlayers()) {
|
||||||
|
sb.append(player.getName() + " player " + player.getLocation().getX() + " " + player.getLocation().getY() + " " + player.getLocation().getZ() + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized(mgr.lock) {
|
||||||
|
for(TileUpdate tu : mgr.tileUpdates) {
|
||||||
|
if(tu.at >= cutoff) {
|
||||||
|
sb.append(tu.tile.px + "_" + tu.tile.py + " " + tu.tile.zpx + "_" + tu.tile.zpy + " t\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] bytes = sb.toString().getBytes();
|
||||||
|
|
||||||
|
String dateStr = new Date().toString();
|
||||||
|
writeHttpHeader(out, 200, "OK");
|
||||||
|
writeHeaderField(out, "Date", dateStr);
|
||||||
|
writeHeaderField(out, "Content-Type", "text/plain");
|
||||||
|
writeHeaderField(out, "Expires", "Thu, 01 Dec 1994 16:00:00 GMT");
|
||||||
|
writeHeaderField(out, "Last-modified", dateStr);
|
||||||
|
writeHeaderField(out, "Content-Length", Integer.toString(bytes.length));
|
||||||
|
writeEndOfHeaders(out);
|
||||||
|
out.write(bytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] readBuffer = new byte[40960];
|
||||||
|
|
||||||
|
public void writeFile(BufferedOutputStream out, String path, InputStream fileInput) throws IOException {
|
||||||
|
int dotindex = path.lastIndexOf('.');
|
||||||
|
String extension = null;
|
||||||
|
if (dotindex > 0) extension = path.substring(dotindex);
|
||||||
|
|
||||||
|
writeHttpHeader(out, 200, "OK");
|
||||||
|
writeHeaderField(out, "Content-Type", getMimeTypeFromExtension(extension));
|
||||||
|
writeHeaderField(out, "Connection", "close");
|
||||||
|
writeEndOfHeaders(out);
|
||||||
|
try {
|
||||||
|
int readBytes;
|
||||||
|
while((readBytes = fileInput.read(readBuffer)) > 0) {
|
||||||
|
out.write(readBuffer, 0, readBytes);
|
||||||
|
}
|
||||||
|
} catch(IOException e) {
|
||||||
|
fileInput.close();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
fileInput.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilePath(String path) {
|
||||||
|
int qmark = path.indexOf('?');
|
||||||
|
if (qmark >= 0) path = path.substring(0, qmark);
|
||||||
|
path = path.substring(1);
|
||||||
|
|
||||||
|
if (path.startsWith("/") || path.startsWith("."))
|
||||||
|
return null;
|
||||||
|
if (path.length() == 0) path = "index.html";
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleMapToJar(BufferedOutputStream out, String path) throws IOException {
|
||||||
|
path = getFilePath(path);
|
||||||
|
if (path != null) {
|
||||||
|
InputStream s = this.getClass().getResourceAsStream("/web/" + path);
|
||||||
|
if (s != null) {
|
||||||
|
writeFile(out, path, s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeHttpHeader(out, 404, "Not found");
|
||||||
|
writeEndOfHeaders(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void handleMapToDirectory(BufferedOutputStream out, String path, String directoryPath) throws IOException {
|
||||||
|
path = getFilePath(path);
|
||||||
|
if (path != null) {
|
||||||
|
File tilesDirectory = new File(directoryPath);
|
||||||
|
File tileFile = new File(tilesDirectory, path);
|
||||||
|
|
||||||
|
if (tileFile.getAbsolutePath().startsWith(tilesDirectory.getAbsolutePath()) && tileFile.isFile()) {
|
||||||
|
FileInputStream s = new FileInputStream(tileFile);
|
||||||
|
writeFile(out, path, s);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
writeHttpHeader(out, 404, "Not found");
|
||||||
|
writeEndOfHeaders(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Map<String, String> mimes = new HashMap<String, String>();
|
||||||
|
static {
|
||||||
|
mimes.put(".html", "text/html");
|
||||||
|
mimes.put(".htm", "text/html");
|
||||||
|
mimes.put(".js", "text/javascript");
|
||||||
|
mimes.put(".png", "image/png");
|
||||||
|
mimes.put(".css", "text/css");
|
||||||
|
mimes.put(".txt", "text/plain");
|
||||||
|
}
|
||||||
|
public static String getMimeTypeFromExtension(String extension) {
|
||||||
|
String m = mimes.get(extension);
|
||||||
|
if (m != null) return m;
|
||||||
|
return "application/octet-steam";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
package org.dynmap.debug;
|
package org.dynmap.debug;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import org.bukkit.Color;
|
||||||
import org.bukkit.Player;
|
import org.bukkit.Player;
|
||||||
import org.bukkit.event.Event;
|
import org.bukkit.event.Event;
|
||||||
import org.bukkit.event.Event.Priority;
|
import org.bukkit.event.Event.Priority;
|
||||||
@ -12,6 +15,10 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
public class BukkitPlayerDebugger implements Debugger {
|
public class BukkitPlayerDebugger implements Debugger {
|
||||||
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
||||||
|
|
||||||
|
private boolean isLogging = true;
|
||||||
|
|
||||||
private JavaPlugin plugin;
|
private JavaPlugin plugin;
|
||||||
private HashSet<Player> debugees = new HashSet<Player>();
|
private HashSet<Player> debugees = new HashSet<Player>();
|
||||||
private String debugCommand;
|
private String debugCommand;
|
||||||
@ -30,6 +37,7 @@ public class BukkitPlayerDebugger implements Debugger {
|
|||||||
public void enable() {
|
public void enable() {
|
||||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, new CommandListener(), Priority.Normal, plugin);
|
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, new CommandListener(), Priority.Normal, plugin);
|
||||||
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, new CommandListener(), Priority.Normal, plugin);
|
plugin.getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, new CommandListener(), Priority.Normal, plugin);
|
||||||
|
log.info("Debugger enabled, use: " + debugCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disable() {
|
public void disable() {
|
||||||
@ -48,12 +56,28 @@ public class BukkitPlayerDebugger implements Debugger {
|
|||||||
debugees.clear();
|
debugees.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void debug(String message) {
|
public void sendToDebuggees(String message) {
|
||||||
for (Player p : debugees) {
|
for (Player p : debugees) {
|
||||||
p.sendMessage(prepend + message);
|
p.sendMessage(prepend + message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void debug(String message) {
|
||||||
|
sendToDebuggees(message);
|
||||||
|
if (isLogging) log.info(prepend + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String message) {
|
||||||
|
sendToDebuggees(prepend + Color.RED + message);
|
||||||
|
if (isLogging) log.log(Level.SEVERE, prepend + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void error(String message, Throwable thrown) {
|
||||||
|
sendToDebuggees(prepend + Color.RED + message);
|
||||||
|
sendToDebuggees(thrown.toString());
|
||||||
|
if (isLogging) log.log(Level.SEVERE, prepend + message);
|
||||||
|
}
|
||||||
|
|
||||||
protected class CommandListener extends PlayerListener {
|
protected class CommandListener extends PlayerListener {
|
||||||
@Override
|
@Override
|
||||||
public void onPlayerCommand(PlayerChatEvent event) {
|
public void onPlayerCommand(PlayerChatEvent event) {
|
||||||
|
@ -2,4 +2,6 @@ package org.dynmap.debug;
|
|||||||
|
|
||||||
public interface Debugger {
|
public interface Debugger {
|
||||||
void debug(String message);
|
void debug(String message);
|
||||||
|
void error(String message);
|
||||||
|
void error(String message, Throwable thrown);
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,12 @@ import java.util.Map;
|
|||||||
|
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
|
import org.dynmap.debug.Debugger;
|
||||||
|
|
||||||
public class CaveTileRenderer extends DayTileRenderer {
|
public class CaveTileRenderer extends DayTileRenderer {
|
||||||
|
|
||||||
public CaveTileRenderer(Map<Integer, Color[]> colors, String outputPath) {
|
public CaveTileRenderer(Debugger debugger, Map<Integer, Color[]> colors, String outputPath) {
|
||||||
super(colors, outputPath);
|
super(debugger, colors, outputPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -16,16 +16,31 @@ import javax.imageio.ImageIO;
|
|||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.dynmap.MapManager;
|
import org.dynmap.MapManager;
|
||||||
import org.dynmap.MapTile;
|
import org.dynmap.MapTile;
|
||||||
|
import org.dynmap.debug.Debugger;
|
||||||
|
|
||||||
public class DayTileRenderer implements MapTileRenderer {
|
public class DayTileRenderer implements MapTileRenderer {
|
||||||
protected static final Logger log = Logger.getLogger("Minecraft");
|
protected Debugger debugger;
|
||||||
protected String outputPath;
|
protected String outputPath;
|
||||||
|
protected String outputZoomPath;
|
||||||
private Map<Integer, Color[]> colors;
|
private Map<Integer, Color[]> colors;
|
||||||
|
|
||||||
public DayTileRenderer(Map<Integer, Color[]> colors, String outputPath) {
|
public DayTileRenderer(Debugger debugger, Map<Integer, Color[]> colors, String outputPath) {
|
||||||
|
this(debugger, colors, outputPath, convertToZoomPath(outputPath));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DayTileRenderer(Debugger debugger, Map<Integer, Color[]> colors, String outputPath, String outputZoomPath) {
|
||||||
|
this.debugger = debugger;
|
||||||
this.colors = colors;
|
this.colors = colors;
|
||||||
this.outputPath = outputPath;
|
this.outputPath = outputPath;
|
||||||
|
this.outputZoomPath = outputZoomPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String convertToZoomPath(String outputPath) {
|
||||||
|
File outputFile = new File(outputPath);
|
||||||
|
String zoomFilename = "z" + outputFile.getName();
|
||||||
|
return new File(outputFile.getParentFile(), zoomFilename).getPath();
|
||||||
|
}
|
||||||
|
|
||||||
public void render(MapTile tile) {
|
public void render(MapTile tile) {
|
||||||
World world = tile.getWorld();
|
World world = tile.getWorld();
|
||||||
BufferedImage im = new BufferedImage(MapManager.tileWidth, MapManager.tileHeight, BufferedImage.TYPE_INT_RGB);
|
BufferedImage im = new BufferedImage(MapManager.tileWidth, MapManager.tileHeight, BufferedImage.TYPE_INT_RGB);
|
||||||
@ -142,14 +157,17 @@ public class DayTileRenderer implements MapTileRenderer {
|
|||||||
String tilePath = outputPath
|
String tilePath = outputPath
|
||||||
.replace("{X}", Integer.toString(tile.px))
|
.replace("{X}", Integer.toString(tile.px))
|
||||||
.replace("{Y}", Integer.toString(tile.py));
|
.replace("{Y}", Integer.toString(tile.py));
|
||||||
|
|
||||||
|
debugger.debug("saving tile " + tilePath);
|
||||||
|
|
||||||
/* save image */
|
/* save image */
|
||||||
try {
|
try {
|
||||||
File file = new File(tilePath);
|
File file = new File(tilePath);
|
||||||
ImageIO.write(im, "png", file);
|
ImageIO.write(im, "png", file);
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
log.log(Level.SEVERE, "Failed to save tile: " + tilePath, e);
|
debugger.error("Failed to save tile: " + tilePath, e);
|
||||||
} catch(java.lang.NullPointerException e) {
|
} catch(java.lang.NullPointerException e) {
|
||||||
log.log(Level.SEVERE, "Failed to save tile (NullPointerException): " + tilePath, e);
|
debugger.error("Failed to save tile (NullPointerException): " + tilePath, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* now update zoom-out tile */
|
/* now update zoom-out tile */
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
name: Dynamic Map
|
name: dynmap
|
||||||
main: org.dynmap.DynmapPlugin
|
main: org.dynmap.DynmapPlugin
|
||||||
version: 0.1
|
version: 0.1
|
||||||
|
Loading…
Reference in New Issue
Block a user