Handle disconnect solely in TransitionService

This commit is contained in:
P0nk
2024-09-13 22:59:55 +02:00
parent 719b079cbc
commit f41268cdde
14 changed files with 85 additions and 275 deletions

View File

@@ -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;
}
}

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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));
}
}

View File

@@ -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;

View File

@@ -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);
}
}
}