Added chat mute and user (de)activation actions to the Mage server console.

This commit is contained in:
LevelX2 2016-10-05 00:59:51 +02:00
parent 7c4b40073c
commit c46f75ac28
18 changed files with 511 additions and 213 deletions

View file

@ -91,15 +91,30 @@ public class User {
private UserState userState;
private UserData userData;
private UserStats userStats;
private Date chatLockedUntil;
private boolean active;
private Date lockedUntil;
private final AuthorizedUser authorizedUser;
public User(String userName, String host) {
public User(String userName, String host, AuthorizedUser authorizedUser) {
this.userId = UUID.randomUUID();
this.userName = userName;
this.host = host;
this.userState = UserState.Created;
this.connectionTime = new Date();
this.lastActivity = new Date();
if (authorizedUser != null) {
this.active = authorizedUser.active;
this.chatLockedUntil = authorizedUser.chatLockedUntil;
this.lockedUntil = authorizedUser.lockedUntil;
this.authorizedUser = authorizedUser;
updateAuthorizedUser();
} else {
this.active = true;
this.chatLockedUntil = null;
this.lockedUntil = null;
this.authorizedUser = null;
}
this.tables = new ConcurrentHashMap<>();
this.gameSessions = new ConcurrentHashMap<>();
@ -128,6 +143,18 @@ public class User {
return sessionId;
}
public Date getChatLockedUntil() {
return chatLockedUntil;
}
public boolean isActive() {
return active;
}
public Date getLockedUntil() {
return lockedUntil;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
if (sessionId.isEmpty()) {
@ -145,6 +172,21 @@ public class User {
}
}
public void setChatLockedUntil(Date chatLockedUntil) {
this.chatLockedUntil = chatLockedUntil;
updateAuthorizedUser();
}
public void setActive(boolean active) {
this.active = active;
updateAuthorizedUser();
}
public void setLockedUntil(Date lockedUntil) {
this.lockedUntil = lockedUntil;
updateAuthorizedUser();
}
public void lostConnection() {
// Because watched games don't get restored after reconnection call stop watching
for (Iterator<UUID> iterator = watchedGames.iterator(); iterator.hasNext();) {
@ -731,4 +773,12 @@ public class User {
}
return number;
}
private void updateAuthorizedUser() {
if (authorizedUser != null) {
authorizedUser.lastConnection = this.connectionTime;
authorizedUser.chatLockedUntil = this.chatLockedUntil;
AuthorizedUserRepository.instance.update(authorizedUser);
}
}
}