forked from External/mage
Changed that player history string of all players were recreated every time the player list is updated (every 2 seconds).
This commit is contained in:
parent
9ccebfdff4
commit
24dddd3e06
2 changed files with 102 additions and 94 deletions
|
|
@ -43,13 +43,11 @@ import mage.constants.TableState;
|
|||
import mage.game.GameException;
|
||||
import mage.game.Table;
|
||||
import mage.game.match.MatchOptions;
|
||||
import mage.game.result.ResultProtos.UserStatsProto;
|
||||
import mage.game.tournament.TournamentOptions;
|
||||
import mage.server.RoomImpl;
|
||||
import mage.server.TableManager;
|
||||
import mage.server.User;
|
||||
import mage.server.UserManager;
|
||||
import mage.server.record.UserStats;
|
||||
import mage.server.tournament.TournamentManager;
|
||||
import mage.server.util.ConfigSettings;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
|
|
@ -93,74 +91,6 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
return tableView;
|
||||
}
|
||||
|
||||
private static void joinStrings(StringBuilder joined, List<String> strings, String separator) {
|
||||
for (int i = 0; i < strings.size(); ++i) {
|
||||
if (i > 0) {
|
||||
joined.append(separator);
|
||||
}
|
||||
joined.append(strings.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
private static String joinBuilders(List<StringBuilder> builders) {
|
||||
if (builders.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder builder = builders.get(0);
|
||||
for (int i = 1; i < builders.size(); ++i) {
|
||||
builder.append(" ");
|
||||
builder.append(builders.get(i));
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private static String userStatsToString(UserStatsProto proto) {
|
||||
List<StringBuilder> builders = new ArrayList<>();
|
||||
if (proto.getMatches() > 0) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Matches:");
|
||||
builder.append(proto.getMatches());
|
||||
List<String> quit = new ArrayList<>();
|
||||
if (proto.getMatchesIdleTimeout() > 0) {
|
||||
quit.add("I:" + Integer.toString(proto.getMatchesIdleTimeout()));
|
||||
}
|
||||
if (proto.getMatchesTimerTimeout() > 0) {
|
||||
quit.add("T:" + Integer.toString(proto.getMatchesTimerTimeout()));
|
||||
}
|
||||
if (proto.getMatchesQuit() > 0) {
|
||||
quit.add("Q:" + Integer.toString(proto.getMatchesQuit()));
|
||||
}
|
||||
if (quit.size() > 0) {
|
||||
builder.append(" (");
|
||||
joinStrings(builder, quit, " ");
|
||||
builder.append(")");
|
||||
}
|
||||
builders.add(builder);
|
||||
}
|
||||
if (proto.getTourneys() > 0) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append("Tourneys:");
|
||||
builder.append(proto.getTourneys());
|
||||
List<String> quit = new ArrayList<>();
|
||||
if (proto.getTourneysQuitDuringDrafting() > 0) {
|
||||
quit.add("D:" + Integer.toString(proto.getTourneysQuitDuringDrafting()));
|
||||
}
|
||||
if (proto.getTourneysQuitDuringConstruction() > 0) {
|
||||
quit.add("C:" + Integer.toString(proto.getTourneysQuitDuringConstruction()));
|
||||
}
|
||||
if (proto.getTourneysQuitDuringRound() > 0) {
|
||||
quit.add("R:" + Integer.toString(proto.getTourneysQuitDuringRound()));
|
||||
}
|
||||
if (quit.size() > 0) {
|
||||
builder.append(" (");
|
||||
joinStrings(builder, quit, " ");
|
||||
builder.append(")");
|
||||
}
|
||||
builders.add(builder);
|
||||
}
|
||||
return joinBuilders(builders);
|
||||
}
|
||||
|
||||
private void update() {
|
||||
ArrayList<TableView> tableList = new ArrayList<>();
|
||||
ArrayList<MatchView> matchList = new ArrayList<>();
|
||||
|
|
@ -183,19 +113,14 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
|
|||
matchView = matchList;
|
||||
List<UsersView> users = new ArrayList<>();
|
||||
for (User user : UserManager.getInstance().getUsers()) {
|
||||
String history = null;
|
||||
UserStats stats = user.getUserStats();
|
||||
if (stats != null) {
|
||||
history = userStatsToString(stats.getProto());
|
||||
}
|
||||
try {
|
||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), history, user.getInfo(), user.getGameInfo(), user.getPingInfo()));
|
||||
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getHistory(), user.getInfo(), user.getGameInfo(), user.getPingInfo()));
|
||||
} catch (Exception ex) {
|
||||
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
|
||||
users.add(new UsersView(
|
||||
(user.getUserData() != null && user.getUserData().getFlagName() != null) ? user.getUserData().getFlagName() : "world",
|
||||
user.getName() != null ? user.getName() : "<no name>",
|
||||
history != null ? history : "<no history>",
|
||||
user.getHistory() != null ? user.getHistory() : "<no history>",
|
||||
user.getInfo() != null ? user.getInfo() : "<no info>",
|
||||
"[exception]",
|
||||
user.getPingInfo() != null ? user.getPingInfo() : "<no ping>"));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue