Add Hwid class for "nibble hwid" part of "remote host"
This commit is contained in:
@@ -31,6 +31,7 @@ import net.server.PlayerBuffValueHolder;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.channel.CharacterIdChannelPair;
|
||||
import net.server.coordinator.session.Hwid;
|
||||
import net.server.coordinator.session.MapleSessionCoordinator;
|
||||
import net.server.coordinator.world.MapleEventRecallCoordinator;
|
||||
import net.server.guild.MapleAlliance;
|
||||
|
||||
@@ -2,10 +2,30 @@ package net.server.coordinator.session;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class Hwid {
|
||||
private static final Pattern VALID_HWID_PATTERN = Pattern.compile("[0-9A-F]{12}_[0-9A-F]{8}");
|
||||
public record Hwid (String hwid) {
|
||||
private static final int HWID_LENGTH = 8;
|
||||
// First part is a mac address (without dashes), second part is the hwid
|
||||
private static final Pattern VALID_RAW_HWID_PATTERN = Pattern.compile("[0-9A-F]{12}_[0-9A-F]{8}");
|
||||
|
||||
public static boolean isValidHwid(String hwid) {
|
||||
return VALID_HWID_PATTERN.matcher(hwid).matches();
|
||||
public static boolean isValidRawHwid(String rawHwid) {
|
||||
return VALID_RAW_HWID_PATTERN.matcher(rawHwid).matches();
|
||||
}
|
||||
|
||||
public static Hwid fromClientString(String clientString) throws IllegalArgumentException {
|
||||
String[] split = clientString.split("_");
|
||||
if (split.length != 2 || split[1].length() != HWID_LENGTH) {
|
||||
throw new IllegalArgumentException("Hwid validation failed for hwid: " + clientString);
|
||||
}
|
||||
|
||||
StringBuilder newHwid = new StringBuilder();
|
||||
String convert = split[1];
|
||||
|
||||
int len = convert.length();
|
||||
for (int i = len - 2; i >= 0; i -= 2) {
|
||||
newHwid.append(convert, i, i + 2);
|
||||
}
|
||||
newHwid.insert(4, "-");
|
||||
|
||||
return new Hwid(newHwid.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,8 +297,9 @@ public class MapleSessionCoordinator {
|
||||
return null;
|
||||
}
|
||||
|
||||
int hwidLen = remoteHwid.length();
|
||||
if (hwidLen <= 8) {
|
||||
final int hwidLen = remoteHwid.length();
|
||||
final boolean isOnlyNibbleHwid = hwidLen <= 8;
|
||||
if (isOnlyNibbleHwid) {
|
||||
session.setAttribute(MapleClient.CLIENT_NIBBLEHWID, remoteHwid);
|
||||
} else {
|
||||
session.setAttribute(MapleClient.CLIENT_HWID, remoteHwid);
|
||||
@@ -326,9 +327,11 @@ public class MapleSessionCoordinator {
|
||||
}
|
||||
|
||||
String hwid = (String) session.removeAttribute(MapleClient.CLIENT_NIBBLEHWID); // making sure to clean up calls to this function on login phase
|
||||
// TODO: client.setNibbleHwid(null);
|
||||
onlineRemoteHwids.remove(hwid);
|
||||
|
||||
hwid = (String) session.removeAttribute(MapleClient.CLIENT_HWID);
|
||||
// TODO: client.setHwid(null);
|
||||
onlineRemoteHwids.remove(hwid);
|
||||
|
||||
if (client != null) {
|
||||
|
||||
@@ -46,10 +46,10 @@ public final class CharSelectedHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
case REMOTE_NO_MATCH:
|
||||
return 17;
|
||||
|
||||
|
||||
case COORDINATOR_ERROR:
|
||||
return 8;
|
||||
|
||||
|
||||
default:
|
||||
return 9;
|
||||
}
|
||||
@@ -62,13 +62,13 @@ public final class CharSelectedHandler extends AbstractMaplePacketHandler {
|
||||
String macs = slea.readMapleAsciiString();
|
||||
String hwid = slea.readMapleAsciiString();
|
||||
|
||||
if (!Hwid.isValidHwid(hwid)) {
|
||||
if (!Hwid.isValidRawHwid(hwid)) {
|
||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||
return;
|
||||
}
|
||||
|
||||
c.updateMacs(macs);
|
||||
c.updateHWID(hwid);
|
||||
c.updateHwid(hwid);
|
||||
|
||||
IoSession session = c.getSession();
|
||||
AntiMulticlientResult res = MapleSessionCoordinator.getInstance().attemptGameSession(session, c.getAccID(), hwid);
|
||||
|
||||
@@ -43,13 +43,13 @@ public class CharSelectedWithPicHandler extends AbstractMaplePacketHandler {
|
||||
String macs = slea.readMapleAsciiString();
|
||||
String hwid = slea.readMapleAsciiString();
|
||||
|
||||
if (!Hwid.isValidHwid(hwid)) {
|
||||
if (!Hwid.isValidRawHwid(hwid)) {
|
||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||
return;
|
||||
}
|
||||
|
||||
c.updateMacs(macs);
|
||||
c.updateHWID(hwid);
|
||||
c.updateHwid(hwid);
|
||||
|
||||
IoSession session = c.getSession();
|
||||
|
||||
|
||||
@@ -43,13 +43,13 @@ public final class RegisterPicHandler extends AbstractMaplePacketHandler {
|
||||
String macs = slea.readMapleAsciiString();
|
||||
String hwid = slea.readMapleAsciiString();
|
||||
|
||||
if (!Hwid.isValidHwid(hwid)) {
|
||||
if (!Hwid.isValidRawHwid(hwid)) {
|
||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||
return;
|
||||
}
|
||||
|
||||
c.updateMacs(macs);
|
||||
c.updateHWID(hwid);
|
||||
c.updateHwid(hwid);
|
||||
|
||||
IoSession session = c.getSession();
|
||||
AntiMulticlientResult res = MapleSessionCoordinator.getInstance().attemptGameSession(session, c.getAccID(), hwid);
|
||||
|
||||
@@ -44,13 +44,13 @@ public final class ViewAllCharRegisterPicHandler extends AbstractMaplePacketHand
|
||||
String mac = slea.readMapleAsciiString();
|
||||
String hwid = slea.readMapleAsciiString();
|
||||
|
||||
if (!Hwid.isValidHwid(hwid)) {
|
||||
if (!Hwid.isValidRawHwid(hwid)) {
|
||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||
return;
|
||||
}
|
||||
|
||||
c.updateMacs(mac);
|
||||
c.updateHWID(hwid);
|
||||
c.updateHwid(hwid);
|
||||
|
||||
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
||||
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
||||
|
||||
@@ -64,13 +64,13 @@ public final class ViewAllCharSelectedHandler extends AbstractMaplePacketHandler
|
||||
String macs = slea.readMapleAsciiString();
|
||||
String hwid = slea.readMapleAsciiString();
|
||||
|
||||
if (!Hwid.isValidHwid(hwid)) {
|
||||
if (!Hwid.isValidRawHwid(hwid)) {
|
||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||
return;
|
||||
}
|
||||
|
||||
c.updateMacs(macs);
|
||||
c.updateHWID(hwid);
|
||||
c.updateHwid(hwid);
|
||||
|
||||
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
||||
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
||||
|
||||
@@ -46,13 +46,13 @@ public class ViewAllCharSelectedWithPicHandler extends AbstractMaplePacketHandle
|
||||
String macs = slea.readMapleAsciiString();
|
||||
String hwid = slea.readMapleAsciiString();
|
||||
|
||||
if (!Hwid.isValidHwid(hwid)) {
|
||||
if (!Hwid.isValidRawHwid(hwid)) {
|
||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||
return;
|
||||
}
|
||||
|
||||
c.updateMacs(macs);
|
||||
c.updateHWID(hwid);
|
||||
c.updateHwid(hwid);
|
||||
|
||||
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
||||
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
||||
|
||||
Reference in New Issue
Block a user