Add client disconnection logic to TransitionService
Problem: disconnecting requires access to CharacterSaver, which is not available in Client. Having it in a service like this solves that problem. Next step is to migrate all calls to Client#disconnect and Client#forceDisconnect to their TransitionService counterparts.
This commit is contained in:
@@ -305,6 +305,10 @@ public class Client extends ChannelInboundHandlerAdapter {
|
||||
return loggedIn;
|
||||
}
|
||||
|
||||
public boolean isInTransition() {
|
||||
return serverTransition;
|
||||
}
|
||||
|
||||
public boolean hasBannedIP() {
|
||||
boolean ret = false;
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
@@ -833,7 +837,7 @@ public class Client extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private synchronized boolean tryDisconnect() {
|
||||
public synchronized boolean tryDisconnect() {
|
||||
if (disconnecting) {
|
||||
return false;
|
||||
}
|
||||
@@ -924,7 +928,7 @@ public class Client extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
private void clear() {
|
||||
public void clear() {
|
||||
// player hard reference removal thanks to Steve (kaito1410)
|
||||
if (this.player != null) {
|
||||
this.player.empty(true); // clears schedules and stuff
|
||||
|
||||
@@ -7,6 +7,7 @@ package client.autoban;
|
||||
|
||||
import client.Character;
|
||||
import config.YamlConfig;
|
||||
import net.netty.GameViolationException;
|
||||
import net.server.Server;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -118,11 +119,10 @@ public class AutobanManager {
|
||||
if (this.timestamp[type] == time) {
|
||||
this.timestampcounter[type]++;
|
||||
if (this.timestampcounter[type] >= times) {
|
||||
if (YamlConfig.config.server.USE_AUTOBAN) {
|
||||
chr.getClient().disconnect(false, false);
|
||||
}
|
||||
|
||||
log.info("Autoban - Chr {} was caught spamming TYPE {} and has been disconnected", chr, type);
|
||||
if (YamlConfig.config.server.USE_AUTOBAN) {
|
||||
throw new GameViolationException("Auto ban");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.timestamp[type] = time;
|
||||
|
||||
@@ -3,15 +3,15 @@ package client.command;
|
||||
import database.character.CharacterSaver;
|
||||
import database.drop.DropProvider;
|
||||
import server.shop.ShopFactory;
|
||||
import service.ChannelService;
|
||||
import service.TransitionService;
|
||||
|
||||
/**
|
||||
* @author Ponk
|
||||
*/
|
||||
public record CommandContext(CommandsExecutor commandsExecutor, DropProvider dropProvider, ShopFactory shopFactory,
|
||||
CharacterSaver characterSaver, ChannelService channelService) {
|
||||
CharacterSaver characterSaver, TransitionService transitionService) {
|
||||
|
||||
public CommandContext with(CommandsExecutor ce) {
|
||||
return new CommandContext(ce, this.dropProvider, this.shopFactory, this.characterSaver, this.channelService);
|
||||
return new CommandContext(ce, this.dropProvider, this.shopFactory, this.characterSaver, this.transitionService);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SummonCommand extends Command {
|
||||
|
||||
if (player.getClient().getChannel() != victim.getClient().getChannel()) {//And then change channel if needed.
|
||||
victim.dropMessage("Changing channel, please wait a moment.");
|
||||
ctx.channelService().changeChannel(victim.getClient(), player.getClient().getChannel());
|
||||
ctx.transitionService().changeChannel(victim.getClient(), player.getClient().getChannel());
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user