Reanimation06

RUSaCis HWID Manager

Sep 22nd, 2025
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 82.33 KB | Gaming | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/model/actor/Player.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/model/actor/Player.java  (revision 15)
  6. +++ java/net/sf/l2j/gameserver/model/actor/Player.java  (working copy)
  7. @@ -486,6 +486,8 @@
  8.     public int _activeBoxes = -1;
  9.     public List<String> _activeBoxesCharacters = new ArrayList<>();
  10.    
  11. +   private String _hwid;
  12. +  
  13.     /**
  14.      * Constructor of Player (use Creature constructor).
  15.      * <ul>
  16. @@ -7761,4 +7763,14 @@
  17.        
  18.         return gms;
  19.     }
  20. +  
  21. +   public String getHWid()
  22. +   {
  23. +       if (getClient() == null)
  24. +       {
  25. +           return _hwid;
  26. +       }
  27. +       _hwid = getClient().getHWID();
  28. +       return _hwid;
  29. +   }
  30.  }
  31. \ No newline at end of file
  32. Index: java/hwid/hwidmanager/hwidAdminBan.java
  33. ===================================================================
  34. --- java/hwid/hwidmanager/hwidAdminBan.java (nonexistent)
  35. +++ java/hwid/hwidmanager/hwidAdminBan.java (working copy)
  36. @@ -0,0 +1,40 @@
  37. +package hwid.hwidmanager;
  38. +
  39. +import net.sf.l2j.Config;
  40. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  41. +import net.sf.l2j.gameserver.model.WorldObject;
  42. +import net.sf.l2j.gameserver.model.actor.Player;
  43. +
  44. +public class hwidAdminBan implements IAdminCommandHandler
  45. +{
  46. +   private static final String[] ADMIN_COMMANDS =
  47. +   {
  48. +       "admin_hwid_ban"
  49. +   };
  50. +
  51. +   @Override
  52. +   public void useAdminCommand(final String command, final Player player)
  53. +    {
  54. +        if (!Config.ALLOW_GUARD_SYSTEM || player == null)
  55. +            return;
  56. +      
  57. +       if (command.startsWith("admin_hwid_ban"))
  58. +        {
  59. +            final WorldObject playerTarget = player.getTarget();
  60. +            if (!(playerTarget instanceof Player))
  61. +            {
  62. +               player.sendMessage("Target is empty");
  63. +                return;
  64. +            }
  65. +            final Player target = (Player)playerTarget;
  66. +            hwidBan.addHWIDBan(target.getClient());
  67. +            player.sendMessage(target.getName() + " banned in HWID");
  68. +        }
  69. +    }
  70. +    
  71. +   @Override
  72. +   public String[] getAdminCommandList()
  73. +   {
  74. +       return ADMIN_COMMANDS;
  75. +   }
  76. +}
  77. \ No newline at end of file
  78. Index: java/hwid/hwidmanager/hwidBan.java
  79. ===================================================================
  80. --- java/hwid/hwidmanager/hwidBan.java  (nonexistent)
  81. +++ java/hwid/hwidmanager/hwidBan.java  (working copy)
  82. @@ -0,0 +1,98 @@
  83. +package hwid.hwidmanager;
  84. +
  85. +import java.sql.Connection;
  86. +import java.sql.PreparedStatement;
  87. +import java.sql.ResultSet;
  88. +import java.util.HashMap;
  89. +import java.util.Map;
  90. +
  91. +import net.sf.l2j.commons.logging.CLogger;
  92. +import net.sf.l2j.commons.pool.ConnectionPool;
  93. +
  94. +import net.sf.l2j.gameserver.network.GameClient;
  95. +
  96. +public class hwidBan
  97. +{
  98. +    protected static CLogger LOGGER = new CLogger(hwidBan.class.getName());
  99. +    private static hwidBan INSTANCE;
  100. +    private static Map<Integer, hwidBanList> _lists = new HashMap<>();
  101. +    
  102. +    public hwidBan()
  103. +    {
  104. +        load();
  105. +        LOGGER.info("Loaded " + hwidBan._lists.size() + " banned(s) HWID(s)");
  106. +    }
  107. +    
  108. +    public static hwidBan getInstance()
  109. +    {
  110. +        if (INSTANCE == null)
  111. +           INSTANCE = new hwidBan();
  112. +        return INSTANCE;
  113. +    }
  114. +    
  115. +    private static void load()
  116. +    {
  117. +        String HWID = "";
  118. +        int counterHWIDBan = 0;
  119. +        try (Connection con = ConnectionPool.getConnection();
  120. +           PreparedStatement statement = con.prepareStatement("SELECT * FROM hwid_bans");
  121. +           ResultSet rset = statement.executeQuery())
  122. +        {
  123. +            while (rset.next())
  124. +            {
  125. +                HWID = rset.getString("HWID");
  126. +                final hwidBanList hb = new hwidBanList(counterHWIDBan);
  127. +                hb.setHWIDBan(HWID);
  128. +                _lists.put(counterHWIDBan, hb);
  129. +                ++counterHWIDBan;
  130. +            }
  131. +        }
  132. +        catch (Exception e)
  133. +        {
  134. +            e.printStackTrace();
  135. +        }
  136. +    }
  137. +    
  138. +    public static void reload()
  139. +    {
  140. +       INSTANCE = new hwidBan();
  141. +    }
  142. +    
  143. +    public boolean checkFullHWIDBanned(final GameClient client)
  144. +    {
  145. +        if (_lists.size() == 0)
  146. +        {
  147. +            return false;
  148. +        }
  149. +        for (int i = 0; i < _lists.size(); ++i)
  150. +        {
  151. +            if (_lists.get(i).getHWID().equals(client.getHWID()))
  152. +                return true;
  153. +        }
  154. +        return false;
  155. +    }
  156. +    
  157. +    public static int getCountHWIDBan()
  158. +    {
  159. +        return _lists.size();
  160. +    }
  161. +    
  162. +    public static void addHWIDBan(final GameClient client)
  163. +    {
  164. +        final String HWID = client.getHWID();
  165. +        final int counterHwidBan = _lists.size();
  166. +        final hwidBanList hb = new hwidBanList(counterHwidBan);
  167. +        hb.setHWIDBan(HWID);
  168. +        _lists.put(counterHwidBan, hb);
  169. +        try (Connection con = ConnectionPool.getConnection();
  170. +           PreparedStatement statement = con.prepareStatement("INSERT INTO hwid_bans SET HWID=?"))
  171. +        {
  172. +            statement.setString(1, HWID);
  173. +            statement.execute();
  174. +        }
  175. +        catch (Exception e)
  176. +        {
  177. +            e.printStackTrace();
  178. +        }
  179. +    }
  180. +}
  181. \ No newline at end of file
  182. Index: java/hwid/hwidmanager/hwidBanList.java
  183. ===================================================================
  184. --- java/hwid/hwidmanager/hwidBanList.java  (nonexistent)
  185. +++ java/hwid/hwidmanager/hwidBanList.java  (working copy)
  186. @@ -0,0 +1,27 @@
  187. +package hwid.hwidmanager;
  188. +
  189. +public class hwidBanList
  190. +{
  191. +    private final int _id;
  192. +    private String _hwid;
  193. +    
  194. +    public hwidBanList(final int id)
  195. +    {
  196. +        _id = id;
  197. +    }
  198. +    
  199. +    public int getId()
  200. +    {
  201. +        return _id;
  202. +    }
  203. +    
  204. +    public String getHWID()
  205. +    {
  206. +        return _hwid;
  207. +    }
  208. +    
  209. +    public void setHWIDBan(final String hwid)
  210. +    {
  211. +       _hwid = hwid;
  212. +    }
  213. +}
  214. Index: java/hwid/hwidmanager/hwidInfoClient.java
  215. ===================================================================
  216. --- java/hwid/hwidmanager/hwidInfoClient.java   (nonexistent)
  217. +++ java/hwid/hwidmanager/hwidInfoClient.java   (working copy)
  218. @@ -0,0 +1,69 @@
  219. +package hwid.hwidmanager;
  220. +
  221. +public class hwidInfoClient
  222. +{
  223. +    private String _playerName;
  224. +    private String _loginName;
  225. +    private int _playerId;
  226. +    private String _hwid;
  227. +    private int _revision;
  228. +    
  229. +    public hwidInfoClient()
  230. +    {
  231. +        _playerName = "";
  232. +        _loginName = "";
  233. +        _playerId = 0;
  234. +        _hwid = "";
  235. +        _revision = 0;
  236. +    }
  237. +    
  238. +    public final String getPlayerName()
  239. +    {
  240. +        return _playerName;
  241. +    }
  242. +    
  243. +    public void setPlayerName(final String name)
  244. +    {
  245. +        _playerName = name;
  246. +    }
  247. +    
  248. +    public void setPlayerId(final int plId)
  249. +    {
  250. +        _playerId = plId;
  251. +    }
  252. +    
  253. +    public int getPlayerId()
  254. +    {
  255. +        return _playerId;
  256. +    }
  257. +    
  258. +    public final String getHWID()
  259. +    {
  260. +        return _hwid;
  261. +    }
  262. +    
  263. +    public void setHWID(final String hwid)
  264. +    {
  265. +        _hwid = hwid;
  266. +    }
  267. +    
  268. +    public void setRevision(final int revision)
  269. +    {
  270. +        _revision = revision;
  271. +    }
  272. +    
  273. +    public int getRevision()
  274. +    {
  275. +        return _revision;
  276. +    }
  277. +    
  278. +    public final String getLoginName()
  279. +    {
  280. +        return _loginName;
  281. +    }
  282. +    
  283. +    public void setLoginName(final String name)
  284. +    {
  285. +        _loginName = name;
  286. +    }
  287. +}
  288. \ No newline at end of file
  289. Index: java/hwid/hwidmanager/hwidInfoList.java
  290. ===================================================================
  291. --- java/hwid/hwidmanager/hwidInfoList.java (nonexistent)
  292. +++ java/hwid/hwidmanager/hwidInfoList.java (working copy)
  293. @@ -0,0 +1,78 @@
  294. +package hwid.hwidmanager;
  295. +
  296. +public class hwidInfoList
  297. +{
  298. +    private final int _id;
  299. +    private String _hwid;
  300. +    private int _count;
  301. +    private int _playerID;
  302. +    private String _login;
  303. +    private LockType _lockType;
  304. +    
  305. +    public hwidInfoList(final int id)
  306. +    {
  307. +        _id = id;
  308. +    }
  309. +    
  310. +    public int get_id()
  311. +    {
  312. +        return _id;
  313. +    }
  314. +    
  315. +    public int getCount()
  316. +    {
  317. +        return _count;
  318. +    }
  319. +    
  320. +    public void setCount(final int count)
  321. +    {
  322. +        _count = count;
  323. +    }
  324. +    
  325. +    public int getPlayerID()
  326. +    {
  327. +        return _playerID;
  328. +    }
  329. +    
  330. +    public void setPlayerID(final int playerID)
  331. +    {
  332. +        _playerID = playerID;
  333. +    }
  334. +    
  335. +    public String getHWID()
  336. +    {
  337. +        return _hwid;
  338. +    }
  339. +    
  340. +    public void setHWID(final String hwid)
  341. +    {
  342. +       _hwid = hwid;
  343. +    }
  344. +    
  345. +    public String getLogin()
  346. +    {
  347. +        return _login;
  348. +    }
  349. +    
  350. +    public void setLogin(final String login)
  351. +    {
  352. +        _login = login;
  353. +    }
  354. +    
  355. +    public LockType getLockType()
  356. +    {
  357. +        return _lockType;
  358. +    }
  359. +    
  360. +    public void setLockType(final LockType lockType)
  361. +    {
  362. +        _lockType = lockType;
  363. +    }
  364. +    
  365. +    public enum LockType
  366. +    {
  367. +        PLAYER_LOCK,
  368. +        ACCOUNT_LOCK,
  369. +        NONE;
  370. +    }
  371. +}
  372. \ No newline at end of file
  373. Index: java/hwid/hwidmanager/hwidManager.java
  374. ===================================================================
  375. --- java/hwid/hwidmanager/hwidManager.java  (nonexistent)
  376. +++ java/hwid/hwidmanager/hwidManager.java  (working copy)
  377. @@ -0,0 +1,117 @@
  378. +package hwid.hwidmanager;
  379. +
  380. +import java.util.ArrayList;
  381. +import java.util.Collection;
  382. +import java.util.HashMap;
  383. +import java.util.List;
  384. +import java.util.Map;
  385. +
  386. +import net.sf.l2j.commons.logging.CLogger;
  387. +
  388. +import net.sf.l2j.Config;
  389. +import net.sf.l2j.gameserver.model.actor.Player;
  390. +import net.sf.l2j.gameserver.network.GameClient;
  391. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  392. +
  393. +public class hwidManager
  394. +{
  395. +    private static final CLogger LOGGER = new CLogger(hwidManager.class.getName());
  396. +    
  397. +    public hwidManager()
  398. +    {
  399. +    }
  400. +    
  401. +    private static boolean multiboxKickTask(final Player activeChar, final Integer numberBox, final Collection<Player> world)
  402. +    {
  403. +        final Map<String, List<Player>> hwidMap = new HashMap<>();
  404. +        for (final Player player : world)
  405. +        {
  406. +            if (player.getClient() != null)
  407. +            {
  408. +                if (player.getClient().isDetached())
  409. +                    continue;
  410. +
  411. +                final String hwid = activeChar.getHWid();
  412. +                final String playerHwid = player.getHWid();
  413. +                if (!hwid.equals(playerHwid))
  414. +                    continue;
  415. +
  416. +                if (hwidMap.get(hwid) == null)
  417. +                    hwidMap.put(hwid, new ArrayList<Player>());
  418. +
  419. +                hwidMap.get(hwid).add(player);
  420. +                if (hwidMap.get(hwid).size() >= numberBox)
  421. +                    return true;
  422. +
  423. +                continue;
  424. +            }
  425. +        }
  426. +        return false;
  427. +    }
  428. +    
  429. +    public boolean validBox(final Player activeChar, final Integer numberBox, final Collection<Player> world, final Boolean forcedLogOut)
  430. +    {
  431. +        if (multiboxKickTask(activeChar, numberBox, world))
  432. +        {
  433. +            if (forcedLogOut)
  434. +            {
  435. +                final GameClient client = activeChar.getClient();
  436. +                LOGGER.warn("Dualbox Protection: " + client.getHWID() + " was trying to use over " + numberBox + " clients!");
  437. +                activeChar.sendMessage("SYS: You have exceeded the PC connection limit = " + Config.PROTECT_WINDOWS_COUNT + " box per PC.");
  438. +                activeChar.sendMessage("SYS: You will be disconnected in 30 seconds.");
  439. +                activeChar.setIsImmobilized(true);
  440. +                activeChar.setInvul(true);
  441. +                activeChar.disableAllSkills();
  442. +                showChatWindow(activeChar, 0);
  443. +                waitSecs(30);
  444. +                activeChar.getClient().closeNow();
  445. +            }
  446. +            return true;
  447. +        }
  448. +        return false;
  449. +    }
  450. +    
  451. +    public void showChatWindow(final Player player, final int val)
  452. +    {
  453. +        final NpcHtmlMessage msg = new NpcHtmlMessage(5);
  454. +        msg.setHtml(ExcedLimit(player));
  455. +        player.sendPacket(msg);
  456. +    }
  457. +    
  458. +    private static String ExcedLimit(final Player player)
  459. +    {
  460. +        final StringBuilder tb = new StringBuilder();
  461. +        tb.append("<html><body><center>");
  462. +        tb.append("<img src=\"L2UI_CH3.herotower_deco\" width=256 height=32>HWID<font color=LEVEL> Dual Box </font>'- Manager");
  463. +        tb.append("<br><table><tr><td height=7><img src=\"L2UI.SquareGray\" width=220 height=1></td></tr></table>");
  464. +        tb.append("<img src=\"L2UI.SquareGray\" width=295 height=1><table width=295 border=0 bgcolor=000000><tr><td align=center>");
  465. +        tb.append("<br>You have exceeded the PC connection limit.<br1>Server have limit to <font color=LEVEL>" + Config.PROTECT_WINDOWS_COUNT + "</font> per PC.<br><br>You will be disconnected in '<font color=LEVEL>30 seconds</font>'.<br1>" + player.getName() + ", Thanks for following the server rules.<br1>Thanks.<br>");
  466. +        tb.append("<br><img src=\"l2ui.squarewhite\" width=\"150\" height=\"1\"><br>");
  467. +        tb.append("<br></td></tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
  468. +        tb.append("<table><tr><td height=7><img src=\"L2UI.SquareGray\" width=220 height=1></td></tr></table><br>");
  469. +        tb.append("<br><br><font color=333333>Respect the rules</font>");
  470. +        return tb.toString();
  471. +    }
  472. +
  473. +    public static void waitSecs(final int i)
  474. +    {
  475. +        try
  476. +        {
  477. +            Thread.sleep(i * 1000);
  478. +        }
  479. +        catch (InterruptedException ie)
  480. +        {
  481. +            ie.printStackTrace();
  482. +        }
  483. +    }
  484. +    
  485. +    public static final hwidManager getInstance()
  486. +    {
  487. +        return SingletonHolder.INSTANCE;
  488. +    }
  489. +    
  490. +    private static class SingletonHolder
  491. +    {
  492. +        protected static final hwidManager INSTANCE = new hwidManager();
  493. +    }
  494. +}
  495. \ No newline at end of file
  496. Index: java/hwid/hwidmanager/hwidPlayer.java
  497. ===================================================================
  498. --- java/hwid/hwidmanager/hwidPlayer.java   (nonexistent)
  499. +++ java/hwid/hwidmanager/hwidPlayer.java   (working copy)
  500. @@ -0,0 +1,199 @@
  501. +package hwid.hwidmanager;
  502. +
  503. +import java.sql.Connection;
  504. +import java.sql.PreparedStatement;
  505. +import java.sql.ResultSet;
  506. +import java.util.HashMap;
  507. +import java.util.Map;
  508. +
  509. +import net.sf.l2j.commons.logging.CLogger;
  510. +import net.sf.l2j.commons.pool.ConnectionPool;
  511. +
  512. +import net.sf.l2j.gameserver.network.GameClient;
  513. +
  514. +import hwid.hwidmanager.hwidInfoList.LockType;
  515. +
  516. +public class hwidPlayer
  517. +{
  518. +    protected static CLogger LOGGER = new CLogger(hwidPlayer.class.getName());
  519. +    private static hwidPlayer INSTANCE;
  520. +    private static Map<Integer, hwidInfoList> _list = new HashMap<>();
  521. +    private static Map<Integer, Integer> _sessions = new HashMap<>();
  522. +    
  523. +    public hwidPlayer()
  524. +    {    
  525. +        load();
  526. +        LOGGER.info("Loaded " + _list.size() + " player(s) HWID(s)");
  527. +    }
  528. +    
  529. +    public static hwidPlayer getInstance()
  530. +    {
  531. +        if (INSTANCE == null)
  532. +           INSTANCE = new hwidPlayer();
  533. +        return INSTANCE;
  534. +    }
  535. +    
  536. +    private static void load()
  537. +    {
  538. +        try (Connection con = ConnectionPool.getConnection();
  539. +           PreparedStatement statement = con.prepareStatement("SELECT * FROM hwid_info");
  540. +           ResultSet rset = statement.executeQuery())
  541. +        {
  542. +            int counterHWIDInfo = 0;
  543. +            while (rset.next())
  544. +            {
  545. +                final hwidInfoList hInfo = new hwidInfoList(counterHWIDInfo);
  546. +                hInfo.setHWID(rset.getString("HWID"));
  547. +                hInfo.setLogin(rset.getString("Account"));
  548. +                hInfo.setPlayerID(rset.getInt("PlayerID"));
  549. +                hInfo.setLockType(LockType.valueOf(rset.getString("LockType")));
  550. +                _list.put(counterHWIDInfo, hInfo);
  551. +                ++counterHWIDInfo;
  552. +            }
  553. +        }
  554. +        catch (Exception e)
  555. +        {
  556. +            e.printStackTrace();
  557. +        }
  558. +    }
  559. +    
  560. +    public static void reload()
  561. +    {
  562. +       INSTANCE = new hwidPlayer();
  563. +    }
  564. +    
  565. +   public static int startSession(int WindowsCount)
  566. +   {
  567. +       synchronized (_list)
  568. +       {
  569. +           if (_sessions.get(WindowsCount) == null)
  570. +               _sessions.put(WindowsCount, 0);
  571. +           _sessions.put(WindowsCount, _sessions.get(WindowsCount) + 1);
  572. +       }
  573. +       return _sessions.get(WindowsCount);
  574. +   }
  575. +  
  576. +   public static void updateHWIDInfo(GameClient client)
  577. +   {
  578. +       updateHWIDInfo(client, LockType.NONE);
  579. +   }
  580. +    
  581. +    public static void updateHWIDInfo(final GameClient client, final LockType lockType)
  582. +    {
  583. +       int counterHwidInfo = _list.size();
  584. +        boolean isFound = false;
  585. +        for (int i = 0; i < _list.size(); ++i)
  586. +        {
  587. +            if (_list.get(i).getHWID().equals(client.getHWID()))
  588. +            {
  589. +               isFound = true;        
  590. +               counterHwidInfo = i;
  591. +                break;
  592. +            }
  593. +        }
  594. +        final hwidInfoList hInfo = new hwidInfoList(counterHwidInfo);
  595. +        hInfo.setHWID(client.getHWID());
  596. +        hInfo.setLogin(client.getAccountName());
  597. +        hInfo.setPlayerID(client.getPlayerId());
  598. +        hInfo.setLockType(lockType);
  599. +        _list.put(counterHwidInfo, hInfo);
  600. +        if (isFound)
  601. +        {
  602. +           try (Connection con = ConnectionPool.getConnection();
  603. +               PreparedStatement statement = con.prepareStatement("UPDATE hwid_info SET Account=?,PlayerID=?,LockType=? WHERE HWID=?"))
  604. +            {
  605. +                statement.setString(1, client.getAccountName());
  606. +                statement.setInt(2, client.getPlayerId());
  607. +                statement.setString(3, lockType.toString());
  608. +                statement.setString(4, client.getHWID());
  609. +                statement.execute();
  610. +            }
  611. +            catch (Exception e)
  612. +            {
  613. +                e.printStackTrace();
  614. +            }
  615. +        }
  616. +        else
  617. +        {
  618. +            try (Connection con = ConnectionPool.getConnection();
  619. +               PreparedStatement statement = con.prepareStatement("INSERT INTO hwid_info (HWID, Account, PlayerID, LockType) values (?,?,?,?)"))
  620. +            {
  621. +                statement.setString(1, client.getHWID());
  622. +                statement.setString(2, client.getAccountName());
  623. +                statement.setInt(3, client.getPlayerId());
  624. +                statement.setString(4, lockType.toString());
  625. +                statement.execute();
  626. +            }
  627. +            catch (Exception e)
  628. +            {
  629. +                e.printStackTrace();
  630. +            }
  631. +        }
  632. +    }
  633. +    
  634. +    public static boolean checkLockedHWID(final GameClient client)
  635. +    {
  636. +        if (_list.size() == 0)
  637. +            return false;
  638. +
  639. +        boolean result = false;
  640. +        for (int i = 0; i < _list.size(); ++i)
  641. +        {
  642. +            switch (_list.get(i).getLockType().ordinal())
  643. +            {
  644. +                case 2:
  645. +                {
  646. +                    if (client.getPlayerId() == 0)
  647. +                        break;
  648. +
  649. +                    if (_list.get(i).getPlayerID() != client.getPlayerId())
  650. +                        break;
  651. +
  652. +                    if (_list.get(i).getHWID().equals(client.getHWID()))
  653. +                        return false;
  654. +
  655. +                    result = true;
  656. +                    break;
  657. +                }
  658. +                case 3:
  659. +                {
  660. +                    if (!_list.get(i).getLogin().equals(client.getLoginName()))
  661. +                        break;
  662. +
  663. +                    if (_list.get(i).getHWID().equals(client.getHWID()))
  664. +                        return false;
  665. +
  666. +                    result = true;
  667. +                    break;
  668. +                }
  669. +            }
  670. +        }
  671. +        return result;
  672. +    }
  673. +    
  674. +    public static int getAllowedWindowsCount(final GameClient client)
  675. +    {
  676. +        if (_list.size() == 0)
  677. +            return -1;
  678. +
  679. +        int i = 0;
  680. +        while (i < _list.size())
  681. +        {
  682. +            if (!_list.get(i).getHWID().equals(client.getHWID()))
  683. +                ++i;
  684. +            else
  685. +            {
  686. +                if (_list.get(i).getHWID().equals(""))
  687. +                    return -1;
  688. +
  689. +                return _list.get(i).getCount();
  690. +            }
  691. +        }
  692. +        return -1;
  693. +    }
  694. +    
  695. +    public static int getCountHwidInfo()
  696. +    {
  697. +        return _list.size();
  698. +    }
  699. +}
  700. \ No newline at end of file
  701. Index: java/hwid/crypt/GameCrypt.java
  702. ===================================================================
  703. --- java/hwid/crypt/GameCrypt.java  (nonexistent)
  704. +++ java/hwid/crypt/GameCrypt.java  (working copy)
  705. @@ -0,0 +1,55 @@
  706. +package hwid.crypt;
  707. +
  708. +import net.sf.l2j.Config;
  709. +
  710. +import hwid.crypt.impl.L2Client;
  711. +import hwid.crypt.impl.L2Server;
  712. +import hwid.crypt.impl.VMPC;
  713. +
  714. +public class GameCrypt
  715. +{
  716. +    private ProtectionCrypt _client;
  717. +    private ProtectionCrypt _server;
  718. +    private boolean _isEnabled;
  719. +    private boolean _isProtected;
  720. +    
  721. +    public GameCrypt()
  722. +    {
  723. +        _isEnabled = false;
  724. +        _isProtected = false;
  725. +    }
  726. +    
  727. +    public void setProtected(final boolean state)
  728. +    {
  729. +        _isProtected = state;
  730. +    }
  731. +    
  732. +    public void setKey(final byte[] key)
  733. +    {
  734. +        if (_isProtected)
  735. +        {
  736. +            (_client = new VMPC()).setup(key, Config.GUARD_CLIENT_CRYPT);
  737. +            (_server = new L2Server()).setup(key, null);
  738. +            (_server = new VMPC()).setup(key, Config.GUARD_SERVER_CRYPT);
  739. +        }
  740. +        else
  741. +        {
  742. +            (_client = new L2Client()).setup(key, null);
  743. +            (_server = new L2Server()).setup(key, null);
  744. +        }
  745. +    }
  746. +    
  747. +    public void decrypt(final byte[] raw, final int offset, final int size)
  748. +    {
  749. +        if (_isEnabled)
  750. +            _client.crypt(raw, offset, size);
  751. +    }
  752. +    
  753. +    public void encrypt(final byte[] raw, final int offset, final int size)
  754. +    {
  755. +        if (_isEnabled)
  756. +            _server.crypt(raw, offset, size);
  757. +        else
  758. +            _isEnabled = true;
  759. +    }
  760. +}
  761. \ No newline at end of file
  762. Index: build.xml
  763. ===================================================================
  764. --- build.xml   (revision 15)
  765. +++ build.xml   (working copy)
  766. @@ -41,6 +41,7 @@
  767.         <fixcrlf srcdir="${build.dist.game}" eol="crlf" eof="remove" includes="**/*.bat" />
  768.         <fixcrlf srcdir="${build.dist.login}" eol="crlf" eof="remove" includes="**/*.bat" />
  769.         <mkdir dir="${build.dist.game}/log" />
  770. +       <mkdir dir="${build.dist.game}/log/hwid" />
  771.         <mkdir dir="${build.dist.login}/log" />
  772.         <mkdir dir="${build.dist.game}/config" />
  773.         <mkdir dir="${build.dist.game}/config/customs" />
  774. Index: java/hwid/crypt/ProtectionPackets.java
  775. ===================================================================
  776. --- java/hwid/crypt/ProtectionPackets.java  (nonexistent)
  777. +++ java/hwid/crypt/ProtectionPackets.java  (working copy)
  778. @@ -0,0 +1,49 @@
  779. +package hwid.crypt;
  780. +
  781. +import net.sf.l2j.commons.random.Rnd;
  782. +
  783. +public class ProtectionPackets
  784. +{
  785. +    public static int readB(final byte[] raw, int offset, final byte[] data, final int size)
  786. +    {
  787. +        for (int i = 0; i < size; ++i)
  788. +        {
  789. +            data[i] = (byte)(raw[offset] ^ raw[0]);
  790. +            offset += (raw[offset + 1] & 0xFF);
  791. +        }
  792. +        return offset;
  793. +    }
  794. +    
  795. +    public static int readS(final byte[] raw, int offset, final byte[] data, final int size)
  796. +    {
  797. +        for (int i = 0; i < size; ++i)
  798. +        {
  799. +            data[i] = (byte)(raw[offset] ^ raw[0]);
  800. +            offset += (raw[offset + 1] & 0xFF);
  801. +            if (data[i] == 0)
  802. +                break;
  803. +        }
  804. +        return offset;
  805. +    }
  806. +    
  807. +    public static int writeB(final byte[] raw, int offset, final byte[] data, final int size)
  808. +    {
  809. +        for (int i = 0; i < size; ++i)
  810. +        {
  811. +            raw[offset] = (byte)(data[i] ^ raw[0]);
  812. +            raw[offset + 1] = (byte)(2 + Rnd.nextInt(10));
  813. +            offset += (raw[offset + 1] & 0xFF);
  814. +        }
  815. +        return offset;
  816. +    }
  817. +    
  818. +    public static byte ck(final byte[] raw, final int offset, final int size)
  819. +    {
  820. +        byte c = -1;
  821. +        for (int i = 0; i < size; ++i)
  822. +        {
  823. +            c ^= raw[offset + i];
  824. +        }
  825. +        return c;
  826. +    }
  827. +}
  828. \ No newline at end of file
  829. Index: java/hwid/crypt/BlowfishEngine.java
  830. ===================================================================
  831. --- java/hwid/crypt/BlowfishEngine.java (nonexistent)
  832. +++ java/hwid/crypt/BlowfishEngine.java (working copy)
  833. @@ -0,0 +1,172 @@
  834. +package hwid.crypt;
  835. +
  836. +import java.io.IOException;
  837. +
  838. +public class BlowfishEngine
  839. +{
  840. +    private static final int[] KP = new int[] { 608135816, -2052912941, 320440878, 57701188, -1542899678, 698298832, 137296536, -330404727, 1160258022, 953160567, -1101764913, 887688300, -1062458953, -914599715, 1065670069, -1253635817, -1843997223, -1988494565 };
  841. +    private static final int[] KS0 = new int[] { -785314906, -1730169428, 805139163, -803545161, -1193168915, 1780907670, -1166241723, -248741991, 614570311, -1282315017, 134345442, -2054226922, 1667834072, 1901547113, -1537671517, -191677058, 227898511, 1921955416, 1904987480, -2112533778, 2069144605, -1034266187, -1674521287, 720527379, -976113629, 677414384, -901678824, -1193592593, -1904616272, 1614419982, 1822297739, -1340175810, -686458943, -1120842969, 2024746970, 1432378464, -430627341, -1437226092, 1464375394, 1676153920, 1439316330, 715854006, -1261675468, 289532110, -1588296017, 2087905683, -1276242927, 1668267050, 732546397, 1947742710, -832815594, -1685613794, -1344882125, 1814351708, 2050118529, 680887927, 999245976, 1800124847, -994056165, 1713906067, 1641548236, -81679983, 1216130144, 1575780402, -276538019, -377129551, -601480446, -345695352, 596196993, -745100091, 258830323, -2081144263, 772490370, -1534844924, 1774776394, -1642095778, 566650946, -152474470, 1728879713, -1412200208, 1783734482, -665571480, -1777359064, -1420741725, 1861159788, 326777828, -1170476976, 2130389656, -1578015459, 967770486, 1724537150, -2109534584, -1930525159, 1164943284, 2105845187, 998989502, -529566248, -2050940813, 1075463327, 1455516326, 1322494562, 910128902, 469688178, 1117454909, 936433444, -804646328, -619713837, 1240580251, 122909385, -2137449605, 634681816, -152510729, -469872614, -1233564613, -1754472259, 79693498, -1045868618, 1084186820, 1583128258, 426386531, 1761308591, 1047286709, 322548459, 995290223, 1845252383, -1691314900, -863943356, -1352745719, -1092366332, -567063811, 1712269319, 422464435, -1060394921, 1170764815, -771006663, -1177289765, 1434042557, 442511882, -694091578, 1076654713, 1738483198, -81812532, -1901729288, -617471240, 1014306527, -43947243, 793779912, -1392160085, 842905082, -48003232, 1395751752, 1040244610, -1638115397, -898659168, 445077038, -552113701, -717051658, 679411651, -1402522938, -1940957837, 1767581616, -1144366904, -503340195, -1192226400, 284835224, -48135240, 1258075500, 768725851, -1705778055, -1225243291, -762426948, 1274779536, -505548070, -1530167757, 1660621633, -823867672, -283063590, 913787905, -797008130, 737222580, -1780753843, -1366257256, -357724559, 1804850592, -795946544, -1345903136, -1908647121, -1904896841, -1879645445, -233690268, -2004305902, -1878134756, 1336762016, 1754252060, -774901359, -1280786003, 791618072, -1106372745, -361419266, -1962795103, -442446833, -1250986776, 413987798, -829824359, -1264037920, -49028937, 2093235073, -760370983, 375366246, -2137688315, -1815317740, 555357303, -424861595, 2008414854, -950779147, -73583153, -338841844, 2067696032, -700376109, -1373733303, 2428461, 544322398, 577241275, 1471733935, 610547355, -267798242, 1432588573, 1507829418, 2025931657, -648391809, 545086370, 48609733, -2094660746, 1653985193, 298326376, 1316178497, -1287180854, 2064951626, 458293330, -1705826027, -703637697, -1130641692, 727753846, -2115603456, 146436021, 1461446943, -224990101, 705550613, -1235000031, -407242314, -13368018, -981117340, 1404054877, -1449160799, 146425753, 1854211946 };
  842. +    private static final int[] KS1 = new int[] { 1266315497, -1246549692, -613086930, -1004984797, -1385257296, 1235738493, -1662099272, -1880247706, -324367247, 1771706367, 1449415276, -1028546847, 422970021, 1963543593, -1604775104, -468174274, 1062508698, 1531092325, 1804592342, -1711849514, -1580033017, -269995787, 1294809318, -265986623, 1289560198, -2072974554, 1669523910, 35572830, 157838143, 1052438473, 1016535060, 1802137761, 1753167236, 1386275462, -1214491899, -1437595849, 1040679964, 2145300060, -1904392980, 1461121720, -1338320329, -263189491, -266592508, 33600511, -1374882534, 1018524850, 629373528, -603381315, -779021319, 2091462646, -1808644237, 586499841, 988145025, 935516892, -927631820, -1695294041, -1455136442, 265290510, -322386114, -1535828415, -499593831, 1005194799, 847297441, 406762289, 1314163512, 1332590856, 1866599683, -167115585, 750260880, 613907577, 1450815602, -1129346641, -560302305, -644675568, -1282691566, -590397650, 1427272223, 778793252, 1343938022, -1618686585, 2052605720, 1946737175, -1130390852, -380928628, -327488454, -612033030, 1661551462, -1000029230, -283371449, 840292616, -582796489, 616741398, 312560963, 711312465, 1351876610, 322626781, 1910503582, 271666773, -2119403562, 1594956187, 70604529, -677132437, 1007753275, 1495573769, -225450259, -1745748998, -1631928532, 504708206, -2031925904, -353800271, -2045878774, 1514023603, 1998579484, 1312622330, 694541497, -1712906993, -2143385130, 1382467621, 776784248, -1676627094, -971698502, -1797068168, -1510196141, 503983604, -218673497, 907881277, 423175695, 432175456, 1378068232, -149744970, -340918674, -356311194, -474200683, -1501837181, -1317062703, 26017576, -1020076561, -1100195163, 1700274565, 1756076034, -288447217, -617638597, 720338349, 1533947780, 354530856, 688349552, -321042571, 1637815568, 332179504, -345916010, 53804574, -1442618417, -1250730864, 1282449977, -711025141, -877994476, -288586052, 1617046695, -1666491221, -1292663698, 1686838959, 431878346, -1608291911, 1700445008, 1080580658, 1009431731, 832498133, -1071531785, -1688990951, -2023776103, -1778935426, 1648197032, -130578278, -1746719369, 300782431, 375919233, 238389289, -941219882, -1763778655, 2019080857, 1475708069, 455242339, -1685863425, 448939670, -843904277, 1395535956, -1881585436, 1841049896, 1491858159, 885456874, -30872223, -293847949, 1565136089, -396052509, 1108368660, 540939232, 1173283510, -1549095958, -613658859, -87339056, -951913406, -278217803, 1699691293, 1103962373, -669091426, -2038084153, -464828566, 1031889488, -815619598, 1535977030, -58162272, -1043876189, 2132092099, 1774941330, 1199868427, 1452454533, 157007616, -1390851939, 342012276, 595725824, 1480756522, 206960106, 497939518, 591360097, 863170706, -1919713727, -698356495, 1814182875, 2094937945, -873565088, 1082520231, -831049106, -1509457788, 435703966, -386934699, 1641649973, -1452693590, -989067582, 1510255612, -2146710820, -1639679442, -1018874748, -36346107, 236887753, -613164077, 274041037, 1734335097, -479771840, -976997275, 1899903192, 1026095262, -244449504, 356393447, -1884275382, -421290197, -612127241 };
  843. +    private static final int[] KS2 = new int[] { -381855128, -1803468553, -162781668, -1805047500, 1091903735, 1979897079, -1124832466, -727580568, -737663887, 857797738, 1136121015, 1342202287, 507115054, -1759230650, 337727348, -1081374656, 1301675037, -1766485585, 1895095763, 1721773893, -1078195732, 62756741, 2142006736, 835421444, -1762973773, 1442658625, -635090970, -1412822374, 676362277, 1392781812, 170690266, -373920261, 1759253602, -683120384, 1745797284, 664899054, 1329594018, -393761396, -1249058810, 2062866102, -1429332356, -751345684, -830954599, 1080764994, 553557557, -638351943, -298199125, 991055499, 499776247, 1265440854, 648242737, -354183246, 980351604, -581221582, 1749149687, -898096901, -83167922, -654396521, 1161844396, -1169648345, 1431517754, 545492359, -26498633, -795437749, 1437099964, -1592419752, -861329053, -1713251533, -1507177898, 1060185593, 1593081372, -1876348548, -34019326, 69676912, -2135222948, 86519011, -1782508216, -456757982, 1220612927, -955283748, 133810670, 1090789135, 1078426020, 1569222167, 845107691, -711212847, -222510705, 1091646820, 628848692, 1613405280, -537335645, 526609435, 236106946, 48312990, -1352249391, -892239595, 1797494240, 859738849, 992217954, -289490654, -2051890674, -424014439, -562951028, 765654824, -804095931, -1783130883, 1685915746, -405998096, 1414112111, -2021832454, -1013056217, -214004450, 172450625, -1724973196, 980381355, -185008841, -1475158944, -1578377736, -1726226100, -613520627, -964995824, 1835478071, 660984891, -590288892, -248967737, -872349789, -1254551662, 1762651403, 1719377915, -824476260, -1601057013, -652910941, -1156370552, 1364962596, 2073328063, 1983633131, 926494387, -871278215, -2144935273, -198299347, 1749200295, -966120645, 309677260, 2016342300, 1779581495, -1215147545, 111262694, 1274766160, 443224088, 298511866, 1025883608, -488520759, 1145181785, 168956806, -653464466, -710153686, 1689216846, -628709281, -1094719096, 1692713982, -1648590761, -252198778, 1618508792, 1610833997, -771914938, -164094032, 2001055236, -684262196, -2092799181, -266425487, -1333771897, 1006657119, 2006996926, -1108824540, 1430667929, -1084739999, 1314452623, -220332638, -193663176, -2021016126, 1399257539, -927756684, -1267338667, 1190975929, 2062231137, -1960976508, -2073424263, -1856006686, 1181637006, 548689776, -1932175983, -922558900, -1190417183, -1149106736, 296247880, 1970579870, -1216407114, -525738999, 1714227617, -1003338189, -396747006, 166772364, 1251581989, 493813264, 448347421, 195405023, -1584991729, 677966185, -591930749, 1463355134, -1578971493, 1338867538, 1343315457, -1492745222, -1610435132, 233230375, -1694987225, 2000651841, -1017099258, 1638401717, -266896856, -1057650976, 6314154, 819756386, 300326615, 590932579, 1405279636, -1027467724, -1144263082, -1866680610, -335774303, -833020554, 1862657033, 1266418056, 963775037, 2089974820, -2031914401, 1917689273, 448879540, -744572676, -313240200, 150775221, -667058989, 1303187396, 508620638, -1318983944, -1568336679, 1817252668, 1876281319, 1457606340, 908771278, -574175177, -677760460, -1838972398, 1729034894, 1080033504 };
  844. +    private static final int[] KS3 = new int[] { 976866871, -738527793, -1413318857, 1522871579, 1555064734, 1336096578, -746444992, -1715692610, -720269667, -1089506539, -701686658, -956251013, -1215554709, 564236357, -1301368386, 1781952180, 1464380207, -1131123079, -962365742, 1699332808, 1393555694, 1183702653, -713881059, 1288719814, 691649499, -1447410096, -1399511320, -1101077756, -1577396752, 1781354906, 1676643554, -1702433246, -1064713544, 1126444790, -1524759638, -1661808476, -2084544070, -1679201715, -1880812208, -1167828010, 673620729, -1489356063, 1269405062, -279616791, -953159725, -145557542, 1057255273, 2012875353, -2132498155, -2018474495, -1693849939, 993977747, -376373926, -1640704105, 753973209, 36408145, -1764381638, 25011837, -774947114, 2088578344, 530523599, -1376601957, 1524020338, 1518925132, -534139791, -535190042, 1202760957, -309069157, -388774771, 674977740, -120232407, 2031300136, 2019492241, -311074731, -141160892, -472686964, 352677332, -1997247046, 60907813, 90501309, -1007968747, 1016092578, -1759044884, -1455814870, 457141659, 509813237, -174299397, 652014361, 1966332200, -1319764491, 55981186, -1967506245, 676427537, -1039476232, -1412673177, -861040033, 1307055953, 942726286, 933058658, -1826555503, -361066302, -79791154, 1361170020, 2001714738, -1464409218, -1020707514, 1222529897, 1679025792, -1565652976, -580013532, 1770335741, 151462246, -1281735158, 1682292957, 1483529935, 471910574, 1539241949, 458788160, -858652289, 1807016891, -576558466, 978976581, 1043663428, -1129001515, 1927990952, -94075717, -1922690386, -1086558393, -761535389, 1412390302, -1362987237, -162634896, 1947078029, -413461673, -126740879, -1353482915, 1077988104, 1320477388, 886195818, 18198404, -508558296, -1785185763, 112762804, -831610808, 1866414978, 891333506, 18488651, 661792760, 1628790961, -409780260, -1153795797, 876946877, -1601685023, 1372485963, 791857591, -1608533303, -534984578, -1127755274, -822013501, -1578587449, 445679433, -732971622, -790962485, -720709064, 54117162, -963561881, -1913048708, -525259953, -140617289, 1140177722, -220915201, 668550556, -1080614356, 367459370, 261225585, -1684794075, -85617823, -826893077, -1029151655, 314222801, -1228863650, -486184436, 282218597, -888953790, -521376242, 379116347, 1285071038, 846784868, -1625320142, -523005217, -744475605, -1989021154, 453669953, 1268987020, -977374944, -1015663912, -550133875, -1684459730, -435458233, 266596637, -447948204, 517658769, -832407089, -851542417, 370717030, -47440635, -2070949179, -151313767, -182193321, -1506642397, -1817692879, 1456262402, -1393524382, 1517677493, 1846949527, -1999473716, -560569710, -2118563376, 1280348187, 1908823572, -423180355, 846861322, 1172426758, -1007518822, -911584259, 1655181056, -1155153950, 901632758, 1897031941, -1308360158, -1228157060, -847864789, 1393639104, 373351379, 950779232, 625454576, -1170726756, -146354570, 2007998917, 544563296, -2050228658, -1964470824, 2058025392, 1291430526, 424198748, 50039436, 29584100, -689184263, -1865090967, -1503863136, 1057563949, -1039604065, -1219600078, -831004069, 1469046755, 985887462 };
  845. +    private static final int ROUNDS = 16;
  846. +    private static final int BLOCK_SIZE = 8;
  847. +    private static final int SBOX_SK = 256;
  848. +    private static final int P_SZ = 18;
  849. +    private final int[] S0;
  850. +    private final int[] S1;
  851. +    private final int[] S2;
  852. +    private final int[] S3;
  853. +    private final int[] P;
  854. +    private boolean encrypting;
  855. +    private byte[] workingKey;
  856. +    
  857. +    public BlowfishEngine()
  858. +    {
  859. +        encrypting = false;
  860. +        workingKey = null;
  861. +        S0 = new int[SBOX_SK];
  862. +        S1 = new int[SBOX_SK];
  863. +        S2 = new int[SBOX_SK];
  864. +        S3 = new int[SBOX_SK];
  865. +        P = new int[P_SZ];
  866. +    }
  867. +    
  868. +    public void init(final boolean pEncrypting, final byte[] key)
  869. +    {
  870. +        encrypting = pEncrypting;
  871. +        setKey(workingKey = key);
  872. +    }
  873. +    
  874. +    public String getAlgorithmName()
  875. +    {
  876. +        return "Blowfish";
  877. +    }
  878. +    
  879. +    public final int processBlock(final byte[] in, final int inOff, final byte[] out, final int outOff) throws IOException
  880. +    {
  881. +        if (workingKey == null)
  882. +        {
  883. +            throw new IllegalStateException("Blowfish not initialised");
  884. +        }
  885. +        if (inOff + BLOCK_SIZE > in.length)
  886. +        {
  887. +            throw new IOException("input buffer too short");
  888. +        }
  889. +        if (outOff + BLOCK_SIZE > out.length)
  890. +        {
  891. +            throw new IOException("output buffer too short");
  892. +        }
  893. +        if (encrypting)
  894. +        {
  895. +            encryptBlock(in, inOff, out, outOff);
  896. +        }
  897. +        else
  898. +        {
  899. +            decryptBlock(in, inOff, out, outOff);
  900. +        }
  901. +        return BLOCK_SIZE;
  902. +    }
  903. +    
  904. +    public void reset() {}
  905. +    
  906. +    public int getBlockSize()
  907. +    {
  908. +        return BLOCK_SIZE;
  909. +    }
  910. +    
  911. +    private int F(final int x)
  912. +    {
  913. +        return (S0[x >>> 24] + S1[x >>> ROUNDS & 0xFF] ^ S2[x >>> BLOCK_SIZE & 0xFF]) + S3[x & 0xFF];
  914. +    }
  915. +    
  916. +    private void processTable(int xl, int xr, final int[] table)
  917. +    {
  918. +        for (int size = table.length, s = 0; s < size; s += 2)
  919. +        {
  920. +            xl ^= P[0];
  921. +            for (int i = 1; i < ROUNDS; i += 2)
  922. +            {
  923. +                xr ^= (F(xl) ^ P[i]);
  924. +                xl ^= (F(xr) ^ P[i + 1]);
  925. +            }
  926. +            xr ^= P[17];
  927. +            table[s] = xr;
  928. +            table[s + 1] = xl;
  929. +            xr = xl;
  930. +            xl = table[s];
  931. +        }
  932. +    }
  933. +    
  934. +    private void setKey(final byte[] key)
  935. +    {
  936. +        System.arraycopy(BlowfishEngine.KS0, 0, S0, 0, SBOX_SK);
  937. +        System.arraycopy(BlowfishEngine.KS1, 0, S1, 0, SBOX_SK);
  938. +        System.arraycopy(BlowfishEngine.KS2, 0, S2, 0, SBOX_SK);
  939. +        System.arraycopy(BlowfishEngine.KS3, 0, S3, 0, SBOX_SK);
  940. +        System.arraycopy(BlowfishEngine.KP, 0, P, 0, P_SZ);
  941. +        final int keyLength = key.length;
  942. +        int keyIndex = 0;
  943. +        for (int i = 0; i < P_SZ; ++i)
  944. +        {
  945. +            int data = 0;
  946. +            for (int j = 0; j < 4; ++j)
  947. +            {
  948. +                data = (data << BLOCK_SIZE | (key[keyIndex++] & 0xFF));
  949. +                if (keyIndex >= keyLength)
  950. +                    keyIndex = 0;
  951. +            }
  952. +            final int[] p = P;
  953. +            final int n = i;
  954. +            p[n] ^= data;
  955. +        }
  956. +        processTable(0, 0, P);
  957. +        processTable(P[ROUNDS], P[17], S0);
  958. +        processTable(S0[254], S0[255], S1);
  959. +        processTable(S1[254], S1[255], S2);
  960. +        processTable(S2[254], S2[255], S3);
  961. +    }
  962. +    
  963. +    public void encryptBlock(final byte[] src, final int srcIndex, final byte[] dst, final int dstIndex)
  964. +    {
  965. +        int xl = BytesTo32bits(src, srcIndex);
  966. +        int xr = BytesTo32bits(src, srcIndex + 4);
  967. +        xl ^= P[0];
  968. +        for (int i = 1; i < ROUNDS; i += 2)
  969. +        {
  970. +            xr ^= (F(xl) ^ P[i]);
  971. +            xl ^= (F(xr) ^ P[i + 1]);
  972. +        }
  973. +        xr ^= P[17];
  974. +        Bits32ToBytes(xr, dst, dstIndex);
  975. +        Bits32ToBytes(xl, dst, dstIndex + 4);
  976. +    }
  977. +    
  978. +    public void decryptBlock(final byte[] src, final int srcIndex, final byte[] dst, final int dstIndex)
  979. +    {
  980. +        int xl = BytesTo32bits(src, srcIndex);
  981. +        int xr = BytesTo32bits(src, srcIndex + 4);
  982. +        xl ^= P[17];
  983. +        for (int i = ROUNDS; i > 0; i -= 2)
  984. +        {
  985. +            xr ^= (F(xl) ^ P[i]);
  986. +            xl ^= (F(xr) ^ P[i - 1]);
  987. +        }
  988. +        xr ^= P[0];
  989. +        Bits32ToBytes(xr, dst, dstIndex);
  990. +        Bits32ToBytes(xl, dst, dstIndex + 4);
  991. +    }
  992. +    
  993. +    private static int BytesTo32bits(final byte[] b, final int i)
  994. +    {
  995. +        return (b[i + 3] & 0xFF) << 24 | (b[i + 2] & 0xFF) << ROUNDS | (b[i + 1] & 0xFF) << BLOCK_SIZE | (b[i] & 0xFF);
  996. +    }
  997. +    
  998. +    private static void Bits32ToBytes(final int in, final byte[] b, final int offset)
  999. +    {
  1000. +        b[offset] = (byte)in;
  1001. +        b[offset + 1] = (byte)(in >> BLOCK_SIZE);
  1002. +        b[offset + 2] = (byte)(in >> ROUNDS);
  1003. +        b[offset + 3] = (byte)(in >> 24);
  1004. +    }
  1005. +}
  1006. \ No newline at end of file
  1007. Index: java/hwid/crypt/impl/VMPC.java
  1008. ===================================================================
  1009. --- java/hwid/crypt/impl/VMPC.java  (nonexistent)
  1010. +++ java/hwid/crypt/impl/VMPC.java  (working copy)
  1011. @@ -0,0 +1,64 @@
  1012. +package hwid.crypt.impl;
  1013. +
  1014. +import hwid.crypt.ProtectionCrypt;
  1015. +
  1016. +public class VMPC implements ProtectionCrypt
  1017. +{
  1018. +    private byte _n;
  1019. +    private byte[] _P;
  1020. +    private byte _s;
  1021. +    
  1022. +    public VMPC()
  1023. +    {
  1024. +        _n = 0;
  1025. +        _P = new byte[256];
  1026. +        _s = 0;
  1027. +    }
  1028. +    
  1029. +    @Override
  1030. +    public void setup(final byte[] key, final byte[] iv)
  1031. +    {
  1032. +        _s = 0;
  1033. +        for (int i = 0; i < 256; ++i)
  1034. +        {
  1035. +            _P[i] = (byte)(i & 0xFF);
  1036. +        }
  1037. +        for (int m = 0; m < 768; ++m)
  1038. +        {
  1039. +            _s = _P[_s + _P[m & 0xFF] + key[m % 64] & 0xFF];
  1040. +            final byte temp = _P[m & 0xFF];
  1041. +            _P[m & 0xFF] = _P[_s & 0xFF];
  1042. +            _P[_s & 0xFF] = temp;
  1043. +        }
  1044. +        for (int m = 0; m < 768; ++m)
  1045. +        {
  1046. +            _s = _P[_s + _P[m & 0xFF] + iv[m % 64] & 0xFF];
  1047. +            final byte temp = _P[m & 0xFF];
  1048. +            _P[m & 0xFF] = _P[_s & 0xFF];
  1049. +            _P[_s & 0xFF] = temp;
  1050. +        }
  1051. +        for (int m = 0; m < 768; ++m)
  1052. +        {
  1053. +            _s = _P[_s + _P[m & 0xFF] + key[m % 64] & 0xFF];
  1054. +            final byte temp = _P[m & 0xFF];
  1055. +            _P[m & 0xFF] = _P[_s & 0xFF];
  1056. +            _P[_s & 0xFF] = temp;
  1057. +        }
  1058. +        _n = 0;
  1059. +    }
  1060. +    
  1061. +    @Override
  1062. +    public void crypt(final byte[] raw, final int offset, final int size)
  1063. +    {
  1064. +        for (int i = 0; i < size; ++i)
  1065. +        {
  1066. +            _s = _P[_s + _P[_n & 0xFF] & 0xFF];
  1067. +            final byte z = _P[_P[_P[_s & 0xFF] & 0xFF] + 1 & 0xFF];
  1068. +            final byte temp = _P[_n & 0xFF];
  1069. +            _P[_n & 0xFF] = _P[_s & 0xFF];
  1070. +            _P[_s & 0xFF] = temp;
  1071. +            _n = (byte)(_n + 1 & 0xFF);
  1072. +            raw[offset + i] ^= z;
  1073. +        }
  1074. +    }
  1075. +}
  1076. \ No newline at end of file
  1077. Index: java/hwid/crypt/Manager.java
  1078. ===================================================================
  1079. --- java/hwid/crypt/Manager.java    (nonexistent)
  1080. +++ java/hwid/crypt/Manager.java    (working copy)
  1081. @@ -0,0 +1,78 @@
  1082. +package hwid.crypt;
  1083. +
  1084. +import java.util.concurrent.ConcurrentHashMap;
  1085. +import java.util.concurrent.ScheduledFuture;
  1086. +
  1087. +import net.sf.l2j.commons.logging.CLogger;
  1088. +
  1089. +import net.sf.l2j.Config;
  1090. +import net.sf.l2j.gameserver.network.GameClient;
  1091. +
  1092. +import hwid.hwidmanager.hwidPlayer;
  1093. +
  1094. +public final class Manager
  1095. +{
  1096. +    protected static CLogger LOGGER = new CLogger(Manager.class.getName());
  1097. +    protected static String _logFile = "Manager";
  1098. +    protected static String _logMainFile = "hwid_logs";
  1099. +    protected static Manager INSTANCE;
  1100. +    protected static ScheduledFuture<?> _GGTask = null;
  1101. +    protected static ConcurrentHashMap<String, InfoSet> _objects = new ConcurrentHashMap<>();
  1102. +    
  1103. +    public static Manager getInstance()
  1104. +    {
  1105. +        if (INSTANCE == null)
  1106. +        {
  1107. +            LOGGER.info("Loaded HWID KEY RUSaCis Project");
  1108. +            LOGGER.info("Loaded HWID IP " + Config.GAMESERVER_HOSTNAME);
  1109. +            LOGGER.info("Loaded Anti Leech key...assigned ");
  1110. +            LOGGER.info("Loaded Restriction Leech...assigned ");
  1111. +            LOGGER.info("Loaded Licensed to Max Players : " + Config.MAXIMUM_ONLINE_USERS);
  1112. +            INSTANCE = new Manager();
  1113. +        }
  1114. +        return INSTANCE;
  1115. +    }
  1116. +    
  1117. +    public void addPlayer(final GameClient client)
  1118. +    {
  1119. +       hwidPlayer.updateHWIDInfo(client);
  1120. +        _objects.put(client.getPlayerName(), new InfoSet(client.getPlayerName(), client.getHWID()));
  1121. +    }
  1122. +    
  1123. +    public static void removePlayer(final String name)
  1124. +    {
  1125. +        if (_objects.containsKey(name))
  1126. +            _objects.remove(name);
  1127. +    }
  1128. +    
  1129. +    public static int getCountByHWID(final String HWID)
  1130. +    {
  1131. +        int result = 0;
  1132. +        for (final InfoSet object : _objects.values())
  1133. +        {
  1134. +            if (object._hwid.equals(HWID))
  1135. +                ++result;
  1136. +        }
  1137. +        return result;
  1138. +    }
  1139. +    
  1140. +    public class InfoSet
  1141. +    {
  1142. +        public String _playerName;
  1143. +        public long _lastGGSendTime;
  1144. +        public long _lastGGRecvTime;
  1145. +        public int _attempts;
  1146. +        public String _hwid;
  1147. +        
  1148. +        public InfoSet(final String name, final String HWID)
  1149. +        {
  1150. +            _playerName = "";
  1151. +            _hwid = "";
  1152. +            _playerName = name;
  1153. +            _lastGGSendTime = System.currentTimeMillis();
  1154. +            _lastGGRecvTime = _lastGGSendTime;
  1155. +            _attempts = 0;
  1156. +            _hwid = HWID;
  1157. +        }
  1158. +    }
  1159. +}
  1160. \ No newline at end of file
  1161. Index: java/hwid/utils/HwidLog.java
  1162. ===================================================================
  1163. --- java/hwid/utils/HwidLog.java    (nonexistent)
  1164. +++ java/hwid/utils/HwidLog.java    (working copy)
  1165. @@ -0,0 +1,53 @@
  1166. +package hwid.utils;
  1167. +
  1168. +import java.io.File;
  1169. +import java.io.FileWriter;
  1170. +import java.io.IOException;
  1171. +import java.text.DateFormat;
  1172. +import java.text.SimpleDateFormat;
  1173. +import java.util.Date;
  1174. +
  1175. +import net.sf.l2j.commons.logging.CLogger;
  1176. +
  1177. +public class HwidLog
  1178. +{
  1179. +   protected static final CLogger LOGGER = new CLogger(HwidLog.class.getName());
  1180. +  
  1181. +   public HwidLog() {}
  1182. +
  1183. +   public static void auditGMAction(String gmName, String action, String params)
  1184. +   {
  1185. +       final File file = new File("log/hwid/" + gmName + ".txt");
  1186. +       if (!file.exists())
  1187. +       {
  1188. +           try
  1189. +           {
  1190. +               file.createNewFile();
  1191. +           }
  1192. +           catch (IOException e) {}
  1193. +       }
  1194. +
  1195. +       try (FileWriter save = new FileWriter(file, true))
  1196. +       {
  1197. +           save.write(formatDate(new Date(), "dd/MM/yyyy H:mm:ss") + " >>> HWID: [" + gmName + "] >>> Player: [" + action + "]\r\n");
  1198. +       }
  1199. +       catch (IOException e)
  1200. +       {
  1201. +           LOGGER.error("HwidLog for Player " + gmName + " could not be saved: ", e);
  1202. +       }
  1203. +   }
  1204. +
  1205. +   public static void auditGMAction(String gmName, String action)
  1206. +   {
  1207. +       auditGMAction(gmName, action, "");
  1208. +   }
  1209. +
  1210. +   public static String formatDate(Date date, String format)
  1211. +   {
  1212. +       final DateFormat dateFormat = new SimpleDateFormat(format);
  1213. +       if (date != null)
  1214. +           return dateFormat.format(date);
  1215. +      
  1216. +       return null;
  1217. +   }
  1218. +}
  1219. \ No newline at end of file
  1220. Index: java/hwid/utils/Util.java
  1221. ===================================================================
  1222. --- java/hwid/utils/Util.java   (nonexistent)
  1223. +++ java/hwid/utils/Util.java   (working copy)
  1224. @@ -0,0 +1,73 @@
  1225. +package hwid.utils;
  1226. +
  1227. +public class Util
  1228. +{
  1229. +    public static void intToBytes(final int value, final byte[] array, int offset)
  1230. +    {
  1231. +        array[offset++] = (byte)(value & 0xFF);
  1232. +        array[offset++] = (byte)(value >> 8 & 0xFF);
  1233. +        array[offset++] = (byte)(value >> 16 & 0xFF);
  1234. +        array[offset++] = (byte)(value >> 24 & 0xFF);
  1235. +    }
  1236. +    
  1237. +    public static String LastErrorConvertion(final Integer LastError)
  1238. +    {
  1239. +        return LastError.toString();
  1240. +    }
  1241. +    
  1242. +    public static final String asHex(final byte[] raw)
  1243. +    {
  1244. +        return asHex(raw, 0, raw.length);
  1245. +    }
  1246. +    
  1247. +    public static final String asHex(final byte[] raw, final int offset, final int size)
  1248. +    {
  1249. +        final StringBuffer strbuf = new StringBuffer(raw.length * 2);
  1250. +        for (int i = 0; i < size; ++i)
  1251. +        {
  1252. +            if ((raw[offset + i] & 0xFF) < 16)
  1253. +                strbuf.append("0");
  1254. +
  1255. +            strbuf.append(Long.toString(raw[offset + i] & 0xFF, 16));
  1256. +        }
  1257. +        return strbuf.toString();
  1258. +    }
  1259. +    
  1260. +    public static int bytesToInt(final byte[] array, int offset)
  1261. +    {
  1262. +        return (array[offset++] & 0xFF) | (array[offset++] & 0xFF) << 8 | (array[offset++] & 0xFF) << 16 | (array[offset++] & 0xFF) << 24;
  1263. +    }
  1264. +    
  1265. +    public static String asHwidString(final String hex)
  1266. +    {
  1267. +        final byte[] buf = asByteArray(hex);
  1268. +        return asHex(buf);
  1269. +    }
  1270. +    
  1271. +    public static byte[] asByteArray(final String hex)
  1272. +    {
  1273. +        final byte[] buf = new byte[hex.length() / 2];
  1274. +        for (int i = 0; i < hex.length(); i += 2)
  1275. +        {
  1276. +            final int j = Integer.parseInt(hex.substring(i, i + 2), 16);
  1277. +            buf[i / 2] = (byte)(j & 0xFF);
  1278. +        }
  1279. +        return buf;
  1280. +    }
  1281. +    
  1282. +    public static boolean verifyChecksum(final byte[] raw, final int offset, final int size)
  1283. +    {
  1284. +        if ((size & 0x3) == 0x0 && size > 4)
  1285. +        {
  1286. +            long chksum = 0L;
  1287. +            final int count = size - 4;
  1288. +            for (int i2 = offset; i2 < count; i2 += 4)
  1289. +            {
  1290. +                chksum ^= bytesToInt(raw, i2);
  1291. +            }
  1292. +            final long check = bytesToInt(raw, count);
  1293. +            return check == chksum;
  1294. +        }
  1295. +        return false;
  1296. +    }
  1297. +}
  1298. \ No newline at end of file
  1299. Index: java/hwid/crypt/FirstKey.java
  1300. ===================================================================
  1301. --- java/hwid/crypt/FirstKey.java   (nonexistent)
  1302. +++ java/hwid/crypt/FirstKey.java   (working copy)
  1303. @@ -0,0 +1,29 @@
  1304. +package hwid.crypt;
  1305. +
  1306. +import net.sf.l2j.commons.logging.CLogger;
  1307. +
  1308. +import net.sf.l2j.Config;
  1309. +
  1310. +public class FirstKey
  1311. +{
  1312. +    protected static CLogger LOGGER = new CLogger(FirstKey.class.getName());
  1313. +    private static final byte[] TKBOX = new byte[] { -112, 22, 124, -93, 68, -116, -19, -125, -4, 101, -62, 5, 70, 25, 29, 81, 65, -86, 79, -69, 2, 97, -108, -11, -84, -56, 17, 7, 31, 52, -34, -41, -110, -60, 57, -5, -6, -24, 98, -100, 23, 4, -74, -37, 1, 6, -2, -14, -77, 12, -7, 3, -29, -17, -75, 49, 44, -78, 94, 21, 0, 35, -18, 83, 9, -42, 60, 93, 54, 20, -49, 114, 106, -82, 113, -90, 86, -124, -73, -81, 90, 121, 115, 125, 47, 24, -28, 73, 56, -31, 8, 71, 122, 58, -33, 108, -111, 102, -118, -103, -122, 88, 28, -76, 67, -115, -67, 78, 36, 117, -8, -25, -97, 107, -91, -50, -53, -52, 111, -114, -58, -128, 84, -98, 63, 74, 10, 41, -32, 126, 69, -68, 11, -119, -44, -39, -107, -40, 85, -87, 61, 91, -1, 50, -72, -117, 15, 55, -51, 43, 87, 105, 120, -88, 116, 80, -48, -123, -127, -105, -22, 76, 109, 19, -46, -30, 112, 16, -10, 45, -63, -47, 123, -106, 27, 38, 104, -70, -79, 18, -99, -16, -85, -23, 30, -66, 48, -89, -61, -113, -12, 51, -95, -15, 32, -9, 62, -38, 14, -45, -80, 66, 100, 103, -104, -27, -43, 110, -83, -26, -101, 46, -120, -54, 37, 42, 13, 75, 82, -109, 26, -94, -57, -64, 119, 53, 39, -13, -121, 33, 72, -126, -65, -36, -71, 118, -35, 92, 96, 89, 64, 34, -20, -96, 77, 40, 127, -21, 59, -55, -102, 95, -3, 99, -59, -92 };
  1314. +    private static final byte[] MGBOX = new byte[] { -14, -108, 90, 75, 15, 115, -38, -37, -125, 29, -77, 9, -4, 54, -72, 70, 65, -44, -48, 85, -13, -121, 118, -102, 40, 53, 113, -5, -9, 28, 3, 125, 21, -124, 10, 67, -6, -98, 96, -105, -104, 126, -93, 82, -47, 41, -91, 89, -59, 122, 47, 37, -31, 59, 56, 12, -112, -58, -39, -10, -40, -49, 22, -107, 33, -89, 109, 31, 88, 81, 72, 42, -66, -85, -15, 93, -101, -7, -128, -19, -27, -90, -11, 111, 49, -70, 121, 79, -123, -127, -79, 35, -28, 114, -22, 44, -54, 107, 106, 30, 92, 4, -43, -82, -78, -26, -61, 57, 77, 95, 58, 69, -76, 103, -56, 78, 26, -92, 48, -32, -52, 16, -67, 51, -50, -73, -29, 52, -60, -118, -1, -80, 63, 2, 124, -36, -65, 8, -33, -115, -3, 108, -21, 18, 110, 36, -51, 46, -103, 94, 20, -114, 80, 127, -86, 19, -119, -113, 68, -25, -120, -71, 32, 38, -95, -57, 5, 7, 105, -17, -34, -81, 24, -74, -35, 100, 1, -46, -94, 43, 13, 17, -87, 11, -69, -62, -126, -63, -64, -23, -97, 27, -18, -53, 84, 0, -106, -83, 39, 116, 91, 104, 14, -24, -42, 34, -88, -84, 62, 61, -2, 112, 23, 119, 73, 6, -122, 55, -99, -41, 83, 99, 60, 87, 45, 120, -55, 117, -117, 98, 123, -8, 76, -16, -30, 64, -96, -109, -75, 25, 101, -110, 86, 50, 71, -12, 74, -100, -116, -68, 66, -20, -45, 102, -111, 97 };
  1315. +    public static final byte[] SKBOX = new byte[] { Config.FST_KEY, Config.SCN_KEY, 2, 15, -5, 17, 24, 23, 18, 45, 1, 21, 122, 16, Config.ANP_KEY, Config.ULT_KEY };
  1316. +    
  1317. +    public static byte[] expandKey(final byte[] key, final int size)
  1318. +    {
  1319. +        final byte[] P = new byte[64];
  1320. +        for (int i = 0; i < 64; ++i)
  1321. +        {
  1322. +            P[i] = key[i % size];
  1323. +        }
  1324. +        for (int i = 0; i < 256; ++i)
  1325. +        {
  1326. +            final byte t = P[i % 64];
  1327. +            final byte m = (byte)((MGBOX[MGBOX[t & 0xFF] & 0xFF] & 0xFF) ^ (TKBOX[TKBOX[i] & 0xFF] & 0xFF));
  1328. +            P[i % 64] = TKBOX[m & 0xFF];
  1329. +        }
  1330. +        return P;
  1331. +    }
  1332. +}
  1333. Index: java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  1334. ===================================================================
  1335. --- java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (revision 15)
  1336. +++ java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java    (working copy)
  1337. @@ -55,6 +55,8 @@
  1338.  import net.sf.l2j.gameserver.skills.L2Skill;
  1339.  import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
  1340.  
  1341. +import hwid.hwid;
  1342. +
  1343.  public class EnterWorld extends L2GameClientPacket
  1344.  {
  1345.     @Override
  1346. @@ -301,6 +303,8 @@
  1347.         if (qs != null)
  1348.             qs.getQuest().notifyEvent("UC", null, player);
  1349.        
  1350. +       hwid.enterlog(player, getClient());
  1351. +      
  1352.         player.sendPacket(ActionFailed.STATIC_PACKET);
  1353.     }
  1354.    
  1355. Index: java/hwid/crypt/ProtectionCrypt.java
  1356. ===================================================================
  1357. --- java/hwid/crypt/ProtectionCrypt.java    (nonexistent)
  1358. +++ java/hwid/crypt/ProtectionCrypt.java    (working copy)
  1359. @@ -0,0 +1,8 @@
  1360. +package hwid.crypt;
  1361. +
  1362. +public interface ProtectionCrypt
  1363. +{
  1364. +    void setup(final byte[] p0, final byte[] p1);
  1365. +    
  1366. +    void crypt(final byte[] p0, final int p1, final int p2);
  1367. +}
  1368. Index: java/hwid/crypt/impl/L2Client.java
  1369. ===================================================================
  1370. --- java/hwid/crypt/impl/L2Client.java  (nonexistent)
  1371. +++ java/hwid/crypt/impl/L2Client.java  (working copy)
  1372. @@ -0,0 +1,50 @@
  1373. +package hwid.crypt.impl;
  1374. +
  1375. +import hwid.crypt.ProtectionCrypt;
  1376. +
  1377. +public class L2Client implements ProtectionCrypt
  1378. +{
  1379. +    private ProtectionCrypt _client;
  1380. +    private byte[] _key;
  1381. +    private byte[] _iv;
  1382. +    
  1383. +    public L2Client()
  1384. +    {
  1385. +        _key = new byte[16];
  1386. +        _iv = null;
  1387. +    }
  1388. +    
  1389. +    @Override
  1390. +    public void setup(final byte[] key, final byte[] iv)
  1391. +    {
  1392. +        System.arraycopy(key, 0, this._key, 0, 16);
  1393. +        _iv = iv;
  1394. +    }
  1395. +    
  1396. +    @Override
  1397. +    public void crypt(final byte[] raw, final int offset, final int size)
  1398. +    {
  1399. +        if (_iv != null)
  1400. +        {
  1401. +            (_client = new VMPC()).setup(_key, _iv);
  1402. +            _client.crypt(raw, offset, size);
  1403. +        }
  1404. +        int temp = 0;
  1405. +        int temp2 = 0;
  1406. +        for (int i = 0; i < size; ++i)
  1407. +        {
  1408. +            temp2 = (raw[offset + i] & 0xFF);
  1409. +            raw[offset + i] = (byte)(temp2 ^ _key[i & 0xF] ^ temp);
  1410. +            temp = temp2;
  1411. +        }
  1412. +        int old = _key[8] & 0xFF;
  1413. +        old |= (_key[9] << 8 & 0xFF00);
  1414. +        old |= (_key[10] << 16 & 0xFF0000);
  1415. +        old |= (_key[11] << 24 & 0xFF000000);
  1416. +        old += size;
  1417. +        _key[8] = (byte)(old & 0xFF);
  1418. +        _key[9] = (byte)(old >> 8 & 0xFF);
  1419. +        _key[10] = (byte)(old >> 16 & 0xFF);
  1420. +        _key[11] = (byte)(old >> 24 & 0xFF);
  1421. +    }
  1422. +}
  1423. \ No newline at end of file
  1424. Index: java/hwid/crypt/impl/L2Server.java
  1425. ===================================================================
  1426. --- java/hwid/crypt/impl/L2Server.java  (nonexistent)
  1427. +++ java/hwid/crypt/impl/L2Server.java  (working copy)
  1428. @@ -0,0 +1,49 @@
  1429. +package hwid.crypt.impl;
  1430. +
  1431. +import hwid.crypt.ProtectionCrypt;
  1432. +
  1433. +public class L2Server implements ProtectionCrypt
  1434. +{
  1435. +    private byte[] _key;
  1436. +    private byte[] _iv;
  1437. +    private ProtectionCrypt _server;
  1438. +    
  1439. +    public L2Server()
  1440. +    {
  1441. +        _key = new byte[16];
  1442. +        _iv = null;
  1443. +    }
  1444. +    
  1445. +    @Override
  1446. +    public void setup(final byte[] key, final byte[] iv)
  1447. +    {
  1448. +        System.arraycopy(key, 0, this._key, 0, 16);
  1449. +        _iv = iv;
  1450. +    }
  1451. +    
  1452. +    @Override
  1453. +    public void crypt(final byte[] raw, final int offset, final int size)
  1454. +    {
  1455. +        int temp = 0;
  1456. +        for (int i = 0; i < size; ++i)
  1457. +        {
  1458. +            final int temp2 = raw[offset + i] & 0xFF;
  1459. +            temp ^= (temp2 ^ _key[i & 0xF]);
  1460. +            raw[offset + i] = (byte)temp;
  1461. +        }
  1462. +        int old = _key[8] & 0xFF;
  1463. +        old |= (_key[9] << 8 & 0xFF00);
  1464. +        old |= (_key[10] << 16 & 0xFF0000);
  1465. +        old |= (_key[11] << 24 & 0xFF000000);
  1466. +        old += size;
  1467. +        _key[8] = (byte)(old & 0xFF);
  1468. +        _key[9] = (byte)(old >> 8 & 0xFF);
  1469. +        _key[10] = (byte)(old >> 16 & 0xFF);
  1470. +        _key[11] = (byte)(old >> 24 & 0xFF);
  1471. +        if (_iv != null)
  1472. +        {
  1473. +            (_server = new VMPC()).setup(_key, _iv);
  1474. +            _server.crypt(raw, offset, size);
  1475. +        }
  1476. +    }
  1477. +}
  1478. \ No newline at end of file
  1479. Index: java/hwid/hwid.java
  1480. ===================================================================
  1481. --- java/hwid/hwid.java (nonexistent)
  1482. +++ java/hwid/hwid.java (working copy)
  1483. @@ -0,0 +1,268 @@
  1484. +package hwid;
  1485. +
  1486. +import java.io.IOException;
  1487. +import java.nio.ByteBuffer;
  1488. +import java.util.concurrent.ConcurrentHashMap;
  1489. +
  1490. +import net.sf.l2j.commons.logging.CLogger;
  1491. +
  1492. +import net.sf.l2j.Config;
  1493. +import net.sf.l2j.gameserver.model.World;
  1494. +import net.sf.l2j.gameserver.model.actor.Player;
  1495. +import net.sf.l2j.gameserver.network.GameClient;
  1496. +import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
  1497. +
  1498. +import hwid.crypt.BlowfishEngine;
  1499. +import hwid.crypt.FirstKey;
  1500. +import hwid.crypt.Manager;
  1501. +import hwid.hwidmanager.hwidBan;
  1502. +import hwid.hwidmanager.hwidPlayer;
  1503. +import hwid.hwidmanager.hwidManager;
  1504. +import hwid.utils.HwidLog;
  1505. +import hwid.utils.Util;
  1506. +
  1507. +public class hwid
  1508. +{
  1509. +    protected static CLogger LOGGER = new CLogger(hwid.class.getName());
  1510. +    private static byte[] _key = new byte[16];
  1511. +    static byte version = 11;
  1512. +    protected static ConcurrentHashMap<String, Manager.InfoSet> _objects = new ConcurrentHashMap<>();
  1513. +    
  1514. +    public static void Init()
  1515. +    {
  1516. +        if (isProtectionOn())
  1517. +        {
  1518. +            hwidBan.getInstance();
  1519. +            hwidPlayer.getInstance();
  1520. +            Manager.getInstance();
  1521. +            hwidManager.getInstance();
  1522. +        }
  1523. +    }
  1524. +    
  1525. +    public static boolean isProtectionOn()
  1526. +    {
  1527. +        return Config.ALLOW_GUARD_SYSTEM;
  1528. +    }
  1529. +    
  1530. +    public static byte[] getKey(final byte[] key)
  1531. +    {
  1532. +        final byte[] bfkey = FirstKey.SKBOX;
  1533. +        try
  1534. +        {
  1535. +            final BlowfishEngine bf = new BlowfishEngine();
  1536. +            bf.init(true, bfkey);
  1537. +            bf.processBlock(key, 0, _key, 0);
  1538. +            bf.processBlock(key, 8, _key, 8);
  1539. +        }
  1540. +        catch (IOException e)
  1541. +        {
  1542. +            LOGGER.warn("HWID: Bad key!!!");
  1543. +        }
  1544. +        return _key;
  1545. +    }
  1546. +    
  1547. +    public static void addPlayer(final GameClient client)
  1548. +    {
  1549. +        if (isProtectionOn() && client != null)
  1550. +            Manager.getInstance().addPlayer(client);
  1551. +    }
  1552. +    
  1553. +    public static void removePlayer(final GameClient client)
  1554. +    {
  1555. +        if (isProtectionOn() && client != null)
  1556. +            Manager.removePlayer(client.getPlayerName());
  1557. +    }
  1558. +    
  1559. +    public static boolean checkVerfiFlag(final GameClient client, final int flag)
  1560. +    {
  1561. +        boolean result = true;
  1562. +        final int fl = Integer.reverseBytes(flag);
  1563. +        if (fl == -1)
  1564. +        {
  1565. +            return false;
  1566. +        }
  1567. +        if (fl == 1342177280)
  1568. +        {
  1569. +            return false;
  1570. +        }
  1571. +        if ((fl & 0x1) != 0x0)
  1572. +        {
  1573. +            result = false;
  1574. +        }
  1575. +        if ((fl & 0x10) != 0x0)
  1576. +        {
  1577. +            result = false;
  1578. +        }
  1579. +        if ((fl & 0x10000000) != 0x0)
  1580. +        {
  1581. +            result = false;
  1582. +        }
  1583. +        return result;
  1584. +    }
  1585. +    
  1586. +    public static int dumpData(final int _id, int position, final GameClient pi)
  1587. +    {
  1588. +        int value = 0;
  1589. +        position = ((position > 4) ? 5 : position);
  1590. +        boolean isIdZero = false;
  1591. +        if (_id == 0)
  1592. +        {
  1593. +            isIdZero = true;
  1594. +        }
  1595. +        switch (position)
  1596. +        {
  1597. +            case 0:
  1598. +            {
  1599. +                if (_id != 1435233386)
  1600. +                {
  1601. +                    if (!isIdZero) {}
  1602. +                    value = 1;
  1603. +                    break;
  1604. +                }
  1605. +                break;
  1606. +            }
  1607. +            case 1:
  1608. +            {
  1609. +                if (_id != 16)
  1610. +                {
  1611. +                    if (!isIdZero) {}
  1612. +                    value = 2;
  1613. +                    break;
  1614. +                }
  1615. +                break;
  1616. +            }
  1617. +            case 2:
  1618. +            case 3:
  1619. +            case 4:
  1620. +            {
  1621. +                final int code = _id & 0xFF000000;
  1622. +                if (code == 204) {}
  1623. +                if (code == 233)
  1624. +                {
  1625. +                    value = 3;
  1626. +                    break;
  1627. +                }
  1628. +                break;
  1629. +            }
  1630. +            default:
  1631. +            {
  1632. +                value = 0;
  1633. +                break;
  1634. +            }
  1635. +        }
  1636. +        return value;
  1637. +    }
  1638. +    
  1639. +    public static int calcPenalty(final byte[] data, final GameClient pi)
  1640. +    {
  1641. +        int sum = -1;
  1642. +        if (Util.verifyChecksum(data, 0, data.length))
  1643. +        {
  1644. +            final ByteBuffer buf = ByteBuffer.wrap(data, 0, data.length - 4);
  1645. +            sum = 0;
  1646. +            for (int lenPenalty = (data.length - 4) / 4, i = 0; i < lenPenalty; ++i)
  1647. +            {
  1648. +                sum += dumpData(buf.getInt(), i, pi);
  1649. +            }
  1650. +        }
  1651. +        return sum;
  1652. +    }
  1653. +    
  1654. +    public static boolean CheckHWIDs(final GameClient client, final int LastError1, final int LastError2)
  1655. +    {
  1656. +        boolean resultHWID = false;
  1657. +        boolean resultLastError = false;
  1658. +        final String HWID = client.getHWID();
  1659. +        if (HWID.equalsIgnoreCase("fab888b1cc9de973c8046519fa841e6") && Config.PROTECT_KICK_WITH_EMPTY_HWID)
  1660. +        {
  1661. +            resultHWID = true;
  1662. +        }
  1663. +        if (LastError1 != 0 && Config.PROTECT_KICK_WITH_LASTERROR_HWID)
  1664. +        {
  1665. +            resultLastError = true;
  1666. +        }
  1667. +        return resultHWID || resultLastError;
  1668. +    }
  1669. +    
  1670. +    public static String fillHex(final int data, final int digits)
  1671. +    {
  1672. +        String number = Integer.toHexString(data);
  1673. +        for (int i = number.length(); i < digits; ++i)
  1674. +        {
  1675. +            number = "0" + number;
  1676. +        }
  1677. +        return number;
  1678. +    }
  1679. +    
  1680. +    public static String ExtractHWID(final byte[] _data)
  1681. +    {
  1682. +        if (!Util.verifyChecksum(_data, 0, _data.length))
  1683. +        {
  1684. +            return null;
  1685. +        }
  1686. +        final StringBuilder resultHWID = new StringBuilder();
  1687. +        for (int i = 0; i < _data.length - 8; ++i)
  1688. +        {
  1689. +            resultHWID.append(fillHex(_data[i] & 0xFF, 2));
  1690. +        }
  1691. +        return resultHWID.toString();
  1692. +    }
  1693. +    
  1694. +    public static boolean doAuthLogin(final GameClient client, final byte[] data, final String loginName)
  1695. +    {
  1696. +        if (!isProtectionOn())
  1697. +            return true;
  1698. +
  1699. +        client.setLoginName(loginName);
  1700. +        final String fullHWID = ExtractHWID(data);
  1701. +        if (fullHWID == null)
  1702. +        {
  1703. +            LOGGER.warn("AuthLogin CRC Check Fail! May be BOT or unprotected client! Client IP: " + client.toString());
  1704. +            client.close(ServerClose.STATIC_PACKET);
  1705. +            return false;
  1706. +        }
  1707. +        final int LastError1 = ByteBuffer.wrap(data, 16, 4).getInt();
  1708. +        if (CheckHWIDs(client, LastError1, 0))
  1709. +        {
  1710. +            LOGGER.warn("HWID error, look protection_logs.txt file, from IP: " + client.toString());
  1711. +            client.close(ServerClose.STATIC_PACKET);
  1712. +            return false;
  1713. +        }
  1714. +        if (hwidBan.getInstance().checkFullHWIDBanned(client))
  1715. +        {
  1716. +            LOGGER.warn("Client " + client + " is banned. Kicked! |HWID: " + client.getHWID() + " IP: " + client.toString());
  1717. +            client.close(ServerClose.STATIC_PACKET);
  1718. +        }
  1719. +        final int VerfiFlag = ByteBuffer.wrap(data, 40, 4).getInt();
  1720. +        return checkVerfiFlag(client, VerfiFlag);
  1721. +    }
  1722. +    
  1723. +    public static void doDisconection(final GameClient client)
  1724. +    {
  1725. +        removePlayer(client);
  1726. +    }
  1727. +    
  1728. +    public static boolean checkPlayerWithHWID(final GameClient client, final int playerID, final String playerName)
  1729. +    {
  1730. +        if (!isProtectionOn())
  1731. +            return true;
  1732. +
  1733. +        client.setPlayerName(playerName);
  1734. +        client.setPlayerId(playerID);
  1735. +        addPlayer(client);
  1736. +        return true;
  1737. +    }
  1738. +    
  1739. +    public static void nopath(final GameClient client)
  1740. +    {
  1741. +        LOGGER.warn("HWID: " + client.toString() + " is trying to loggin server without client side hwid.");
  1742. +        client.close(ServerClose.STATIC_PACKET);
  1743. +    }
  1744. +    
  1745. +    public static void enterlog(final Player player, final GameClient client)
  1746. +    {
  1747. +        hwidManager.getInstance().validBox(player, Config.PROTECT_WINDOWS_COUNT + 1, World.getInstance().getPlayers(), true);
  1748. +        LOGGER.info("HWID: [" + client.getHWID() + "], character: [" + player.getName() + "]");
  1749. +        HwidLog.auditGMAction(player.getHWid(), player.getName());
  1750. +    }
  1751. +}
  1752. \ No newline at end of file
  1753. Index: java/net/sf/l2j/gameserver/network/clientpackets/AuthLogin.java
  1754. ===================================================================
  1755. --- java/net/sf/l2j/gameserver/network/clientpackets/AuthLogin.java (revision 15)
  1756. +++ java/net/sf/l2j/gameserver/network/clientpackets/AuthLogin.java (working copy)
  1757. @@ -3,6 +3,8 @@
  1758.  import net.sf.l2j.gameserver.LoginServerThread;
  1759.  import net.sf.l2j.gameserver.network.SessionKey;
  1760.  
  1761. +import hwid.hwid;
  1762. +
  1763.  public final class AuthLogin extends L2GameClientPacket
  1764.  {
  1765.     private String _loginName;
  1766. @@ -10,6 +12,7 @@
  1767.     private int _playKey2;
  1768.     private int _loginKey1;
  1769.     private int _loginKey2;
  1770. +   private final byte[] _data = new byte[48];
  1771.    
  1772.     @Override
  1773.     protected void readImpl()
  1774. @@ -24,6 +27,12 @@
  1775.     @Override
  1776.     protected void runImpl()
  1777.     {
  1778. +       if (hwid.isProtectionOn())
  1779. +       {
  1780. +           if (!hwid.doAuthLogin(getClient(), _data, _loginName))
  1781. +               return;
  1782. +       }
  1783. +      
  1784.         if (getClient().getAccountName() != null)
  1785.             return;
  1786.        
  1787. Index: java/net/sf/l2j/gameserver/network/GameClient.java
  1788. ===================================================================
  1789. --- java/net/sf/l2j/gameserver/network/GameClient.java  (revision 15)
  1790. +++ java/net/sf/l2j/gameserver/network/GameClient.java  (working copy)
  1791. @@ -33,6 +33,8 @@
  1792.  import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  1793.  import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
  1794.  
  1795. +import hwid.hwid;
  1796. +
  1797.  /**
  1798.   * Represents a client connected on Game Server.<br>
  1799.   * <br>
  1800. @@ -264,6 +266,10 @@
  1801.     {
  1802.         byte[] key = BlowFishKeygen.getRandomKey();
  1803.         _crypt.setKey(key);
  1804. +       if (hwid.isProtectionOn())
  1805. +       {
  1806. +           key = hwid.getKey(key);
  1807. +       }
  1808.         return key;
  1809.     }
  1810.    
  1811. @@ -630,6 +636,7 @@
  1812.             return;
  1813.        
  1814.         getConnection().close(gsp);
  1815. +       hwid.removePlayer(null);
  1816.     }
  1817.    
  1818.     /**
  1819. @@ -821,4 +828,72 @@
  1820.             return true;
  1821.         }
  1822.     }
  1823. +  
  1824. +   // HWID
  1825. +   private String _playerName;
  1826. +   private String _loginName;
  1827. +   private int _playerId;
  1828. +   private int _count;
  1829. +   private String _hwid;
  1830. +   private int _revision;
  1831. +
  1832. +   public final String getPlayerName()
  1833. +   {
  1834. +       return _playerName;
  1835. +   }
  1836. +
  1837. +   public void setPlayerName(String name)
  1838. +   {
  1839. +       _playerName = name;
  1840. +   }
  1841. +  
  1842. +   public void setPlayerId(int plId)
  1843. +   {
  1844. +       _playerId = plId;
  1845. +   }
  1846. +  
  1847. +   public int getPlayerId()
  1848. +   {
  1849. +       return _playerId;
  1850. +   }
  1851. +  
  1852. +    public int getCount()
  1853. +    {
  1854. +        return _count;
  1855. +    }
  1856. +    
  1857. +    public void setCount(int count)
  1858. +    {
  1859. +        _count = count;
  1860. +    }
  1861. +  
  1862. +   public final String getHWID()
  1863. +   {
  1864. +       return _hwid;
  1865. +   }
  1866. +  
  1867. +   public void setHWID(String hwid)
  1868. +   {
  1869. +       _hwid = hwid;
  1870. +   }
  1871. +  
  1872. +   public void setRevision(int revision)
  1873. +   {
  1874. +       _revision = revision;
  1875. +   }
  1876. +  
  1877. +   public int getRevision()
  1878. +   {
  1879. +       return _revision;
  1880. +   }
  1881. +  
  1882. +   public final String getLoginName()
  1883. +   {
  1884. +       return _loginName;
  1885. +   }
  1886. +  
  1887. +   public void setLoginName(String name)
  1888. +   {
  1889. +       _loginName = name;
  1890. +   }
  1891.  }
  1892. \ No newline at end of file
  1893. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestGameStart.java
  1894. ===================================================================
  1895. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestGameStart.java  (revision 15)
  1896. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestGameStart.java  (working copy)
  1897. @@ -8,6 +8,8 @@
  1898.  import net.sf.l2j.gameserver.network.serverpackets.CharSelected;
  1899.  import net.sf.l2j.gameserver.network.serverpackets.SSQInfo;
  1900.  
  1901. +import hwid.hwid;
  1902. +
  1903.  public class RequestGameStart extends L2GameClientPacket
  1904.  {
  1905.     private int _slot;
  1906. @@ -52,6 +54,9 @@
  1907.                    
  1908.                     sendPacket(SSQInfo.sendSky());
  1909.                    
  1910. +                   if (!hwid.checkPlayerWithHWID(getClient(), player.getObjectId(), player.getName()))
  1911. +                       return;
  1912. +                  
  1913.                     client.setState(GameClientState.ENTERING);
  1914.                    
  1915.                     sendPacket(new CharSelected(player, client.getSessionId().playOkID1));
  1916. Index: java/net/sf/l2j/Config.java
  1917. ===================================================================
  1918. --- java/net/sf/l2j/Config.java (revision 15)
  1919. +++ java/net/sf/l2j/Config.java (working copy)
  1920. @@ -24,6 +24,8 @@
  1921.  import net.sf.l2j.gameserver.model.holder.IntIntHolder;
  1922.  import net.sf.l2j.gameserver.model.olympiad.enums.OlympiadPeriod;
  1923.  
  1924. +import hwid.crypt.FirstKey;
  1925. +
  1926.  /**
  1927.   * This class contains global server configuration.<br>
  1928.   * It has static final fields initialized from configuration files.
  1929. @@ -46,6 +48,7 @@
  1930.     public static final String RUS_ACIS_FILE = "./config/rus_acis.properties";
  1931.     public static final String SERVER_FILE = "./config/server.properties";
  1932.     public static final String SIEGE_FILE = "./config/siege.properties";
  1933. +   public static final String HWID_FILE = "./config/hwid.properties";
  1934.    
  1935.     // --------------------------------------------------
  1936.     // Clans settings
  1937. @@ -741,6 +744,26 @@
  1938.     public static int BUY_PREMIUM_DAYS_28;
  1939.     public static int BUY_PREMIUM_DAYS_28_PRICE;
  1940.    
  1941. +   /** hwid settings */
  1942. +  
  1943. +    public static final boolean PROTECT_DEBUG = false;
  1944. +    public static final boolean PROTECT_ENABLE_HWID_LOCK = false;
  1945. +    public static byte[] GUARD_CLIENT_CRYPT_KEY;
  1946. +    public static byte[] GUARD_CLIENT_CRYPT;
  1947. +    public static byte[] GUARD_SERVER_CRYPT_KEY;
  1948. +    public static byte[] GUARD_SERVER_CRYPT;
  1949. +    public static boolean ALLOW_GUARD_SYSTEM;
  1950. +    public static int PROTECT_WINDOWS_COUNT;
  1951. +    public static int GET_CLIENT_HWID;
  1952. +    public static boolean ENABLE_CONSOLE_LOG;
  1953. +    public static boolean PROTECT_KICK_WITH_EMPTY_HWID;
  1954. +    public static boolean PROTECT_KICK_WITH_LASTERROR_HWID;
  1955. +    public static byte FST_KEY = 110;
  1956. +    public static byte SCN_KEY = 36;
  1957. +    public static byte ANP_KEY = -5;
  1958. +    public static byte ULT_KEY = 12;
  1959. +    public static int NPROTECT_KEY = -1;
  1960. +  
  1961.     /**
  1962.      * Initialize {@link ExProperties} from specified configuration file.
  1963.      * @param filename : File name to be loaded.
  1964. @@ -1243,7 +1266,7 @@
  1965.         final ExProperties server = initProperties(SERVER_FILE);
  1966.        
  1967.         HOSTNAME = server.getProperty("Hostname", "*");
  1968. -       GAMESERVER_HOSTNAME = server.getProperty("GameserverHostname");
  1969. +       GAMESERVER_HOSTNAME = server.getProperty("GameserverHostname", "*");
  1970.         GAMESERVER_PORT = server.getProperty("GameserverPort", 7777);
  1971.         GAMESERVER_LOGIN_HOSTNAME = server.getProperty("LoginHost", "127.0.0.1");
  1972.         GAMESERVER_LOGIN_PORT = server.getProperty("LoginPort", 9014);
  1973. @@ -1503,6 +1526,40 @@
  1974.     }
  1975.    
  1976.     /**
  1977. +    * Loads hwid settings.<br>
  1978. +    */
  1979. +   private static final void loadHwid()
  1980. +   {
  1981. +       // Hwid settings
  1982. +       final ExProperties hwid = initProperties(HWID_FILE);
  1983. +        ALLOW_GUARD_SYSTEM = hwid.getProperty("AllowGuardSystem", true);
  1984. +        PROTECT_WINDOWS_COUNT = hwid.getProperty("AllowedWindowsCount", 1);
  1985. +
  1986. +        GET_CLIENT_HWID = hwid.getProperty("UseClientHWID", 2);
  1987. +        ENABLE_CONSOLE_LOG = hwid.getProperty("EnableConsoleLog", false);
  1988. +        PROTECT_KICK_WITH_EMPTY_HWID = hwid.getProperty("KickWithEmptyHWID", false);
  1989. +        PROTECT_KICK_WITH_LASTERROR_HWID = hwid.getProperty("KickWithLastErrorHWID", false);
  1990. +
  1991. +        String key_client = "GOGX2_RB(]Slnjt15~EgyqTv%[$YR]!1E~ayK?$9[R%%m4{zoMF$D?f:zvS2q&>~";
  1992. +        String key_server = "b*qR43<9J1pD>Q4Uns6FsKao~VbU0H]y`A0ytTveiWn)SuSYsM?m*eblL!pwza!t";
  1993. +        byte[] keyS = key_server.getBytes();
  1994. +        byte[] tmpS = new byte[32];
  1995. +        
  1996. +        byte[] keyC = key_client.getBytes();
  1997. +        byte[] tmpC = new byte[32];
  1998. +      
  1999. +        System.arraycopy(keyC, 0, tmpC, 0, 32);
  2000. +        GUARD_CLIENT_CRYPT_KEY = FirstKey.expandKey(tmpC, 32);
  2001. +        System.arraycopy(keyC, 32, tmpC, 0, 32);
  2002. +        GUARD_CLIENT_CRYPT = FirstKey.expandKey(tmpC, 32);
  2003. +        
  2004. +        System.arraycopy(keyS, 0, tmpS, 0, 32);
  2005. +        GUARD_SERVER_CRYPT_KEY = FirstKey.expandKey(tmpS, 32);
  2006. +        System.arraycopy(keyS, 32, tmpS, 0, 32);
  2007. +        GUARD_SERVER_CRYPT = FirstKey.expandKey(tmpS, 32);
  2008. +   }
  2009. +  
  2010. +   /**
  2011.      * Loads loginserver settings.<br>
  2012.      * IP addresses, database, account, misc.
  2013.      */
  2014. @@ -1575,6 +1632,9 @@
  2015.        
  2016.         // rusacis settings
  2017.         loadRusAcis();
  2018. +      
  2019. +       // hwid settings
  2020. +       loadHwid();
  2021.     }
  2022.    
  2023.     public static final void loadLoginServer()
  2024. Index: java/net/sf/l2j/gameserver/GameServer.java
  2025. ===================================================================
  2026. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 15)
  2027. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  2028. @@ -106,6 +106,8 @@
  2029.  import net.sf.l2j.util.DeadLockDetector;
  2030.  import net.sf.l2j.util.IPv4Filter;
  2031.  
  2032. +import hwid.hwid;
  2033. +
  2034.  public class GameServer
  2035.  {
  2036.     private static final CLogger LOGGER = new CLogger(GameServer.class.getName());
  2037. @@ -302,6 +304,9 @@
  2038.         LOGGER.info("Maximum allowed players: {}.", Config.MAXIMUM_ONLINE_USERS);
  2039.         LOGGER.info("Server loaded in " + (System.currentTimeMillis() - serverLoadStart) / 1000 + " seconds");
  2040.        
  2041. +       StringUtil.printSection("Hwid Manager");
  2042. +       hwid.Init();
  2043. +      
  2044.         StringUtil.printSection("Login");
  2045.         LoginServerThread.getInstance().start();
  2046.        
  2047. Index: config/en/hwid.properties
  2048. ===================================================================
  2049. --- config/en/hwid.properties   (nonexistent)
  2050. +++ config/en/hwid.properties   (working copy)
  2051. @@ -0,0 +1,28 @@
  2052. +#=============================================================
  2053. +#                    Hwid System Manager
  2054. +#=============================================================
  2055. +# Allow Guard Protection System
  2056. +AllowGuardSystem = True
  2057. +
  2058. +# Installing client HWID
  2059. +# 1 = HWID HDD
  2060. +# 2 = HWID MAC
  2061. +# 3 = HWID CPU
  2062. +UseClientHWID = 2
  2063. +KickWithEmptyHWID = True
  2064. +KickWithLastErrorHWID = True
  2065. +
  2066. +# What is the criterion to prohibit the launch of multiple windows?
  2067. +# IP - to IP, HWID - client on HWID
  2068. +ClientWindowsCountSec = HWID
  2069. +
  2070. +# Configure the number of open windows client
  2071. +# If 0 = Unlimited
  2072. +AllowedWindowsCount = 2
  2073. +
  2074. +# Enable log on Console Server - Player, HWID, NAME, ID
  2075. +EnableConsoleLog = True
  2076. +EnableHWIDBans = True
  2077. +EnableHWIDBonus = True
  2078. +StoreHWID = True
  2079. +LogHWIDs = True
  2080. Index: java/net/sf/l2j/gameserver/network/clientpackets/SendProtocolVersion.java
  2081. ===================================================================
  2082. --- java/net/sf/l2j/gameserver/network/clientpackets/SendProtocolVersion.java   (revision 15)
  2083. +++ java/net/sf/l2j/gameserver/network/clientpackets/SendProtocolVersion.java   (working copy)
  2084. @@ -1,21 +1,61 @@
  2085.  package net.sf.l2j.gameserver.network.clientpackets;
  2086.  
  2087. +import net.sf.l2j.Config;
  2088.  import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  2089.  import net.sf.l2j.gameserver.network.serverpackets.VersionCheck;
  2090.  
  2091. +import hwid.hwid;
  2092. +
  2093.  public final class SendProtocolVersion extends L2GameClientPacket
  2094.  {
  2095.     private int _version;
  2096. +   private byte _data[];
  2097. +   private String _hwidHdd = "NoHWID-HD";
  2098. +   private String _hwidMac = "NoHWID-MAC";
  2099. +   private String _hwidCPU = "NoHWID-CPU";
  2100.    
  2101.     @Override
  2102.     protected void readImpl()
  2103.     {
  2104.         _version = readD();
  2105. +       if (hwid.isProtectionOn())
  2106. +       {
  2107. +           if (_buf.remaining() > 260)
  2108. +           {
  2109. +               _data = new byte[260];
  2110. +               readB(_data);
  2111. +               _hwidHdd = readS();
  2112. +               _hwidMac = readS();
  2113. +               _hwidCPU = readS();
  2114. +           }
  2115. +          
  2116. +           if (_hwidHdd.equals("NoHWID-HD") && _hwidMac.equals("NoHWID-MAC") && _hwidCPU.equals("NoHWID-CPU"))
  2117. +           {
  2118. +               hwid.nopath(getClient());
  2119. +               getClient().close((L2GameServerPacket) null);
  2120. +           }
  2121. +       }
  2122.     }
  2123.    
  2124.     @Override
  2125.     protected void runImpl()
  2126.     {
  2127. +       if (hwid.isProtectionOn())
  2128. +       {
  2129. +           switch (Config.GET_CLIENT_HWID)
  2130. +           {
  2131. +               case 1:
  2132. +                   getClient().setHWID(_hwidHdd);
  2133. +                   break;
  2134. +               case 2:
  2135. +                   getClient().setHWID(_hwidMac);
  2136. +                   break;
  2137. +               case 3:
  2138. +                   getClient().setHWID(_hwidCPU);
  2139. +                   break;
  2140. +           }
  2141. +       }
  2142. +      
  2143.         switch (_version)
  2144.         {
  2145.             case 737:
  2146. #P aCis_datapack
  2147. Index: data/xml/adminCommands.xml
  2148. ===================================================================
  2149. --- data/xml/adminCommands.xml  (revision 15)
  2150. +++ data/xml/adminCommands.xml  (working copy)
  2151. @@ -166,4 +166,7 @@
  2152.  
  2153.     <!-- ZONE -->
  2154.     <aCar name="admin_zone" accessLevel="7" params="[show - all|clear|id]" desc="Show the zone panel, or the zone visually."/>
  2155. +  
  2156. +   <!-- HWID -->
  2157. +   <aCar name="admin_hwid_ban" accessLevel="7" params="" desc=""/>
  2158.  </list>
  2159. \ No newline at end of file
  2160. Index: tools/database_installer.sh
  2161. ===================================================================
  2162. --- tools/database_installer.sh (revision 15)
  2163. +++ tools/database_installer.sh (working copy)
  2164. @@ -121,6 +121,8 @@
  2165.  $MYG < ../sql/grandboss_list.sql &> /dev/null
  2166.  $MYG < ../sql/heroes_diary.sql &> /dev/null
  2167.  $MYG < ../sql/heroes.sql &> /dev/null
  2168. +$MYG < ../sql/hwid_bans.sql &> /dev/null
  2169. +$MYG < ../sql/hwid_info.sql &> /dev/null
  2170.  $MYG < ../sql/items.sql &> /dev/null
  2171.  $MYG < ../sql/items_on_ground.sql &> /dev/null
  2172.  $MYG < ../sql/mdt_bets.sql &> /dev/null
  2173. Index: sql/hwid_info.sql
  2174. ===================================================================
  2175. --- sql/hwid_info.sql   (nonexistent)
  2176. +++ sql/hwid_info.sql   (working copy)
  2177. @@ -0,0 +1,7 @@
  2178. +CREATE TABLE IF NOT EXISTS `hwid_info` (
  2179. +  `HWID` varchar(32) NOT NULL DEFAULT '',
  2180. +  `Account` varchar(45) NOT NULL DEFAULT '',
  2181. +  `PlayerID` int(10) unsigned NOT NULL DEFAULT '0',
  2182. +  `LockType` enum('PLAYER_LOCK','ACCOUNT_LOCK','NONE') NOT NULL DEFAULT 'NONE',
  2183. +  PRIMARY KEY (`HWID`)
  2184. +) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  2185. \ No newline at end of file
  2186. Index: sql/hwid_bans.sql
  2187. ===================================================================
  2188. --- sql/hwid_bans.sql   (nonexistent)
  2189. +++ sql/hwid_bans.sql   (working copy)
  2190. @@ -0,0 +1,7 @@
  2191. +CREATE TABLE IF NOT EXISTS `hwid_bans` (
  2192. +  `HWID` varchar(32) DEFAULT NULL,
  2193. +  `HWIDSecond` varchar(32) DEFAULT NULL,
  2194. +  `expiretime` int(11) NOT NULL DEFAULT '0',
  2195. +  `comments` varchar(255) DEFAULT '',
  2196. +  UNIQUE KEY `HWID` (`HWID`)
  2197. +) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  2198. \ No newline at end of file
  2199. Index: tools/database_installer.bat
  2200. ===================================================================
  2201. --- tools/database_installer.bat    (revision 15)
  2202. +++ tools/database_installer.bat    (working copy)
  2203. @@ -101,6 +101,8 @@
  2204.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/grandboss_list.sql
  2205.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/heroes_diary.sql
  2206.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/heroes.sql
  2207. +%mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/hwid_bans.sql
  2208. +%mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/hwid_info.sql
  2209.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/items.sql
  2210.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/items_on_ground.sql
  2211.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/mdt_bets.sql
  2212. Index: tools/full_install.sql
  2213. ===================================================================
  2214. --- tools/full_install.sql  (revision 15)
  2215. +++ tools/full_install.sql  (working copy)
  2216. @@ -44,6 +44,8 @@
  2217.  DROP TABLE IF EXISTS grandboss_list;
  2218.  DROP TABLE IF EXISTS heroes_diary;
  2219.  DROP TABLE IF EXISTS heroes;
  2220. +DROP TABLE IF EXISTS hwid_bans;
  2221. +DROP TABLE IF EXISTS hwid_info;
  2222.  DROP TABLE IF EXISTS items;
  2223.  DROP TABLE IF EXISTS items_on_ground;
  2224.  DROP TABLE IF EXISTS mdt_bets;
  2225.  
Add Comment
Please, Sign In to add comment