Add Hwid class for "nibble hwid" part of "remote host"
This commit is contained in:
@@ -89,6 +89,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
public static final String CLIENT_NIBBLEHWID = "HWID2";
|
public static final String CLIENT_NIBBLEHWID = "HWID2";
|
||||||
public static final String CLIENT_REMOTE_ADDRESS = "REMOTE_IP";
|
public static final String CLIENT_REMOTE_ADDRESS = "REMOTE_IP";
|
||||||
|
|
||||||
|
private Hwid hwid;
|
||||||
private String remoteAddress;
|
private String remoteAddress;
|
||||||
private volatile boolean inTransition;
|
private volatile boolean inTransition;
|
||||||
|
|
||||||
@@ -116,7 +117,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
private int pinattempt = 0;
|
private int pinattempt = 0;
|
||||||
private String pic = "";
|
private String pic = "";
|
||||||
private int picattempt = 0;
|
private int picattempt = 0;
|
||||||
private String hwid = null;
|
|
||||||
private byte csattempt = 0;
|
private byte csattempt = 0;
|
||||||
private byte gender = -1;
|
private byte gender = -1;
|
||||||
private boolean disconnecting = false;
|
private boolean disconnecting = false;
|
||||||
@@ -260,6 +260,14 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
return session;
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Hwid getHwid() {
|
||||||
|
return hwid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHwid(Hwid hwid) {
|
||||||
|
this.hwid = hwid;
|
||||||
|
}
|
||||||
|
|
||||||
public String getRemoteAddress() {
|
public String getRemoteAddress() {
|
||||||
return remoteAddress;
|
return remoteAddress;
|
||||||
}
|
}
|
||||||
@@ -387,7 +395,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
boolean ret = false;
|
boolean ret = false;
|
||||||
try (Connection con = DatabaseConnection.getConnection();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?")) {
|
PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?")) {
|
||||||
ps.setString(1, hwid);
|
ps.setString(1, hwid.hwid());
|
||||||
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
if (rs != null && rs.next()) {
|
if (rs != null && rs.next()) {
|
||||||
@@ -445,7 +453,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
hwid = rs.getString("hwid");
|
hwid = new Hwid(rs.getString("hwid"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -477,7 +485,7 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
|
|
||||||
try (Connection con = DatabaseConnection.getConnection();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
PreparedStatement ps = con.prepareStatement("INSERT INTO hwidbans (hwid) VALUES (?)")) {
|
PreparedStatement ps = con.prepareStatement("INSERT INTO hwidbans (hwid) VALUES (?)")) {
|
||||||
ps.setString(1, hwid);
|
ps.setString(1, hwid.hwid());
|
||||||
ps.executeUpdate();
|
ps.executeUpdate();
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
@@ -739,30 +747,25 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
return ipAddress;
|
return ipAddress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateHWID(String newHwid) {
|
public void updateHwid(String hwidClientString) {
|
||||||
String[] split = newHwid.split("_");
|
final Hwid hwid;
|
||||||
if (split.length > 1 && split[1].length() == 8) {
|
try {
|
||||||
StringBuilder hwid = new StringBuilder();
|
hwid = Hwid.fromClientString(hwidClientString);
|
||||||
String convert = split[1];
|
} catch (IllegalArgumentException e) {
|
||||||
|
log.warn("Failed to create hwid from client string: {}", hwidClientString, e);
|
||||||
|
this.disconnect(false, false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int len = convert.length();
|
this.hwid = hwid;
|
||||||
for (int i = len - 2; i >= 0; i -= 2) {
|
|
||||||
hwid.append(convert, i, i + 2);
|
|
||||||
}
|
|
||||||
hwid.insert(4, "-");
|
|
||||||
|
|
||||||
this.hwid = hwid.toString();
|
try (Connection con = DatabaseConnection.getConnection();
|
||||||
|
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?")) {
|
||||||
try (Connection con = DatabaseConnection.getConnection();
|
ps.setString(1, hwid.hwid());
|
||||||
PreparedStatement ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?")) {
|
ps.setInt(2, accId);
|
||||||
ps.setString(1, this.hwid);
|
ps.executeUpdate();
|
||||||
ps.setInt(2, accId);
|
} catch (SQLException e) {
|
||||||
ps.executeUpdate();
|
e.printStackTrace();
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.disconnect(false, false); // Invalid HWID...
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1173,14 +1176,6 @@ public class MapleClient extends ChannelInboundHandlerAdapter {
|
|||||||
}, TimeUnit.SECONDS.toMillis(15));
|
}, TimeUnit.SECONDS.toMillis(15));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getHWID() {
|
|
||||||
return hwid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setHWID(String hwid) {
|
|
||||||
this.hwid = hwid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<String> getMacs() {
|
public Set<String> getMacs() {
|
||||||
return Collections.unmodifiableSet(macs);
|
return Collections.unmodifiableSet(macs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ import net.server.PlayerBuffValueHolder;
|
|||||||
import net.server.Server;
|
import net.server.Server;
|
||||||
import net.server.channel.Channel;
|
import net.server.channel.Channel;
|
||||||
import net.server.channel.CharacterIdChannelPair;
|
import net.server.channel.CharacterIdChannelPair;
|
||||||
|
import net.server.coordinator.session.Hwid;
|
||||||
import net.server.coordinator.session.MapleSessionCoordinator;
|
import net.server.coordinator.session.MapleSessionCoordinator;
|
||||||
import net.server.coordinator.world.MapleEventRecallCoordinator;
|
import net.server.coordinator.world.MapleEventRecallCoordinator;
|
||||||
import net.server.guild.MapleAlliance;
|
import net.server.guild.MapleAlliance;
|
||||||
|
|||||||
@@ -2,10 +2,30 @@ package net.server.coordinator.session;
|
|||||||
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Hwid {
|
public record Hwid (String hwid) {
|
||||||
private static final Pattern VALID_HWID_PATTERN = Pattern.compile("[0-9A-F]{12}_[0-9A-F]{8}");
|
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) {
|
public static boolean isValidRawHwid(String rawHwid) {
|
||||||
return VALID_HWID_PATTERN.matcher(hwid).matches();
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
int hwidLen = remoteHwid.length();
|
final int hwidLen = remoteHwid.length();
|
||||||
if (hwidLen <= 8) {
|
final boolean isOnlyNibbleHwid = hwidLen <= 8;
|
||||||
|
if (isOnlyNibbleHwid) {
|
||||||
session.setAttribute(MapleClient.CLIENT_NIBBLEHWID, remoteHwid);
|
session.setAttribute(MapleClient.CLIENT_NIBBLEHWID, remoteHwid);
|
||||||
} else {
|
} else {
|
||||||
session.setAttribute(MapleClient.CLIENT_HWID, remoteHwid);
|
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
|
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);
|
onlineRemoteHwids.remove(hwid);
|
||||||
|
|
||||||
hwid = (String) session.removeAttribute(MapleClient.CLIENT_HWID);
|
hwid = (String) session.removeAttribute(MapleClient.CLIENT_HWID);
|
||||||
|
// TODO: client.setHwid(null);
|
||||||
onlineRemoteHwids.remove(hwid);
|
onlineRemoteHwids.remove(hwid);
|
||||||
|
|
||||||
if (client != null) {
|
if (client != null) {
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ public final class CharSelectedHandler extends AbstractMaplePacketHandler {
|
|||||||
|
|
||||||
case REMOTE_NO_MATCH:
|
case REMOTE_NO_MATCH:
|
||||||
return 17;
|
return 17;
|
||||||
|
|
||||||
case COORDINATOR_ERROR:
|
case COORDINATOR_ERROR:
|
||||||
return 8;
|
return 8;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 9;
|
return 9;
|
||||||
}
|
}
|
||||||
@@ -62,13 +62,13 @@ public final class CharSelectedHandler extends AbstractMaplePacketHandler {
|
|||||||
String macs = slea.readMapleAsciiString();
|
String macs = slea.readMapleAsciiString();
|
||||||
String hwid = slea.readMapleAsciiString();
|
String hwid = slea.readMapleAsciiString();
|
||||||
|
|
||||||
if (!Hwid.isValidHwid(hwid)) {
|
if (!Hwid.isValidRawHwid(hwid)) {
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.updateMacs(macs);
|
c.updateMacs(macs);
|
||||||
c.updateHWID(hwid);
|
c.updateHwid(hwid);
|
||||||
|
|
||||||
IoSession session = c.getSession();
|
IoSession session = c.getSession();
|
||||||
AntiMulticlientResult res = MapleSessionCoordinator.getInstance().attemptGameSession(session, c.getAccID(), hwid);
|
AntiMulticlientResult res = MapleSessionCoordinator.getInstance().attemptGameSession(session, c.getAccID(), hwid);
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public class CharSelectedWithPicHandler extends AbstractMaplePacketHandler {
|
|||||||
String macs = slea.readMapleAsciiString();
|
String macs = slea.readMapleAsciiString();
|
||||||
String hwid = slea.readMapleAsciiString();
|
String hwid = slea.readMapleAsciiString();
|
||||||
|
|
||||||
if (!Hwid.isValidHwid(hwid)) {
|
if (!Hwid.isValidRawHwid(hwid)) {
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.updateMacs(macs);
|
c.updateMacs(macs);
|
||||||
c.updateHWID(hwid);
|
c.updateHwid(hwid);
|
||||||
|
|
||||||
IoSession session = c.getSession();
|
IoSession session = c.getSession();
|
||||||
|
|
||||||
|
|||||||
@@ -43,13 +43,13 @@ public final class RegisterPicHandler extends AbstractMaplePacketHandler {
|
|||||||
String macs = slea.readMapleAsciiString();
|
String macs = slea.readMapleAsciiString();
|
||||||
String hwid = slea.readMapleAsciiString();
|
String hwid = slea.readMapleAsciiString();
|
||||||
|
|
||||||
if (!Hwid.isValidHwid(hwid)) {
|
if (!Hwid.isValidRawHwid(hwid)) {
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.updateMacs(macs);
|
c.updateMacs(macs);
|
||||||
c.updateHWID(hwid);
|
c.updateHwid(hwid);
|
||||||
|
|
||||||
IoSession session = c.getSession();
|
IoSession session = c.getSession();
|
||||||
AntiMulticlientResult res = MapleSessionCoordinator.getInstance().attemptGameSession(session, c.getAccID(), hwid);
|
AntiMulticlientResult res = MapleSessionCoordinator.getInstance().attemptGameSession(session, c.getAccID(), hwid);
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ public final class ViewAllCharRegisterPicHandler extends AbstractMaplePacketHand
|
|||||||
String mac = slea.readMapleAsciiString();
|
String mac = slea.readMapleAsciiString();
|
||||||
String hwid = slea.readMapleAsciiString();
|
String hwid = slea.readMapleAsciiString();
|
||||||
|
|
||||||
if (!Hwid.isValidHwid(hwid)) {
|
if (!Hwid.isValidRawHwid(hwid)) {
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.updateMacs(mac);
|
c.updateMacs(mac);
|
||||||
c.updateHWID(hwid);
|
c.updateHwid(hwid);
|
||||||
|
|
||||||
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
||||||
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
||||||
|
|||||||
@@ -64,13 +64,13 @@ public final class ViewAllCharSelectedHandler extends AbstractMaplePacketHandler
|
|||||||
String macs = slea.readMapleAsciiString();
|
String macs = slea.readMapleAsciiString();
|
||||||
String hwid = slea.readMapleAsciiString();
|
String hwid = slea.readMapleAsciiString();
|
||||||
|
|
||||||
if (!Hwid.isValidHwid(hwid)) {
|
if (!Hwid.isValidRawHwid(hwid)) {
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.updateMacs(macs);
|
c.updateMacs(macs);
|
||||||
c.updateHWID(hwid);
|
c.updateHwid(hwid);
|
||||||
|
|
||||||
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
||||||
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ public class ViewAllCharSelectedWithPicHandler extends AbstractMaplePacketHandle
|
|||||||
String macs = slea.readMapleAsciiString();
|
String macs = slea.readMapleAsciiString();
|
||||||
String hwid = slea.readMapleAsciiString();
|
String hwid = slea.readMapleAsciiString();
|
||||||
|
|
||||||
if (!Hwid.isValidHwid(hwid)) {
|
if (!Hwid.isValidRawHwid(hwid)) {
|
||||||
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
c.announce(MaplePacketCreator.getAfterLoginError(17));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
c.updateMacs(macs);
|
c.updateMacs(macs);
|
||||||
c.updateHWID(hwid);
|
c.updateHwid(hwid);
|
||||||
|
|
||||||
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
if (c.hasBannedMac() || c.hasBannedHWID()) {
|
||||||
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
MapleSessionCoordinator.getInstance().closeSession(c.getSession(), true);
|
||||||
|
|||||||
Reference in New Issue
Block a user