Handle disconnect solely in TransitionService
This commit is contained in:
@@ -4,13 +4,18 @@ import client.Client;
|
||||
|
||||
public class DisconnectException extends RuntimeException {
|
||||
private final Client client;
|
||||
private final boolean shutdown;
|
||||
|
||||
public DisconnectException(Client client, String message) {
|
||||
super(message);
|
||||
public DisconnectException(Client client, boolean shutdown) {
|
||||
this.client = client;
|
||||
this.shutdown = shutdown;
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public boolean isShutdown() {
|
||||
return shutdown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ public class DisconnectHandler extends ChannelInboundHandlerAdapter {
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
|
||||
if (cause instanceof DisconnectException de) {
|
||||
var client = de.getClient();
|
||||
transitionService.disconnect(client, true, false);
|
||||
transitionService.disconnect(client, true);
|
||||
} else {
|
||||
ctx.fireExceptionCaught(cause);
|
||||
}
|
||||
|
||||
@@ -1923,7 +1923,7 @@ public class Server {
|
||||
|
||||
for (Client c : toDisconnect) { // thanks Lei for pointing a deadlock issue with srvLock
|
||||
if (c.isLoggedIn()) {
|
||||
channelDependencies.transitionService().disconnect(c, false, false);
|
||||
channelDependencies.transitionService().disconnect(c, false);
|
||||
} else {
|
||||
SessionCoordinator.getInstance().closeSession(c, true);
|
||||
}
|
||||
|
||||
@@ -195,7 +195,7 @@ public final class AdminCommandHandler extends AbstractPacketHandler {
|
||||
private void sendPolice(Client c, String reason) {
|
||||
c.sendPacket(PacketCreator.sendPolice(String.format("You have been blocked by the#b %s Police for %s.#k", "Cosmic", reason)));
|
||||
c.getPlayer().setBanned();
|
||||
TimerManager.getInstance().schedule(() -> transitionService.disconnect(c, false, false),
|
||||
TimerManager.getInstance().schedule(() -> transitionService.disconnect(c, false),
|
||||
TimeUnit.SECONDS.toMillis(6));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,24 +109,6 @@ public class SessionCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Overwrites any existing online client for the account id, making sure to disconnect it as well.
|
||||
*/
|
||||
public void updateOnlineClient(Client client) {
|
||||
if (client != null) {
|
||||
int accountId = client.getAccID();
|
||||
disconnectClientIfOnline(accountId);
|
||||
onlineClients.put(accountId, client);
|
||||
}
|
||||
}
|
||||
|
||||
private void disconnectClientIfOnline(int accountId) {
|
||||
Client ingameClient = onlineClients.get(accountId);
|
||||
if (ingameClient != null) { // thanks MedicOP for finding out a loss of loggedin account uniqueness when using the CMS "Unstuck" feature
|
||||
ingameClient.forceDisconnect();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean canStartLoginSession(Client client) {
|
||||
if (!YamlConfig.config.server.DETERRED_MULTICLIENT) {
|
||||
return true;
|
||||
|
||||
@@ -28,7 +28,7 @@ public class TimeoutTask extends BaseTask implements Runnable {
|
||||
for (Character chr : chars) {
|
||||
if (time - chr.getClient().getLastPacket() > YamlConfig.config.server.TIMEOUT_DURATION) {
|
||||
log.info("Chr {} auto-disconnected due to inactivity", chr.getName());
|
||||
transitionService.disconnect(chr.getClient(), true, chr.getCashShop().isOpened());
|
||||
transitionService.disconnect(chr.getClient(), true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user