Use Hwid for login bypass

This commit is contained in:
P0nk
2021-07-15 22:08:19 +02:00
parent a1ed7ed821
commit cce85ea663
4 changed files with 40 additions and 52 deletions

View File

@@ -579,7 +579,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
} }
if (pin.equals(other)) { if (pin.equals(other)) {
pinattempt = 0; pinattempt = 0;
MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(getNibbleHWID(), accId, false); MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(hwid, accId, false);
return true; return true;
} }
return false; return false;
@@ -612,7 +612,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
} }
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
picattempt = 0; picattempt = 0;
MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(getNibbleHWID(), accId, true); MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(hwid, accId, true);
return true; return true;
} }
return false; return false;
@@ -1597,21 +1597,12 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
announce(MaplePacketCreator.enableCSUse(player)); announce(MaplePacketCreator.enableCSUse(player));
} }
@Deprecated
public String getNibbleHWID() {
if (hwid != null) {
return hwid.hwid();
}
return null;
}
public boolean canBypassPin() { public boolean canBypassPin() {
return MapleLoginBypassCoordinator.getInstance().canLoginBypass(getNibbleHWID(), accId, false); return MapleLoginBypassCoordinator.getInstance().canLoginBypass(hwid, accId, false);
} }
public boolean canBypassPic() { public boolean canBypassPic() {
return MapleLoginBypassCoordinator.getInstance().canLoginBypass(getNibbleHWID(), accId, true); return MapleLoginBypassCoordinator.getInstance().canLoginBypass(hwid, accId, true);
} }
public int getLanguage() { public int getLanguage() {
@@ -1621,8 +1612,4 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
public void setLanguage(int lingua) { public void setLanguage(int lingua) {
this.lang = lingua; this.lang = lingua;
} }
public static MapleClient getPlaceholder() {
return null;
}
} }

View File

@@ -36,7 +36,7 @@ public class EnableAuthCommand extends Command {
public void execute(MapleClient c, String[] params) { public void execute(MapleClient c, String[] params) {
if (c.tryacquireClient()) { if (c.tryacquireClient()) {
try { try {
MapleLoginBypassCoordinator.getInstance().unregisterLoginBypassEntry(c.getNibbleHWID(), c.getAccID()); MapleLoginBypassCoordinator.getInstance().unregisterLoginBypassEntry(c.getHwid(), c.getAccID());
} finally { } finally {
c.releaseClient(); c.releaseClient();
} }

View File

@@ -19,7 +19,14 @@
*/ */
package net.server.coordinator.login; package net.server.coordinator.login;
import client.MapleCharacter;
import client.MapleClient;
import config.YamlConfig; import config.YamlConfig;
import net.server.Server;
import net.server.coordinator.session.Hwid;
import net.server.world.World;
import tools.Pair;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@@ -27,62 +34,56 @@ import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import client.MapleCharacter;
import client.MapleClient;
import net.server.world.World;
import net.server.Server;
import tools.Pair;
/** /**
*
* @author Ronan * @author Ronan
*/ */
public class MapleLoginBypassCoordinator { public class MapleLoginBypassCoordinator {
private final static MapleLoginBypassCoordinator instance = new MapleLoginBypassCoordinator(); private final static MapleLoginBypassCoordinator instance = new MapleLoginBypassCoordinator();
public static MapleLoginBypassCoordinator getInstance() { public static MapleLoginBypassCoordinator getInstance() {
return instance; return instance;
} }
private final ConcurrentHashMap<Pair<String, Integer>, Pair<Boolean, Long>> loginBypass = new ConcurrentHashMap<>(); // optimized PIN & PIC check private final ConcurrentHashMap<Pair<Hwid, Integer>, Pair<Boolean, Long>> loginBypass = new ConcurrentHashMap<>(); // optimized PIN & PIC check
public boolean canLoginBypass(String nibbleHwid, int accId, boolean pic) { public boolean canLoginBypass(Hwid hwid, int accId, boolean pic) {
try { try {
Pair<String, Integer> entry = new Pair<>(nibbleHwid, accId); Pair<Hwid, Integer> entry = new Pair<>(hwid, accId);
Boolean p = loginBypass.get(entry).getLeft(); Boolean p = loginBypass.get(entry).getLeft();
return !pic || p; return !pic || p;
} catch (NullPointerException npe) { } catch (NullPointerException npe) {
return false; return false;
} }
} }
public void registerLoginBypassEntry(String nibbleHwid, int accId, boolean pic) { public void registerLoginBypassEntry(Hwid hwid, int accId, boolean pic) {
long expireTime = (pic ? YamlConfig.config.server.BYPASS_PIC_EXPIRATION : YamlConfig.config.server.BYPASS_PIN_EXPIRATION); long expireTime = (pic ? YamlConfig.config.server.BYPASS_PIC_EXPIRATION : YamlConfig.config.server.BYPASS_PIN_EXPIRATION);
if (expireTime > 0) { if (expireTime > 0) {
Pair<String, Integer> entry = new Pair<>(nibbleHwid, accId); Pair<Hwid, Integer> entry = new Pair<>(hwid, accId);
expireTime = Server.getInstance().getCurrentTime() + expireTime * 60 * 1000; expireTime = Server.getInstance().getCurrentTime() + expireTime * 60 * 1000;
try { try {
pic |= loginBypass.get(entry).getLeft(); pic |= loginBypass.get(entry).getLeft();
expireTime = Math.max(loginBypass.get(entry).getRight(), expireTime); expireTime = Math.max(loginBypass.get(entry).getRight(), expireTime);
} catch (NullPointerException npe) {} } catch (NullPointerException npe) {
}
loginBypass.put(entry, new Pair<>(pic, expireTime)); loginBypass.put(entry, new Pair<>(pic, expireTime));
} }
} }
public void unregisterLoginBypassEntry(String nibbleHwid, int accId) { public void unregisterLoginBypassEntry(Hwid hwid, int accId) {
Pair<String, Integer> entry = new Pair<>(nibbleHwid, accId); String hwidValue = hwid == null ? null : hwid.hwid();
Pair<String, Integer> entry = new Pair<>(hwidValue, accId);
loginBypass.remove(entry); loginBypass.remove(entry);
} }
public void runUpdateLoginBypass() { public void runUpdateLoginBypass() {
if (!loginBypass.isEmpty()) { if (!loginBypass.isEmpty()) {
List<Pair<String, Integer>> toRemove = new LinkedList<>(); List<Pair<Hwid, Integer>> toRemove = new LinkedList<>();
Set<Integer> onlineAccounts = new HashSet<>(); Set<Integer> onlineAccounts = new HashSet<>();
long timeNow = Server.getInstance().getCurrentTime(); long timeNow = Server.getInstance().getCurrentTime();
for (World w : Server.getInstance().getWorlds()) { for (World w : Server.getInstance().getWorlds()) {
for (MapleCharacter chr : w.getPlayerStorage().getAllCharacters()) { for (MapleCharacter chr : w.getPlayerStorage().getAllCharacters()) {
MapleClient c = chr.getClient(); MapleClient c = chr.getClient();
@@ -91,8 +92,8 @@ public class MapleLoginBypassCoordinator {
} }
} }
} }
for (Entry<Pair<String, Integer>, Pair<Boolean, Long>> e : loginBypass.entrySet()) { for (Entry<Pair<Hwid, Integer>, Pair<Boolean, Long>> e : loginBypass.entrySet()) {
if (onlineAccounts.contains(e.getKey().getRight())) { if (onlineAccounts.contains(e.getKey().getRight())) {
long expireTime = timeNow + 2 * 60 * 1000; long expireTime = timeNow + 2 * 60 * 1000;
if (expireTime > e.getValue().getRight()) { if (expireTime > e.getValue().getRight()) {
@@ -102,13 +103,13 @@ public class MapleLoginBypassCoordinator {
toRemove.add(e.getKey()); toRemove.add(e.getKey());
} }
} }
if (!toRemove.isEmpty()) { if (!toRemove.isEmpty()) {
for (Pair<String, Integer> p : toRemove) { for (Pair<Hwid, Integer> p : toRemove) {
loginBypass.remove(p); loginBypass.remove(p);
} }
} }
} }
} }
} }

View File

@@ -93,10 +93,10 @@ public class MapleSessionCoordinator {
} }
public static String getSessionRemoteHost(MapleClient client) { public static String getSessionRemoteHost(MapleClient client) {
String nibbleHwid = client.getNibbleHWID(); Hwid hwid = client.getHwid();
if (nibbleHwid != null) { if (hwid != null) {
return client.getRemoteAddress() + "-" + nibbleHwid; return client.getRemoteAddress() + "-" + hwid.hwid();
} else { } else {
return client.getRemoteAddress(); return client.getRemoteAddress();
} }