diff --git a/DMFlatFileSource.java b/DMFlatFileSource.java new file mode 100644 index 00000000..9eb96eea --- /dev/null +++ b/DMFlatFileSource.java @@ -0,0 +1,13 @@ +/* FlatFileSource class wrapper to expose protected properties */ + +import java.util.List; + +public class DMFlatFileSource extends FlatFileSource { + public List getAllWarps() { + return this.warps; + } + + public List getAllHomes() { + return this.homes; + } +} diff --git a/DMMySQLSource.java b/DMMySQLSource.java new file mode 100644 index 00000000..86b9780f --- /dev/null +++ b/DMMySQLSource.java @@ -0,0 +1,13 @@ +/* MySQLSource class wrapper to expose protected properties */ + +import java.util.List; + +public class DMMySQLSource extends MySQLSource { + public List getAllWarps() { + return this.warps; + } + + public List getAllHomes() { + return this.homes; + } +} diff --git a/MapManager.java b/MapManager.java index a310f729..ebaeb411 100644 --- a/MapManager.java +++ b/MapManager.java @@ -1,11 +1,19 @@ +import java.awt.Color; +import java.awt.Graphics2D; +import java.util.List; +import java.awt.RenderingHints; +import java.awt.image.BufferedImage; +import java.awt.image.WritableRaster; +import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; import java.io.Writer; -import java.util.ArrayList; import java.util.Collection; +import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -14,17 +22,9 @@ import java.util.ListIterator; import java.util.NoSuchElementException; import java.util.Scanner; import java.util.Vector; -import java.util.Comparator; import java.util.logging.Level; import java.util.logging.Logger; -import java.awt.image.BufferedImage; - -import java.io.File; -import java.io.IOException; - -import java.awt.*; -import java.awt.image.*; import javax.imageio.ImageIO; public class MapManager extends Thread { @@ -66,7 +66,7 @@ public class MapManager extends Thread { public String tilepath = "tiles/"; /* path to markers file */ - public String markerpath = "markers.csv"; + public String markerpath = "markers.txt"; /* port to run web server on */ public int serverport = 8123; @@ -110,7 +110,7 @@ public class MapManager extends Thread { try { tilepath = properties.getString("map-tilepath", "tiles/"); colorsetpath = properties.getString("map-colorsetpath", "colors.txt"); - markerpath = properties.getString("map-markerpath", "markers.csv"); + markerpath = properties.getString("map-markerpath", "markers.txt"); serverport = Integer.parseInt(properties.getString("map-serverport", "8123")); } catch(Exception ex) { log.log(Level.SEVERE, "Exception while reading properties for dynamic map", ex); @@ -590,7 +590,7 @@ public class MapManager extends Thread { } catch(IOException e) { - log.log(Level.SEVERE, "Failed to save markers.csv", e); + log.log(Level.SEVERE, "Failed to save markers.txt", e); } return false; @@ -613,7 +613,7 @@ public class MapManager extends Thread { } catch(IOException e) { - log.log(Level.SEVERE, "Failed to save markers.csv", e); + log.log(Level.SEVERE, "Failed to save markers.txt", e); } } else @@ -656,14 +656,27 @@ public class MapManager extends Thread { while (scanner.hasNextLine()) { String line = scanner.nextLine(); - String[] values = line.split(","); - MapMarker marker = new MapMarker(); - marker.name = values[0]; - marker.owner = values[1]; - marker.px = Double.parseDouble(values[2]); - marker.py = Double.parseDouble(values[3]); - marker.pz = Double.parseDouble(values[4]); - markers.put(marker.name, marker); + String[] values = line.split(":"); + // If user has old style of file (CSV) + if (values.length != 5) + { + values = line.split(","); + } + + if (values.length == 5) + { + MapMarker marker = new MapMarker(); + marker.name = values[0]; + marker.owner = values[1]; + marker.px = Double.parseDouble(values[2]); + marker.py = Double.parseDouble(values[3]); + marker.pz = Double.parseDouble(values[4]); + markers.put(marker.name, marker); + } + else + { + log.log(Level.INFO, "Failed to load marker: " + values[0]); + } } } catch(FileNotFoundException e) @@ -688,7 +701,7 @@ public class MapManager extends Thread { while(it.hasNext()) { MapMarker marker = it.next(); - String line = marker.name + "," + marker.owner + "," + marker.px + "," + marker.py + "," + marker.pz + "\r\n"; + String line = marker.name + ":" + marker.owner + ":" + marker.px + ":" + marker.py + ":" + marker.pz + "\n"; out.write(line); } } @@ -698,7 +711,7 @@ public class MapManager extends Thread { } catch(FileNotFoundException e) { - log.log(Level.SEVERE, "markers.csv not found", e); + log.log(Level.SEVERE, "markers.txt not found", e); } finally { @@ -706,41 +719,53 @@ public class MapManager extends Thread { } } - /* load the warps file (doesn't work with SQL data source) */ - /* find a way to load this from the server itself, loading the file each time isn't good */ - public ArrayList loadWarps() + /* TODO: Is there a cleaner way to get warps/homes than using custom DataSource classes to expose the protected properties? */ + + protected List loadWarps() { - ArrayList warps = new ArrayList(); - Scanner scanner = null; - - try - { - scanner = new Scanner(new FileInputStream("warps.txt"), "UTF-8"); - while (scanner.hasNextLine()) - { - String line = scanner.nextLine(); - String[] values = line.split(":"); - Warp warp = new Warp(); - warp.Name = values[0]; - warp.Location = new Location( - Double.parseDouble(values[1]), - Double.parseDouble(values[2]), - Double.parseDouble(values[3]), - Float.parseFloat(values[4]), - Float.parseFloat(values[5]) - ); - warps.add(warp); - } - } - catch(FileNotFoundException e) - { + PropertiesFile props = new PropertiesFile("server.properties"); - } - finally - { - if (scanner != null) scanner.close(); - } - - return warps; + List warps = null; + + if (props.getString("data-source").equals("flatfile")) { + DMFlatFileSource dataSource = new DMFlatFileSource(); + dataSource.initialize(); + dataSource.loadWarps(); + dataSource.loadHomes(); + warps = dataSource.getAllWarps(); + } + else if (props.getString("data-source").equals("mysql")) { + DMMySQLSource dataSource = new DMMySQLSource(); + dataSource.initialize(); + dataSource.loadWarps(); + dataSource.loadHomes(); + warps = dataSource.getAllWarps(); + } + + return warps; + } + + protected List loadHomes() + { + PropertiesFile props = new PropertiesFile("server.properties"); + + List homes = null; + + if (props.getString("data-source").equals("flatfile")) { + DMFlatFileSource dataSource = new DMFlatFileSource(); + dataSource.initialize(); + dataSource.loadWarps(); + dataSource.loadHomes(); + homes = dataSource.getAllHomes(); + } + else if (props.getString("data-source").equals("mysql")) { + DMMySQLSource dataSource = new DMMySQLSource(); + dataSource.initialize(); + dataSource.loadWarps(); + dataSource.loadHomes(); + homes = dataSource.getAllHomes(); + } + + return homes; } } diff --git a/WebServerRequest.java b/WebServerRequest.java index fe52fd0c..464ad0b0 100644 --- a/WebServerRequest.java +++ b/WebServerRequest.java @@ -1,7 +1,11 @@ -import java.io.*; -import java.net.*; -import java.util.*; - +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.Socket; +import java.util.Date; +import java.util.List; import java.util.logging.Logger; public class WebServerRequest extends Thread { @@ -77,14 +81,25 @@ public class WebServerRequest extends Thread { sb.append(marker.name + " marker " + marker.owner + " " + marker.px + " " + marker.py + " " + marker.pz + "\n"); } - // TODO: Find a way to load the warps from the server. Currently loading the from the flatfile over and over... - ArrayList warps = mgr.loadWarps(); + List warps = mgr.loadWarps(); + List homes = mgr.loadHomes(); - for(Warp warp : warps) - { - sb.append(warp.Name + " warp unknown " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + Location spawnLocation = etc.getServer().getSpawnLocation(); + + if (warps != null) { + for(Warp warp : warps) { + sb.append(warp.Name + " warp unknown " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + } } + if (homes != null) { + for(Warp warp : homes) { + sb.append(warp.Name + " home " + warp.Name + " " + warp.Location.x + " " + warp.Location.y + " " + warp.Location.z + "\n"); + } + } + + sb.append("Spawn spawn none " + spawnLocation.x + " " + spawnLocation.y + " " + spawnLocation.z + "\n"); + synchronized(mgr.lock) { for(TileUpdate tu : mgr.tileUpdates) { if(tu.at >= cutoff) { diff --git a/build.bat b/build.bat index 2046edbf..2d1b70b3 100644 --- a/build.bat +++ b/build.bat @@ -1,9 +1,24 @@ @ECHO OFF -CD E:\Users\Fescen9\workspace\DynamicMap\branches\fescen9 -del *.class -del ..\..\..\map.jar +CD E:\Projects\DynamicMap\branches\fescen9 + +CALL clean.bat + +MKDIR plugins +MKDIR plugins\web +MKDIR plugins\web\tiles +MKDIR plugins\web\up + javac *.java -cp ..\..\..\Minecraft_Mod.jar;..\..\..\minecraft_server.jar -jar cvf ..\..\..\map.jar *.class +jar cvf plugins\map.jar *.class + + +COPY colors.txt .\plugins +COPY readme.txt .\plugins +COPY .\web\*.* .\plugins\web +COPY .\web\tiles\*.* .\plugins\web\tiles +COPY .\web\up\*.* .\plugins\web\up + +CALL "C:\Program Files\WinRAR\Rar.exe" a -m5 -ed -r DynamicMap.rar .\plugins\*.* PAUSE \ No newline at end of file diff --git a/clean.bat b/clean.bat index 02c0434b..b9d0d0bc 100644 --- a/clean.bat +++ b/clean.bat @@ -1,5 +1,7 @@ @ECHO OFF -CD E:\Users\Fescen9\workspace\DynamicMap\branches\fescen9 -del *.class -del ..\..\..\map.jar \ No newline at end of file +CD E:\Projects\DynamicMap\branches\fescen9 + +DEL /Q *.rar +DEL /Q *.class +RMDIR /S /Q .\plugins \ No newline at end of file diff --git a/web/home.png b/web/home.png new file mode 100644 index 00000000..5b15f03d Binary files /dev/null and b/web/home.png differ diff --git a/web/index.html b/web/index.html index fc7ebb1e..dff45480 100644 --- a/web/index.html +++ b/web/index.html @@ -21,10 +21,14 @@
- warps + Warps
- marker - + Markers +
+ Homes +
+ Spawn +
diff --git a/web/map.js b/web/map.js index f13651b4..5d014da4 100644 --- a/web/map.js +++ b/web/map.js @@ -1,6 +1,6 @@ var setup = { tileUrl: 'http://www.yourdomain.com/minecraft/tiles/', - updateUrl: 'http://www.yourdomain.com/minecraft/up/', + updateUrl: 'http://www.yourdomain.com/minecraft/up/', // Or if using ASP.NET: http://www.yourdomain.com/minecraft/up/default.aspx?lasttimestamp= updateRate: 2000 //Seconds the map should poll for updates. (Seconds) * 1000. The default is 2000 (every 2 seconds). }; @@ -566,6 +566,8 @@ function makeRequest(url, func, type, fail, post, contenttype) var loggedin = new Array(); var showWarps = document.getElementById('showWarps').checked; var showMarkers = document.getElementById('showMarkers').checked; + var showHomes = document.getElementById('showHomes').checked; + var showSpawn = document.getElementById('showSpawn').checked; lasttimestamp = rows[0]; delete rows[0]; @@ -574,6 +576,12 @@ function makeRequest(url, func, type, fail, post, contenttype) for(var line in rows) { var p = rows[line].split(' '); + + // Hack to keep duplicate markers/warps/players from conflicting with eachother + if(p.length == 6) { + p[0] = p[0] + '' + p[1] + ''; + } + loggedin[p[0]] = 1; if(p[0] == '') continue; @@ -599,22 +607,25 @@ function makeRequest(url, func, type, fail, post, contenttype) labelClass: "labels", clickable: false, flat: true, - icon: new google.maps.MarkerImage('marker.png', new google.maps.Size(28, 28), new google.maps.Point(0, 0), new google.maps.Point(14, 14)) + icon: new google.maps.MarkerImage('player.png', new google.maps.Size(28, 28), new google.maps.Point(0, 0), new google.maps.Point(14, 14)) }); markers[p[0]] = marker; } } else if(p.length == 6) { - var image = 'sign.png'; - if (p[1] == 'warp') - { - image = 'watch.png'; - } + var image = p[1] + '.png'; + + var hideMarker = ( + (p[1] == 'warp' && showWarps == false) || + (p[1] == 'marker' && showMarkers == false) || + (p[1] == 'home' && showHomes == false) || + (p[1] == 'spawn' && showSpawn == false) + ); if(p[0] in markers) { var m = markers[p[0]]; - if ((p[1] == 'warp' && showWarps == false) || (p[1] == 'marker' && showMarkers == false)) { + if (hideMarker) { m.setMap(null); continue; } @@ -625,7 +636,7 @@ function makeRequest(url, func, type, fail, post, contenttype) var converted = fromWorldToLatLng(p[3], p[4], p[5]); m.setPosition(converted); } else { - if ((p[1] == 'warp' && showWarps == false) || (p[1] == 'marker' && showMarkers == false)) { + if (hideMarker) { continue; } diff --git a/web/marker.png b/web/marker.png index 1fd60c71..8d8573ce 100644 Binary files a/web/marker.png and b/web/marker.png differ diff --git a/web/player.png b/web/player.png new file mode 100644 index 00000000..1fd60c71 Binary files /dev/null and b/web/player.png differ diff --git a/web/sign.png b/web/sign.png deleted file mode 100644 index 8d8573ce..00000000 Binary files a/web/sign.png and /dev/null differ diff --git a/web/spawn.png b/web/spawn.png new file mode 100644 index 00000000..177650bb Binary files /dev/null and b/web/spawn.png differ diff --git a/web/watch.png b/web/warp.png similarity index 100% rename from web/watch.png rename to web/warp.png