forked from External/mage
Changed user disconnect handling. The user in the server is no longer deleted directly after connection problem, disconnect or quit. The user object remains now for 8 minutes so the rejoin not possible after disconnect problem should be solved (I hope so). We will see. Also fixed the problem, that the table panel was not shown, if a player disconected and reconected.
This commit is contained in:
parent
5dbb89772e
commit
bae7f154df
10 changed files with 220 additions and 170 deletions
|
|
@ -64,7 +64,10 @@ public class User {
|
|||
|
||||
public enum UserState {
|
||||
|
||||
Created, Connected, Disconnected, Reconnected, Expired
|
||||
Created, // Used if user is created an not connected to the session
|
||||
Connected, // Used if user is correctly connected
|
||||
Disconnected, // Used if the user lost connection
|
||||
Offline // set if the user was disconnected and expired or regularly left XMage. Removed is the user later after some time
|
||||
}
|
||||
|
||||
private final UUID userId;
|
||||
|
|
@ -164,7 +167,7 @@ public class User {
|
|||
userState = UserState.Connected;
|
||||
logger.trace("USER - created: " + userName + " id: " + userId);
|
||||
} else {
|
||||
userState = UserState.Reconnected;
|
||||
userState = UserState.Connected;
|
||||
reconnect();
|
||||
logger.trace("USER - reconnected: " + userName + " id: " + userId);
|
||||
}
|
||||
|
|
@ -212,23 +215,14 @@ public class User {
|
|||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return userState == UserState.Connected || userState == UserState.Reconnected;
|
||||
return userState == UserState.Connected;
|
||||
}
|
||||
|
||||
public String getDisconnectDuration() {
|
||||
long secondsDisconnected = getSecondsDisconnected();
|
||||
long secondsLeft;
|
||||
String sign = "";
|
||||
if (secondsDisconnected > (3 * 60)) {
|
||||
sign = "-";
|
||||
secondsLeft = secondsDisconnected - (3 * 60);
|
||||
} else {
|
||||
secondsLeft = (3 * 60) - secondsDisconnected;
|
||||
}
|
||||
|
||||
int minutes = (int) secondsLeft / 60;
|
||||
int seconds = (int) secondsLeft % 60;
|
||||
return new StringBuilder(sign).append(Integer.toString(minutes)).append(':').append(seconds > 9 ? seconds : '0' + Integer.toString(seconds)).toString();
|
||||
int minutes = (int) secondsDisconnected / 60;
|
||||
int seconds = (int) secondsDisconnected % 60;
|
||||
return Integer.toString(minutes) + ':' + (seconds > 9 ? seconds : '0' + Integer.toString(seconds));
|
||||
}
|
||||
|
||||
public long getSecondsDisconnected() {
|
||||
|
|
@ -239,6 +233,20 @@ public class User {
|
|||
return connectionTime;
|
||||
}
|
||||
|
||||
public Date getLastActivity() {
|
||||
return lastActivity;
|
||||
}
|
||||
|
||||
public String getConnectionDuration() {
|
||||
int minutes = (int) SystemUtil.getDateDiff(connectionTime, new Date(), TimeUnit.SECONDS) / 60;
|
||||
int hours = 0;
|
||||
if (minutes > 59) {
|
||||
hours = (int) minutes / 60;
|
||||
minutes = minutes - (hours * 60);
|
||||
}
|
||||
return Integer.toString(hours) + ":" + (minutes > 9 ? Integer.toString(minutes) : '0' + Integer.toString(minutes));
|
||||
}
|
||||
|
||||
public void fireCallback(final ClientCallback call) {
|
||||
if (isConnected()) {
|
||||
SessionManager.instance.getSession(sessionId).ifPresent(session
|
||||
|
|
@ -331,19 +339,17 @@ public class User {
|
|||
}
|
||||
lastActivity = new Date();
|
||||
if (userState == UserState.Disconnected) { // this can happen if user reconnects very fast after disconnect
|
||||
userState = UserState.Reconnected;
|
||||
userState = UserState.Connected;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isExpired(Date expired) {
|
||||
if (lastActivity.before(expired)) {
|
||||
logger.trace(userName + " is expired!");
|
||||
userState = UserState.Expired;
|
||||
return true;
|
||||
}
|
||||
logger.trace("isExpired: User " + userName + " lastActivity: " + lastActivity + " expired: " + expired);
|
||||
return false;
|
||||
/*userState == UserState.Disconnected && */
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -511,11 +517,15 @@ public class User {
|
|||
tournament++;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!isConnected()) {
|
||||
tournamentPlayer.setDisconnectInfo(" (discon. " + getDisconnectDuration() + ')');
|
||||
} else {
|
||||
tournamentPlayer.setDisconnectInfo("");
|
||||
switch (getUserState()) {
|
||||
case Disconnected:
|
||||
tournamentPlayer.setDisconnectInfo(" (discon. " + getDisconnectDuration() + ')');
|
||||
break;
|
||||
case Offline:
|
||||
tournamentPlayer.setDisconnectInfo(" Offline");
|
||||
break;
|
||||
default:
|
||||
tournamentPlayer.setDisconnectInfo("");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -586,11 +596,18 @@ public class User {
|
|||
return userState;
|
||||
}
|
||||
|
||||
public void setUserState(UserState userState) {
|
||||
this.userState = userState;
|
||||
}
|
||||
|
||||
public String getPingInfo() {
|
||||
if (isConnected()) {
|
||||
return pingInfo;
|
||||
} else {
|
||||
return " (discon. " + getDisconnectDuration() + ')';
|
||||
switch (getUserState()) {
|
||||
case Disconnected:
|
||||
return " (discon. " + getDisconnectDuration() + ')';
|
||||
case Offline:
|
||||
return " Offline";
|
||||
default:
|
||||
return pingInfo + " " + getConnectionDuration();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue