mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
Added chat mute and user (de)activation actions to the Mage server console.
This commit is contained in:
parent
f51d4f4e0f
commit
fae1cb8cce
3 changed files with 27 additions and 5 deletions
|
@ -1108,8 +1108,8 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lockUser(String sessionId, final String userName, final long durationMinutes) throws MageException {
|
public void lockUser(final String sessionId, final String userName, final long durationMinutes) throws MageException {
|
||||||
execute("muteUser", sessionId, new Action() {
|
execute("lockUser", sessionId, new Action() {
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
User user = UserManager.getInstance().getUserByName(userName);
|
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));
|
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.showUserMessage("Admin info", "Your user profile was locked until " + SystemUtil.dateFormat.format(lockUntil) + ".");
|
||||||
user.setLockedUntil(lockUntil);
|
user.setLockedUntil(lockUntil);
|
||||||
|
if (user.isConnected()) {
|
||||||
|
SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1124,13 +1127,16 @@ public class MageServerImpl implements MageServer {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toggleActivation(String sessionId, final String userName) throws MageException {
|
public void toggleActivation(final String sessionId, final String userName) throws MageException {
|
||||||
execute("muteUser", sessionId, new Action() {
|
execute("toggleActivation", sessionId, new Action() {
|
||||||
@Override
|
@Override
|
||||||
public void execute() {
|
public void execute() {
|
||||||
User user = UserManager.getInstance().getUserByName(userName);
|
User user = UserManager.getInstance().getUserByName(userName);
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
user.setActive(!user.isActive());
|
user.setActive(!user.isActive());
|
||||||
|
if (!user.isActive() && user.isConnected()) {
|
||||||
|
SessionManager.getInstance().disconnectUser(sessionId, user.getSessionId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
*/
|
*/
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -42,6 +43,7 @@ import mage.players.net.UserData;
|
||||||
import mage.players.net.UserGroup;
|
import mage.players.net.UserGroup;
|
||||||
import mage.server.game.GamesRoomManager;
|
import mage.server.game.GamesRoomManager;
|
||||||
import mage.server.util.ConfigSettings;
|
import mage.server.util.ConfigSettings;
|
||||||
|
import mage.server.util.SystemUtil;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
|
import org.jboss.remoting.callback.AsynchInvokerCallbackHandler;
|
||||||
import org.jboss.remoting.callback.Callback;
|
import org.jboss.remoting.callback.Callback;
|
||||||
|
@ -186,8 +188,20 @@ public class Session {
|
||||||
if (authorizedUser == null || !authorizedUser.doCredentialsMatch(userName, password)) {
|
if (authorizedUser == null || !authorizedUser.doCredentialsMatch(userName, password)) {
|
||||||
return "Wrong username or password. In case you haven't, please register your account first.";
|
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);
|
User user = UserManager.getInstance().createUser(userName, host, authorizedUser);
|
||||||
boolean reconnect = false;
|
boolean reconnect = false;
|
||||||
if (user == null) { // user already exists
|
if (user == null) { // user already exists
|
||||||
|
|
|
@ -778,6 +778,8 @@ public class User {
|
||||||
if (authorizedUser != null) {
|
if (authorizedUser != null) {
|
||||||
authorizedUser.lastConnection = this.connectionTime;
|
authorizedUser.lastConnection = this.connectionTime;
|
||||||
authorizedUser.chatLockedUntil = this.chatLockedUntil;
|
authorizedUser.chatLockedUntil = this.chatLockedUntil;
|
||||||
|
authorizedUser.lockedUntil = this.lockedUntil;
|
||||||
|
authorizedUser.active = this.active;
|
||||||
AuthorizedUserRepository.instance.update(authorizedUser);
|
AuthorizedUserRepository.instance.update(authorizedUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue