From fa97e4647e8eb43b473cfc5f12a00f5573fb1c87 Mon Sep 17 00:00:00 2001 From: spjspj Date: Sun, 5 Feb 2017 14:11:05 +1100 Subject: [PATCH] Add field for server console --- .../java/mage/client/dialog/ConnectDialog.java | 3 ++- .../java/mage/client/dialog/PreferencesDialog.java | 4 +++- Mage.Common/src/mage/interfaces/MageServer.java | 4 ++-- Mage.Common/src/mage/remote/Connection.java | 9 +++++++++ Mage.Common/src/mage/remote/SessionImpl.java | 8 ++++---- Mage.Common/src/mage/view/UserView.java | 9 +++++++-- .../src/main/java/mage/server/MageServerImpl.java | 13 +++++++------ Mage.Server/src/main/java/mage/server/Session.java | 3 ++- .../src/main/java/mage/server/SessionManager.java | 8 ++++---- Mage.Server/src/main/java/mage/server/User.java | 14 ++++++++++++-- Mage/src/main/java/mage/players/net/UserData.java | 7 +++++-- 11 files changed, 57 insertions(+), 25 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java b/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java index a738721cfe..b748988ab9 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/ConnectDialog.java @@ -26,7 +26,7 @@ * or implied, of BetaSteward_at_googlemail.com. */ -/* + /* * ConnectDialog.java * * Created on 20-Jan-2010, 9:37:07 PM @@ -391,6 +391,7 @@ public class ConnectDialog extends MageDialog { connection.setUsername(this.txtUserName.getText().trim()); connection.setPassword(this.txtPassword.getText().trim()); connection.setForceDBComparison(this.chkForceUpdateDB.isSelected()); + connection.setUserIdStr(System.getProperty("user.name")); MageFrame.getPreferences().put(KEY_CONNECT_FLAG, ((CountryItemEditor) cbFlag.getEditor()).getImageItem()); PreferencesDialog.setProxyInformation(connection); diff --git a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java index 4423038e08..1c63bcec16 100644 --- a/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java +++ b/Mage.Client/src/main/java/mage/client/dialog/PreferencesDialog.java @@ -3520,6 +3520,7 @@ public class PreferencesDialog extends javax.swing.JDialog { if (selectedAvatarId == 0) { getSelectedAvatar(); } + String userStrId = System.getProperty("user.name"); return new UserData(UserGroup.PLAYER, PreferencesDialog.selectedAvatarId, PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true"), @@ -3533,7 +3534,8 @@ public class PreferencesDialog extends javax.swing.JDialog { PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_CAST, "true").equals("true"), PreferencesDialog.getCachedValue(PreferencesDialog.KEY_PASS_PRIORITY_ACTIVATION, "true").equals("true"), PreferencesDialog.getCachedValue(PreferencesDialog.KEY_AUTO_ORDER_TRIGGER, "true").equals("true"), - PreferencesDialog.getCachedValue(PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY, "false").equals("true") + PreferencesDialog.getCachedValue(PreferencesDialog.KEY_USE_FIRST_MANA_ABILITY, "false").equals("true"), + userStrId ); } diff --git a/Mage.Common/src/mage/interfaces/MageServer.java b/Mage.Common/src/mage/interfaces/MageServer.java index 817ccf84a9..d7da351f8b 100644 --- a/Mage.Common/src/mage/interfaces/MageServer.java +++ b/Mage.Common/src/mage/interfaces/MageServer.java @@ -62,7 +62,7 @@ public interface MageServer { boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException; - boolean connectUser(String userName, String password, String sessionId, MageVersion version) throws MageException; + boolean connectUser(String userName, String password, String sessionId, MageVersion version, String userIdStr) throws MageException; boolean connectAdmin(String password, String sessionId, MageVersion version) throws MageException; @@ -72,7 +72,7 @@ public interface MageServer { List getMissingCardsData(List classNames); // user methods - boolean setUserData(String userName, String sessionId, UserData userData, String clientVersion) throws MageException; + boolean setUserData(String userName, String sessionId, UserData userData, String clientVersion, String userIdStr) throws MageException; void sendFeedbackMessage(String sessionId, String username, String title, String type, String message, String email) throws MageException; diff --git a/Mage.Common/src/mage/remote/Connection.java b/Mage.Common/src/mage/remote/Connection.java index 2a989da8dc..87e1f634be 100644 --- a/Mage.Common/src/mage/remote/Connection.java +++ b/Mage.Common/src/mage/remote/Connection.java @@ -55,6 +55,7 @@ public class Connection { private String proxyPassword; private int clientCardDatabaseVersion; private boolean forceDBComparison; + private String userIdStr; private UserData userData; @@ -167,6 +168,14 @@ public class Connection { this.username = username; } + public String getUserIdStr() { + return userIdStr; + } + + public void setUserIdStr(String userIdStr) { + this.userIdStr = userIdStr; + } + public String getPassword() { return password; } diff --git a/Mage.Common/src/mage/remote/SessionImpl.java b/Mage.Common/src/mage/remote/SessionImpl.java index 594bf09430..f1cfa362fc 100644 --- a/Mage.Common/src/mage/remote/SessionImpl.java +++ b/Mage.Common/src/mage/remote/SessionImpl.java @@ -222,9 +222,9 @@ public class SessionImpl implements Session { boolean registerResult; if (connection.getAdminPassword() == null) { // for backward compatibility. don't remove twice call - first one does nothing but for version checking - registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion()); + registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion(), connection.getUserIdStr()); if (registerResult) { - server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString()); + server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString(), connection.getUserIdStr()); } } else { registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion()); @@ -1466,7 +1466,7 @@ public class SessionImpl implements Session { } return false; } - + @Override public boolean setActivation(String userName, boolean active) { try { @@ -1571,7 +1571,7 @@ public class SessionImpl implements Session { public boolean updatePreferencesForServer(UserData userData) { try { if (isConnected()) { - server.setUserData(connection.getUsername(), sessionId, userData, null); + server.setUserData(connection.getUsername(), sessionId, userData, null, null); } return true; } catch (MageException ex) { diff --git a/Mage.Common/src/mage/view/UserView.java b/Mage.Common/src/mage/view/UserView.java index d8d5e6a1de..1b4a9d082a 100644 --- a/Mage.Common/src/mage/view/UserView.java +++ b/Mage.Common/src/mage/view/UserView.java @@ -46,8 +46,9 @@ public class UserView implements Serializable { private final Date muteChatUntil; private final String clientVersion; private final String email; + private final String userIdStr; - public UserView(String userName, String host, String sessionId, Date timeConnected, String gameInfo, String userState, Date muteChatUntil, String clientVersion, String email) { + public UserView(String userName, String host, String sessionId, Date timeConnected, String gameInfo, String userState, Date muteChatUntil, String clientVersion, String email, String userIdStr) { this.userName = userName; this.host = host; this.sessionId = sessionId; @@ -57,6 +58,7 @@ public class UserView implements Serializable { this.muteChatUntil = muteChatUntil; this.clientVersion = clientVersion; this.email = email; + this.userIdStr = userIdStr; } public String getUserName() { @@ -90,9 +92,12 @@ public class UserView implements Serializable { public Date getTimeConnected() { return timeConnected; } - + public String getEmail() { return email; } + public String getUserIdStr() { + return userIdStr; + } } diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index d4384d241c..f642694fd5 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -132,7 +132,7 @@ public class MageServerImpl implements MageServer { } return true; } - + @Override public boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException { if (!ConfigSettings.getInstance().isAuthenticationActivated()) { @@ -158,13 +158,13 @@ public class MageServerImpl implements MageServer { } @Override - public boolean connectUser(String userName, String password, String sessionId, MageVersion version) throws MageException { + public boolean connectUser(String userName, String password, String sessionId, MageVersion version, String userIdStr) throws MageException { try { if (version.compareTo(Main.getVersion()) != 0) { logger.info("MageVersionException: userName=" + userName + ", version=" + version); throw new MageVersionException(version, Main.getVersion()); } - return SessionManager.getInstance().connectUser(sessionId, userName, password); + return SessionManager.getInstance().connectUser(sessionId, userName, password, userIdStr); } catch (MageException ex) { if (ex instanceof MageVersionException) { throw (MageVersionException) ex; @@ -175,11 +175,11 @@ public class MageServerImpl implements MageServer { } @Override - public boolean setUserData(final String userName, final String sessionId, final UserData userData, final String clientVersion) throws MageException { + public boolean setUserData(final String userName, final String sessionId, final UserData userData, final String clientVersion, final String userIdStr) throws MageException { return executeWithResult("setUserData", sessionId, new ActionWithBooleanResult() { @Override public Boolean execute() throws MageException { - return SessionManager.getInstance().setUserData(userName, sessionId, userData, clientVersion); + return SessionManager.getInstance().setUserData(userName, sessionId, userData, clientVersion, userIdStr); } }); } @@ -943,7 +943,8 @@ public class MageServerImpl implements MageServer { user.getUserState().toString(), user.getChatLockedUntil(), user.getClientVersion(), - user.getEmail() + user.getEmail(), + user.getUserIdStr() )); } return users; diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index ab6f404de2..e4c4e7d3c1 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -264,12 +264,13 @@ public class Session { this.userId = user.getId(); } - public boolean setUserData(String userName, UserData userData, String clientVersion) { + public boolean setUserData(String userName, UserData userData, String clientVersion, String userIdStr) { User user = UserManager.getInstance().getUserByName(userName); if (user != null) { if (clientVersion != null) { user.setClientVersion(clientVersion); } + user.setUserIdStr(userIdStr); if (user.getUserData() == null || user.getUserData().getGroupId() == UserGroup.DEFAULT.getGroupId()) { user.setUserData(userData); } else { diff --git a/Mage.Server/src/main/java/mage/server/SessionManager.java b/Mage.Server/src/main/java/mage/server/SessionManager.java index 34b148da7a..faaecf004b 100644 --- a/Mage.Server/src/main/java/mage/server/SessionManager.java +++ b/Mage.Server/src/main/java/mage/server/SessionManager.java @@ -88,7 +88,7 @@ public class SessionManager { return true; } - public boolean connectUser(String sessionId, String userName, String password) throws MageException { + public boolean connectUser(String sessionId, String userName, String password, String userIdStr) throws MageException { Session session = sessions.get(sessionId); if (session != null) { String returnMessage = session.connectUser(userName, password); @@ -117,10 +117,10 @@ public class SessionManager { return false; } - public boolean setUserData(String userName, String sessionId, UserData userData, String clientVersion) throws MageException { + public boolean setUserData(String userName, String sessionId, UserData userData, String clientVersion, String userIdStr) throws MageException { Session session = sessions.get(sessionId); if (session != null) { - session.setUserData(userName, userData, clientVersion); + session.setUserData(userName, userData, clientVersion, userIdStr); return true; } return false; @@ -217,7 +217,7 @@ public class SessionManager { if (session != null) { return UserManager.getInstance().getUser(sessions.get(sessionId).getUserId()); } - logger.error(String.format("Session %s could not be found",sessionId)); + logger.error(String.format("Session %s could not be found", sessionId)); return Optional.empty(); } diff --git a/Mage.Server/src/main/java/mage/server/User.java b/Mage.Server/src/main/java/mage/server/User.java index c4411ff94f..94ee9b84c3 100644 --- a/Mage.Server/src/main/java/mage/server/User.java +++ b/Mage.Server/src/main/java/mage/server/User.java @@ -96,6 +96,7 @@ public class User { private Date lockedUntil; private final AuthorizedUser authorizedUser; private String clientVersion; + private String userIdStr; public User(String userName, String host, AuthorizedUser authorizedUser) { this.userId = UUID.randomUUID(); @@ -127,6 +128,7 @@ public class User { this.tablesToDelete = new ArrayList<>(); this.sessionId = ""; this.clientVersion = ""; + this.userIdStr = ""; } public String getName() { @@ -178,6 +180,14 @@ public class User { this.clientVersion = clientVersion; } + public void setUserIdStr(String userIdStr) { + this.userIdStr = userIdStr; + } + + public String getUserIdStr() { + return this.userIdStr; + } + public String getClientVersion() { return clientVersion; } @@ -199,7 +209,7 @@ public class User { public void lostConnection() { // Because watched games don't get restored after reconnection call stop watching - for (Iterator iterator = watchedGames.iterator(); iterator.hasNext(); ) { + for (Iterator iterator = watchedGames.iterator(); iterator.hasNext();) { UUID gameId = iterator.next(); GameManager.getInstance().stopWatching(gameId, userId); iterator.remove(); @@ -781,7 +791,7 @@ public class User { } return number; } - + public String getEmail() { if (authorizedUser != null) { return authorizedUser.email; diff --git a/Mage/src/main/java/mage/players/net/UserData.java b/Mage/src/main/java/mage/players/net/UserData.java index b5d52c9d0a..b6bb290d8f 100644 --- a/Mage/src/main/java/mage/players/net/UserData.java +++ b/Mage/src/main/java/mage/players/net/UserData.java @@ -23,6 +23,7 @@ public class UserData implements Serializable { protected boolean passPriorityActivation; protected boolean autoOrderTrigger; protected boolean useFirstManaAbility = false; + private String userIdStr; protected String matchHistory; protected int matchQuitRatio; @@ -36,7 +37,7 @@ public class UserData implements Serializable { public UserData(UserGroup userGroup, int avatarId, boolean showAbilityPickerForced, boolean allowRequestShowHandCards, boolean confirmEmptyManaPool, UserSkipPrioritySteps userSkipPrioritySteps, String flagName, boolean askMoveToGraveOrder, boolean manaPoolAutomatic, boolean manaPoolAutomaticRestricted, - boolean passPriorityCast, boolean passPriorityActivation, boolean autoOrderTrigger, boolean useFirstManaAbility) { + boolean passPriorityCast, boolean passPriorityActivation, boolean autoOrderTrigger, boolean useFirstManaAbility, String userIdStr) { this.groupId = userGroup.getGroupId(); this.avatarId = avatarId; this.showAbilityPickerForced = showAbilityPickerForced; @@ -55,6 +56,7 @@ public class UserData implements Serializable { this.matchQuitRatio = 0; this.tourneyHistory = ""; this.tourneyQuitRatio = 0; + this.userIdStr = userIdStr; } public void update(UserData userData) { @@ -72,11 +74,12 @@ public class UserData implements Serializable { this.passPriorityActivation = userData.passPriorityActivation; this.autoOrderTrigger = userData.autoOrderTrigger; this.useFirstManaAbility = userData.useFirstManaAbility; + this.userIdStr = userData.userIdStr; // todo: why we don't copy user stats here? } public static UserData getDefaultUserDataView() { - return new UserData(UserGroup.DEFAULT, 0, false, false, true, null, getDefaultFlagName(), false, true, true, false, false, false, false); + return new UserData(UserGroup.DEFAULT, 0, false, false, true, null, getDefaultFlagName(), false, true, true, false, false, false, false, ""); } public void setGroupId(int groupId) {