Advertisement
BezneR

RUSaCis HWID Manager

Jul 24th, 2021 (edited)
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 87.76 KB | None | 0 0
  1. diff --git a/aCis_datapack/data/xml/adminCommands.xml b/aCis_datapack/data/xml/adminCommands.xml
  2. index 833d64e53552002c1736307add438de01552f679..ec7bb827aedabb1e82b28e7c3e244fc19a41c22e 100644
  3. --- a/aCis_datapack/data/xml/adminCommands.xml
  4. +++ b/aCis_datapack/data/xml/adminCommands.xml
  5. @@ -191,4 +191,7 @@
  6.  
  7.     <!-- ZONE -->
  8.     <aCar name="admin_zone" accessLevel="7" params="[show - all|clear|id]" desc="Show the zone panel, or the zone visually."/>
  9. +  
  10. +   <!-- HWID -->
  11. +   <aCar name="admin_hwid_ban" accessLevel="7" params="" desc=""/>
  12.  </list>
  13. \ No newline at end of file
  14. diff --git a/aCis_datapack/sql/hwid_bans.sql b/aCis_datapack/sql/hwid_bans.sql
  15. new file mode 100644
  16. index 0000000000000000000000000000000000000000..bf5808548c74fa21024ea6d828c7afdd9f0fd6ad
  17. --- /dev/null
  18. +++ b/aCis_datapack/sql/hwid_bans.sql
  19. @@ -0,0 +1,7 @@
  20. +CREATE TABLE IF NOT EXISTS `hwid_bans` (
  21. +  `HWID` varchar(32) DEFAULT NULL,
  22. +  `HWIDSecond` varchar(32) DEFAULT NULL,
  23. +  `expiretime` int(11) NOT NULL DEFAULT '0',
  24. +  `comments` varchar(255) DEFAULT '',
  25. +  UNIQUE KEY `HWID` (`HWID`)
  26. +) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  27. \ No newline at end of file
  28. diff --git a/aCis_datapack/sql/hwid_info.sql b/aCis_datapack/sql/hwid_info.sql
  29. new file mode 100644
  30. index 0000000000000000000000000000000000000000..d8eebfec659c2f67ee31b1dd1ce7bf700ed2d04b
  31. --- /dev/null
  32. +++ b/aCis_datapack/sql/hwid_info.sql
  33. @@ -0,0 +1,7 @@
  34. +CREATE TABLE IF NOT EXISTS `hwid_info` (
  35. +  `HWID` varchar(32) NOT NULL DEFAULT '',
  36. +  `Account` varchar(45) NOT NULL DEFAULT '',
  37. +  `PlayerID` int(10) unsigned NOT NULL DEFAULT '0',
  38. +  `LockType` enum('PLAYER_LOCK','ACCOUNT_LOCK','NONE') NOT NULL DEFAULT 'NONE',
  39. +  PRIMARY KEY (`HWID`)
  40. +) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  41. \ No newline at end of file
  42. diff --git a/aCis_datapack/tools/database_installer.bat b/aCis_datapack/tools/database_installer.bat
  43. index 53582a37c1db0a29f0c9f2aa5c3620148e931344..9ac044d551cf4ea446e8267fd168527880e6fd5b 100644
  44. --- a/aCis_datapack/tools/database_installer.bat
  45. +++ b/aCis_datapack/tools/database_installer.bat
  46. @@ -105,6 +105,8 @@ echo Installing empty character-related tables.
  47.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/grandboss_list.sql
  48.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/heroes_diary.sql
  49.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/heroes.sql
  50. +%mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/hwid_bans.sql
  51. +%mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/hwid_info.sql
  52.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/items.sql
  53.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/items_on_ground.sql
  54.  %mysqlPath% -h %gshost% -u %gsuser% --password=%gspass% -D %gsdb% < ../sql/mdt_bets.sql
  55. diff --git a/aCis_datapack/tools/database_installer.sh b/aCis_datapack/tools/database_installer.sh
  56. index 216b33983639b86696f03acae0d1a798dcac11a7..b8d3f81d5ab42d6fa1fff99d546936646923017d 100644
  57. --- a/aCis_datapack/tools/database_installer.sh
  58. +++ b/aCis_datapack/tools/database_installer.sh
  59. @@ -125,6 +125,8 @@ $MYG < ../sql/grandboss_data.sql &> /dev/null
  60.  $MYG < ../sql/grandboss_list.sql &> /dev/null
  61.  $MYG < ../sql/heroes_diary.sql &> /dev/null
  62.  $MYG < ../sql/heroes.sql &> /dev/null
  63. +$MYG < ../sql/hwid_bans.sql &> /dev/null
  64. +$MYG < ../sql/hwid_info.sql &> /dev/null
  65.  $MYG < ../sql/items.sql &> /dev/null
  66.  $MYG < ../sql/items_on_ground.sql &> /dev/null
  67.  $MYG < ../sql/mdt_bets.sql &> /dev/null
  68. diff --git a/aCis_datapack/tools/full_install.sql b/aCis_datapack/tools/full_install.sql
  69. index 6ce24b8fc9c0f507c9ddf686b3fdff33c055e16f..f676ec989aa962a0da507384e931fe21db111e02 100644
  70. --- a/aCis_datapack/tools/full_install.sql
  71. +++ b/aCis_datapack/tools/full_install.sql
  72. @@ -50,6 +50,8 @@ DROP TABLE IF EXISTS games;
  73.  DROP TABLE IF EXISTS grandboss_list;
  74.  DROP TABLE IF EXISTS heroes_diary;
  75.  DROP TABLE IF EXISTS heroes;
  76. +DROP TABLE IF EXISTS hwid_bans;
  77. +DROP TABLE IF EXISTS hwid_info;
  78.  DROP TABLE IF EXISTS items;
  79.  DROP TABLE IF EXISTS items_delayed;
  80.  DROP TABLE IF EXISTS items_on_ground;
  81. diff --git a/aCis_gameserver/build.xml b/aCis_gameserver/build.xml
  82. index 6f94e077b3412c85d69e81303a6105911c4ce8e6..6caf8766ce95c1dc7bf50188a49ead7b8ffbfe0e 100644
  83. --- a/aCis_gameserver/build.xml
  84. +++ b/aCis_gameserver/build.xml
  85. @@ -41,6 +41,7 @@
  86.         <fixcrlf srcdir="${build.dist.game}" eol="crlf" eof="remove" includes="**/*.bat" />
  87.         <fixcrlf srcdir="${build.dist.login}" eol="crlf" eof="remove" includes="**/*.bat" />
  88.         <mkdir dir="${build.dist.game}/log" />
  89. +       <mkdir dir="${build.dist.game}/log/hwid" />
  90.         <mkdir dir="${build.dist.login}/log" />
  91.         <mkdir dir="${build.dist.game}/config" />
  92.         <mkdir dir="${build.dist.login}/config" />
  93. diff --git a/aCis_gameserver/config/en/hwid.properties b/aCis_gameserver/config/en/hwid.properties
  94. new file mode 100644
  95. index 0000000000000000000000000000000000000000..9c1c7aab9f51db4a8558784af9a590d5ec016173
  96. --- /dev/null
  97. +++ b/aCis_gameserver/config/en/hwid.properties
  98. @@ -0,0 +1,28 @@
  99. +#=============================================================
  100. +#                    Hwid System Manager
  101. +#=============================================================
  102. +# Allow Guard Protection System
  103. +AllowGuardSystem = False
  104. +
  105. +# Installing client HWID
  106. +# 1 = HWID HDD
  107. +# 2 = HWID MAC
  108. +# 3 = HWID CPU
  109. +UseClientHWID = 2
  110. +KickWithEmptyHWID = True
  111. +KickWithLastErrorHWID = True
  112. +
  113. +# What is the criterion to prohibit the launch of multiple windows?
  114. +# IP - to IP, HWID - client on HWID
  115. +ClientWindowsCountSec = HWID
  116. +
  117. +# Configure the number of open windows client
  118. +# If 0 = Unlimited
  119. +AllowedWindowsCount = 2
  120. +
  121. +# Enable log on Console Server - Player, HWID, NAME, ID
  122. +EnableConsoleLog = True
  123. +EnableHWIDBans = True
  124. +EnableHWIDBonus = True
  125. +StoreHWID = True
  126. +LogHWIDs = True
  127. diff --git a/aCis_gameserver/config/hwid.properties b/aCis_gameserver/config/hwid.properties
  128. new file mode 100644
  129. index 0000000000000000000000000000000000000000..9c1c7aab9f51db4a8558784af9a590d5ec016173
  130. --- /dev/null
  131. +++ b/aCis_gameserver/config/hwid.properties
  132. @@ -0,0 +1,28 @@
  133. +#=============================================================
  134. +#                    Hwid System Manager
  135. +#=============================================================
  136. +# Allow Guard Protection System
  137. +AllowGuardSystem = False
  138. +
  139. +# Installing client HWID
  140. +# 1 = HWID HDD
  141. +# 2 = HWID MAC
  142. +# 3 = HWID CPU
  143. +UseClientHWID = 2
  144. +KickWithEmptyHWID = True
  145. +KickWithLastErrorHWID = True
  146. +
  147. +# What is the criterion to prohibit the launch of multiple windows?
  148. +# IP - to IP, HWID - client on HWID
  149. +ClientWindowsCountSec = HWID
  150. +
  151. +# Configure the number of open windows client
  152. +# If 0 = Unlimited
  153. +AllowedWindowsCount = 2
  154. +
  155. +# Enable log on Console Server - Player, HWID, NAME, ID
  156. +EnableConsoleLog = True
  157. +EnableHWIDBans = True
  158. +EnableHWIDBonus = True
  159. +StoreHWID = True
  160. +LogHWIDs = True
  161. diff --git a/aCis_gameserver/java/hwid/crypt/BlowfishEngine.java b/aCis_gameserver/java/hwid/crypt/BlowfishEngine.java
  162. new file mode 100644
  163. index 0000000000000000000000000000000000000000..3010a49e9c77e003fb0098676f481789fd12eba0
  164. --- /dev/null
  165. +++ b/aCis_gameserver/java/hwid/crypt/BlowfishEngine.java
  166. @@ -0,0 +1,172 @@
  167. +package hwid.crypt;
  168. +
  169. +import java.io.IOException;
  170. +
  171. +public class BlowfishEngine
  172. +{
  173. +    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 };
  174. +    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 };
  175. +    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 };
  176. +    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 };
  177. +    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 };
  178. +    private static final int ROUNDS = 16;
  179. +    private static final int BLOCK_SIZE = 8;
  180. +    private static final int SBOX_SK = 256;
  181. +    private static final int P_SZ = 18;
  182. +    private final int[] S0;
  183. +    private final int[] S1;
  184. +    private final int[] S2;
  185. +    private final int[] S3;
  186. +    private final int[] P;
  187. +    private boolean encrypting;
  188. +    private byte[] workingKey;
  189. +    
  190. +    public BlowfishEngine()
  191. +    {
  192. +        encrypting = false;
  193. +        workingKey = null;
  194. +        S0 = new int[SBOX_SK];
  195. +        S1 = new int[SBOX_SK];
  196. +        S2 = new int[SBOX_SK];
  197. +        S3 = new int[SBOX_SK];
  198. +        P = new int[P_SZ];
  199. +    }
  200. +    
  201. +    public void init(final boolean pEncrypting, final byte[] key)
  202. +    {
  203. +        encrypting = pEncrypting;
  204. +        setKey(workingKey = key);
  205. +    }
  206. +    
  207. +    public String getAlgorithmName()
  208. +    {
  209. +        return "Blowfish";
  210. +    }
  211. +    
  212. +    public final int processBlock(final byte[] in, final int inOff, final byte[] out, final int outOff) throws IOException
  213. +    {
  214. +        if (workingKey == null)
  215. +        {
  216. +            throw new IllegalStateException("Blowfish not initialised");
  217. +        }
  218. +        if (inOff + BLOCK_SIZE > in.length)
  219. +        {
  220. +            throw new IOException("input buffer too short");
  221. +        }
  222. +        if (outOff + BLOCK_SIZE > out.length)
  223. +        {
  224. +            throw new IOException("output buffer too short");
  225. +        }
  226. +        if (encrypting)
  227. +        {
  228. +            encryptBlock(in, inOff, out, outOff);
  229. +        }
  230. +        else
  231. +        {
  232. +            decryptBlock(in, inOff, out, outOff);
  233. +        }
  234. +        return BLOCK_SIZE;
  235. +    }
  236. +    
  237. +    public void reset() {}
  238. +    
  239. +    public int getBlockSize()
  240. +    {
  241. +        return BLOCK_SIZE;
  242. +    }
  243. +    
  244. +    private int F(final int x)
  245. +    {
  246. +        return (S0[x >>> 24] + S1[x >>> ROUNDS & 0xFF] ^ S2[x >>> BLOCK_SIZE & 0xFF]) + S3[x & 0xFF];
  247. +    }
  248. +    
  249. +    private void processTable(int xl, int xr, final int[] table)
  250. +    {
  251. +        for (int size = table.length, s = 0; s < size; s += 2)
  252. +        {
  253. +            xl ^= P[0];
  254. +            for (int i = 1; i < ROUNDS; i += 2)
  255. +            {
  256. +                xr ^= (F(xl) ^ P[i]);
  257. +                xl ^= (F(xr) ^ P[i + 1]);
  258. +            }
  259. +            xr ^= P[17];
  260. +            table[s] = xr;
  261. +            table[s + 1] = xl;
  262. +            xr = xl;
  263. +            xl = table[s];
  264. +        }
  265. +    }
  266. +    
  267. +    private void setKey(final byte[] key)
  268. +    {
  269. +        System.arraycopy(BlowfishEngine.KS0, 0, S0, 0, SBOX_SK);
  270. +        System.arraycopy(BlowfishEngine.KS1, 0, S1, 0, SBOX_SK);
  271. +        System.arraycopy(BlowfishEngine.KS2, 0, S2, 0, SBOX_SK);
  272. +        System.arraycopy(BlowfishEngine.KS3, 0, S3, 0, SBOX_SK);
  273. +        System.arraycopy(BlowfishEngine.KP, 0, P, 0, P_SZ);
  274. +        final int keyLength = key.length;
  275. +        int keyIndex = 0;
  276. +        for (int i = 0; i < P_SZ; ++i)
  277. +        {
  278. +            int data = 0;
  279. +            for (int j = 0; j < 4; ++j)
  280. +            {
  281. +                data = (data << BLOCK_SIZE | (key[keyIndex++] & 0xFF));
  282. +                if (keyIndex >= keyLength)
  283. +                    keyIndex = 0;
  284. +            }
  285. +            final int[] p = P;
  286. +            final int n = i;
  287. +            p[n] ^= data;
  288. +        }
  289. +        processTable(0, 0, P);
  290. +        processTable(P[ROUNDS], P[17], S0);
  291. +        processTable(S0[254], S0[255], S1);
  292. +        processTable(S1[254], S1[255], S2);
  293. +        processTable(S2[254], S2[255], S3);
  294. +    }
  295. +    
  296. +    public void encryptBlock(final byte[] src, final int srcIndex, final byte[] dst, final int dstIndex)
  297. +    {
  298. +        int xl = BytesTo32bits(src, srcIndex);
  299. +        int xr = BytesTo32bits(src, srcIndex + 4);
  300. +        xl ^= P[0];
  301. +        for (int i = 1; i < ROUNDS; i += 2)
  302. +        {
  303. +            xr ^= (F(xl) ^ P[i]);
  304. +            xl ^= (F(xr) ^ P[i + 1]);
  305. +        }
  306. +        xr ^= P[17];
  307. +        Bits32ToBytes(xr, dst, dstIndex);
  308. +        Bits32ToBytes(xl, dst, dstIndex + 4);
  309. +    }
  310. +    
  311. +    public void decryptBlock(final byte[] src, final int srcIndex, final byte[] dst, final int dstIndex)
  312. +    {
  313. +        int xl = BytesTo32bits(src, srcIndex);
  314. +        int xr = BytesTo32bits(src, srcIndex + 4);
  315. +        xl ^= P[17];
  316. +        for (int i = ROUNDS; i > 0; i -= 2)
  317. +        {
  318. +            xr ^= (F(xl) ^ P[i]);
  319. +            xl ^= (F(xr) ^ P[i - 1]);
  320. +        }
  321. +        xr ^= P[0];
  322. +        Bits32ToBytes(xr, dst, dstIndex);
  323. +        Bits32ToBytes(xl, dst, dstIndex + 4);
  324. +    }
  325. +    
  326. +    private static int BytesTo32bits(final byte[] b, final int i)
  327. +    {
  328. +        return (b[i + 3] & 0xFF) << 24 | (b[i + 2] & 0xFF) << ROUNDS | (b[i + 1] & 0xFF) << BLOCK_SIZE | (b[i] & 0xFF);
  329. +    }
  330. +    
  331. +    private static void Bits32ToBytes(final int in, final byte[] b, final int offset)
  332. +    {
  333. +        b[offset] = (byte)in;
  334. +        b[offset + 1] = (byte)(in >> BLOCK_SIZE);
  335. +        b[offset + 2] = (byte)(in >> ROUNDS);
  336. +        b[offset + 3] = (byte)(in >> 24);
  337. +    }
  338. +}
  339. \ No newline at end of file
  340. diff --git a/aCis_gameserver/java/hwid/crypt/FirstKey.java b/aCis_gameserver/java/hwid/crypt/FirstKey.java
  341. new file mode 100644
  342. index 0000000000000000000000000000000000000000..80da89163a4f9b4c7c27624cabe7ddb4fe14c5c3
  343. --- /dev/null
  344. +++ b/aCis_gameserver/java/hwid/crypt/FirstKey.java
  345. @@ -0,0 +1,29 @@
  346. +package hwid.crypt;
  347. +
  348. +import net.sf.l2j.commons.logging.CLogger;
  349. +
  350. +import net.sf.l2j.Config;
  351. +
  352. +public class FirstKey
  353. +{
  354. +    protected static CLogger LOGGER = new CLogger(FirstKey.class.getName());
  355. +    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 };
  356. +    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 };
  357. +    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 };
  358. +    
  359. +    public static byte[] expandKey(final byte[] key, final int size)
  360. +    {
  361. +        final byte[] P = new byte[64];
  362. +        for (int i = 0; i < 64; ++i)
  363. +        {
  364. +            P[i] = key[i % size];
  365. +        }
  366. +        for (int i = 0; i < 256; ++i)
  367. +        {
  368. +            final byte t = P[i % 64];
  369. +            final byte m = (byte)((MGBOX[MGBOX[t & 0xFF] & 0xFF] & 0xFF) ^ (TKBOX[TKBOX[i] & 0xFF] & 0xFF));
  370. +            P[i % 64] = TKBOX[m & 0xFF];
  371. +        }
  372. +        return P;
  373. +    }
  374. +}
  375. diff --git a/aCis_gameserver/java/hwid/crypt/GameCrypt.java b/aCis_gameserver/java/hwid/crypt/GameCrypt.java
  376. new file mode 100644
  377. index 0000000000000000000000000000000000000000..11ef8215a39e52d5ff372e2fe4f89b54f97730bb
  378. --- /dev/null
  379. +++ b/aCis_gameserver/java/hwid/crypt/GameCrypt.java
  380. @@ -0,0 +1,55 @@
  381. +package hwid.crypt;
  382. +
  383. +import net.sf.l2j.Config;
  384. +
  385. +import hwid.crypt.impl.L2Client;
  386. +import hwid.crypt.impl.L2Server;
  387. +import hwid.crypt.impl.VMPC;
  388. +
  389. +public class GameCrypt
  390. +{
  391. +    private ProtectionCrypt _client;
  392. +    private ProtectionCrypt _server;
  393. +    private boolean _isEnabled;
  394. +    private boolean _isProtected;
  395. +    
  396. +    public GameCrypt()
  397. +    {
  398. +        _isEnabled = false;
  399. +        _isProtected = false;
  400. +    }
  401. +    
  402. +    public void setProtected(final boolean state)
  403. +    {
  404. +        _isProtected = state;
  405. +    }
  406. +    
  407. +    public void setKey(final byte[] key)
  408. +    {
  409. +        if (_isProtected)
  410. +        {
  411. +            (_client = new VMPC()).setup(key, Config.GUARD_CLIENT_CRYPT);
  412. +            (_server = new L2Server()).setup(key, null);
  413. +            (_server = new VMPC()).setup(key, Config.GUARD_SERVER_CRYPT);
  414. +        }
  415. +        else
  416. +        {
  417. +            (_client = new L2Client()).setup(key, null);
  418. +            (_server = new L2Server()).setup(key, null);
  419. +        }
  420. +    }
  421. +    
  422. +    public void decrypt(final byte[] raw, final int offset, final int size)
  423. +    {
  424. +        if (_isEnabled)
  425. +            _client.crypt(raw, offset, size);
  426. +    }
  427. +    
  428. +    public void encrypt(final byte[] raw, final int offset, final int size)
  429. +    {
  430. +        if (_isEnabled)
  431. +            _server.crypt(raw, offset, size);
  432. +        else
  433. +            _isEnabled = true;
  434. +    }
  435. +}
  436. \ No newline at end of file
  437. diff --git a/aCis_gameserver/java/hwid/crypt/Manager.java b/aCis_gameserver/java/hwid/crypt/Manager.java
  438. new file mode 100644
  439. index 0000000000000000000000000000000000000000..86240080a68be5a3dd0872c1892a733a0ee8e411
  440. --- /dev/null
  441. +++ b/aCis_gameserver/java/hwid/crypt/Manager.java
  442. @@ -0,0 +1,78 @@
  443. +package hwid.crypt;
  444. +
  445. +import java.util.concurrent.ConcurrentHashMap;
  446. +import java.util.concurrent.ScheduledFuture;
  447. +
  448. +import net.sf.l2j.commons.logging.CLogger;
  449. +
  450. +import net.sf.l2j.Config;
  451. +import net.sf.l2j.gameserver.network.GameClient;
  452. +
  453. +import hwid.hwidmanager.hwidPlayer;
  454. +
  455. +public final class Manager
  456. +{
  457. +    protected static CLogger LOGGER = new CLogger(Manager.class.getName());
  458. +    protected static String _logFile = "Manager";
  459. +    protected static String _logMainFile = "hwid_logs";
  460. +    protected static Manager INSTANCE;
  461. +    protected static ScheduledFuture<?> _GGTask = null;
  462. +    protected static ConcurrentHashMap<String, InfoSet> _objects = new ConcurrentHashMap<>();
  463. +    
  464. +    public static Manager getInstance()
  465. +    {
  466. +        if (INSTANCE == null)
  467. +        {
  468. +            LOGGER.info("Loaded HWID KEY RUSaCis Project");
  469. +            LOGGER.info("Loaded HWID IP " + Config.GAMESERVER_HOSTNAME);
  470. +            LOGGER.info("Loaded Anti Leech key...assigned ");
  471. +            LOGGER.info("Loaded Restriction Leech...assigned ");
  472. +            LOGGER.info("Loaded Licensed to Max Players : " + Config.MAXIMUM_ONLINE_USERS);
  473. +            INSTANCE = new Manager();
  474. +        }
  475. +        return INSTANCE;
  476. +    }
  477. +    
  478. +    public void addPlayer(final GameClient client)
  479. +    {
  480. +       hwidPlayer.updateHWIDInfo(client);
  481. +        _objects.put(client.getPlayerName(), new InfoSet(client.getPlayerName(), client.getHWID()));
  482. +    }
  483. +    
  484. +    public static void removePlayer(final String name)
  485. +    {
  486. +        if (_objects.containsKey(name))
  487. +            _objects.remove(name);
  488. +    }
  489. +    
  490. +    public static int getCountByHWID(final String HWID)
  491. +    {
  492. +        int result = 0;
  493. +        for (final InfoSet object : _objects.values())
  494. +        {
  495. +            if (object._hwid.equals(HWID))
  496. +                ++result;
  497. +        }
  498. +        return result;
  499. +    }
  500. +    
  501. +    public class InfoSet
  502. +    {
  503. +        public String _playerName;
  504. +        public long _lastGGSendTime;
  505. +        public long _lastGGRecvTime;
  506. +        public int _attempts;
  507. +        public String _hwid;
  508. +        
  509. +        public InfoSet(final String name, final String HWID)
  510. +        {
  511. +            _playerName = "";
  512. +            _hwid = "";
  513. +            _playerName = name;
  514. +            _lastGGSendTime = System.currentTimeMillis();
  515. +            _lastGGRecvTime = _lastGGSendTime;
  516. +            _attempts = 0;
  517. +            _hwid = HWID;
  518. +        }
  519. +    }
  520. +}
  521. \ No newline at end of file
  522. diff --git a/aCis_gameserver/java/hwid/crypt/ProtectionCrypt.java b/aCis_gameserver/java/hwid/crypt/ProtectionCrypt.java
  523. new file mode 100644
  524. index 0000000000000000000000000000000000000000..1bfcecf28d43a279cd9759ac38aaf8a8cc7928d4
  525. --- /dev/null
  526. +++ b/aCis_gameserver/java/hwid/crypt/ProtectionCrypt.java
  527. @@ -0,0 +1,8 @@
  528. +package hwid.crypt;
  529. +
  530. +public interface ProtectionCrypt
  531. +{
  532. +    void setup(final byte[] p0, final byte[] p1);
  533. +    
  534. +    void crypt(final byte[] p0, final int p1, final int p2);
  535. +}
  536. diff --git a/aCis_gameserver/java/hwid/crypt/ProtectionPackets.java b/aCis_gameserver/java/hwid/crypt/ProtectionPackets.java
  537. new file mode 100644
  538. index 0000000000000000000000000000000000000000..41cc1e30d3e74a4426b2dabb48ec7bc6afce6610
  539. --- /dev/null
  540. +++ b/aCis_gameserver/java/hwid/crypt/ProtectionPackets.java
  541. @@ -0,0 +1,49 @@
  542. +package hwid.crypt;
  543. +
  544. +import net.sf.l2j.commons.random.Rnd;
  545. +
  546. +public class ProtectionPackets
  547. +{
  548. +    public static int readB(final byte[] raw, int offset, final byte[] data, final int size)
  549. +    {
  550. +        for (int i = 0; i < size; ++i)
  551. +        {
  552. +            data[i] = (byte)(raw[offset] ^ raw[0]);
  553. +            offset += (raw[offset + 1] & 0xFF);
  554. +        }
  555. +        return offset;
  556. +    }
  557. +    
  558. +    public static int readS(final byte[] raw, int offset, final byte[] data, final int size)
  559. +    {
  560. +        for (int i = 0; i < size; ++i)
  561. +        {
  562. +            data[i] = (byte)(raw[offset] ^ raw[0]);
  563. +            offset += (raw[offset + 1] & 0xFF);
  564. +            if (data[i] == 0)
  565. +                break;
  566. +        }
  567. +        return offset;
  568. +    }
  569. +    
  570. +    public static int writeB(final byte[] raw, int offset, final byte[] data, final int size)
  571. +    {
  572. +        for (int i = 0; i < size; ++i)
  573. +        {
  574. +            raw[offset] = (byte)(data[i] ^ raw[0]);
  575. +            raw[offset + 1] = (byte)(2 + Rnd.nextInt(10));
  576. +            offset += (raw[offset + 1] & 0xFF);
  577. +        }
  578. +        return offset;
  579. +    }
  580. +    
  581. +    public static byte ck(final byte[] raw, final int offset, final int size)
  582. +    {
  583. +        byte c = -1;
  584. +        for (int i = 0; i < size; ++i)
  585. +        {
  586. +            c ^= raw[offset + i];
  587. +        }
  588. +        return c;
  589. +    }
  590. +}
  591. \ No newline at end of file
  592. diff --git a/aCis_gameserver/java/hwid/crypt/impl/L2Client.java b/aCis_gameserver/java/hwid/crypt/impl/L2Client.java
  593. new file mode 100644
  594. index 0000000000000000000000000000000000000000..8c6b55c26fa837e7a340795716c17bedef945009
  595. --- /dev/null
  596. +++ b/aCis_gameserver/java/hwid/crypt/impl/L2Client.java
  597. @@ -0,0 +1,50 @@
  598. +package hwid.crypt.impl;
  599. +
  600. +import hwid.crypt.ProtectionCrypt;
  601. +
  602. +public class L2Client implements ProtectionCrypt
  603. +{
  604. +    private ProtectionCrypt _client;
  605. +    private byte[] _key;
  606. +    private byte[] _iv;
  607. +    
  608. +    public L2Client()
  609. +    {
  610. +        _key = new byte[16];
  611. +        _iv = null;
  612. +    }
  613. +    
  614. +    @Override
  615. +    public void setup(final byte[] key, final byte[] iv)
  616. +    {
  617. +        System.arraycopy(key, 0, _key, 0, 16);
  618. +        _iv = iv;
  619. +    }
  620. +    
  621. +    @Override
  622. +    public void crypt(final byte[] raw, final int offset, final int size)
  623. +    {
  624. +        if (_iv != null)
  625. +        {
  626. +            (_client = new VMPC()).setup(_key, _iv);
  627. +            _client.crypt(raw, offset, size);
  628. +        }
  629. +        int temp = 0;
  630. +        int temp2 = 0;
  631. +        for (int i = 0; i < size; ++i)
  632. +        {
  633. +            temp2 = (raw[offset + i] & 0xFF);
  634. +            raw[offset + i] = (byte)(temp2 ^ _key[i & 0xF] ^ temp);
  635. +            temp = temp2;
  636. +        }
  637. +        int old = _key[8] & 0xFF;
  638. +        old |= (_key[9] << 8 & 0xFF00);
  639. +        old |= (_key[10] << 16 & 0xFF0000);
  640. +        old |= (_key[11] << 24 & 0xFF000000);
  641. +        old += size;
  642. +        _key[8] = (byte)(old & 0xFF);
  643. +        _key[9] = (byte)(old >> 8 & 0xFF);
  644. +        _key[10] = (byte)(old >> 16 & 0xFF);
  645. +        _key[11] = (byte)(old >> 24 & 0xFF);
  646. +    }
  647. +}
  648. \ No newline at end of file
  649. diff --git a/aCis_gameserver/java/hwid/crypt/impl/L2Server.java b/aCis_gameserver/java/hwid/crypt/impl/L2Server.java
  650. new file mode 100644
  651. index 0000000000000000000000000000000000000000..a8aecb79a953dee93ca33798e100c5606d210445
  652. --- /dev/null
  653. +++ b/aCis_gameserver/java/hwid/crypt/impl/L2Server.java
  654. @@ -0,0 +1,49 @@
  655. +package hwid.crypt.impl;
  656. +
  657. +import hwid.crypt.ProtectionCrypt;
  658. +
  659. +public class L2Server implements ProtectionCrypt
  660. +{
  661. +    private byte[] _key;
  662. +    private byte[] _iv;
  663. +    private ProtectionCrypt _server;
  664. +    
  665. +    public L2Server()
  666. +    {
  667. +        _key = new byte[16];
  668. +        _iv = null;
  669. +    }
  670. +    
  671. +    @Override
  672. +    public void setup(final byte[] key, final byte[] iv)
  673. +    {
  674. +        System.arraycopy(key, 0, _key, 0, 16);
  675. +        _iv = iv;
  676. +    }
  677. +    
  678. +    @Override
  679. +    public void crypt(final byte[] raw, final int offset, final int size)
  680. +    {
  681. +        int temp = 0;
  682. +        for (int i = 0; i < size; ++i)
  683. +        {
  684. +            final int temp2 = raw[offset + i] & 0xFF;
  685. +            temp ^= (temp2 ^ _key[i & 0xF]);
  686. +            raw[offset + i] = (byte)temp;
  687. +        }
  688. +        int old = _key[8] & 0xFF;
  689. +        old |= (_key[9] << 8 & 0xFF00);
  690. +        old |= (_key[10] << 16 & 0xFF0000);
  691. +        old |= (_key[11] << 24 & 0xFF000000);
  692. +        old += size;
  693. +        _key[8] = (byte)(old & 0xFF);
  694. +        _key[9] = (byte)(old >> 8 & 0xFF);
  695. +        _key[10] = (byte)(old >> 16 & 0xFF);
  696. +        _key[11] = (byte)(old >> 24 & 0xFF);
  697. +        if (_iv != null)
  698. +        {
  699. +            (_server = new VMPC()).setup(_key, _iv);
  700. +            _server.crypt(raw, offset, size);
  701. +        }
  702. +    }
  703. +}
  704. \ No newline at end of file
  705. diff --git a/aCis_gameserver/java/hwid/crypt/impl/VMPC.java b/aCis_gameserver/java/hwid/crypt/impl/VMPC.java
  706. new file mode 100644
  707. index 0000000000000000000000000000000000000000..10b5eae92f1c93716ecb9506eb8c8e6fa0828693
  708. --- /dev/null
  709. +++ b/aCis_gameserver/java/hwid/crypt/impl/VMPC.java
  710. @@ -0,0 +1,64 @@
  711. +package hwid.crypt.impl;
  712. +
  713. +import hwid.crypt.ProtectionCrypt;
  714. +
  715. +public class VMPC implements ProtectionCrypt
  716. +{
  717. +    private byte _n;
  718. +    private byte[] _P;
  719. +    private byte _s;
  720. +    
  721. +    public VMPC()
  722. +    {
  723. +        _n = 0;
  724. +        _P = new byte[256];
  725. +        _s = 0;
  726. +    }
  727. +    
  728. +    @Override
  729. +    public void setup(final byte[] key, final byte[] iv)
  730. +    {
  731. +        _s = 0;
  732. +        for (int i = 0; i < 256; ++i)
  733. +        {
  734. +            _P[i] = (byte)(i & 0xFF);
  735. +        }
  736. +        for (int m = 0; m < 768; ++m)
  737. +        {
  738. +            _s = _P[_s + _P[m & 0xFF] + key[m % 64] & 0xFF];
  739. +            final byte temp = _P[m & 0xFF];
  740. +            _P[m & 0xFF] = _P[_s & 0xFF];
  741. +            _P[_s & 0xFF] = temp;
  742. +        }
  743. +        for (int m = 0; m < 768; ++m)
  744. +        {
  745. +            _s = _P[_s + _P[m & 0xFF] + iv[m % 64] & 0xFF];
  746. +            final byte temp = _P[m & 0xFF];
  747. +            _P[m & 0xFF] = _P[_s & 0xFF];
  748. +            _P[_s & 0xFF] = temp;
  749. +        }
  750. +        for (int m = 0; m < 768; ++m)
  751. +        {
  752. +            _s = _P[_s + _P[m & 0xFF] + key[m % 64] & 0xFF];
  753. +            final byte temp = _P[m & 0xFF];
  754. +            _P[m & 0xFF] = _P[_s & 0xFF];
  755. +            _P[_s & 0xFF] = temp;
  756. +        }
  757. +        _n = 0;
  758. +    }
  759. +    
  760. +    @Override
  761. +    public void crypt(final byte[] raw, final int offset, final int size)
  762. +    {
  763. +        for (int i = 0; i < size; ++i)
  764. +        {
  765. +            _s = _P[_s + _P[_n & 0xFF] & 0xFF];
  766. +            final byte z = _P[_P[_P[_s & 0xFF] & 0xFF] + 1 & 0xFF];
  767. +            final byte temp = _P[_n & 0xFF];
  768. +            _P[_n & 0xFF] = _P[_s & 0xFF];
  769. +            _P[_s & 0xFF] = temp;
  770. +            _n = (byte)(_n + 1 & 0xFF);
  771. +            raw[offset + i] ^= z;
  772. +        }
  773. +    }
  774. +}
  775. \ No newline at end of file
  776. diff --git a/aCis_gameserver/java/hwid/hwid.java b/aCis_gameserver/java/hwid/hwid.java
  777. new file mode 100644
  778. index 0000000000000000000000000000000000000000..d8e3803a5e3f0b4b7719b694a8adc453dbc4e1f4
  779. --- /dev/null
  780. +++ b/aCis_gameserver/java/hwid/hwid.java
  781. @@ -0,0 +1,268 @@
  782. +package hwid;
  783. +
  784. +import java.io.IOException;
  785. +import java.nio.ByteBuffer;
  786. +import java.util.concurrent.ConcurrentHashMap;
  787. +
  788. +import net.sf.l2j.commons.logging.CLogger;
  789. +
  790. +import net.sf.l2j.Config;
  791. +import net.sf.l2j.gameserver.model.World;
  792. +import net.sf.l2j.gameserver.model.actor.Player;
  793. +import net.sf.l2j.gameserver.network.GameClient;
  794. +import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
  795. +
  796. +import hwid.crypt.BlowfishEngine;
  797. +import hwid.crypt.FirstKey;
  798. +import hwid.crypt.Manager;
  799. +import hwid.hwidmanager.hwidBan;
  800. +import hwid.hwidmanager.hwidPlayer;
  801. +import hwid.hwidmanager.hwidManager;
  802. +import hwid.utils.HwidLog;
  803. +import hwid.utils.Util;
  804. +
  805. +public class hwid
  806. +{
  807. +    protected static CLogger LOGGER = new CLogger(hwid.class.getName());
  808. +    private static byte[] _key = new byte[16];
  809. +    static byte version = 11;
  810. +    protected static ConcurrentHashMap<String, Manager.InfoSet> _objects = new ConcurrentHashMap<>();
  811. +    
  812. +    public static void Init()
  813. +    {
  814. +        if (isProtectionOn())
  815. +        {
  816. +            hwidBan.getInstance();
  817. +            hwidPlayer.getInstance();
  818. +            Manager.getInstance();
  819. +            hwidManager.getInstance();
  820. +        }
  821. +    }
  822. +    
  823. +    public static boolean isProtectionOn()
  824. +    {
  825. +        return Config.ALLOW_GUARD_SYSTEM;
  826. +    }
  827. +    
  828. +    public static byte[] getKey(final byte[] key)
  829. +    {
  830. +        final byte[] bfkey = FirstKey.SKBOX;
  831. +        try
  832. +        {
  833. +            final BlowfishEngine bf = new BlowfishEngine();
  834. +            bf.init(true, bfkey);
  835. +            bf.processBlock(key, 0, _key, 0);
  836. +            bf.processBlock(key, 8, _key, 8);
  837. +        }
  838. +        catch (IOException e)
  839. +        {
  840. +            LOGGER.warn("HWID: Bad key!!!");
  841. +        }
  842. +        return _key;
  843. +    }
  844. +    
  845. +    public static void addPlayer(final GameClient client)
  846. +    {
  847. +        if (isProtectionOn() && client != null)
  848. +            Manager.getInstance().addPlayer(client);
  849. +    }
  850. +    
  851. +    public static void removePlayer(final GameClient client)
  852. +    {
  853. +        if (isProtectionOn() && client != null)
  854. +            Manager.removePlayer(client.getPlayerName());
  855. +    }
  856. +    
  857. +    public static boolean checkVerfiFlag(final GameClient client, final int flag)
  858. +    {
  859. +        boolean result = true;
  860. +        final int fl = Integer.reverseBytes(flag);
  861. +        if (fl == -1)
  862. +        {
  863. +            return false;
  864. +        }
  865. +        if (fl == 1342177280)
  866. +        {
  867. +            return false;
  868. +        }
  869. +        if ((fl & 0x1) != 0x0)
  870. +        {
  871. +            result = false;
  872. +        }
  873. +        if ((fl & 0x10) != 0x0)
  874. +        {
  875. +            result = false;
  876. +        }
  877. +        if ((fl & 0x10000000) != 0x0)
  878. +        {
  879. +            result = false;
  880. +        }
  881. +        return result;
  882. +    }
  883. +    
  884. +    public static int dumpData(final int _id, int position, final GameClient pi)
  885. +    {
  886. +        int value = 0;
  887. +        position = ((position > 4) ? 5 : position);
  888. +        boolean isIdZero = false;
  889. +        if (_id == 0)
  890. +        {
  891. +            isIdZero = true;
  892. +        }
  893. +        switch (position)
  894. +        {
  895. +            case 0:
  896. +            {
  897. +                if (_id != 1435233386)
  898. +                {
  899. +                    if (!isIdZero) {}
  900. +                    value = 1;
  901. +                    break;
  902. +                }
  903. +                break;
  904. +            }
  905. +            case 1:
  906. +            {
  907. +                if (_id != 16)
  908. +                {
  909. +                    if (!isIdZero) {}
  910. +                    value = 2;
  911. +                    break;
  912. +                }
  913. +                break;
  914. +            }
  915. +            case 2:
  916. +            case 3:
  917. +            case 4:
  918. +            {
  919. +                final int code = _id & 0xFF000000;
  920. +                if (code == 204) {}
  921. +                if (code == 233)
  922. +                {
  923. +                    value = 3;
  924. +                    break;
  925. +                }
  926. +                break;
  927. +            }
  928. +            default:
  929. +            {
  930. +                value = 0;
  931. +                break;
  932. +            }
  933. +        }
  934. +        return value;
  935. +    }
  936. +    
  937. +    public static int calcPenalty(final byte[] data, final GameClient pi)
  938. +    {
  939. +        int sum = -1;
  940. +        if (Util.verifyChecksum(data, 0, data.length))
  941. +        {
  942. +            final ByteBuffer buf = ByteBuffer.wrap(data, 0, data.length - 4);
  943. +            sum = 0;
  944. +            for (int lenPenalty = (data.length - 4) / 4, i = 0; i < lenPenalty; ++i)
  945. +            {
  946. +                sum += dumpData(buf.getInt(), i, pi);
  947. +            }
  948. +        }
  949. +        return sum;
  950. +    }
  951. +    
  952. +    public static boolean CheckHWIDs(final GameClient client, final int LastError1, final int LastError2)
  953. +    {
  954. +        boolean resultHWID = false;
  955. +        boolean resultLastError = false;
  956. +        final String HWID = client.getHWID();
  957. +        if (HWID.equalsIgnoreCase("fab888b1cc9de973c8046519fa841e6") && Config.PROTECT_KICK_WITH_EMPTY_HWID)
  958. +        {
  959. +            resultHWID = true;
  960. +        }
  961. +        if (LastError1 != 0 && Config.PROTECT_KICK_WITH_LASTERROR_HWID)
  962. +        {
  963. +            resultLastError = true;
  964. +        }
  965. +        return resultHWID || resultLastError;
  966. +    }
  967. +    
  968. +    public static String fillHex(final int data, final int digits)
  969. +    {
  970. +        String number = Integer.toHexString(data);
  971. +        for (int i = number.length(); i < digits; ++i)
  972. +        {
  973. +            number = "0" + number;
  974. +        }
  975. +        return number;
  976. +    }
  977. +    
  978. +    public static String ExtractHWID(final byte[] _data)
  979. +    {
  980. +        if (!Util.verifyChecksum(_data, 0, _data.length))
  981. +        {
  982. +            return null;
  983. +        }
  984. +        final StringBuilder resultHWID = new StringBuilder();
  985. +        for (int i = 0; i < _data.length - 8; ++i)
  986. +        {
  987. +            resultHWID.append(fillHex(_data[i] & 0xFF, 2));
  988. +        }
  989. +        return resultHWID.toString();
  990. +    }
  991. +    
  992. +    public static boolean doAuthLogin(final GameClient client, final byte[] data, final String loginName)
  993. +    {
  994. +        if (!isProtectionOn())
  995. +            return true;
  996. +
  997. +        client.setLoginName(loginName);
  998. +        final String fullHWID = ExtractHWID(data);
  999. +        if (fullHWID == null)
  1000. +        {
  1001. +            LOGGER.warn("AuthLogin CRC Check Fail! May be BOT or unprotected client! Client IP: " + client.toString());
  1002. +            client.close(ServerClose.STATIC_PACKET);
  1003. +            return false;
  1004. +        }
  1005. +        final int LastError1 = ByteBuffer.wrap(data, 16, 4).getInt();
  1006. +        if (CheckHWIDs(client, LastError1, 0))
  1007. +        {
  1008. +            LOGGER.warn("HWID error, look protection_logs.txt file, from IP: " + client.toString());
  1009. +            client.close(ServerClose.STATIC_PACKET);
  1010. +            return false;
  1011. +        }
  1012. +        if (hwidBan.getInstance().checkFullHWIDBanned(client))
  1013. +        {
  1014. +            LOGGER.warn("Client " + client + " is banned. Kicked! |HWID: " + client.getHWID() + " IP: " + client.toString());
  1015. +            client.close(ServerClose.STATIC_PACKET);
  1016. +        }
  1017. +        final int VerfiFlag = ByteBuffer.wrap(data, 40, 4).getInt();
  1018. +        return checkVerfiFlag(client, VerfiFlag);
  1019. +    }
  1020. +    
  1021. +    public static void doDisconection(final GameClient client)
  1022. +    {
  1023. +        removePlayer(client);
  1024. +    }
  1025. +    
  1026. +    public static boolean checkPlayerWithHWID(final GameClient client, final int playerID, final String playerName)
  1027. +    {
  1028. +        if (!isProtectionOn())
  1029. +            return true;
  1030. +
  1031. +        client.setPlayerName(playerName);
  1032. +        client.setPlayerId(playerID);
  1033. +        addPlayer(client);
  1034. +        return true;
  1035. +    }
  1036. +    
  1037. +    public static void nopath(final GameClient client)
  1038. +    {
  1039. +        LOGGER.warn("HWID: " + client.toString() + " is trying to loggin server without client side hwid.");
  1040. +        client.close(ServerClose.STATIC_PACKET);
  1041. +    }
  1042. +    
  1043. +    public static void enterlog(final Player player, final GameClient client)
  1044. +    {
  1045. +        hwidManager.getInstance().validBox(player, Config.PROTECT_WINDOWS_COUNT + 1, World.getInstance().getPlayers(), true);
  1046. +        LOGGER.info("HWID: [" + client.getHWID() + "], character: [" + player.getName() + "]");
  1047. +        HwidLog.auditGMAction(player.getHWid(), player.getName());
  1048. +    }
  1049. +}
  1050. \ No newline at end of file
  1051. diff --git a/aCis_gameserver/java/hwid/hwidmanager/hwidAdminBan.java b/aCis_gameserver/java/hwid/hwidmanager/hwidAdminBan.java
  1052. new file mode 100644
  1053. index 0000000000000000000000000000000000000000..9ff73004ab7d5fa4020a199cdafd29f12bbe91f2
  1054. --- /dev/null
  1055. +++ b/aCis_gameserver/java/hwid/hwidmanager/hwidAdminBan.java
  1056. @@ -0,0 +1,40 @@
  1057. +package hwid.hwidmanager;
  1058. +
  1059. +import net.sf.l2j.Config;
  1060. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  1061. +import net.sf.l2j.gameserver.model.WorldObject;
  1062. +import net.sf.l2j.gameserver.model.actor.Player;
  1063. +
  1064. +public class hwidAdminBan implements IAdminCommandHandler
  1065. +{
  1066. +   private static final String[] ADMIN_COMMANDS =
  1067. +   {
  1068. +       "admin_hwid_ban"
  1069. +   };
  1070. +
  1071. +   @Override
  1072. +   public void useAdminCommand(final String command, final Player player)
  1073. +    {
  1074. +        if (!Config.ALLOW_GUARD_SYSTEM || player == null)
  1075. +            return;
  1076. +      
  1077. +       if (command.startsWith("admin_hwid_ban"))
  1078. +        {
  1079. +            final WorldObject playerTarget = player.getTarget();
  1080. +            if (!(playerTarget instanceof Player))
  1081. +            {
  1082. +               player.sendMessage("Target is empty");
  1083. +                return;
  1084. +            }
  1085. +            final Player target = (Player)playerTarget;
  1086. +            hwidBan.addHWIDBan(target.getClient());
  1087. +            player.sendMessage(target.getName() + " banned in HWID");
  1088. +        }
  1089. +    }
  1090. +    
  1091. +   @Override
  1092. +   public String[] getAdminCommandList()
  1093. +   {
  1094. +       return ADMIN_COMMANDS;
  1095. +   }
  1096. +}
  1097. \ No newline at end of file
  1098. diff --git a/aCis_gameserver/java/hwid/hwidmanager/hwidBan.java b/aCis_gameserver/java/hwid/hwidmanager/hwidBan.java
  1099. new file mode 100644
  1100. index 0000000000000000000000000000000000000000..3ab0a8d81e778607e143f57f0a7c6a427a560164
  1101. --- /dev/null
  1102. +++ b/aCis_gameserver/java/hwid/hwidmanager/hwidBan.java
  1103. @@ -0,0 +1,98 @@
  1104. +package hwid.hwidmanager;
  1105. +
  1106. +import java.sql.Connection;
  1107. +import java.sql.PreparedStatement;
  1108. +import java.sql.ResultSet;
  1109. +import java.util.HashMap;
  1110. +import java.util.Map;
  1111. +
  1112. +import net.sf.l2j.commons.logging.CLogger;
  1113. +import net.sf.l2j.commons.pool.ConnectionPool;
  1114. +
  1115. +import net.sf.l2j.gameserver.network.GameClient;
  1116. +
  1117. +public class hwidBan
  1118. +{
  1119. +    protected static CLogger LOGGER = new CLogger(hwidBan.class.getName());
  1120. +    private static hwidBan INSTANCE;
  1121. +    private static Map<Integer, hwidBanList> _lists = new HashMap<>();
  1122. +    
  1123. +    public hwidBan()
  1124. +    {
  1125. +        load();
  1126. +        LOGGER.info("Loaded " + hwidBan._lists.size() + " banned(s) HWID(s)");
  1127. +    }
  1128. +    
  1129. +    public static hwidBan getInstance()
  1130. +    {
  1131. +        if (INSTANCE == null)
  1132. +           INSTANCE = new hwidBan();
  1133. +        return INSTANCE;
  1134. +    }
  1135. +    
  1136. +    private static void load()
  1137. +    {
  1138. +        String HWID = "";
  1139. +        int counterHWIDBan = 0;
  1140. +        try (Connection con = ConnectionPool.getConnection();
  1141. +           PreparedStatement statement = con.prepareStatement("SELECT * FROM hwid_bans");
  1142. +           ResultSet rset = statement.executeQuery())
  1143. +        {
  1144. +            while (rset.next())
  1145. +            {
  1146. +                HWID = rset.getString("HWID");
  1147. +                final hwidBanList hb = new hwidBanList(counterHWIDBan);
  1148. +                hb.setHWIDBan(HWID);
  1149. +                _lists.put(counterHWIDBan, hb);
  1150. +                ++counterHWIDBan;
  1151. +            }
  1152. +        }
  1153. +        catch (Exception e)
  1154. +        {
  1155. +            e.printStackTrace();
  1156. +        }
  1157. +    }
  1158. +    
  1159. +    public static void reload()
  1160. +    {
  1161. +       INSTANCE = new hwidBan();
  1162. +    }
  1163. +    
  1164. +    public boolean checkFullHWIDBanned(final GameClient client)
  1165. +    {
  1166. +        if (_lists.size() == 0)
  1167. +        {
  1168. +            return false;
  1169. +        }
  1170. +        for (int i = 0; i < _lists.size(); ++i)
  1171. +        {
  1172. +            if (_lists.get(i).getHWID().equals(client.getHWID()))
  1173. +                return true;
  1174. +        }
  1175. +        return false;
  1176. +    }
  1177. +    
  1178. +    public static int getCountHWIDBan()
  1179. +    {
  1180. +        return _lists.size();
  1181. +    }
  1182. +    
  1183. +    public static void addHWIDBan(final GameClient client)
  1184. +    {
  1185. +        final String HWID = client.getHWID();
  1186. +        final int counterHwidBan = _lists.size();
  1187. +        final hwidBanList hb = new hwidBanList(counterHwidBan);
  1188. +        hb.setHWIDBan(HWID);
  1189. +        _lists.put(counterHwidBan, hb);
  1190. +        try (Connection con = ConnectionPool.getConnection();
  1191. +           PreparedStatement statement = con.prepareStatement("INSERT INTO hwid_bans SET HWID=?"))
  1192. +        {
  1193. +            statement.setString(1, HWID);
  1194. +            statement.execute();
  1195. +        }
  1196. +        catch (Exception e)
  1197. +        {
  1198. +            e.printStackTrace();
  1199. +        }
  1200. +    }
  1201. +}
  1202. \ No newline at end of file
  1203. diff --git a/aCis_gameserver/java/hwid/hwidmanager/hwidBanList.java b/aCis_gameserver/java/hwid/hwidmanager/hwidBanList.java
  1204. new file mode 100644
  1205. index 0000000000000000000000000000000000000000..b6f579e81f0a91adc74c55a7864b4cea58d402c1
  1206. --- /dev/null
  1207. +++ b/aCis_gameserver/java/hwid/hwidmanager/hwidBanList.java
  1208. @@ -0,0 +1,27 @@
  1209. +package hwid.hwidmanager;
  1210. +
  1211. +public class hwidBanList
  1212. +{
  1213. +    private final int _id;
  1214. +    private String _hwid;
  1215. +    
  1216. +    public hwidBanList(final int id)
  1217. +    {
  1218. +        _id = id;
  1219. +    }
  1220. +    
  1221. +    public int getId()
  1222. +    {
  1223. +        return _id;
  1224. +    }
  1225. +    
  1226. +    public String getHWID()
  1227. +    {
  1228. +        return _hwid;
  1229. +    }
  1230. +    
  1231. +    public void setHWIDBan(final String hwid)
  1232. +    {
  1233. +       _hwid = hwid;
  1234. +    }
  1235. +}
  1236. diff --git a/aCis_gameserver/java/hwid/hwidmanager/hwidInfoClient.java b/aCis_gameserver/java/hwid/hwidmanager/hwidInfoClient.java
  1237. new file mode 100644
  1238. index 0000000000000000000000000000000000000000..4a6ea708fbb917d53eb4eb4405b02870bf18fba7
  1239. --- /dev/null
  1240. +++ b/aCis_gameserver/java/hwid/hwidmanager/hwidInfoClient.java
  1241. @@ -0,0 +1,69 @@
  1242. +package hwid.hwidmanager;
  1243. +
  1244. +public class hwidInfoClient
  1245. +{
  1246. +    private String _playerName;
  1247. +    private String _loginName;
  1248. +    private int _playerId;
  1249. +    private String _hwid;
  1250. +    private int _revision;
  1251. +    
  1252. +    public hwidInfoClient()
  1253. +    {
  1254. +        _playerName = "";
  1255. +        _loginName = "";
  1256. +        _playerId = 0;
  1257. +        _hwid = "";
  1258. +        _revision = 0;
  1259. +    }
  1260. +    
  1261. +    public final String getPlayerName()
  1262. +    {
  1263. +        return _playerName;
  1264. +    }
  1265. +    
  1266. +    public void setPlayerName(final String name)
  1267. +    {
  1268. +        _playerName = name;
  1269. +    }
  1270. +    
  1271. +    public void setPlayerId(final int plId)
  1272. +    {
  1273. +        _playerId = plId;
  1274. +    }
  1275. +    
  1276. +    public int getPlayerId()
  1277. +    {
  1278. +        return _playerId;
  1279. +    }
  1280. +    
  1281. +    public final String getHWID()
  1282. +    {
  1283. +        return _hwid;
  1284. +    }
  1285. +    
  1286. +    public void setHWID(final String hwid)
  1287. +    {
  1288. +        _hwid = hwid;
  1289. +    }
  1290. +    
  1291. +    public void setRevision(final int revision)
  1292. +    {
  1293. +        _revision = revision;
  1294. +    }
  1295. +    
  1296. +    public int getRevision()
  1297. +    {
  1298. +        return _revision;
  1299. +    }
  1300. +    
  1301. +    public final String getLoginName()
  1302. +    {
  1303. +        return _loginName;
  1304. +    }
  1305. +    
  1306. +    public void setLoginName(final String name)
  1307. +    {
  1308. +        _loginName = name;
  1309. +    }
  1310. +}
  1311. \ No newline at end of file
  1312. diff --git a/aCis_gameserver/java/hwid/hwidmanager/hwidInfoList.java b/aCis_gameserver/java/hwid/hwidmanager/hwidInfoList.java
  1313. new file mode 100644
  1314. index 0000000000000000000000000000000000000000..d1ac4ddf17c6e09f1bac360bf6391ddccaeea5e1
  1315. --- /dev/null
  1316. +++ b/aCis_gameserver/java/hwid/hwidmanager/hwidInfoList.java
  1317. @@ -0,0 +1,78 @@
  1318. +package hwid.hwidmanager;
  1319. +
  1320. +public class hwidInfoList
  1321. +{
  1322. +    private final int _id;
  1323. +    private String _hwid;
  1324. +    private int _count;
  1325. +    private int _playerID;
  1326. +    private String _login;
  1327. +    private LockType _lockType;
  1328. +    
  1329. +    public hwidInfoList(final int id)
  1330. +    {
  1331. +        _id = id;
  1332. +    }
  1333. +    
  1334. +    public int get_id()
  1335. +    {
  1336. +        return _id;
  1337. +    }
  1338. +    
  1339. +    public int getCount()
  1340. +    {
  1341. +        return _count;
  1342. +    }
  1343. +    
  1344. +    public void setCount(final int count)
  1345. +    {
  1346. +        _count = count;
  1347. +    }
  1348. +    
  1349. +    public int getPlayerID()
  1350. +    {
  1351. +        return _playerID;
  1352. +    }
  1353. +    
  1354. +    public void setPlayerID(final int playerID)
  1355. +    {
  1356. +        _playerID = playerID;
  1357. +    }
  1358. +    
  1359. +    public String getHWID()
  1360. +    {
  1361. +        return _hwid;
  1362. +    }
  1363. +    
  1364. +    public void setHWID(final String hwid)
  1365. +    {
  1366. +       _hwid = hwid;
  1367. +    }
  1368. +    
  1369. +    public String getLogin()
  1370. +    {
  1371. +        return _login;
  1372. +    }
  1373. +    
  1374. +    public void setLogin(final String login)
  1375. +    {
  1376. +        _login = login;
  1377. +    }
  1378. +    
  1379. +    public LockType getLockType()
  1380. +    {
  1381. +        return _lockType;
  1382. +    }
  1383. +    
  1384. +    public void setLockType(final LockType lockType)
  1385. +    {
  1386. +        _lockType = lockType;
  1387. +    }
  1388. +    
  1389. +    public enum LockType
  1390. +    {
  1391. +        PLAYER_LOCK,
  1392. +        ACCOUNT_LOCK,
  1393. +        NONE;
  1394. +    }
  1395. +}
  1396. \ No newline at end of file
  1397. diff --git a/aCis_gameserver/java/hwid/hwidmanager/hwidManager.java b/aCis_gameserver/java/hwid/hwidmanager/hwidManager.java
  1398. new file mode 100644
  1399. index 0000000000000000000000000000000000000000..589f90566c57b0d63ecd05de36de83f433a52bcb
  1400. --- /dev/null
  1401. +++ b/aCis_gameserver/java/hwid/hwidmanager/hwidManager.java
  1402. @@ -0,0 +1,117 @@
  1403. +package hwid.hwidmanager;
  1404. +
  1405. +import java.util.ArrayList;
  1406. +import java.util.Collection;
  1407. +import java.util.HashMap;
  1408. +import java.util.List;
  1409. +import java.util.Map;
  1410. +
  1411. +import net.sf.l2j.commons.logging.CLogger;
  1412. +
  1413. +import net.sf.l2j.Config;
  1414. +import net.sf.l2j.gameserver.model.actor.Player;
  1415. +import net.sf.l2j.gameserver.network.GameClient;
  1416. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  1417. +
  1418. +public class hwidManager
  1419. +{
  1420. +    private static final CLogger LOGGER = new CLogger(hwidManager.class.getName());
  1421. +    
  1422. +    public hwidManager()
  1423. +    {
  1424. +    }
  1425. +    
  1426. +    private static boolean multiboxKickTask(final Player activeChar, final Integer numberBox, final Collection<Player> world)
  1427. +    {
  1428. +        final Map<String, List<Player>> hwidMap = new HashMap<>();
  1429. +        for (final Player player : world)
  1430. +        {
  1431. +            if (player.getClient() != null)
  1432. +            {
  1433. +                if (player.getClient().isDetached())
  1434. +                    continue;
  1435. +
  1436. +                final String hwid = activeChar.getHWid();
  1437. +                final String playerHwid = player.getHWid();
  1438. +                if (!hwid.equals(playerHwid))
  1439. +                    continue;
  1440. +
  1441. +                if (hwidMap.get(hwid) == null)
  1442. +                    hwidMap.put(hwid, new ArrayList<Player>());
  1443. +
  1444. +                hwidMap.get(hwid).add(player);
  1445. +                if (hwidMap.get(hwid).size() >= numberBox)
  1446. +                    return true;
  1447. +
  1448. +                continue;
  1449. +            }
  1450. +        }
  1451. +        return false;
  1452. +    }
  1453. +    
  1454. +    public boolean validBox(final Player activeChar, final Integer numberBox, final Collection<Player> world, final Boolean forcedLogOut)
  1455. +    {
  1456. +        if (multiboxKickTask(activeChar, numberBox, world))
  1457. +        {
  1458. +            if (forcedLogOut)
  1459. +            {
  1460. +                final GameClient client = activeChar.getClient();
  1461. +                LOGGER.warn("Dualbox Protection: " + client.getHWID() + " was trying to use over " + numberBox + " clients!");
  1462. +                activeChar.sendMessage("SYS: You have exceeded the PC connection limit = " + Config.PROTECT_WINDOWS_COUNT + " box per PC.");
  1463. +                activeChar.sendMessage("SYS: You will be disconnected in 30 seconds.");
  1464. +                activeChar.setIsImmobilized(true);
  1465. +                activeChar.setInvul(true);
  1466. +                activeChar.disableAllSkills();
  1467. +                showChatWindow(activeChar, 0);
  1468. +                waitSecs(30);
  1469. +                activeChar.getClient().closeNow();
  1470. +            }
  1471. +            return true;
  1472. +        }
  1473. +        return false;
  1474. +    }
  1475. +    
  1476. +    public void showChatWindow(final Player player, final int val)
  1477. +    {
  1478. +        final NpcHtmlMessage msg = new NpcHtmlMessage(5);
  1479. +        msg.setHtml(ExcedLimit(player));
  1480. +        player.sendPacket(msg);
  1481. +    }
  1482. +    
  1483. +    private static String ExcedLimit(final Player player)
  1484. +    {
  1485. +        final StringBuilder tb = new StringBuilder();
  1486. +        tb.append("<html><body><center>");
  1487. +        tb.append("<img src=\"L2UI_CH3.herotower_deco\" width=256 height=32>HWID<font color=LEVEL> Dual Box </font>'- Manager");
  1488. +        tb.append("<br><table><tr><td height=7><img src=\"L2UI.SquareGray\" width=220 height=1></td></tr></table>");
  1489. +        tb.append("<img src=\"L2UI.SquareGray\" width=295 height=1><table width=295 border=0 bgcolor=000000><tr><td align=center>");
  1490. +        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>");
  1491. +        tb.append("<br><img src=\"l2ui.squarewhite\" width=\"150\" height=\"1\"><br>");
  1492. +        tb.append("<br></td></tr></table><img src=\"L2UI.SquareGray\" width=295 height=1>");
  1493. +        tb.append("<table><tr><td height=7><img src=\"L2UI.SquareGray\" width=220 height=1></td></tr></table><br>");
  1494. +        tb.append("<br><br><font color=333333>Respect the rules</font>");
  1495. +        return tb.toString();
  1496. +    }
  1497. +
  1498. +    public static void waitSecs(final int i)
  1499. +    {
  1500. +        try
  1501. +        {
  1502. +            Thread.sleep(i * 1000);
  1503. +        }
  1504. +        catch (InterruptedException ie)
  1505. +        {
  1506. +            ie.printStackTrace();
  1507. +        }
  1508. +    }
  1509. +    
  1510. +    public static final hwidManager getInstance()
  1511. +    {
  1512. +        return SingletonHolder.INSTANCE;
  1513. +    }
  1514. +    
  1515. +    private static class SingletonHolder
  1516. +    {
  1517. +        protected static final hwidManager INSTANCE = new hwidManager();
  1518. +    }
  1519. +}
  1520. \ No newline at end of file
  1521. diff --git a/aCis_gameserver/java/hwid/hwidmanager/hwidPlayer.java b/aCis_gameserver/java/hwid/hwidmanager/hwidPlayer.java
  1522. new file mode 100644
  1523. index 0000000000000000000000000000000000000000..dd14367b4620760145e6b2792d82fe17243e6835
  1524. --- /dev/null
  1525. +++ b/aCis_gameserver/java/hwid/hwidmanager/hwidPlayer.java
  1526. @@ -0,0 +1,199 @@
  1527. +package hwid.hwidmanager;
  1528. +
  1529. +import java.sql.Connection;
  1530. +import java.sql.PreparedStatement;
  1531. +import java.sql.ResultSet;
  1532. +import java.util.HashMap;
  1533. +import java.util.Map;
  1534. +
  1535. +import net.sf.l2j.commons.logging.CLogger;
  1536. +import net.sf.l2j.commons.pool.ConnectionPool;
  1537. +
  1538. +import net.sf.l2j.gameserver.network.GameClient;
  1539. +
  1540. +import hwid.hwidmanager.hwidInfoList.LockType;
  1541. +
  1542. +public class hwidPlayer
  1543. +{
  1544. +    protected static CLogger LOGGER = new CLogger(hwidPlayer.class.getName());
  1545. +    private static hwidPlayer INSTANCE;
  1546. +    private static Map<Integer, hwidInfoList> _list = new HashMap<>();
  1547. +    private static Map<Integer, Integer> _sessions = new HashMap<>();
  1548. +    
  1549. +    public hwidPlayer()
  1550. +    {    
  1551. +        load();
  1552. +        LOGGER.info("Loaded " + _list.size() + " player(s) HWID(s)");
  1553. +    }
  1554. +    
  1555. +    public static hwidPlayer getInstance()
  1556. +    {
  1557. +        if (INSTANCE == null)
  1558. +           INSTANCE = new hwidPlayer();
  1559. +        return INSTANCE;
  1560. +    }
  1561. +    
  1562. +    private static void load()
  1563. +    {
  1564. +        try (Connection con = ConnectionPool.getConnection();
  1565. +           PreparedStatement statement = con.prepareStatement("SELECT * FROM hwid_info");
  1566. +           ResultSet rset = statement.executeQuery())
  1567. +        {
  1568. +            int counterHWIDInfo = 0;
  1569. +            while (rset.next())
  1570. +            {
  1571. +                final hwidInfoList hInfo = new hwidInfoList(counterHWIDInfo);
  1572. +                hInfo.setHWID(rset.getString("HWID"));
  1573. +                hInfo.setLogin(rset.getString("Account"));
  1574. +                hInfo.setPlayerID(rset.getInt("PlayerID"));
  1575. +                hInfo.setLockType(LockType.valueOf(rset.getString("LockType")));
  1576. +                _list.put(counterHWIDInfo, hInfo);
  1577. +                ++counterHWIDInfo;
  1578. +            }
  1579. +        }
  1580. +        catch (Exception e)
  1581. +        {
  1582. +            e.printStackTrace();
  1583. +        }
  1584. +    }
  1585. +    
  1586. +    public static void reload()
  1587. +    {
  1588. +       INSTANCE = new hwidPlayer();
  1589. +    }
  1590. +    
  1591. +   public static int startSession(int WindowsCount)
  1592. +   {
  1593. +       synchronized (_list)
  1594. +       {
  1595. +           if (_sessions.get(WindowsCount) == null)
  1596. +               _sessions.put(WindowsCount, 0);
  1597. +           _sessions.put(WindowsCount, _sessions.get(WindowsCount) + 1);
  1598. +       }
  1599. +       return _sessions.get(WindowsCount);
  1600. +   }
  1601. +  
  1602. +   public static void updateHWIDInfo(GameClient client)
  1603. +   {
  1604. +       updateHWIDInfo(client, LockType.NONE);
  1605. +   }
  1606. +    
  1607. +    public static void updateHWIDInfo(final GameClient client, final LockType lockType)
  1608. +    {
  1609. +       int counterHwidInfo = _list.size();
  1610. +        boolean isFound = false;
  1611. +        for (int i = 0; i < _list.size(); ++i)
  1612. +        {
  1613. +            if (_list.get(i).getHWID().equals(client.getHWID()))
  1614. +            {
  1615. +               isFound = true;        
  1616. +               counterHwidInfo = i;
  1617. +                break;
  1618. +            }
  1619. +        }
  1620. +        final hwidInfoList hInfo = new hwidInfoList(counterHwidInfo);
  1621. +        hInfo.setHWID(client.getHWID());
  1622. +        hInfo.setLogin(client.getAccountName());
  1623. +        hInfo.setPlayerID(client.getPlayerId());
  1624. +        hInfo.setLockType(lockType);
  1625. +        _list.put(counterHwidInfo, hInfo);
  1626. +        if (isFound)
  1627. +        {
  1628. +           try (Connection con = ConnectionPool.getConnection();
  1629. +               PreparedStatement statement = con.prepareStatement("UPDATE hwid_info SET Account=?,PlayerID=?,LockType=? WHERE HWID=?"))
  1630. +            {
  1631. +                statement.setString(1, client.getAccountName());
  1632. +                statement.setInt(2, client.getPlayerId());
  1633. +                statement.setString(3, lockType.toString());
  1634. +                statement.setString(4, client.getHWID());
  1635. +                statement.execute();
  1636. +            }
  1637. +            catch (Exception e)
  1638. +            {
  1639. +                e.printStackTrace();
  1640. +            }
  1641. +        }
  1642. +        else
  1643. +        {
  1644. +            try (Connection con = ConnectionPool.getConnection();
  1645. +               PreparedStatement statement = con.prepareStatement("INSERT INTO hwid_info (HWID, Account, PlayerID, LockType) values (?,?,?,?)"))
  1646. +            {
  1647. +                statement.setString(1, client.getHWID());
  1648. +                statement.setString(2, client.getAccountName());
  1649. +                statement.setInt(3, client.getPlayerId());
  1650. +                statement.setString(4, lockType.toString());
  1651. +                statement.execute();
  1652. +            }
  1653. +            catch (Exception e)
  1654. +            {
  1655. +                e.printStackTrace();
  1656. +            }
  1657. +        }
  1658. +    }
  1659. +    
  1660. +    public static boolean checkLockedHWID(final GameClient client)
  1661. +    {
  1662. +        if (_list.size() == 0)
  1663. +            return false;
  1664. +
  1665. +        boolean result = false;
  1666. +        for (int i = 0; i < _list.size(); ++i)
  1667. +        {
  1668. +            switch (_list.get(i).getLockType().ordinal())
  1669. +            {
  1670. +                case 2:
  1671. +                {
  1672. +                    if (client.getPlayerId() == 0)
  1673. +                        break;
  1674. +
  1675. +                    if (_list.get(i).getPlayerID() != client.getPlayerId())
  1676. +                        break;
  1677. +
  1678. +                    if (_list.get(i).getHWID().equals(client.getHWID()))
  1679. +                        return false;
  1680. +
  1681. +                    result = true;
  1682. +                    break;
  1683. +                }
  1684. +                case 3:
  1685. +                {
  1686. +                    if (!_list.get(i).getLogin().equals(client.getLoginName()))
  1687. +                        break;
  1688. +
  1689. +                    if (_list.get(i).getHWID().equals(client.getHWID()))
  1690. +                        return false;
  1691. +
  1692. +                    result = true;
  1693. +                    break;
  1694. +                }
  1695. +            }
  1696. +        }
  1697. +        return result;
  1698. +    }
  1699. +    
  1700. +    public static int getAllowedWindowsCount(final GameClient client)
  1701. +    {
  1702. +        if (_list.size() == 0)
  1703. +            return -1;
  1704. +
  1705. +        int i = 0;
  1706. +        while (i < _list.size())
  1707. +        {
  1708. +            if (!_list.get(i).getHWID().equals(client.getHWID()))
  1709. +                ++i;
  1710. +            else
  1711. +            {
  1712. +                if (_list.get(i).getHWID().equals(""))
  1713. +                    return -1;
  1714. +
  1715. +                return _list.get(i).getCount();
  1716. +            }
  1717. +        }
  1718. +        return -1;
  1719. +    }
  1720. +    
  1721. +    public static int getCountHwidInfo()
  1722. +    {
  1723. +        return _list.size();
  1724. +    }
  1725. +}
  1726. \ No newline at end of file
  1727. diff --git a/aCis_gameserver/java/hwid/utils/HwidLog.java b/aCis_gameserver/java/hwid/utils/HwidLog.java
  1728. new file mode 100644
  1729. index 0000000000000000000000000000000000000000..9c7cef65ca4cb2acb97aba3d4144428bc0e6c84c
  1730. --- /dev/null
  1731. +++ b/aCis_gameserver/java/hwid/utils/HwidLog.java
  1732. @@ -0,0 +1,53 @@
  1733. +package hwid.utils;
  1734. +
  1735. +import java.io.File;
  1736. +import java.io.FileWriter;
  1737. +import java.io.IOException;
  1738. +import java.text.DateFormat;
  1739. +import java.text.SimpleDateFormat;
  1740. +import java.util.Date;
  1741. +
  1742. +import net.sf.l2j.commons.logging.CLogger;
  1743. +
  1744. +public class HwidLog
  1745. +{
  1746. +   protected static final CLogger LOGGER = new CLogger(HwidLog.class.getName());
  1747. +  
  1748. +   public HwidLog() {}
  1749. +
  1750. +   public static void auditGMAction(String gmName, String action, String params)
  1751. +   {
  1752. +       final File file = new File("log/hwid/" + gmName + ".txt");
  1753. +       if (!file.exists())
  1754. +       {
  1755. +           try
  1756. +           {
  1757. +               file.createNewFile();
  1758. +           }
  1759. +           catch (IOException e) {}
  1760. +       }
  1761. +
  1762. +       try (FileWriter save = new FileWriter(file, true))
  1763. +       {
  1764. +           save.write(formatDate(new Date(), "dd/MM/yyyy H:mm:ss") + " >>> HWID: [" + gmName + "] >>> Player: [" + action + "]\r\n");
  1765. +       }
  1766. +       catch (IOException e)
  1767. +       {
  1768. +           LOGGER.error("HwidLog for Player " + gmName + " could not be saved: ", e);
  1769. +       }
  1770. +   }
  1771. +
  1772. +   public static void auditGMAction(String gmName, String action)
  1773. +   {
  1774. +       auditGMAction(gmName, action, "");
  1775. +   }
  1776. +
  1777. +   public static String formatDate(Date date, String format)
  1778. +   {
  1779. +       final DateFormat dateFormat = new SimpleDateFormat(format);
  1780. +       if (date != null)
  1781. +           return dateFormat.format(date);
  1782. +      
  1783. +       return null;
  1784. +   }
  1785. +}
  1786. \ No newline at end of file
  1787. diff --git a/aCis_gameserver/java/hwid/utils/Util.java b/aCis_gameserver/java/hwid/utils/Util.java
  1788. new file mode 100644
  1789. index 0000000000000000000000000000000000000000..2a9176c77243bbfc3ddf60352c72ef6315f2ccd2
  1790. --- /dev/null
  1791. +++ b/aCis_gameserver/java/hwid/utils/Util.java
  1792. @@ -0,0 +1,73 @@
  1793. +package hwid.utils;
  1794. +
  1795. +public class Util
  1796. +{
  1797. +    public static void intToBytes(final int value, final byte[] array, int offset)
  1798. +    {
  1799. +        array[offset++] = (byte)(value & 0xFF);
  1800. +        array[offset++] = (byte)(value >> 8 & 0xFF);
  1801. +        array[offset++] = (byte)(value >> 16 & 0xFF);
  1802. +        array[offset++] = (byte)(value >> 24 & 0xFF);
  1803. +    }
  1804. +    
  1805. +    public static String LastErrorConvertion(final Integer LastError)
  1806. +    {
  1807. +        return LastError.toString();
  1808. +    }
  1809. +    
  1810. +    public static final String asHex(final byte[] raw)
  1811. +    {
  1812. +        return asHex(raw, 0, raw.length);
  1813. +    }
  1814. +    
  1815. +    public static final String asHex(final byte[] raw, final int offset, final int size)
  1816. +    {
  1817. +        final StringBuffer strbuf = new StringBuffer(raw.length * 2);
  1818. +        for (int i = 0; i < size; ++i)
  1819. +        {
  1820. +            if ((raw[offset + i] & 0xFF) < 16)
  1821. +                strbuf.append("0");
  1822. +
  1823. +            strbuf.append(Long.toString(raw[offset + i] & 0xFF, 16));
  1824. +        }
  1825. +        return strbuf.toString();
  1826. +    }
  1827. +    
  1828. +    public static int bytesToInt(final byte[] array, int offset)
  1829. +    {
  1830. +        return (array[offset++] & 0xFF) | (array[offset++] & 0xFF) << 8 | (array[offset++] & 0xFF) << 16 | (array[offset++] & 0xFF) << 24;
  1831. +    }
  1832. +    
  1833. +    public static String asHwidString(final String hex)
  1834. +    {
  1835. +        final byte[] buf = asByteArray(hex);
  1836. +        return asHex(buf);
  1837. +    }
  1838. +    
  1839. +    public static byte[] asByteArray(final String hex)
  1840. +    {
  1841. +        final byte[] buf = new byte[hex.length() / 2];
  1842. +        for (int i = 0; i < hex.length(); i += 2)
  1843. +        {
  1844. +            final int j = Integer.parseInt(hex.substring(i, i + 2), 16);
  1845. +            buf[i / 2] = (byte)(j & 0xFF);
  1846. +        }
  1847. +        return buf;
  1848. +    }
  1849. +    
  1850. +    public static boolean verifyChecksum(final byte[] raw, final int offset, final int size)
  1851. +    {
  1852. +        if ((size & 0x3) == 0x0 && size > 4)
  1853. +        {
  1854. +            long chksum = 0L;
  1855. +            final int count = size - 4;
  1856. +            for (int i2 = offset; i2 < count; i2 += 4)
  1857. +            {
  1858. +                chksum ^= bytesToInt(raw, i2);
  1859. +            }
  1860. +            final long check = bytesToInt(raw, count);
  1861. +            return check == chksum;
  1862. +        }
  1863. +        return false;
  1864. +    }
  1865. +}
  1866. \ No newline at end of file
  1867. diff --git a/aCis_gameserver/java/net/sf/l2j/Config.java b/aCis_gameserver/java/net/sf/l2j/Config.java
  1868. index f4f4028b80ee36afaa03ce3272c90865c6e06895..1b3a59f6838be39a817f3238443a1b08b97b06b1 100644
  1869. --- a/aCis_gameserver/java/net/sf/l2j/Config.java
  1870. +++ b/aCis_gameserver/java/net/sf/l2j/Config.java
  1871. @@ -25,6 +25,8 @@ import net.sf.l2j.commons.math.MathUtil;
  1872.  import net.sf.l2j.gameserver.enums.GeoType;
  1873.  import net.sf.l2j.gameserver.model.holder.IntIntHolder;
  1874.  
  1875. +import hwid.crypt.FirstKey;
  1876. +
  1877.  /**
  1878.   * This class contains global server configuration.<br>
  1879.   * It has static final fields initialized from configuration files.
  1880. @@ -47,6 +49,7 @@ public final class Config
  1881.     public static final String RUS_ACIS_FILE = "./config/rus_acis.properties";
  1882.     public static final String SERVER_FILE = "./config/server.properties";
  1883.     public static final String SIEGE_FILE = "./config/siege.properties";
  1884. +   public static final String HWID_FILE = "./config/hwid.properties";
  1885.    
  1886.     // --------------------------------------------------
  1887.     // Clans settings
  1888. @@ -951,6 +954,25 @@ public final class Config
  1889.     public static int CKM_PK_NPC_TITLE_COLOR;
  1890.     public static int CKM_PK_NPC_NAME_COLOR;
  1891.    
  1892. +   /** hwid settings */       
  1893. +   public static final boolean PROTECT_DEBUG = false;
  1894. +   public static final boolean PROTECT_ENABLE_HWID_LOCK = false;
  1895. +   public static byte[] GUARD_CLIENT_CRYPT_KEY;
  1896. +   public static byte[] GUARD_CLIENT_CRYPT;
  1897. +   public static byte[] GUARD_SERVER_CRYPT_KEY;
  1898. +   public static byte[] GUARD_SERVER_CRYPT;
  1899. +   public static boolean ALLOW_GUARD_SYSTEM;
  1900. +   public static int PROTECT_WINDOWS_COUNT;
  1901. +   public static int GET_CLIENT_HWID;
  1902. +   public static boolean ENABLE_CONSOLE_LOG;
  1903. +   public static boolean PROTECT_KICK_WITH_EMPTY_HWID;
  1904. +   public static boolean PROTECT_KICK_WITH_LASTERROR_HWID;
  1905. +   public static byte FST_KEY = 110;
  1906. +   public static byte SCN_KEY = 36;
  1907. +   public static byte ANP_KEY = -5;
  1908. +   public static byte ULT_KEY = 12;
  1909. +   public static int NPROTECT_KEY = -1;
  1910. +  
  1911.     /**
  1912.      * Initialize {@link ExProperties} from specified configuration file.
  1913.      * @param filename : File name to be loaded.
  1914. @@ -2480,7 +2502,7 @@ public final class Config
  1915.         final ExProperties server = initProperties(SERVER_FILE);
  1916.        
  1917.         HOSTNAME = server.getProperty("Hostname", "*");
  1918. -       GAMESERVER_HOSTNAME = server.getProperty("GameserverHostname");
  1919. +       GAMESERVER_HOSTNAME = server.getProperty("GameserverHostname", "*");
  1920.         GAMESERVER_PORT = server.getProperty("GameserverPort", 7777);
  1921.         GAMESERVER_LOGIN_HOSTNAME = server.getProperty("LoginHost", "127.0.0.1");
  1922.         GAMESERVER_LOGIN_PORT = server.getProperty("LoginPort", 9014);
  1923. @@ -2784,6 +2806,40 @@ public final class Config
  1924.         CKM_PK_NPC_NAME_COLOR = Integer.decode("0x" + rusacis.getProperty("CKMPKNpcNameColor", "FFFFFF"));
  1925.     }
  1926.    
  1927. +   /**
  1928. +    * Loads hwid settings.<br>
  1929. +    */
  1930. +   private static final void loadHwid()
  1931. +   {
  1932. +       // Hwid settings
  1933. +       final ExProperties hwid = initProperties(HWID_FILE);
  1934. +        ALLOW_GUARD_SYSTEM = hwid.getProperty("AllowGuardSystem", true);
  1935. +        PROTECT_WINDOWS_COUNT = hwid.getProperty("AllowedWindowsCount", 1);
  1936. +
  1937. +        GET_CLIENT_HWID = hwid.getProperty("UseClientHWID", 2);
  1938. +        ENABLE_CONSOLE_LOG = hwid.getProperty("EnableConsoleLog", false);
  1939. +        PROTECT_KICK_WITH_EMPTY_HWID = hwid.getProperty("KickWithEmptyHWID", false);
  1940. +        PROTECT_KICK_WITH_LASTERROR_HWID = hwid.getProperty("KickWithLastErrorHWID", false);
  1941. +
  1942. +        String key_client = "GOGX2_RB(]Slnjt15~EgyqTv%[$YR]!1E~ayK?$9[R%%m4{zoMF$D?f:zvS2q&>~";
  1943. +        String key_server = "b*qR43<9J1pD>Q4Uns6FsKao~VbU0H]y`A0ytTveiWn)SuSYsM?m*eblL!pwza!t";
  1944. +        byte[] keyS = key_server.getBytes();
  1945. +        byte[] tmpS = new byte[32];
  1946. +        
  1947. +        byte[] keyC = key_client.getBytes();
  1948. +        byte[] tmpC = new byte[32];
  1949. +      
  1950. +        System.arraycopy(keyC, 0, tmpC, 0, 32);
  1951. +        GUARD_CLIENT_CRYPT_KEY = FirstKey.expandKey(tmpC, 32);
  1952. +        System.arraycopy(keyC, 32, tmpC, 0, 32);
  1953. +        GUARD_CLIENT_CRYPT = FirstKey.expandKey(tmpC, 32);
  1954. +        
  1955. +        System.arraycopy(keyS, 0, tmpS, 0, 32);
  1956. +        GUARD_SERVER_CRYPT_KEY = FirstKey.expandKey(tmpS, 32);
  1957. +        System.arraycopy(keyS, 32, tmpS, 0, 32);
  1958. +        GUARD_SERVER_CRYPT = FirstKey.expandKey(tmpS, 32);
  1959. +   }
  1960. +  
  1961.     /**
  1962.      * Loads loginserver settings.<br>
  1963.      * IP addresses, database, account, misc.
  1964. @@ -2852,6 +2908,9 @@ public final class Config
  1965.        
  1966.         // rusacis settings
  1967.         loadRusAcis();
  1968. +      
  1969. +       // hwid settings
  1970. +       loadHwid();
  1971.     }
  1972.    
  1973.     public static final void loadLoginServer()
  1974. diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java b/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
  1975. index 58e8f4179b1a396933c21751d0b048516d14752b..5f2bbd08279275ca8ec59a695ef78740ae5700e1 100644
  1976. --- a/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
  1977. +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/GameServer.java
  1978. @@ -109,6 +109,8 @@ import net.sf.l2j.gameserver.taskmanager.WaterTaskManager;
  1979.  import net.sf.l2j.util.DeadLockDetector;
  1980.  import net.sf.l2j.util.IPv4Filter;
  1981.  
  1982. +import hwid.hwid;
  1983. +
  1984.  public class GameServer
  1985.  {
  1986.     private static final CLogger LOGGER = new CLogger(GameServer.class.getName());
  1987. @@ -317,7 +317,11 @@ public class GameServer
  1988.         LOGGER.info("Maximum allowed players: {}.", Config.MAXIMUM_ONLINE_USERS);
  1989.         LOGGER.info("Server loaded in " + (System.currentTimeMillis() - serverLoadStart) / 1000 + " seconds");
  1990.        
  1991. +       if (Config.ALLOW_GUARD_SYSTEM)
  1992. +           hwid.Init();
  1993. +       else
  1994. +           LOGGER.info("Hwid Manager is disabled.");
  1995. +      
  1996.         StringUtil.printSection("Login");
  1997.         LoginServerThread.getInstance().start();
  1998.        
  1999. diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
  2000. index 882ad47f347c94c14358e6b58d8e65fa09f2394a..7e1143b1d6f02f685101af75620733a3adad1864 100644
  2001. --- a/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
  2002. +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/model/actor/Player.java
  2003. @@ -513,6 +513,8 @@ public final class Player extends Playable
  2004.     private int _eventPoints = 0;
  2005.     public String _originalTitle;
  2006.    
  2007. +   private String _hwid;
  2008. +  
  2009.     /**
  2010.      * Constructor of Player (use Creature constructor).
  2011.      * <ul>
  2012. @@ -8061,4 +8063,13 @@ public final class Player extends Playable
  2013.         // Stop skill effect by ID
  2014.         _effects.stopSkillEffects(skill.getId());
  2015.     }
  2016. +  
  2017. +   public String getHWid()
  2018. +   {
  2019. +       if (getClient() == null)
  2020. +           return _hwid;
  2021. +
  2022. +       _hwid = getClient().getHWID();
  2023. +       return _hwid;
  2024. +   }
  2025.  }
  2026. \ No newline at end of file
  2027. diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/GameClient.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/GameClient.java
  2028. index c54a7d6c2f786c74c7700a53eb848633a93a1a7c..5cb01a724074e58876711de6b574d93261ef75da 100644
  2029. --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/GameClient.java
  2030. +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/GameClient.java
  2031. @@ -35,6 +35,8 @@ import net.sf.l2j.gameserver.model.pledge.Clan;
  2032.  import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  2033.  import net.sf.l2j.gameserver.network.serverpackets.ServerClose;
  2034.  
  2035. +import hwid.hwid;
  2036. +
  2037.  /**
  2038.   * Represents a client connected on Game Server.<br>
  2039.   * <br>
  2040. @@ -232,6 +234,10 @@ public final class GameClient extends MMOClient<MMOConnection<GameClient>>
  2041.     {
  2042.         byte[] key = BlowFishKeygen.getRandomKey();
  2043.         _crypt.setKey(key);
  2044. +       if (hwid.isProtectionOn())
  2045. +       {
  2046. +           key = hwid.getKey(key);
  2047. +       }
  2048.         return key;
  2049.     }
  2050.    
  2051. @@ -577,6 +583,7 @@ public final class GameClient extends MMOClient<MMOConnection<GameClient>>
  2052.             return;
  2053.        
  2054.         getConnection().close(gsp);
  2055. +       hwid.removePlayer(null);
  2056.     }
  2057.    
  2058.     /**
  2059. @@ -667,4 +674,72 @@ public final class GameClient extends MMOClient<MMOConnection<GameClient>>
  2060.             return true;
  2061.         }
  2062.     }
  2063. +  
  2064. +   // HWID
  2065. +   private String _playerName;
  2066. +   private String _loginName;
  2067. +   private int _playerId;
  2068. +   private int _count;
  2069. +   private String _hwid;
  2070. +   private int _revision;
  2071. +
  2072. +   public final String getPlayerName()
  2073. +   {
  2074. +       return _playerName;
  2075. +   }
  2076. +
  2077. +   public void setPlayerName(String name)
  2078. +   {
  2079. +       _playerName = name;
  2080. +   }
  2081. +  
  2082. +   public void setPlayerId(int plId)
  2083. +   {
  2084. +       _playerId = plId;
  2085. +   }
  2086. +  
  2087. +   public int getPlayerId()
  2088. +   {
  2089. +       return _playerId;
  2090. +   }
  2091. +  
  2092. +    public int getCount()
  2093. +    {
  2094. +        return _count;
  2095. +    }
  2096. +    
  2097. +    public void setCount(int count)
  2098. +    {
  2099. +        _count = count;
  2100. +    }
  2101. +  
  2102. +   public final String getHWID()
  2103. +   {
  2104. +       return _hwid;
  2105. +   }
  2106. +  
  2107. +   public void setHWID(String hwid)
  2108. +   {
  2109. +       _hwid = hwid;
  2110. +   }
  2111. +  
  2112. +   public void setRevision(int revision)
  2113. +   {
  2114. +       _revision = revision;
  2115. +   }
  2116. +  
  2117. +   public int getRevision()
  2118. +   {
  2119. +       return _revision;
  2120. +   }
  2121. +  
  2122. +   public final String getLoginName()
  2123. +   {
  2124. +       return _loginName;
  2125. +   }
  2126. +  
  2127. +   public void setLoginName(String name)
  2128. +   {
  2129. +       _loginName = name;
  2130. +   }
  2131.  }
  2132. \ No newline at end of file
  2133. diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/AuthLogin.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/AuthLogin.java
  2134. index 6dbecbdccf165caad6675029fb1d202096b286d3..dd1a18cd25e1f7419aeaeea54e06ea452a28d92f 100644
  2135. --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/AuthLogin.java
  2136. +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/AuthLogin.java
  2137. @@ -3,6 +3,8 @@ package net.sf.l2j.gameserver.network.clientpackets;
  2138.  import net.sf.l2j.gameserver.LoginServerThread;
  2139.  import net.sf.l2j.gameserver.network.SessionKey;
  2140.  
  2141. +import hwid.hwid;
  2142. +
  2143.  public final class AuthLogin extends L2GameClientPacket
  2144.  {
  2145.     private String _loginName;
  2146. @@ -10,6 +12,7 @@ public final class AuthLogin extends L2GameClientPacket
  2147.     private int _playKey2;
  2148.     private int _loginKey1;
  2149.     private int _loginKey2;
  2150. +   private final byte[] _data = new byte[48];
  2151.    
  2152.     @Override
  2153.     protected void readImpl()
  2154. @@ -24,6 +27,12 @@ public final class AuthLogin extends L2GameClientPacket
  2155.     @Override
  2156.     protected void runImpl()
  2157.     {
  2158. +       if (hwid.isProtectionOn())
  2159. +       {
  2160. +           if (!hwid.doAuthLogin(getClient(), _data, _loginName))
  2161. +               return;
  2162. +       }
  2163. +      
  2164.         if (getClient().getAccountName() != null)
  2165.             return;
  2166.        
  2167. diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  2168. index d284949dcab49dacad817487689bc632ac346331..0dc167fc69ac7949c0b27c4a930a18dc6df1afec 100644
  2169. --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  2170. +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/EnterWorld.java
  2171. @@ -65,6 +65,8 @@ import net.sf.l2j.gameserver.skills.L2Skill;
  2172.  import net.sf.l2j.gameserver.taskmanager.GameTimeTaskManager;
  2173.  import net.sf.l2j.util.CustomMessage;
  2174.  
  2175. +import hwid.hwid;
  2176. +
  2177.  public class EnterWorld extends L2GameClientPacket
  2178.  {
  2179.     @Override
  2180. @@ -355,7 +355,8 @@ public class EnterWorld extends L2GameClientPacket
  2181.         if (qs != null)
  2182.             qs.getQuest().notifyEvent("UC", null, player);
  2183.        
  2184. +       if (hwid.isProtectionOn())
  2185. +           hwid.enterlog(player, getClient());
  2186. +      
  2187.         player.sendPacket(ActionFailed.STATIC_PACKET);
  2188.     }
  2189.    
  2190. diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestGameStart.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestGameStart.java
  2191. index e46f6fd2951526a9639b1a27be545af8f207caf4..ad61fed30bd25406a42ac8d0f2c4f65cd8c9dcd2 100644
  2192. --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestGameStart.java
  2193. +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/RequestGameStart.java
  2194. @@ -11,6 +11,8 @@ import net.sf.l2j.gameserver.network.serverpackets.CharSelected;
  2195.  import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  2196.  import net.sf.l2j.gameserver.network.serverpackets.SSQInfo;
  2197.  
  2198. +import hwid.hwid;
  2199. +
  2200.  public class RequestGameStart extends L2GameClientPacket
  2201.  {
  2202.     private int _slot;
  2203. @@ -64,6 +66,9 @@ public class RequestGameStart extends L2GameClientPacket
  2204.                    
  2205.                     sendPacket(SSQInfo.sendSky());
  2206.                    
  2207. +                   if (hwid.isProtectionOn() && !hwid.checkPlayerWithHWID(getClient(), player.getObjectId(), player.getName()))
  2208. +                       return;
  2209. +                  
  2210.                     client.setState(GameClientState.ENTERING);
  2211.                    
  2212.                     sendPacket(new CharSelected(player, client.getSessionId().playOkID1));
  2213. diff --git a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/SendProtocolVersion.java b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/SendProtocolVersion.java
  2214. index 2dba43d529f885b7cb33d98be688e2128bf60963..0a0d105c94741a30b37fecf516618258d491d8fa 100644
  2215. --- a/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/SendProtocolVersion.java
  2216. +++ b/aCis_gameserver/java/net/sf/l2j/gameserver/network/clientpackets/SendProtocolVersion.java
  2217. @@ -1,21 +1,61 @@
  2218.  package net.sf.l2j.gameserver.network.clientpackets;
  2219.  
  2220. +import net.sf.l2j.Config;
  2221.  import net.sf.l2j.gameserver.network.serverpackets.L2GameServerPacket;
  2222.  import net.sf.l2j.gameserver.network.serverpackets.VersionCheck;
  2223.  
  2224. +import hwid.hwid;
  2225. +
  2226.  public final class SendProtocolVersion extends L2GameClientPacket
  2227.  {
  2228.     private int _version;
  2229. +   private byte _data[];
  2230. +   private String _hwidHdd = "NoHWID-HD";
  2231. +   private String _hwidMac = "NoHWID-MAC";
  2232. +   private String _hwidCPU = "NoHWID-CPU";
  2233.    
  2234.     @Override
  2235.     protected void readImpl()
  2236.     {
  2237.         _version = readD();
  2238. +       if (hwid.isProtectionOn())
  2239. +       {
  2240. +           if (_buf.remaining() > 260)
  2241. +           {
  2242. +               _data = new byte[260];
  2243. +               readB(_data);
  2244. +               _hwidHdd = readS();
  2245. +               _hwidMac = readS();
  2246. +               _hwidCPU = readS();
  2247. +           }
  2248. +          
  2249. +           if (_hwidHdd.equals("NoHWID-HD") && _hwidMac.equals("NoHWID-MAC") && _hwidCPU.equals("NoHWID-CPU"))
  2250. +           {
  2251. +               hwid.nopath(getClient());
  2252. +               getClient().close((L2GameServerPacket) null);
  2253. +           }
  2254. +       }
  2255.     }
  2256.    
  2257.     @Override
  2258.     protected void runImpl()
  2259.     {
  2260. +       if (hwid.isProtectionOn())
  2261. +       {
  2262. +           switch (Config.GET_CLIENT_HWID)
  2263. +           {
  2264. +               case 1:
  2265. +                   getClient().setHWID(_hwidHdd);
  2266. +                   break;
  2267. +               case 2:
  2268. +                   getClient().setHWID(_hwidMac);
  2269. +                   break;
  2270. +               case 3:
  2271. +                   getClient().setHWID(_hwidCPU);
  2272. +                   break;
  2273. +           }
  2274. +       }
  2275. +      
  2276.         switch (_version)
  2277.         {
  2278.             case 737:
  2279.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement