Clean up Client - visibleWorlds & canRequestCharlist

canRequestCharlist is a relic from the past when "View all char"
functionality was hacked together with wrong packets.

visibleWorlds I'm less sure about. I suppose it's useful if you add world
(via command) while someone is still on the login screen.
But the functionality of adding/removing worlds live is a recipe for disaster
and will eventually (likely) be removed.
This commit is contained in:
P0nk
2023-08-06 20:02:39 +02:00
parent f44083aeba
commit 48d9aaa871
4 changed files with 8 additions and 37 deletions

View File

@@ -81,6 +81,7 @@ import static java.util.concurrent.TimeUnit.SECONDS;
public class Client extends ChannelInboundHandlerAdapter { public class Client extends ChannelInboundHandlerAdapter {
private static final Logger log = LoggerFactory.getLogger(Client.class); private static final Logger log = LoggerFactory.getLogger(Client.class);
private static final int MAX_FAILED_LOGIN_ATTEMPTS = 5;
public static final int LOGIN_NOTLOGGEDIN = 0; public static final int LOGIN_NOTLOGGEDIN = 0;
public static final int LOGIN_SERVER_TRANSITION = 1; public static final int LOGIN_SERVER_TRANSITION = 1;
@@ -122,7 +123,6 @@ public class Client extends ChannelInboundHandlerAdapter {
private final Lock announcerLock = new ReentrantLock(true); private final Lock announcerLock = new ReentrantLock(true);
// thanks Masterrulax & try2hack for pointing out a bottleneck issue with shared locks, shavit for noticing an opportunity for improvement // thanks Masterrulax & try2hack for pointing out a bottleneck issue with shared locks, shavit for noticing an opportunity for improvement
private Calendar tempBanCalendar; private Calendar tempBanCalendar;
private int visibleWorlds;
private long lastNpcClick; private long lastNpcClick;
private long lastPacket = System.currentTimeMillis(); private long lastPacket = System.currentTimeMillis();
private int lang = 0; private int lang = 0;
@@ -545,8 +545,7 @@ public class Client extends ChannelInboundHandlerAdapter {
return true; return true;
} }
pinattempt++; if (++pinattempt >= MAX_FAILED_LOGIN_ATTEMPTS) {
if (pinattempt > 5) {
SessionCoordinator.getInstance().closeSession(this, false); SessionCoordinator.getInstance().closeSession(this, false);
} }
if (pin.equals(other)) { if (pin.equals(other)) {
@@ -578,8 +577,7 @@ public class Client extends ChannelInboundHandlerAdapter {
return true; return true;
} }
picattempt++; if (++picattempt >= MAX_FAILED_LOGIN_ATTEMPTS) {
if (picattempt > 5) {
SessionCoordinator.getInstance().closeSession(this, false); SessionCoordinator.getInstance().closeSession(this, false);
} }
if (pic.equals(other)) { // thanks ryantpayton (HeavenClient) for noticing null pics being checked here if (pic.equals(other)) { // thanks ryantpayton (HeavenClient) for noticing null pics being checked here
@@ -593,8 +591,7 @@ public class Client extends ChannelInboundHandlerAdapter {
public int login(String login, String pwd, Hwid hwid) { public int login(String login, String pwd, Hwid hwid) {
int loginok = 5; int loginok = 5;
loginattempt++; if (++loginattempt >= MAX_FAILED_LOGIN_ATTEMPTS) {
if (loginattempt > 4) {
loggedIn = false; loggedIn = false;
SessionCoordinator.getInstance().closeSession(this, false); SessionCoordinator.getInstance().closeSession(this, false);
return 6; // thanks Survival_Project for finding out an issue with AUTOMATIC_REGISTER here return 6; // thanks Survival_Project for finding out an issue with AUTOMATIC_REGISTER here
@@ -1379,10 +1376,6 @@ public class Client extends ChannelInboundHandlerAdapter {
return this.sessionId; return this.sessionId;
} }
public boolean canRequestCharlist() {
return lastNpcClick + 877 < Server.getInstance().getCurrentTime();
}
public boolean canClickNPC() { public boolean canClickNPC() {
return lastNpcClick + 500 < Server.getInstance().getCurrentTime(); return lastNpcClick + 500 < Server.getInstance().getCurrentTime();
} }
@@ -1395,15 +1388,6 @@ public class Client extends ChannelInboundHandlerAdapter {
lastNpcClick = 0; lastNpcClick = 0;
} }
public int getVisibleWorlds() {
return visibleWorlds;
}
public void requestedServerlist(int worlds) {
visibleWorlds = worlds;
setClickedNPC();
}
public void closePlayerScriptInteractions() { public void closePlayerScriptInteractions() {
this.removeClickedNPC(); this.removeClickedNPC();
NPCScriptManager.getInstance().dispose(this); NPCScriptManager.getInstance().dispose(this);

View File

@@ -1497,11 +1497,8 @@ public class Server {
} }
} }
public SortedMap<Integer, List<Character>> loadAccountCharlist(int accountId, int visibleWorlds) { public SortedMap<Integer, List<Character>> loadAccountCharlist(int accountId) {
List<World> worlds = this.getWorlds(); List<World> worlds = this.getWorlds();
if (worlds.size() > visibleWorlds) {
worlds = worlds.subList(0, visibleWorlds);
}
SortedMap<Integer, List<Character>> worldChrs = new TreeMap<>(); SortedMap<Integer, List<Character>> worldChrs = new TreeMap<>();
int chrTotal = 0; int chrTotal = 0;

View File

@@ -29,17 +29,12 @@ import net.server.Server;
import net.server.world.World; import net.server.world.World;
import tools.PacketCreator; import tools.PacketCreator;
import java.util.List;
public final class ServerlistRequestHandler extends AbstractPacketHandler { public final class ServerlistRequestHandler extends AbstractPacketHandler {
@Override @Override
public final void handlePacket(InPacket p, Client c) { public final void handlePacket(InPacket p, Client c) {
Server server = Server.getInstance(); Server server = Server.getInstance();
List<World> worlds = server.getWorlds(); for (World world : server.getWorlds()) {
c.requestedServerlist(worlds.size());
for (World world : worlds) {
c.sendPacket(PacketCreator.getServerList(world.getId(), GameConstants.WORLD_NAMES[world.getId()], world.getFlag(), world.getEventMessage(), world.getChannels())); c.sendPacket(PacketCreator.getServerList(world.getId(), GameConstants.WORLD_NAMES[world.getId()], world.getFlag(), world.getEventMessage(), world.getChannels()));
} }
c.sendPacket(PacketCreator.getEndOfServerList()); c.sendPacket(PacketCreator.getEndOfServerList());

View File

@@ -37,12 +37,7 @@ public final class ViewAllCharHandler extends AbstractPacketHandler {
@Override @Override
public final void handlePacket(InPacket p, Client c) { public final void handlePacket(InPacket p, Client c) {
try { try {
if (!c.canRequestCharlist()) { // client breaks if the charlist request pops too soon SortedMap<Integer, List<Character>> worldChrs = Server.getInstance().loadAccountCharlist(c.getAccID());
c.sendPacket(PacketCreator.showAllCharacter(0, 0));
return;
}
SortedMap<Integer, List<Character>> worldChrs = Server.getInstance().loadAccountCharlist(c.getAccID(), c.getVisibleWorlds());
worldChrs = limitTotalChrs(worldChrs, CHARACTER_LIMIT); worldChrs = limitTotalChrs(worldChrs, CHARACTER_LIMIT);
padChrsIfNeeded(worldChrs); padChrsIfNeeded(worldChrs);