Disconnect client with TransitionService
This commit is contained in:
@@ -431,10 +431,8 @@ public class Server {
|
||||
String event_message = YamlConfig.config.worlds.get(i).event_message;
|
||||
String why_am_i_recommended = YamlConfig.config.worlds.get(i).why_am_i_recommended;
|
||||
|
||||
World world = new World(i,
|
||||
flag,
|
||||
event_message,
|
||||
exprate, droprate, bossdroprate, mesorate, questrate, travelrate, fishingrate);
|
||||
World world = new World(i, flag, event_message, exprate, droprate, bossdroprate, mesorate, questrate,
|
||||
travelrate, fishingrate, channelDependencies.transitionService());
|
||||
|
||||
Map<Integer, String> channelInfo = new HashMap<>();
|
||||
long bootTime = getCurrentTime();
|
||||
@@ -928,7 +926,7 @@ public class Server {
|
||||
}
|
||||
}
|
||||
|
||||
loginServer = initLoginServer(8484, channelDependencies.characterSaver());
|
||||
loginServer = initLoginServer(8484, channelDependencies.transitionService());
|
||||
|
||||
log.info("Listening on port 8484");
|
||||
|
||||
@@ -999,8 +997,8 @@ public class Server {
|
||||
return channelDependencies;
|
||||
}
|
||||
|
||||
private LoginServer initLoginServer(int port, CharacterSaver characterSaver) {
|
||||
LoginServer loginServer = new LoginServer(port, characterSaver);
|
||||
private LoginServer initLoginServer(int port, TransitionService transitionService) {
|
||||
LoginServer loginServer = new LoginServer(port, transitionService);
|
||||
loginServer.start();
|
||||
return loginServer;
|
||||
}
|
||||
@@ -1898,7 +1896,7 @@ public class Server {
|
||||
|
||||
for (Client c : toDisconnect) { // thanks Lei for pointing a deadlock issue with srvLock
|
||||
if (c.isLoggedIn()) {
|
||||
c.disconnect(false, false);
|
||||
channelDependencies.transitionService().disconnect(c, false, false);
|
||||
} else {
|
||||
SessionCoordinator.getInstance().closeSession(c, true);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ package net.server.channel;
|
||||
import client.Character;
|
||||
import config.YamlConfig;
|
||||
import constants.id.MapId;
|
||||
import database.character.CharacterSaver;
|
||||
import database.drop.DropProvider;
|
||||
import net.ChannelDependencies;
|
||||
import net.netty.ChannelServer;
|
||||
@@ -45,6 +44,7 @@ import server.events.gm.Event;
|
||||
import server.expeditions.Expedition;
|
||||
import server.expeditions.ExpeditionType;
|
||||
import server.maps.*;
|
||||
import service.TransitionService;
|
||||
import tools.PacketCreator;
|
||||
import tools.Pair;
|
||||
|
||||
@@ -126,7 +126,7 @@ public final class Channel {
|
||||
this.merchWlock = rwLock.writeLock();
|
||||
|
||||
try {
|
||||
this.channelServer = initServer(port, world, channel, channelDependencies.characterSaver());
|
||||
this.channelServer = initServer(port, world, channel, channelDependencies.transitionService());
|
||||
expedType.addAll(Arrays.asList(ExpeditionType.values()));
|
||||
|
||||
if (Server.getInstance().isOnline()) { // postpone event loading to improve boot time... thanks Riizade, daronhudson for noticing slow startup times
|
||||
@@ -154,8 +154,8 @@ public final class Channel {
|
||||
}
|
||||
}
|
||||
|
||||
private ChannelServer initServer(int port, int world, int channel, CharacterSaver characterSaver) {
|
||||
ChannelServer channelServer = new ChannelServer(port, world, channel, characterSaver);
|
||||
private ChannelServer initServer(int port, int world, int channel, TransitionService transitionService) {
|
||||
ChannelServer channelServer = new ChannelServer(port, world, channel, transitionService);
|
||||
channelServer.start();
|
||||
return channelServer;
|
||||
}
|
||||
|
||||
@@ -31,19 +31,27 @@ import net.packet.InPacket;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import server.ItemInformationProvider;
|
||||
import server.TimerManager;
|
||||
import server.life.LifeFactory;
|
||||
import server.life.Monster;
|
||||
import server.maps.MapObject;
|
||||
import server.maps.MapObjectType;
|
||||
import server.quest.Quest;
|
||||
import service.TransitionService;
|
||||
import tools.PacketCreator;
|
||||
import tools.Randomizer;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class AdminCommandHandler extends AbstractPacketHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(AdminCommandHandler.class);
|
||||
private final TransitionService transitionService;
|
||||
|
||||
public AdminCommandHandler(TransitionService transitionService) {
|
||||
this.transitionService = transitionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(InPacket p, Client c) {
|
||||
@@ -95,7 +103,7 @@ public final class AdminCommandHandler extends AbstractPacketHandler {
|
||||
target.ban(description + " " + reason);
|
||||
} else {
|
||||
target.block(type, duration, description);
|
||||
target.sendPolice(duration, reason, 6000);
|
||||
sendPolice(target.getClient(), reason);
|
||||
}
|
||||
c.sendPacket(PacketCreator.getGMEffect(4, (byte) 0));
|
||||
} else if (Character.ban(victim, reason, false)) {
|
||||
@@ -183,4 +191,11 @@ public final class AdminCommandHandler extends AbstractPacketHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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),
|
||||
TimeUnit.SECONDS.toMillis(6));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import config.YamlConfig;
|
||||
import net.server.world.World;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import service.TransitionService;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
@@ -13,6 +14,12 @@ import java.util.Collection;
|
||||
*/
|
||||
public class TimeoutTask extends BaseTask implements Runnable {
|
||||
private static final Logger log = LoggerFactory.getLogger(TimeoutTask.class);
|
||||
private final TransitionService transitionService;
|
||||
|
||||
public TimeoutTask(World world, TransitionService transitionService) {
|
||||
super(world);
|
||||
this.transitionService = transitionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -21,12 +28,8 @@ 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());
|
||||
chr.getClient().disconnect(true, chr.getCashShop().isOpened());
|
||||
transitionService.disconnect(chr.getClient(), true, chr.getCashShop().isOpened());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public TimeoutTask(World world) {
|
||||
super(world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +53,7 @@ import scripting.event.EventInstanceManager;
|
||||
import server.Storage;
|
||||
import server.TimerManager;
|
||||
import server.maps.*;
|
||||
import service.TransitionService;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.PacketCreator;
|
||||
import tools.Pair;
|
||||
@@ -161,7 +162,8 @@ public class World {
|
||||
private ScheduledFuture<?> timeoutSchedule;
|
||||
private ScheduledFuture<?> hpDecSchedule;
|
||||
|
||||
public World(int world, int flag, String eventmsg, int exprate, int droprate, int bossdroprate, int mesorate, int questrate, int travelrate, int fishingrate) {
|
||||
public World(int world, int flag, String eventmsg, int exprate, int droprate, int bossdroprate, int mesorate,
|
||||
int questrate, int travelrate, int fishingrate, TransitionService transitionService) {
|
||||
this.id = world;
|
||||
this.flag = flag;
|
||||
this.eventmsg = eventmsg;
|
||||
@@ -200,7 +202,7 @@ public class World {
|
||||
mapOwnershipSchedule = tman.register(new MapOwnershipTask(this), SECONDS.toMillis(20), SECONDS.toMillis(20));
|
||||
fishingSchedule = tman.register(new FishingTask(this), SECONDS.toMillis(10), SECONDS.toMillis(10));
|
||||
partySearchSchedule = tman.register(new PartySearchTask(this), SECONDS.toMillis(10), SECONDS.toMillis(10));
|
||||
timeoutSchedule = tman.register(new TimeoutTask(this), SECONDS.toMillis(10), SECONDS.toMillis(10));
|
||||
timeoutSchedule = tman.register(new TimeoutTask(this, transitionService), SECONDS.toMillis(10), SECONDS.toMillis(10));
|
||||
hpDecSchedule = tman.register(new CharacterHpDecreaseTask(this), YamlConfig.config.server.MAP_DAMAGE_OVERTIME_INTERVAL, YamlConfig.config.server.MAP_DAMAGE_OVERTIME_INTERVAL);
|
||||
|
||||
if (YamlConfig.config.server.USE_FAMILY_SYSTEM) {
|
||||
|
||||
Reference in New Issue
Block a user