Use Hwid for login bypass
This commit is contained in:
@@ -579,7 +579,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
if (pin.equals(other)) {
|
||||
pinattempt = 0;
|
||||
MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(getNibbleHWID(), accId, false);
|
||||
MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(hwid, accId, false);
|
||||
return true;
|
||||
}
|
||||
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
|
||||
picattempt = 0;
|
||||
MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(getNibbleHWID(), accId, true);
|
||||
MapleLoginBypassCoordinator.getInstance().registerLoginBypassEntry(hwid, accId, true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -1597,21 +1597,12 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
announce(MaplePacketCreator.enableCSUse(player));
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public String getNibbleHWID() {
|
||||
if (hwid != null) {
|
||||
return hwid.hwid();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean canBypassPin() {
|
||||
return MapleLoginBypassCoordinator.getInstance().canLoginBypass(getNibbleHWID(), accId, false);
|
||||
return MapleLoginBypassCoordinator.getInstance().canLoginBypass(hwid, accId, false);
|
||||
}
|
||||
|
||||
public boolean canBypassPic() {
|
||||
return MapleLoginBypassCoordinator.getInstance().canLoginBypass(getNibbleHWID(), accId, true);
|
||||
return MapleLoginBypassCoordinator.getInstance().canLoginBypass(hwid, accId, true);
|
||||
}
|
||||
|
||||
public int getLanguage() {
|
||||
@@ -1621,8 +1612,4 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
||||
public void setLanguage(int lingua) {
|
||||
this.lang = lingua;
|
||||
}
|
||||
|
||||
public static MapleClient getPlaceholder() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ public class EnableAuthCommand extends Command {
|
||||
public void execute(MapleClient c, String[] params) {
|
||||
if (c.tryacquireClient()) {
|
||||
try {
|
||||
MapleLoginBypassCoordinator.getInstance().unregisterLoginBypassEntry(c.getNibbleHWID(), c.getAccID());
|
||||
MapleLoginBypassCoordinator.getInstance().unregisterLoginBypassEntry(c.getHwid(), c.getAccID());
|
||||
} finally {
|
||||
c.releaseClient();
|
||||
}
|
||||
|
||||
@@ -19,7 +19,14 @@
|
||||
*/
|
||||
package net.server.coordinator.login;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import client.MapleClient;
|
||||
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.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -27,62 +34,56 @@ import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
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
|
||||
*/
|
||||
public class MapleLoginBypassCoordinator {
|
||||
|
||||
private final static MapleLoginBypassCoordinator instance = new MapleLoginBypassCoordinator();
|
||||
|
||||
|
||||
public static MapleLoginBypassCoordinator getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
private final ConcurrentHashMap<Pair<String, Integer>, Pair<Boolean, Long>> loginBypass = new ConcurrentHashMap<>(); // optimized PIN & PIC check
|
||||
|
||||
public boolean canLoginBypass(String nibbleHwid, int accId, boolean pic) {
|
||||
|
||||
private final ConcurrentHashMap<Pair<Hwid, Integer>, Pair<Boolean, Long>> loginBypass = new ConcurrentHashMap<>(); // optimized PIN & PIC check
|
||||
|
||||
public boolean canLoginBypass(Hwid hwid, int accId, boolean pic) {
|
||||
try {
|
||||
Pair<String, Integer> entry = new Pair<>(nibbleHwid, accId);
|
||||
Pair<Hwid, Integer> entry = new Pair<>(hwid, accId);
|
||||
Boolean p = loginBypass.get(entry).getLeft();
|
||||
|
||||
|
||||
return !pic || p;
|
||||
} catch (NullPointerException npe) {
|
||||
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);
|
||||
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;
|
||||
try {
|
||||
pic |= loginBypass.get(entry).getLeft();
|
||||
expireTime = Math.max(loginBypass.get(entry).getRight(), expireTime);
|
||||
} catch (NullPointerException npe) {}
|
||||
|
||||
} catch (NullPointerException npe) {
|
||||
}
|
||||
|
||||
loginBypass.put(entry, new Pair<>(pic, expireTime));
|
||||
}
|
||||
}
|
||||
|
||||
public void unregisterLoginBypassEntry(String nibbleHwid, int accId) {
|
||||
Pair<String, Integer> entry = new Pair<>(nibbleHwid, accId);
|
||||
|
||||
public void unregisterLoginBypassEntry(Hwid hwid, int accId) {
|
||||
String hwidValue = hwid == null ? null : hwid.hwid();
|
||||
Pair<String, Integer> entry = new Pair<>(hwidValue, accId);
|
||||
loginBypass.remove(entry);
|
||||
}
|
||||
|
||||
|
||||
public void runUpdateLoginBypass() {
|
||||
if (!loginBypass.isEmpty()) {
|
||||
List<Pair<String, Integer>> toRemove = new LinkedList<>();
|
||||
List<Pair<Hwid, Integer>> toRemove = new LinkedList<>();
|
||||
Set<Integer> onlineAccounts = new HashSet<>();
|
||||
long timeNow = Server.getInstance().getCurrentTime();
|
||||
|
||||
|
||||
for (World w : Server.getInstance().getWorlds()) {
|
||||
for (MapleCharacter chr : w.getPlayerStorage().getAllCharacters()) {
|
||||
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())) {
|
||||
long expireTime = timeNow + 2 * 60 * 1000;
|
||||
if (expireTime > e.getValue().getRight()) {
|
||||
@@ -102,13 +103,13 @@ public class MapleLoginBypassCoordinator {
|
||||
toRemove.add(e.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!toRemove.isEmpty()) {
|
||||
for (Pair<String, Integer> p : toRemove) {
|
||||
for (Pair<Hwid, Integer> p : toRemove) {
|
||||
loginBypass.remove(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -93,10 +93,10 @@ public class MapleSessionCoordinator {
|
||||
}
|
||||
|
||||
public static String getSessionRemoteHost(MapleClient client) {
|
||||
String nibbleHwid = client.getNibbleHWID();
|
||||
Hwid hwid = client.getHwid();
|
||||
|
||||
if (nibbleHwid != null) {
|
||||
return client.getRemoteAddress() + "-" + nibbleHwid;
|
||||
if (hwid != null) {
|
||||
return client.getRemoteAddress() + "-" + hwid.hwid();
|
||||
} else {
|
||||
return client.getRemoteAddress();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user