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 13099587e0
commit 6ab82174a5
6 changed files with 18 additions and 9 deletions

View File

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

View File

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

View File

@ -67,6 +67,6 @@ public class DynmapPlayerListener extends PlayerListener {
* Relevant event details
*/
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();
Client.Update update = new Client.Update();
update.timestamp = current;
update.servertime = world.getTime();
update.timestamp = current;
update.servertime = world.getTime() % 24000;

View File

@ -159,7 +159,7 @@ public class MapManager {
public boolean render(MapTile 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;
}

View File

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