Added expiration timer to sessions. Sessions will now last up to 10 minutes (by default) before removed, so you can quickly disconnect (or crash) and come back and still maintain your history.

This commit is contained in:
sk89q
2011-05-01 17:37:05 -07:00
parent a18546d698
commit d71d4a8569
9 changed files with 198 additions and 36 deletions

View File

@ -51,9 +51,11 @@ import com.sk89q.worldedit.regions.RegionSelector;
*/
public class LocalSession {
public static int MAX_HISTORY_SIZE = 15;
public static int EXPIRATION_GRACE = 600000;
private LocalConfiguration config;
private long expirationTime = 0;
private LocalWorld selectionWorld;
private RegionSelector selector = new CuboidRegionSelector();
private boolean placeAtPos1 = false;
@ -615,4 +617,20 @@ public class LocalSession {
return date.getBeginCalendar();
}
}
/**
* Update the last update time for calculating expiration.
*/
public void update() {
expirationTime = System.currentTimeMillis();
}
/**
* Returns whether this session has expired.
*
* @return
*/
public boolean hasExpired() {
return System.currentTimeMillis() - expirationTime > EXPIRATION_GRACE;
}
}