mirror of
https://github.com/magefree/mage.git
synced 2025-12-25 04:52:07 -08:00
Some minor changes to server handling.
This commit is contained in:
parent
4665348ca7
commit
44d9a538ee
3 changed files with 36 additions and 32 deletions
|
|
@ -97,12 +97,13 @@ public class Session {
|
|||
if (user == null) { // user already exists
|
||||
user = UserManager.getInstance().findUser(userName);
|
||||
if (user.getHost().equals(host)) {
|
||||
user.updateLastActivity(); // minimizes possible expiration
|
||||
if (user.getSessionId().isEmpty()) {
|
||||
// TODO Send Chat message to tables (user is not registered yet)
|
||||
// ChatManager.getInstance().broadcast([CHAT ID TABLES], "has reconnected", ChatMessage.MessageColor.GREEN);
|
||||
logger.info("Reconnecting session for " + userName);
|
||||
} else {
|
||||
//throw new MageException("This machine is already connected");
|
||||
//throw new MageException("This machine is already connected");
|
||||
//disconnect previous one
|
||||
logger.info("Disconnecting another user instance: " + userName);
|
||||
UserManager.getInstance().disconnect(user.getId(), DisconnectReason.ConnectingOtherInstance);
|
||||
|
|
@ -113,7 +114,7 @@ public class Session {
|
|||
}
|
||||
if (!UserManager.getInstance().connectToSession(sessionId, user.getId())) {
|
||||
return new StringBuilder("Error connecting ").append(userName).toString();
|
||||
}
|
||||
}
|
||||
this.userId = user.getId();
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -74,7 +74,6 @@ public class User {
|
|||
private final Map<UUID, TournamentSession> constructing;
|
||||
private final Map<UUID, Deck> sideboarding;
|
||||
private final List<UUID> watchedGames;
|
||||
private final ArrayList<UUID> tablesToRemove = new ArrayList<>();
|
||||
private String sessionId;
|
||||
private String info;
|
||||
private Date lastActivity;
|
||||
|
|
@ -387,16 +386,16 @@ public class User {
|
|||
break;
|
||||
}
|
||||
if (!isConnected()) {
|
||||
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo(disconnectInfo);
|
||||
tournamentPlayer.setDisconnectInfo(disconnectInfo);
|
||||
} else {
|
||||
table.getTournament().getPlayer(tableEntry.getKey()).setDisconnectInfo("");
|
||||
tournamentPlayer.setDisconnectInfo("");
|
||||
}
|
||||
} else {
|
||||
tablesToRemove.add(tableEntry.getKey());
|
||||
logger.error(getName() + " tournament player missing - tournamentId:" + table.getId(), null);
|
||||
// can happen if tournamet has just ended
|
||||
logger.debug(getName() + " tournament player missing - tableId:" + table.getId(), null);
|
||||
}
|
||||
} else {
|
||||
logger.error(getName() + " tournament key missing - tournamentId: " + table.getId(), null);
|
||||
logger.error(getName() + " tournament key missing - tableId: " + table.getId(), null);
|
||||
}
|
||||
} else {
|
||||
switch (table.getState()) {
|
||||
|
|
@ -411,12 +410,6 @@ public class User {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!tablesToRemove.isEmpty()) {
|
||||
for (UUID tableKey : tablesToRemove) {
|
||||
tables.remove(tableKey);
|
||||
}
|
||||
tablesToRemove.clear();
|
||||
}
|
||||
if (match > 0) {
|
||||
sb.append("Match: ").append(match).append(" ");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,6 @@ import java.util.concurrent.Executors;
|
|||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import mage.server.util.ThreadExecutor;
|
||||
import mage.view.ChatMessage;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
|
|
@ -102,17 +101,20 @@ public class UserManager {
|
|||
}
|
||||
|
||||
public boolean connectToSession(String sessionId, UUID userId) {
|
||||
if (users.containsKey(userId)) {
|
||||
users.get(userId).setSessionId(sessionId);
|
||||
if (userId != null) {
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
user.setSessionId(sessionId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void disconnect(UUID userId, DisconnectReason reason) {
|
||||
if (userId != null) {
|
||||
if (users.containsKey(userId)) {
|
||||
User user = users.get(userId);
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
user.setSessionId(""); // Session will be set again with new id if user reconnects
|
||||
}
|
||||
ChatManager.getInstance().removeUser(userId, reason);
|
||||
|
|
@ -120,28 +122,36 @@ public class UserManager {
|
|||
}
|
||||
|
||||
public boolean isAdmin(UUID userId) {
|
||||
if (users.containsKey(userId)) {
|
||||
return users.get(userId).getName().equals("Admin");
|
||||
if (userId != null) {
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
return user.getName().equals("Admin");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeUser(UUID userId, DisconnectReason reason) {
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
logger.debug("User " + user.getName() + " will be removed (" + reason.toString() + ") userId: " + userId);
|
||||
user.kill(reason);
|
||||
users.remove(userId);
|
||||
logger.debug("User " + user.getName() + " removed");
|
||||
} else {
|
||||
logger.warn(new StringBuilder("Trying to remove userId: ").append(userId).append(" but it does not exist."));
|
||||
if (userId != null) {
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
logger.debug("User " + user.getName() + " will be removed (" + reason.toString() + ") userId: " + userId);
|
||||
user.kill(reason);
|
||||
users.remove(userId);
|
||||
logger.debug("User " + user.getName() + " removed");
|
||||
} else {
|
||||
logger.warn(new StringBuilder("Trying to remove userId: ").append(userId).append(" but it does not exist."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean extendUserSession(UUID userId) {
|
||||
if (users.containsKey(userId)) {
|
||||
users.get(userId).updateLastActivity();
|
||||
return true;
|
||||
if (userId != null) {
|
||||
User user = users.get(userId);
|
||||
if (user != null) {
|
||||
user.updateLastActivity();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue