Attempt to store HWID in temporary trace map and account variables.

This commit is contained in:
MobiusDevelopment
2020-10-16 09:28:40 +00:00
parent 9d7ddf9ea4
commit d77326f074
75 changed files with 2760 additions and 420 deletions

View File

@@ -16,6 +16,9 @@
*/
package org.l2jmobius.gameserver.model.holders;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.variables.AccountVariables;
/**
* @author Mobius
*/
@@ -64,6 +67,77 @@ public class ClientHardwareInfoHolder
_vgaDriverVersion = vgaDriverVersion;
}
public ClientHardwareInfoHolder(String info)
{
final String[] split = info.split(AccountVariables.HWIDSLIT_VAR);
_macAddress = split[0];
_windowsPlatformId = Integer.valueOf(split[1]);
_windowsMajorVersion = Integer.valueOf(split[2]);
_windowsMinorVersion = Integer.valueOf(split[3]);
_windowsBuildNumber = Integer.valueOf(split[4]);
_directxVersion = Integer.valueOf(split[5]);
_directxRevision = Integer.valueOf(split[6]);
_cpuName = split[7];
_cpuSpeed = Integer.valueOf(split[8]);
_cpuCoreCount = Integer.valueOf(split[9]);
_vgaCount = Integer.valueOf(split[10]);
_vgaPcxSpeed = Integer.valueOf(split[11]);
_physMemorySlot1 = Integer.valueOf(split[12]);
_physMemorySlot2 = Integer.valueOf(split[13]);
_physMemorySlot3 = Integer.valueOf(split[14]);
_videoMemory = Integer.valueOf(split[15]);
_vgaVersion = Integer.valueOf(split[16]);
_vgaName = split[17];
_vgaDriverVersion = split[18];
}
/**
* Save hardware info to account variables for later use.
* @param player The PlayerInstance related with this hardware info.
*/
public void store(PlayerInstance player)
{
final StringBuilder sb = new StringBuilder();
sb.append(_macAddress);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_windowsPlatformId);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_windowsMajorVersion);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_windowsMinorVersion);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_windowsBuildNumber);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_directxVersion);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_directxRevision);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_cpuName);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_cpuSpeed);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_cpuCoreCount);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_vgaCount);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_vgaPcxSpeed);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_physMemorySlot1);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_physMemorySlot2);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_physMemorySlot3);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_videoMemory);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_vgaVersion);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_vgaName);
sb.append(AccountVariables.HWIDSLIT_VAR);
sb.append(_vgaDriverVersion);
player.getAccountVariables().set(AccountVariables.HWID, sb.toString());
}
/**
* @return the macAddress
*/
@@ -215,4 +289,36 @@ public class ClientHardwareInfoHolder
{
return _vgaDriverVersion;
}
@Override
public boolean equals(Object obj)
{
if (obj instanceof ClientHardwareInfoHolder)
{
final ClientHardwareInfoHolder info = (ClientHardwareInfoHolder) obj;
if ((_macAddress.equals(info.getMacAddress())) && //
(_windowsPlatformId == info.getWindowsPlatformId()) && //
(_windowsMajorVersion == info.getWindowsMajorVersion()) && //
(_windowsMinorVersion == info.getWindowsMinorVersion()) && //
(_windowsBuildNumber == info.getWindowsBuildNumber()) && //
(_directxVersion == info.getDirectxVersion()) && //
(_directxRevision == info.getDirectxRevision()) && //
(_cpuName.equals(info.getCpuName())) && //
(_cpuSpeed == info.getCpuSpeed()) && //
(_cpuCoreCount == info.getCpuCoreCount()) && //
(_vgaCount == info.getVgaCount()) && //
(_vgaPcxSpeed == info.getVgaPcxSpeed()) && //
(_physMemorySlot1 == info.getPhysMemorySlot1()) && //
(_physMemorySlot2 == info.getPhysMemorySlot2()) && //
(_physMemorySlot3 == info.getPhysMemorySlot3()) && //
(_videoMemory == info.getVideoMemory()) && //
(_vgaVersion == info.getVgaVersion()) && //
(_vgaName.equals(info.getVgaName())) && //
(_vgaDriverVersion.equals(info.getVgaDriverVersion())))
{
return true;
}
}
return false;
}
}

View File

@@ -38,6 +38,10 @@ public class AccountVariables extends AbstractVariables
private static final String DELETE_QUERY = "DELETE FROM account_gsdata WHERE account_name = ?";
private static final String INSERT_QUERY = "INSERT INTO account_gsdata (account_name, var, value) VALUES (?, ?, ?)";
// Public variable names
public static final String HWID = "HWID";
public static final String HWIDSLIT_VAR = " ";
private final String _accountName;
public AccountVariables(String accountName)

View File

@@ -16,6 +16,9 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.l2jmobius.Config;
import org.l2jmobius.commons.concurrent.ThreadPool;
import org.l2jmobius.commons.network.PacketReader;
@@ -50,10 +53,12 @@ import org.l2jmobius.gameserver.model.entity.FortSiege;
import org.l2jmobius.gameserver.model.entity.GameEvent;
import org.l2jmobius.gameserver.model.entity.Siege;
import org.l2jmobius.gameserver.model.holders.AttendanceInfoHolder;
import org.l2jmobius.gameserver.model.holders.ClientHardwareInfoHolder;
import org.l2jmobius.gameserver.model.instancezone.Instance;
import org.l2jmobius.gameserver.model.items.instance.ItemInstance;
import org.l2jmobius.gameserver.model.quest.Quest;
import org.l2jmobius.gameserver.model.skills.AbnormalVisualEffect;
import org.l2jmobius.gameserver.model.variables.AccountVariables;
import org.l2jmobius.gameserver.model.variables.PlayerVariables;
import org.l2jmobius.gameserver.model.zone.ZoneId;
import org.l2jmobius.gameserver.network.ConnectionState;
@@ -111,7 +116,9 @@ import org.l2jmobius.gameserver.util.BuilderUtil;
*/
public class EnterWorld implements IClientIncomingPacket
{
private final int[][] tracert = new int[5][4];
private static final Map<String, ClientHardwareInfoHolder> TRACE_HWINFO = new ConcurrentHashMap<>();
private final int[][] _tracert = new int[5][4];
@Override
public boolean read(GameClient client, PacketReader packet)
@@ -120,7 +127,7 @@ public class EnterWorld implements IClientIncomingPacket
{
for (int o = 0; o < 4; o++)
{
tracert[i][o] = packet.readC();
_tracert[i][o] = packet.readC();
}
}
packet.readD(); // Unknown Value
@@ -148,11 +155,11 @@ public class EnterWorld implements IClientIncomingPacket
final String[] adress = new String[5];
for (int i = 0; i < 5; i++)
{
adress[i] = tracert[i][0] + "." + tracert[i][1] + "." + tracert[i][2] + "." + tracert[i][3];
adress[i] = _tracert[i][0] + "." + _tracert[i][1] + "." + _tracert[i][2] + "." + _tracert[i][3];
}
LoginServerThread.getInstance().sendClientTracert(player.getAccountName(), adress);
client.setClientTracert(tracert);
client.setClientTracert(_tracert);
player.broadcastUserInfo();
@@ -647,10 +654,69 @@ public class EnterWorld implements IClientIncomingPacket
{
ThreadPool.schedule(() ->
{
if (client.getHardwareInfo() == null)
// Generate trace string.
final StringBuilder sb = new StringBuilder();
for (int[] i : _tracert)
{
Disconnection.of(client).defaultSequence(false);
return;
for (int j : i)
{
sb.append(j);
sb.append(".");
}
}
final String trace = sb.toString();
// Get hardware info from client.
ClientHardwareInfoHolder hwInfo = client.getHardwareInfo();
if (hwInfo != null)
{
hwInfo.store(player);
TRACE_HWINFO.put(trace, hwInfo);
}
else
{
// Get hardware info from stored tracert map.
hwInfo = TRACE_HWINFO.get(trace);
if (hwInfo != null)
{
hwInfo.store(player);
client.setHardwareInfo(hwInfo);
}
// Get hardware info from account variables.
else
{
final String storedInfo = player.getAccountVariables().getString(AccountVariables.HWID, "");
if (!storedInfo.isEmpty())
{
hwInfo = new ClientHardwareInfoHolder(storedInfo);
TRACE_HWINFO.put(trace, hwInfo);
client.setHardwareInfo(hwInfo);
}
}
}
// Check max players.
if (Config.MAX_PLAYERS_PER_HWID > 0)
{
if (hwInfo == null)
{
Disconnection.of(client).defaultSequence(false);
}
else
{
int count = 0;
for (PlayerInstance plr : World.getInstance().getPlayers())
{
if ((plr.isOnlineInt() == 1) && (plr.getClient().getHardwareInfo().equals(hwInfo)))
{
count++;
}
}
if (count >= Config.MAX_PLAYERS_PER_HWID)
{
Disconnection.of(client).defaultSequence(false);
}
}
}
}, 5000);
}

View File

@@ -16,12 +16,8 @@
*/
package org.l2jmobius.gameserver.network.clientpackets;
import org.l2jmobius.Config;
import org.l2jmobius.commons.network.PacketReader;
import org.l2jmobius.gameserver.model.World;
import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
import org.l2jmobius.gameserver.model.holders.ClientHardwareInfoHolder;
import org.l2jmobius.gameserver.network.Disconnection;
import org.l2jmobius.gameserver.network.GameClient;
/**
@@ -82,20 +78,5 @@ public class RequestHardWareInfo implements IClientIncomingPacket
public void run(GameClient client)
{
client.setHardwareInfo(new ClientHardwareInfoHolder(_macAddress, _windowsPlatformId, _windowsMajorVersion, _windowsMinorVersion, _windowsBuildNumber, _directxVersion, _directxRevision, _cpuName, _cpuSpeed, _cpuCoreCount, _vgaCount, _vgaPcxSpeed, _physMemorySlot1, _physMemorySlot2, _physMemorySlot3, _videoMemory, _vgaVersion, _vgaName, _vgaDriverVersion));
if (Config.HARDWARE_INFO_ENABLED && (Config.MAX_PLAYERS_PER_HWID > 0))
{
int count = 0;
for (PlayerInstance player : World.getInstance().getPlayers())
{
if ((player.isOnlineInt() == 1) && (player.getClient().getHardwareInfo().equals(client.getHardwareInfo())))
{
count++;
}
}
if (count >= Config.MAX_PLAYERS_PER_HWID)
{
Disconnection.of(client).defaultSequence(false);
}
}
}
}