Added timestamp support to Update Tiles and Chat.

New web config to handle for jsonfile method
Modified webclient to handle timestamps to prevent duplication.
Removed duplicate code in JsonTimerTask.java
This commit is contained in:
Jason Booth 2011-02-19 18:55:01 -06:00
parent 7e858e39d5
commit 8469b323d3
6 changed files with 18 additions and 9 deletions

View file

@ -42,6 +42,9 @@ web:
# Interval the browser should poll for updates. # Interval the browser should poll for updates.
updaterate: 2000 updaterate: 2000
# Handles the clientside updates differently only enable if using jsonfile
jsonfile: false
showchatballoons: true showchatballoons: true
showplayerfacesonmap: true showplayerfacesonmap: true
showplayerfacesinmenu: true showplayerfacesinmenu: true

View file

@ -27,19 +27,23 @@ public class Client {
public String type = "chat"; public String type = "chat";
public String playerName; public String playerName;
public String message; public String message;
public long timestamp;
public ChatMessage(String playerName, String message) { public ChatMessage(String playerName, String message, long timestamp) {
this.playerName = playerName; this.playerName = playerName;
this.message = message; this.message = message;
this.timestamp = timestamp;
} }
} }
public static class Tile { public static class Tile {
public String type = "tile"; public String type = "tile";
public String name; public String name;
public long timestamp;
public Tile(String name) { public Tile(String name, long timestamp) {
this.name = name; this.name = name;
this.timestamp = timestamp;
} }
} }
} }

View file

@ -67,6 +67,6 @@ public class DynmapPlayerListener extends PlayerListener {
* Relevant event details * Relevant event details
*/ */
public void onPlayerChat(PlayerChatEvent event) { public void onPlayerChat(PlayerChatEvent event) {
mgr.pushUpdate(new Client.ChatMessage(event.getPlayer().getName(), event.getMessage())); mgr.pushUpdate(new Client.ChatMessage(event.getPlayer().getName(), event.getMessage(), System.currentTimeMillis()));
} }
} }

View file

@ -37,8 +37,6 @@ class JsonTimerTask extends TimerTask
long current = System.currentTimeMillis(); long current = System.currentTimeMillis();
Client.Update update = new Client.Update(); Client.Update update = new Client.Update();
update.timestamp = current;
update.servertime = world.getTime();
update.timestamp = current; update.timestamp = current;
update.servertime = world.getTime() % 24000; update.servertime = world.getTime() % 24000;

View file

@ -159,7 +159,7 @@ public class MapManager {
public boolean render(MapTile tile) { public boolean render(MapTile tile) {
boolean result = tile.getMap().render(tile, getTileFile(tile)); boolean result = tile.getMap().render(tile, getTileFile(tile));
pushUpdate(tile.getWorld(), new Client.Tile(tile.getFilename())); pushUpdate(tile.getWorld(), new Client.Tile(tile.getFilename(), System.currentTimeMillis()));
return result; return result;
} }

View file

@ -221,7 +221,6 @@ DynMap.prototype = {
$.getJSON(me.options.updateUrl + "world/" + me.world + "/" + me.lasttimestamp, function(update) { $.getJSON(me.options.updateUrl + "world/" + me.world + "/" + me.lasttimestamp, function(update) {
me.alertbox.hide(); me.alertbox.hide();
me.lasttimestamp = update.timestamp;
me.clock.setTime(update.servertime); me.clock.setTime(update.servertime);
var typeVisibleMap = {}; var typeVisibleMap = {};
@ -243,12 +242,16 @@ DynMap.prototype = {
$.each(update.updates, function(index, update) { $.each(update.updates, function(index, update) {
swtch(update.type, { swtch(update.type, {
tile: function() { tile: function() {
me.onTileUpdated(update.name);
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onTileUpdated(update.name);
}, },
chat: function() { chat: function() {
if (!me.options.showchatballoons) if (!me.options.showchatballoons)
return; return;
me.onPlayerChat(update.playerName, update.message);
if(me.lasttimestamp <= update.timestamp || !me.options.jsonfile)
me.onPlayerChat(update.playerName, update.message);
} }
}, function(type) { }, function(type) {
console.log('Unknown type ', value, '!'); console.log('Unknown type ', value, '!');
@ -265,6 +268,7 @@ DynMap.prototype = {
delete me.markers[m]; delete me.markers[m];
} }
} }
me.lasttimestamp = update.timestamp;
setTimeout(function() { me.update(); }, me.options.updaterate); setTimeout(function() { me.update(); }, me.options.updaterate);
}, function(request, statusText, ex) { }, function(request, statusText, ex) {
me.alertbox me.alertbox