mirror of
https://github.com/correl/mage.git
synced 2025-03-16 01:06:34 -09:00
Merge pull request #3023 from ingmargoudt/inspecting_npe
Inspecting npe
This commit is contained in:
commit
8da4f72f8d
1 changed files with 36 additions and 34 deletions
|
@ -222,45 +222,47 @@ public class Session {
|
||||||
);
|
);
|
||||||
|
|
||||||
}
|
}
|
||||||
Optional<User> selectUser = UserManager.instance.createUser(userName, host, authorizedUser);
|
}
|
||||||
boolean reconnect = false;
|
}
|
||||||
if (!selectUser.isPresent()) { // user already exists
|
Optional<User> selectUser = UserManager.instance.createUser(userName, host, authorizedUser);
|
||||||
selectUser = UserManager.instance.getUserByName(userName);
|
boolean reconnect = false;
|
||||||
if (selectUser.isPresent()) {
|
if (!selectUser.isPresent()) { // user already exists
|
||||||
User user = selectUser.get();
|
selectUser = UserManager.instance.getUserByName(userName);
|
||||||
// If authentication is not activated, check the identity using IP address.
|
if (selectUser.isPresent()) {
|
||||||
if (ConfigSettings.instance.isAuthenticationActivated() || user.getHost().equals(host)) {
|
|
||||||
user.updateLastActivity(null); // minimizes possible expiration
|
|
||||||
this.userId = user.getId();
|
|
||||||
if (user.getSessionId().isEmpty()) {
|
|
||||||
logger.info("Reconnecting session for " + userName);
|
|
||||||
reconnect = true;
|
|
||||||
} else {
|
|
||||||
//disconnect previous session
|
|
||||||
logger.info("Disconnecting another user instance: " + userName);
|
|
||||||
SessionManager.instance.disconnect(user.getSessionId(), DisconnectReason.ConnectingOtherInstance);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "User name " + userName + " already in use (or your IP address changed)";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
User user = selectUser.get();
|
User user = selectUser.get();
|
||||||
if (!UserManager.instance.connectToSession(sessionId, user.getId())) {
|
// If authentication is not activated, check the identity using IP address.
|
||||||
return "Error connecting " + userName;
|
if (ConfigSettings.instance.isAuthenticationActivated() || user.getHost().equals(host)) {
|
||||||
}
|
user.updateLastActivity(null); // minimizes possible expiration
|
||||||
this.userId = user.getId();
|
this.userId = user.getId();
|
||||||
if (reconnect) { // must be connected to receive the message
|
if (user.getSessionId().isEmpty()) {
|
||||||
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(GamesRoomManager.instance.getMainRoomId());
|
logger.info("Reconnecting session for " + userName);
|
||||||
if (!room.isPresent()) {
|
reconnect = true;
|
||||||
logger.error("main room not found");
|
} else {
|
||||||
return null;
|
//disconnect previous session
|
||||||
|
logger.info("Disconnecting another user instance: " + userName);
|
||||||
|
SessionManager.instance.disconnect(user.getSessionId(), DisconnectReason.ConnectingOtherInstance);
|
||||||
}
|
}
|
||||||
ChatManager.instance.joinChat(room.get().getChatId(), userId);
|
} else {
|
||||||
ChatManager.instance.sendReconnectMessage(userId);
|
return "User name " + userName + " already in use (or your IP address changed)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
User user = selectUser.get();
|
||||||
|
if (!UserManager.instance.connectToSession(sessionId, user.getId())) {
|
||||||
|
return "Error connecting " + userName;
|
||||||
|
}
|
||||||
|
this.userId = user.getId();
|
||||||
|
if (reconnect) { // must be connected to receive the message
|
||||||
|
Optional<GamesRoom> room = GamesRoomManager.instance.getRoom(GamesRoomManager.instance.getMainRoomId());
|
||||||
|
if (!room.isPresent()) {
|
||||||
|
logger.error("main room not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ChatManager.instance.joinChat(room.get().getChatId(), userId);
|
||||||
|
ChatManager.instance.sendReconnectMessage(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue