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 {
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_SERVER_TRANSITION = 1;
@@ -122,7 +123,6 @@ public class Client extends ChannelInboundHandlerAdapter {
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
private Calendar tempBanCalendar;
private int visibleWorlds;
private long lastNpcClick;
private long lastPacket = System.currentTimeMillis();
private int lang = 0;
@@ -545,8 +545,7 @@ public class Client extends ChannelInboundHandlerAdapter {
return true;
}
pinattempt++;
if (pinattempt > 5) {
if (++pinattempt >= MAX_FAILED_LOGIN_ATTEMPTS) {
SessionCoordinator.getInstance().closeSession(this, false);
}
if (pin.equals(other)) {
@@ -578,8 +577,7 @@ public class Client extends ChannelInboundHandlerAdapter {
return true;
}
picattempt++;
if (picattempt > 5) {
if (++picattempt >= MAX_FAILED_LOGIN_ATTEMPTS) {
SessionCoordinator.getInstance().closeSession(this, false);
}
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) {
int loginok = 5;
loginattempt++;
if (loginattempt > 4) {
if (++loginattempt >= MAX_FAILED_LOGIN_ATTEMPTS) {
loggedIn = false;
SessionCoordinator.getInstance().closeSession(this, false);
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;
}
public boolean canRequestCharlist() {
return lastNpcClick + 877 < Server.getInstance().getCurrentTime();
}
public boolean canClickNPC() {
return lastNpcClick + 500 < Server.getInstance().getCurrentTime();
}
@@ -1395,15 +1388,6 @@ public class Client extends ChannelInboundHandlerAdapter {
lastNpcClick = 0;
}
public int getVisibleWorlds() {
return visibleWorlds;
}
public void requestedServerlist(int worlds) {
visibleWorlds = worlds;
setClickedNPC();
}
public void closePlayerScriptInteractions() {
this.removeClickedNPC();
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();
if (worlds.size() > visibleWorlds) {
worlds = worlds.subList(0, visibleWorlds);
}
SortedMap<Integer, List<Character>> worldChrs = new TreeMap<>();
int chrTotal = 0;

View File

@@ -29,21 +29,16 @@ import net.server.Server;
import net.server.world.World;
import tools.PacketCreator;
import java.util.List;
public final class ServerlistRequestHandler extends AbstractPacketHandler {
@Override
public final void handlePacket(InPacket p, Client c) {
Server server = Server.getInstance();
List<World> worlds = server.getWorlds();
c.requestedServerlist(worlds.size());
for (World world : worlds) {
for (World world : server.getWorlds()) {
c.sendPacket(PacketCreator.getServerList(world.getId(), GameConstants.WORLD_NAMES[world.getId()], world.getFlag(), world.getEventMessage(), world.getChannels()));
}
c.sendPacket(PacketCreator.getEndOfServerList());
c.sendPacket(PacketCreator.selectWorld(0));//too lazy to make a check lol
c.sendPacket(PacketCreator.sendRecommended(server.worldRecommendedList()));
}
}
}

View File

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