Move some Client#forceDisconnect calls to TransitionService
This commit is contained in:
@@ -22,7 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package client;
|
||||
|
||||
import config.YamlConfig;
|
||||
import constants.game.GameConstants;
|
||||
import constants.id.MapId;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
@@ -1092,22 +1091,6 @@ public class Client extends ChannelInboundHandlerAdapter {
|
||||
return disconnect;
|
||||
}
|
||||
|
||||
public void checkChar(int accid) { /// issue with multiple chars from same account login found by shavit, resinate
|
||||
if (!YamlConfig.config.server.USE_CHARACTER_ACCOUNT_CHECK) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (World w : Server.getInstance().getWorlds()) {
|
||||
for (Character chr : w.getPlayerStorage().getAllCharacters()) {
|
||||
if (accid == chr.getAccountID()) {
|
||||
log.warn("Chr {} has been removed from world {}. Possible Dupe attempt.", chr.getName(), GameConstants.WORLD_NAMES[w.getId()]);
|
||||
chr.getClient().forceDisconnect();
|
||||
w.getPlayerStorage().removePlayer(chr.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void lockClient() {
|
||||
lock.lock();
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public final class PacketProcessor {
|
||||
registerHandler(RecvOpcode.SERVERLIST_REREQUEST, new ServerlistRequestHandler());
|
||||
registerHandler(RecvOpcode.CHARLIST_REQUEST, new CharlistRequestHandler());
|
||||
registerHandler(RecvOpcode.CHAR_SELECT, new CharSelectedHandler());
|
||||
registerHandler(RecvOpcode.LOGIN_PASSWORD, new LoginPasswordHandler());
|
||||
registerHandler(RecvOpcode.LOGIN_PASSWORD, new LoginPasswordHandler(channelDeps.transitionService()));
|
||||
registerHandler(RecvOpcode.RELOG, new RelogRequestHandler());
|
||||
registerHandler(RecvOpcode.SERVERLIST_REQUEST, new ServerlistRequestHandler());
|
||||
registerHandler(RecvOpcode.SERVERSTATUS_REQUEST, new ServerStatusRequestHandler());
|
||||
@@ -128,7 +128,7 @@ public final class PacketProcessor {
|
||||
registerHandler(RecvOpcode.VIEW_ALL_CHAR, new ViewAllCharHandler());
|
||||
registerHandler(RecvOpcode.PICK_ALL_CHAR, new ViewAllCharSelectedHandler());
|
||||
registerHandler(RecvOpcode.REGISTER_PIN, new RegisterPinHandler());
|
||||
registerHandler(RecvOpcode.GUEST_LOGIN, new GuestLoginHandler());
|
||||
registerHandler(RecvOpcode.GUEST_LOGIN, new GuestLoginHandler(channelDeps.transitionService()));
|
||||
registerHandler(RecvOpcode.REGISTER_PIC, new RegisterPicHandler());
|
||||
registerHandler(RecvOpcode.CHAR_SELECT_WITH_PIC, new CharSelectedWithPicHandler());
|
||||
registerHandler(RecvOpcode.SET_GENDER, new SetGenderHandler());
|
||||
|
||||
@@ -23,6 +23,7 @@ package net.server;
|
||||
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import service.TransitionService;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -30,12 +31,14 @@ import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class PlayerStorage {
|
||||
private final TransitionService transitionService;
|
||||
private final Map<Integer, Character> storage = new LinkedHashMap<>();
|
||||
private final Map<String, Character> nameStorage = new LinkedHashMap<>();
|
||||
private final Lock rlock;
|
||||
private final Lock wlock;
|
||||
|
||||
public PlayerStorage() {
|
||||
public PlayerStorage(TransitionService transitionService) {
|
||||
this.transitionService = transitionService;
|
||||
ReadWriteLock readWriteLock = new ReentrantReadWriteLock(true);
|
||||
this.rlock = readWriteLock.readLock();
|
||||
this.wlock = readWriteLock.writeLock();
|
||||
@@ -104,7 +107,7 @@ public class PlayerStorage {
|
||||
for (Character mc : chrList) {
|
||||
Client client = mc.getClient();
|
||||
if (client != null) {
|
||||
client.forceDisconnect();
|
||||
transitionService.forceDisconnect(client);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,4 +127,4 @@ public class PlayerStorage {
|
||||
rlock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,13 +70,14 @@ public final class Channel {
|
||||
private final int world;
|
||||
private final int channel;
|
||||
|
||||
private PlayerStorage players = new PlayerStorage();
|
||||
private PlayerStorage players;
|
||||
private ChannelServer channelServer;
|
||||
private String serverMessage;
|
||||
private MapManager mapManager;
|
||||
private EventScriptManager eventSM;
|
||||
private ServicesManager services;
|
||||
private final DropProvider dropProvider;
|
||||
private final TransitionService transitionService;
|
||||
private final Map<Integer, HiredMerchant> hiredMerchants = new HashMap<>();
|
||||
private final Map<Integer, Integer> storedVars = new HashMap<>();
|
||||
private final Set<Integer> playersAway = new HashSet<>();
|
||||
@@ -115,6 +116,8 @@ public final class Channel {
|
||||
this.world = world;
|
||||
this.channel = channel;
|
||||
this.dropProvider = channelDependencies.dropProvider();
|
||||
this.transitionService = channelDependencies.transitionService();
|
||||
this.players = new PlayerStorage(channelDependencies.transitionService());
|
||||
|
||||
this.ongoingStartTime = startTime + 10000; // rude approach to a world's last channel boot time, placeholder for the 1st wedding reservation ever
|
||||
this.mapManager = new MapManager(null, world, channel, dropProvider);
|
||||
@@ -341,7 +344,7 @@ public final class Channel {
|
||||
for (Integer cid : playersAway) {
|
||||
Character chr = wserv.getPlayerStorage().getCharacterById(cid);
|
||||
if (chr != null && chr.isLoggedin()) {
|
||||
chr.getClient().forceDisconnect();
|
||||
transitionService.forceDisconnect(chr.getClient());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,23 @@ package net.server.handlers.login;
|
||||
import client.Client;
|
||||
import net.AbstractPacketHandler;
|
||||
import net.packet.InPacket;
|
||||
import service.TransitionService;
|
||||
import tools.PacketCreator;
|
||||
|
||||
/*
|
||||
* @author David
|
||||
*/
|
||||
public final class GuestLoginHandler extends AbstractPacketHandler {
|
||||
private final TransitionService transitionService;
|
||||
|
||||
public GuestLoginHandler(TransitionService transitionService) {
|
||||
this.transitionService = transitionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void handlePacket(InPacket p, Client c) {
|
||||
c.sendPacket(PacketCreator.sendGuestTOS());
|
||||
//System.out.println(slea.toString());
|
||||
new LoginPasswordHandler().handlePacket(p, c);
|
||||
new LoginPasswordHandler(transitionService).handlePacket(p, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,19 @@
|
||||
*/
|
||||
package net.server.handlers.login;
|
||||
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import client.DefaultDates;
|
||||
import config.YamlConfig;
|
||||
import constants.game.GameConstants;
|
||||
import net.PacketHandler;
|
||||
import net.packet.InPacket;
|
||||
import net.server.Server;
|
||||
import net.server.coordinator.session.Hwid;
|
||||
import net.server.world.World;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import service.TransitionService;
|
||||
import tools.BCrypt;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.HexTool;
|
||||
@@ -41,6 +47,12 @@ import java.sql.*;
|
||||
import java.util.Calendar;
|
||||
|
||||
public final class LoginPasswordHandler implements PacketHandler {
|
||||
private static final Logger log = LoggerFactory.getLogger(LoginPasswordHandler.class);
|
||||
private final TransitionService transitionService;
|
||||
|
||||
public LoginPasswordHandler(TransitionService transitionService) {
|
||||
this.transitionService = transitionService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean validateState(Client c) {
|
||||
@@ -124,13 +136,30 @@ public final class LoginPasswordHandler implements PacketHandler {
|
||||
return;
|
||||
}
|
||||
if (c.finishLogin()) {
|
||||
c.checkChar(c.getAccID());
|
||||
checkChar(c);
|
||||
login(c);
|
||||
} else {
|
||||
c.sendPacket(PacketCreator.getLoginFailed(7));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkChar(Client c) { // issue with multiple chars from same account login found by shavit, resinate
|
||||
if (!YamlConfig.config.server.USE_CHARACTER_ACCOUNT_CHECK) {
|
||||
return;
|
||||
}
|
||||
|
||||
final int accId = c.getAccID();
|
||||
for (World w : Server.getInstance().getWorlds()) {
|
||||
for (Character chr : w.getPlayerStorage().getAllCharacters()) {
|
||||
if (accId == chr.getAccountID()) {
|
||||
log.warn("Chr {} has been removed from world {}. Possible Dupe attempt.", chr.getName(), GameConstants.WORLD_NAMES[w.getId()]);
|
||||
transitionService.forceDisconnect(c);
|
||||
w.getPlayerStorage().removePlayer(chr.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void login(Client c) {
|
||||
c.sendPacket(PacketCreator.getAuthSuccess(c));//why the fk did I do c.getAccountName()?
|
||||
Server.getInstance().registerLoginState(c);
|
||||
|
||||
@@ -98,7 +98,7 @@ public class World {
|
||||
private final Map<Integer, Integer> relationships = new HashMap<>();
|
||||
private final Map<Integer, Pair<Integer, Integer>> relationshipCouples = new HashMap<>();
|
||||
private final Map<Integer, GuildSummary> gsStore = new HashMap<>();
|
||||
private PlayerStorage players = new PlayerStorage();
|
||||
private PlayerStorage players;
|
||||
private final ServicesManager services = new ServicesManager(WorldServices.SAVE_CHARACTER);
|
||||
private final MatchCheckerCoordinator matchChecker = new MatchCheckerCoordinator();
|
||||
private final PartySearchCoordinator partySearch = new PartySearchCoordinator();
|
||||
@@ -177,6 +177,8 @@ public class World {
|
||||
runningPartyId.set(1000000001); // partyid must not clash with charid to solve update item looting issues, found thanks to Vcoc
|
||||
runningMessengerId.set(1);
|
||||
|
||||
this.players = new PlayerStorage(transitionService);
|
||||
|
||||
ReadWriteLock channelLock = new ReentrantReadWriteLock(true);
|
||||
this.chnRLock = channelLock.readLock();
|
||||
this.chnWLock = channelLock.writeLock();
|
||||
|
||||
Reference in New Issue
Block a user