diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index bc4c03c985..2a0ca6fe11 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -1108,8 +1108,8 @@ public class MageServerImpl implements MageServer { } @Override - public void lockUser(String sessionId, final String userName, final long durationMinutes) throws MageException { - execute("muteUser", sessionId, new Action() { + public void lockUser(final String sessionId, final String userName, final long durationMinutes) throws MageException { + execute("lockUser", sessionId, new Action() { @Override public void execute() { User user = UserManager.getInstance().getUserByName(userName); @@ -1117,6 +1117,9 @@ public class MageServerImpl implements MageServer { Date lockUntil = new Date(Calendar.getInstance().getTimeInMillis() + (durationMinutes * Timer.ONE_MINUTE)); user.showUserMessage("Admin info", "Your user profile was locked until " + SystemUtil.dateFormat.format(lockUntil) + "."); user.setLockedUntil(lockUntil); + if (user.isConnected()) { + SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId()); + } } } @@ -1124,13 +1127,16 @@ public class MageServerImpl implements MageServer { } @Override - public void toggleActivation(String sessionId, final String userName) throws MageException { - execute("muteUser", sessionId, new Action() { + public void toggleActivation(final String sessionId, final String userName) throws MageException { + execute("toggleActivation", sessionId, new Action() { @Override public void execute() { User user = UserManager.getInstance().getUserByName(userName); if (user != null) { user.setActive(!user.isActive()); + if (!user.isActive() && user.isConnected()) { + SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId()); + } } } diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index 934168c375..4482732226 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -27,6 +27,7 @@ */ package mage.server; +import java.util.Calendar; import java.util.Date; import java.util.LinkedList; import java.util.List; @@ -42,6 +43,7 @@ import mage.players.net.UserData; import mage.players.net.UserGroup; import mage.server.game.GamesRoomManager; import mage.server.util.ConfigSettings; +import mage.server.util.SystemUtil; import org.apache.log4j.Logger; import org.jboss.remoting.callback.AsynchInvokerCallbackHandler; import org.jboss.remoting.callback.Callback; @@ -186,8 +188,20 @@ public class Session { if (authorizedUser == null || !authorizedUser.doCredentialsMatch(userName, password)) { return "Wrong username or password. In case you haven't, please register your account first."; } + if (!authorizedUser.active) { + return "Your profile is deactivated, you can't sign on."; + } + if (authorizedUser.lockedUntil != null) { + if (authorizedUser.lockedUntil.compareTo(Calendar.getInstance().getTime()) > 0) { + return "Your profile is deactivated until " + SystemUtil.dateFormat.format(authorizedUser.lockedUntil); + } else { + User user = UserManager.getInstance().createUser(userName, host, authorizedUser); + if (user != null && authorizedUser.lockedUntil != null) { + user.setLockedUntil(null); + } + } + } } - User user = UserManager.getInstance().createUser(userName, host, authorizedUser); boolean reconnect = false; if (user == null) { // user already exists diff --git a/Mage.Server/src/main/java/mage/server/User.java b/Mage.Server/src/main/java/mage/server/User.java index c31aa62fb2..5f6c1e90ef 100644 --- a/Mage.Server/src/main/java/mage/server/User.java +++ b/Mage.Server/src/main/java/mage/server/User.java @@ -778,6 +778,8 @@ public class User { if (authorizedUser != null) { authorizedUser.lastConnection = this.connectionTime; authorizedUser.chatLockedUntil = this.chatLockedUntil; + authorizedUser.lockedUntil = this.lockedUntil; + authorizedUser.active = this.active; AuthorizedUserRepository.instance.update(authorizedUser); } }