Improved reconnect and tournament handling. Reconnect time is now shown for disconneted players on player list and tournament panel. You can now reconnect (during 3 minutes) to a tournament also if meanwhile new game (after sideboarding ended) or round was started. Conceding the complete match in a tournament can no longer result in a draw, if you won games before. Quitting a tournament does now always end all active games of that quitting player.

This commit is contained in:
LevelX2 2014-03-31 02:24:59 +02:00
parent c76529bf91
commit 9ff5bcbd92
29 changed files with 282 additions and 109 deletions

View file

@ -34,6 +34,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import mage.cards.decks.Deck;
import mage.game.Table;
import mage.interfaces.callback.ClientCallback;
@ -42,6 +43,7 @@ import mage.server.draft.DraftSession;
import mage.server.game.GameManager;
import mage.server.game.GameSession;
import mage.server.tournament.TournamentSession;
import mage.server.util.SystemUtil;
import mage.view.TableClientMessage;
import org.apache.log4j.Logger;
@ -133,6 +135,13 @@ public class User {
return userState == UserState.Connected || userState == UserState.Reconnected;
}
public String getDisconnectDuration() {
long secondsDisconnected = SystemUtil.getDateDiff(lastActivity, new Date(), TimeUnit.SECONDS);
int minutes = (int) secondsDisconnected / 60;
int seconds = (int) secondsDisconnected % 60;
return new StringBuilder(Integer.toString(minutes)).append(":").append(seconds > 9 ? seconds: "0" + Integer.toString(seconds)).toString();
}
public Date getConnectionTime() {
return connectionTime;
}
@ -246,7 +255,7 @@ public class User {
}
for (Entry<UUID, TournamentSession> entry: constructing.entrySet()) {
entry.getValue().construct(0);
entry.getValue().construct(0); // TODO: Check if this is correct
}
for (Entry<UUID, Deck> entry: sideboarding.entrySet()) {
TableController controller = TableManager.getInstance().getController(entry.getKey());
@ -323,10 +332,15 @@ public class User {
}
public String getGameInfo() {
StringBuilder sb = new StringBuilder();
String disconnectInfo = "";
if (!isConnected()) {
disconnectInfo = new StringBuilder(" (discon. ").append(getDisconnectDuration()).append(")").toString();
}
int draft = 0, match = 0, sideboard = 0, tournament = 0, construct = 0;
for (Table table : tables.values()) {
for (Map.Entry<UUID, Table> tableEntry : tables.entrySet()) {
Table table = tableEntry.getValue();
if (table.isTournament()) {
switch (table.getState()) {
case CONSTRUCTING:
@ -339,6 +353,11 @@ public class User {
tournament++;
break;
}
if (!isConnected()) {
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo(disconnectInfo);
} else {
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo("");
}
} else {
switch (table.getState()) {
case SIDEBOARDING:
@ -365,6 +384,7 @@ public class User {
if (tournament > 0) {
sb.append("TP: ").append(tournament).append(" ");
}
sb.append(disconnectInfo);
return sb.toString();
}