Advertisement
l2TopgameserverNet

L2JMobius-Homonculus-8.0 - Vote Reward System - l2.topgameserver.net

Mar 19th, 2021 (edited)
1,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 84.64 KB | None | 0 0
  1. diff --git a/L2J_Mobius_8.0_Homunculus/.classpath b/L2J_Mobius_8.0_Homunculus/.classpath
  2. index 0acf8a4..2db41cf 100644
  3. --- a/L2J_Mobius_8.0_Homunculus/.classpath
  4. +++ b/L2J_Mobius_8.0_Homunculus/.classpath
  5. @@ -1,5 +1,7 @@
  6.  <?xml version="1.0" encoding="UTF-8"?>
  7.  <classpath>
  8. +   <classpathentry including="**/*.java" kind="src" path="dist/game/data/scripts"/>
  9. +   <classpathentry kind="src" path="java"/>
  10.     <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-15">
  11.         <attributes>
  12.             <attribute name="module" value="true"/>
  13. @@ -9,7 +11,6 @@
  14.     <classpathentry kind="lib" path="dist/libs/exp4j-0.4.8.jar" sourcepath="dist/libs/exp4j-0.4.8-sources.jar"/>
  15.     <classpathentry kind="lib" path="dist/libs/mariadb-java-client-2.6.1.jar" sourcepath="dist/libs/mariadb-java-client-2.6.1-sources.jar"/>
  16.     <classpathentry kind="lib" path="dist/libs/netty-all-4.1.50.Final.jar" sourcepath="dist/libs/netty-all-4.1.50.Final-sources.jar"/>
  17. -   <classpathentry including="**/*.java" kind="src" path="dist/game/data/scripts"/>
  18. -   <classpathentry kind="src" path="java"/>
  19. +   <classpathentry kind="lib" path="C:/Users/escor/git/l2_projects/L2J_Mobius_8.0_Homunculus/dist/libs/json-simple-1.1.1.jar"/>
  20.     <classpathentry kind="output" path="bin"/>
  21.  </classpath>
  22. diff --git a/L2J_Mobius_8.0_Homunculus/bin/.gitignore b/L2J_Mobius_8.0_Homunculus/bin/.gitignore
  23. new file mode 100644
  24. index 0000000..cab9996
  25. --- /dev/null
  26. +++ b/L2J_Mobius_8.0_Homunculus/bin/.gitignore
  27. @@ -0,0 +1,9 @@
  28. +/ai/
  29. +/custom/
  30. +/events/
  31. +/handlers/
  32. +/instances/
  33. +/org/
  34. +/quests/
  35. +/vehicles/
  36. +/village_master/
  37. diff --git a/L2J_Mobius_8.0_Homunculus/bin/handlers/MasterHandler.class b/L2J_Mobius_8.0_Homunculus/bin/handlers/MasterHandler.class
  38. index 8504577..ca878d9 100644
  39. --- a/L2J_Mobius_8.0_Homunculus/bin/handlers/MasterHandler.class
  40. +++ b/L2J_Mobius_8.0_Homunculus/bin/handlers/MasterHandler.class
  41. Binary files differ
  42. diff --git a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config$IPConfigData.class b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config$IPConfigData.class
  43. index 6ee7e44..cddf500 100644
  44. --- a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config$IPConfigData.class
  45. +++ b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config$IPConfigData.class
  46. Binary files differ
  47. diff --git a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config.class b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config.class
  48. index 66d4f68..4863679 100644
  49. --- a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config.class
  50. +++ b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/Config.class
  51. Binary files differ
  52. diff --git a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/GameServer.class b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/GameServer.class
  53. index 1b23e16..8e2c8a5 100644
  54. --- a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/GameServer.class
  55. +++ b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/GameServer.class
  56. Binary files differ
  57. diff --git a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$SingletonHolder.class b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$SingletonHolder.class
  58. index 916ad89..874dbae 100644
  59. --- a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$SingletonHolder.class
  60. +++ b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$SingletonHolder.class
  61. Binary files differ
  62. diff --git a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$TimeCounter.class b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$TimeCounter.class
  63. index e225ec1..d96c616 100644
  64. --- a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$TimeCounter.class
  65. +++ b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown$TimeCounter.class
  66. Binary files differ
  67. diff --git a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown.class b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown.class
  68. index de9e04d..edd886c 100644
  69. --- a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown.class
  70. +++ b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/Shutdown.class
  71. Binary files differ
  72. diff --git a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.class b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.class
  73. index 0aba714..cbe7ccd 100644
  74. --- a/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.class
  75. +++ b/L2J_Mobius_8.0_Homunculus/bin/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.class
  76. Binary files differ
  77. diff --git a/L2J_Mobius_8.0_Homunculus/dist/game/config/votesystem.ini b/L2J_Mobius_8.0_Homunculus/dist/game/config/votesystem.ini
  78. new file mode 100644
  79. index 0000000..dc29ac4
  80. --- /dev/null
  81. +++ b/L2J_Mobius_8.0_Homunculus/dist/game/config/votesystem.ini
  82. @@ -0,0 +1,95 @@
  83. +EnableVoteSystem = True
  84. +
  85. +EnableGlobalVote = True
  86. +
  87. +EnableIndividualVote = True
  88. +
  89. +## Time to Update table totalVotes from DB
  90. +NextTimeToAutoUpdateTotalVote = 2
  91. +
  92. +## Time to update table individualVotes
  93. +NextTimeToAutoUpdateIndividualVotes = 2
  94. +
  95. +NextTimeToAutoCleanInnecesaryVotes = 30
  96. +
  97. +NextTimeToCheckAutoGlobalVotesReward = 1
  98. +
  99. +IntervalToNextVote = 12
  100. +
  101. +GlobalVotesAmountToNextReward = 1
  102. +
  103. +EnableVotingCommand = True
  104. +
  105. +VotingCommand = getreward
  106. +
  107. +## l2.topgameserver.net
  108. +VoteLinkTgs = http://l2.topgameserver.net/lineage/VoteApi/
  109. +
  110. +TgsApiKey =
  111. +
  112. +## l2top.co
  113. +VoteLinkTopCo = https://l2top.co/reward/
  114. +
  115. +TopCoSrvId =
  116. +
  117. +## ITopz.com
  118. +VoteLinkItopz = https://itopz.com/check/
  119. +
  120. +ItopzZpiKey =
  121. +
  122. +ItopzSrvId =
  123. +
  124. +## l2votes.com
  125. +VoteLinkVts = https://l2votes.com/
  126. +
  127. +VtsApiKey =
  128. +
  129. +VtsSid =
  130. +
  131. +## Hopzone.net
  132. +VoteLinkHz = https://api.hopzone.net/lineage2/
  133. +
  134. +HzApiKey =
  135. +
  136. +## l2network.eu
  137. +VoteNetworkLink = https://l2network.eu/api.php
  138. +
  139. +VoteNetworkUserName =
  140. +
  141. +VoteNetworkApiKey =
  142. +
  143. +## L2TopServer.com
  144. +VoteLinkTss = https://l2topservers.com/votes?
  145. +
  146. +TssApiToken =
  147. +
  148. +TsSrvId = 453
  149. +
  150. +TsDomainName= l2catgang
  151. +
  152. +## top.l2jbrasil.com
  153. +BrasilVoteLink = https://top.l2jbrasil.com/votesystem/index.php?
  154. +
  155. +BrasilUserName = julioguzman
  156. +
  157. +## Mmotop.eu
  158. +VoteLinkMmotop = https://l2jtop.com/api/
  159. +
  160. +MmotopApiKey =
  161. +
  162. +## L2TopZone.com
  163. +VoteLinkTz = https://api.l2topzone.com/v1/
  164. +
  165. +TzApiKey =
  166. +
  167. +## L2Servers.com
  168. +VoteLinkServers = https://www.l2servers.com/api/
  169. +
  170. +ServersHashCode =
  171. +
  172. +ServersSrvId =
  173. +
  174. +
  175. +## for localhost test if your project is live, put the word off or leave it blank
  176. +TestIp =
  177. +
  178. diff --git a/L2J_Mobius_8.0_Homunculus/dist/game/data/html/mods/votesystem/905105.html b/L2J_Mobius_8.0_Homunculus/dist/game/data/html/mods/votesystem/905105.html
  179. new file mode 100644
  180. index 0000000..b2a5624
  181. --- /dev/null
  182. +++ b/L2J_Mobius_8.0_Homunculus/dist/game/data/html/mods/votesystem/905105.html
  183. @@ -0,0 +1,19 @@
  184. +<html>
  185. +<title>Voting panel</title>
  186. +<body><center>
  187. +   <br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
  188. +   <table cellpadding=2 width=280>
  189. +       <tr><td width="280">Hello <font color="C6AF00">%accountName%</font>, welcome to the voting rewards dashboard, please help us by voting by server every <font color="C6AF00">%everyXtime% hours</font> in all voting sites.</td></tr>
  190. +   </table>
  191. +   <table width="290"><tr><td width="290" align="center">You can vote: </td></tr></table>
  192. +   <br><img src="l2ui.SquareWhite" width=290 height=1><br>
  193. +
  194. +   %enablevote%
  195. +
  196. +   <br>
  197. +   <img src="l2ui.SquareWhite" width=290 height=1><br>
  198. +
  199. +
  200. +
  201. +</center></body>
  202. +</html>
  203. \ No newline at end of file
  204. diff --git a/L2J_Mobius_8.0_Homunculus/dist/game/data/scripts/handlers/MasterHandler.java b/L2J_Mobius_8.0_Homunculus/dist/game/data/scripts/handlers/MasterHandler.java
  205. index 3b4bba8..5baa248 100644
  206. --- a/L2J_Mobius_8.0_Homunculus/dist/game/data/scripts/handlers/MasterHandler.java
  207. +++ b/L2J_Mobius_8.0_Homunculus/dist/game/data/scripts/handlers/MasterHandler.java
  208. @@ -340,6 +340,7 @@
  209.  import handlers.voicedcommandhandlers.ChatAdmin;
  210.  import handlers.voicedcommandhandlers.Lang;
  211.  import handlers.voicedcommandhandlers.Premium;
  212. +import handlers.voicedcommandhandlers.VoteReward;
  213.  
  214.  /**
  215.   * Master handler.
  216. @@ -600,6 +601,7 @@
  217.             Config.ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null,
  218.             Config.PREMIUM_SYSTEM_ENABLED ? Premium.class : null,
  219.             Config.AUTO_POTIONS_ENABLED ? AutoPotion.class : null,
  220. +           (Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTING_COMMAND ? VoteReward.class : null),
  221.         },
  222.         {
  223.             // Target Handlers
  224. diff --git a/L2J_Mobius_8.0_Homunculus/dist/game/data/scripts/handlers/voicedcommandhandlers/VoteReward.java b/L2J_Mobius_8.0_Homunculus/dist/game/data/scripts/handlers/voicedcommandhandlers/VoteReward.java
  225. new file mode 100644
  226. index 0000000..679fc1e
  227. --- /dev/null
  228. +++ b/L2J_Mobius_8.0_Homunculus/dist/game/data/scripts/handlers/voicedcommandhandlers/VoteReward.java
  229. @@ -0,0 +1,88 @@
  230. +/*
  231. + * This file is part of the L2J Mobius project.
  232. + *
  233. + * This program is free software: you can redistribute it and/or modify
  234. + * it under the terms of the GNU General Public License as published by
  235. + * the Free Software Foundation, either version 3 of the License, or
  236. + * (at your option) any later version.
  237. + *
  238. + * This program is distributed in the hope that it will be useful,
  239. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  240. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  241. + * General Public License for more details.
  242. + *
  243. + * You should have received a copy of the GNU General Public License
  244. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  245. + */
  246. +package handlers.voicedcommandhandlers;
  247. +
  248. +import org.l2jmobius.Config;
  249. +import org.l2jmobius.gameserver.handler.IVoicedCommandHandler;
  250. +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  251. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  252. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  253. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  254. +
  255. +/**
  256. + * @author l2.topgameserver.net
  257. + */
  258. +public class VoteReward implements IVoicedCommandHandler
  259. +{
  260. +  
  261. +   @Override
  262. +   public boolean useVoicedCommand(String command, PlayerInstance player, String params)
  263. +   {
  264. +       if (command.equalsIgnoreCase(Config.VOTING_COMMAND))
  265. +       {
  266. +           if (player.isJailed())
  267. +           {
  268. +               player.sendMessage("You cannot use this function while you are jailed");
  269. +               return false;
  270. +           }
  271. +           if (!Config.ENABLE_VOTE_SYSTEM)
  272. +           {
  273. +               player.sendMessage("The rewards system has been disabled by your administrator");
  274. +               return false;
  275. +           }
  276. +           if (!Config.ENABLE_INDIVIDUAL_VOTE)
  277. +           {
  278. +               player.sendMessage("The individual reward system is disabled");
  279. +               return false;
  280. +           }
  281. +           if (!Config.ENABLE_VOTING_COMMAND)
  282. +           {
  283. +               player.sendMessage("Voting command reward is disabled");
  284. +               return false;
  285. +           }
  286. +          
  287. +           for (voteSite vs : voteSite.values())
  288. +           {
  289. +               new Thread(() ->
  290. +               {
  291. +                   voteManager.getInatance().getReward(player, vs.ordinal());
  292. +               }).start();
  293. +           }
  294. +          
  295. +           return true;
  296. +          
  297. +       }
  298. +       if (command.equalsIgnoreCase("reloadrewards") && player.isGM())
  299. +       {
  300. +           ReadJson.getInstance().load();
  301. +           player.sendMessage("=============All reward has been reloaded=============");
  302. +           return true;
  303. +       }
  304. +       return false;
  305. +   }
  306. +  
  307. +   @Override
  308. +   public String[] getVoicedCommandList()
  309. +   {
  310. +       return new String[]
  311. +       {
  312. +           Config.VOTING_COMMAND,
  313. +           "reloadrewards",
  314. +       };
  315. +   }
  316. +  
  317. +}
  318. \ No newline at end of file
  319. diff --git a/L2J_Mobius_8.0_Homunculus/dist/game/data/stats/npcs/custom/custom.xml b/L2J_Mobius_8.0_Homunculus/dist/game/data/stats/npcs/custom/custom.xml
  320. index 2e508bf..f6d7ee2 100644
  321. --- a/L2J_Mobius_8.0_Homunculus/dist/game/data/stats/npcs/custom/custom.xml
  322. +++ b/L2J_Mobius_8.0_Homunculus/dist/game/data/stats/npcs/custom/custom.xml
  323. @@ -90,4 +90,22 @@
  324.             <height normal="12.5" />
  325.         </collision>
  326.     </npc>
  327. +   <npc id="905105" displayId="32365" name="Kaaya" usingServerSideName="true" title="Vote Reward System" type="NpcVoteReward">
  328. +       <race>HUMAN</race>
  329. +       <sex>FEMALE</sex>
  330. +       <stats>
  331. +           <vitals hp="2444.46819" hpRegen="7.5" mp="1345.8" mpRegen="2.7" />
  332. +           <attack physical="688.86373" magical="470.40463" random="30" critical="4" accuracy="95" attackSpeed="253" type="SWORD" range="40" distance="80" width="120" />
  333. +           <defence physical="295.91597" magical="216.53847" />
  334. +           <speed>
  335. +               <walk ground="50" />
  336. +               <run ground="120" />
  337. +           </speed>
  338. +       </stats>
  339. +       <status attackable="false" />
  340. +       <collision>
  341. +           <radius normal="11" />
  342. +           <height normal="22.25" />
  343. +       </collision>
  344. +   </npc>
  345.  </list>
  346. \ No newline at end of file
  347. diff --git a/L2J_Mobius_8.0_Homunculus/dist/game/data/votesystem.json b/L2J_Mobius_8.0_Homunculus/dist/game/data/votesystem.json
  348. new file mode 100644
  349. index 0000000..31ae14e
  350. --- /dev/null
  351. +++ b/L2J_Mobius_8.0_Homunculus/dist/game/data/votesystem.json
  352. @@ -0,0 +1,14 @@
  353. +[
  354. +   {"votesite":{"ordinal":"0","name":"l2.topgameserver.net","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  355. +   {"votesite":{"ordinal":"1","name":"Itopz.com","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  356. +   {"votesite":{"ordinal":"2","name":"L2Top.co","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  357. +   {"votesite":{"ordinal":"3","name":"L2Votes.com","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  358. +   {"votesite":{"ordinal":"4","name":"Hopzone.net","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  359. +   {"votesite":{"ordinal":"5","name":"L2Network.eu","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  360. +   {"votesite":{"ordinal":"6","name":"L2Topservers.com","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  361. +   {"votesite":{"ordinal":"7","name":"top.l2jbrasil.com","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  362. +   {"votesite":{"ordinal":"8","name":"MMOTOP.eu","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  363. +   {"votesite":{"ordinal":"9","name":"L2Topzone.com","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  364. +   {"votesite":{"ordinal":"10","name":"L2Servers.com","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}},
  365. +   {"votesite":{"ordinal":"11","name":"globalVotes","rewards":[{"item_id":"57","item_count":"100000"},{"item_id":"6673","item_count":"1"}]}}
  366. +]
  367. \ No newline at end of file
  368. diff --git a/L2J_Mobius_8.0_Homunculus/dist/libs/json-simple-1.1.1.jar b/L2J_Mobius_8.0_Homunculus/dist/libs/json-simple-1.1.1.jar
  369. new file mode 100644
  370. index 0000000..66347a6
  371. --- /dev/null
  372. +++ b/L2J_Mobius_8.0_Homunculus/dist/libs/json-simple-1.1.1.jar
  373. Binary files differ
  374. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/Config.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/Config.java
  375. index cd13b4c..55529eb 100644
  376. --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/Config.java
  377. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/Config.java
  378.  
  379. import java.util.Properties;
  380. +import java.util.concurrent.TimeUnit;
  381. import java.util.logging.Level;
  382.  
  383.  
  384. @@ -108,6 +108,7 @@
  385.     private static final String CHAT_FILTER_FILE = "./config/chatfilter.txt";
  386.     private static final String HEXID_FILE = "./config/hexid.txt";
  387.     private static final String IPCONFIG_FILE = "./config/ipconfig.xml";
  388. +   private static final String VOTE_SYSTEM_FILE = "./config/votesystem.ini";
  389.    
  390.     // --------------------------------------------------
  391.     // Custom Config File Definitions
  392. @@ -147,6 +148,50 @@
  393.     private static final String CUSTOM_VOTE_REWARD_CONFIG_FILE = "./config/Custom/VoteReward.ini";
  394.     private static final String CUSTOM_WALKER_BOT_PROTECTION_CONFIG_FILE = "./config/Custom/WalkerBotProtection.ini";
  395.    
  396. +   // ---------------------------------------------------
  397. +   // VOTE SYSTEM
  398. +   // ---------------------------------------------------
  399. +   public static boolean ENABLE_VOTE_SYSTEM;
  400. +   public static boolean ENABLE_INDIVIDUAL_VOTE;
  401. +   public static boolean ENABLE_GLOBAL_VOTE;
  402. +   public static long NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE;
  403. +   public static long NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES;
  404. +   public static long NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES;
  405. +   public static long NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD;
  406. +   public static long INTERVAL_TO_NEXT_VOTE;
  407. +   public static int GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD;
  408. +   public static boolean ENABLE_VOTING_COMMAND;
  409. +   public static String VOTING_COMMAND;
  410. +   public static String VOTE_LINK_TGS;
  411. +   public static String TGS_API_KEY;
  412. +   public static String VOTE_LINK_TOP_CO;
  413. +   public static String TOP_CO_SRV_ID;
  414. +   public static String VOTE_LINK_ITOPZ;
  415. +   public static String ITOPZ_API_KEY;
  416. +   public static String ITOPZ_SRV_ID;
  417. +   public static String VOTE_LINK_VTS;
  418. +   public static String VTS_API_KEY;
  419. +   public static String VTS_SID;
  420. +   public static String VOTE_LINK_HZ;
  421. +   public static String HZ_API_KEY;
  422. +   public static String VOTE_NETWORK_LINK;
  423. +   public static String VOTE_NETWORK_USER_NAME;
  424. +   public static String VOTE_NETWORK_API_KEY;
  425. +   public static String VOTE_LINK_TSS;
  426. +   public static String TSS_API_TOKEN;
  427. +   public static String TS_SRV_ID;
  428. +   public static String TS_DOMAIN_NAME;
  429. +   public static String BRASIL_VOTE_LINK;
  430. +   public static String BRASIL_USER_NAME;
  431. +   public static String VOTE_LINK_MMOTOP;
  432. +   public static String MMOTOP_API_KEY;
  433. +   public static String VOTE_LINK_TZ;
  434. +   public static String TZ_API_KEY;
  435. +   public static String VOTE_LINK_SERVERS;
  436. +   public static String SERVERS_HASH_CODE;
  437. +   public static String SERVERS_SRV_ID;
  438. +   public static String TEST_IP;
  439. +  
  440.     // --------------------------------------------------
  441.     // Variable Definitions
  442.     // --------------------------------------------------
  443. @@ -3468,6 +3513,50 @@
  444.             PREMIUM_HENNA_SLOT_ALL_DYES = PremiumSystem.getBoolean("EnableAnyHennaAtPremiumSlot", false);
  445.             PREMIUM_ONLY_FISHING = PremiumSystem.getBoolean("PremiumOnlyFishing", true);
  446.            
  447. +           // Load VoteSystem config file
  448. +           final PropertiesParser votesystem = new PropertiesParser(VOTE_SYSTEM_FILE);
  449. +          
  450. +           ENABLE_VOTE_SYSTEM = votesystem.getBoolean("EnableVoteSystem", true);
  451. +           ENABLE_INDIVIDUAL_VOTE = votesystem.getBoolean("EnableIndividualVote", true);
  452. +           ENABLE_GLOBAL_VOTE = votesystem.getBoolean("EnableGlobalVote", true);
  453. +           NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoUpdateTotalVote", 60));// -> minutes
  454. +       NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoUpdateIndividualVotes", 60));// -> minutes
  455. +       NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToAutoCleanInnecesaryVotes", 30));// -> minutes
  456. +       NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = TimeUnit.MINUTES.toMillis(votesystem.getInt("NextTimeToCheckAutoGlobalVotesReward", 5));// -> minutes
  457. +       INTERVAL_TO_NEXT_VOTE = TimeUnit.HOURS.toMillis(votesystem.getInt("IntervalTimeToNextVote", 12)); // -> hours
  458. +           GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = votesystem.getInt("GlobalVotesAmountToNextReward", 50);
  459. +           ENABLE_VOTING_COMMAND = votesystem.getBoolean("EnableVotingCommand", true);
  460. +           VOTING_COMMAND = votesystem.getString("VotingCommand", "getreward");
  461. +           VOTE_LINK_TGS = votesystem.getString("VoteLinkTgs", "");
  462. +           TGS_API_KEY = votesystem.getString("TgsApiKey", "");
  463. +           VOTE_LINK_TOP_CO = votesystem.getString("VoteLinkTopCo", "");
  464. +           TOP_CO_SRV_ID = votesystem.getString("TopCoSrvId", "");
  465. +           VOTE_LINK_ITOPZ = votesystem.getString("VoteLinkItopz", "");
  466. +           ITOPZ_API_KEY = votesystem.getString("ItopzZpiKey", "");
  467. +           ITOPZ_SRV_ID = votesystem.getString("ItopzSrvId", "");
  468. +           VOTE_LINK_VTS = votesystem.getString("VoteLinkVts", "");
  469. +           VTS_API_KEY = votesystem.getString("VtsApiKey", "");
  470. +           VTS_SID = votesystem.getString("VtsSid", "");
  471. +           VOTE_LINK_HZ = votesystem.getString("VoteLinkHz", "");
  472. +           HZ_API_KEY = votesystem.getString("HzApiKey", "");
  473. +           VOTE_NETWORK_LINK = votesystem.getString("VoteNetworkLink", "");
  474. +           VOTE_NETWORK_USER_NAME = votesystem.getString("VoteNetworkUserName", "");
  475. +           VOTE_NETWORK_API_KEY = votesystem.getString("VoteNetworkApiKey", "");
  476. +           VOTE_LINK_TSS = votesystem.getString("VoteLinkTss", "");
  477. +           TSS_API_TOKEN = votesystem.getString("TssApiToken", "");
  478. +           TS_SRV_ID = votesystem.getString("TsSrvId", "");
  479. +           TS_DOMAIN_NAME = votesystem.getString("TsDomainName", "");
  480. +           BRASIL_VOTE_LINK = votesystem.getString("BrasilVoteLink", "");
  481. +           BRASIL_USER_NAME = votesystem.getString("BrasilUserName", "");
  482. +           VOTE_LINK_MMOTOP = votesystem.getString("VoteLinkMmotop", "");
  483. +           MMOTOP_API_KEY = votesystem.getString("MmotopApiKey", "");
  484. +           VOTE_LINK_TZ = votesystem.getString("VoteLinkTz", "");
  485. +           TZ_API_KEY = votesystem.getString("TzApiKey", "");
  486. +           VOTE_LINK_SERVERS = votesystem.getString("VoteLinkServers", "");
  487. +           SERVERS_HASH_CODE = votesystem.getString("ServersHashCode", "");
  488. +           SERVERS_SRV_ID = votesystem.getString("ServersSrvId", "");
  489. +           TEST_IP = votesystem.getString("TestIp", "");
  490. +          
  491.             // Load PrivateStoreRange config file (if exists)
  492.             final PropertiesParser PrivateStoreRange = new PropertiesParser(CUSTOM_PRIVATE_STORE_RANGE_CONFIG_FILE);
  493.             SHOP_MIN_RANGE_FROM_PLAYER = PrivateStoreRange.getInt("ShopMinRangeFromPlayer", 50);
  494. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameServer.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameServer.java
  495. index 3d1449c..15f52ed 100644
  496. --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameServer.java
  497. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/GameServer.java
  498. @@ -164,6 +164,8 @@
  499.  import org.l2jmobius.gameserver.taskmanager.TaskManager;
  500.  import org.l2jmobius.gameserver.ui.Gui;
  501.  import org.l2jmobius.gameserver.util.Broadcast;
  502. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  503. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  504.  
  505.  public class GameServer
  506.  {
  507. @@ -336,6 +338,19 @@
  508.         GrandBossManager.getInstance();
  509.         EventDroplist.getInstance();
  510.        
  511. +       // load vote reward system
  512. +       printSection("Vote Reward System");
  513. +       if (Config.ENABLE_VOTE_SYSTEM)
  514. +       {
  515. +           voteManager.getInatance();
  516. +           LOGGER.info("======================Vote System Enabled=========================");
  517. +           ReadJson.getInstance();
  518. +       }
  519. +       else
  520. +       {
  521. +           LOGGER.info("======================Vote System Disabled=========================");
  522. +       }
  523. +      
  524.         printSection("Instance");
  525.         InstanceManager.getInstance();
  526.        
  527. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/Shutdown.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/Shutdown.java
  528. index dfee7aa..74d87d8 100644
  529. --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/Shutdown.java
  530. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/Shutdown.java
  531. @@ -49,6 +49,7 @@
  532.  import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
  533.  import org.l2jmobius.gameserver.network.telnet.TelnetServer;
  534.  import org.l2jmobius.gameserver.util.Broadcast;
  535. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  536.  
  537.  /**
  538.   * This class provides the functions for shutting down and restarting the server.<br>
  539. @@ -478,6 +479,12 @@
  540.         GlobalVariablesManager.getInstance().storeMe();
  541.         LOGGER.info("Global Variables Manager: Variables saved(" + tc.getEstimatedTimeAndRestartCounter() + "ms).");
  542.        
  543. +       // Save individual votes data
  544. +       if (Config.ENABLE_VOTE_SYSTEM)
  545. +       {
  546. +           voteManager.getInatance().Shutdown();
  547. +       }
  548. +      
  549.         // Save items on ground before closing
  550.         if (Config.SAVE_DROPPED_ITEM)
  551.         {
  552. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java
  553. new file mode 100644
  554. index 0000000..f344a04
  555. --- /dev/null
  556. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/model/actor/instance/NpcVoteRewardInstance.java
  557. @@ -0,0 +1,119 @@
  558. +/*
  559. + * This file is part of the L2J Mobius project.
  560. + *
  561. + * This program is free software: you can redistribute it and/or modify
  562. + * it under the terms of the GNU General Public License as published by
  563. + * the Free Software Foundation, either version 3 of the License, or
  564. + * (at your option) any later version.
  565. + *
  566. + * This program is distributed in the hope that it will be useful,
  567. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  568. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  569. + * General Public License for more details.
  570. + *
  571. + * You should have received a copy of the GNU General Public License
  572. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  573. + */
  574. +package org.l2jmobius.gameserver.model.actor.instance;
  575. +
  576. +import org.l2jmobius.Config;
  577. +import org.l2jmobius.gameserver.data.ItemTable;
  578. +import org.l2jmobius.gameserver.model.actor.templates.NpcTemplate;
  579. +import org.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage;
  580. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  581. +import org.l2jmobius.gameserver.votesystem.Handler.voteManager;
  582. +import org.l2jmobius.gameserver.votesystem.Model.Reward;
  583. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  584. +
  585. +/**
  586. + * @author l2.topgameserver.net
  587. + */
  588. +public class NpcVoteRewardInstance extends NpcInstance
  589. +{
  590. +  
  591. +   /**
  592. +    * @param template
  593. +    */
  594. +   public NpcVoteRewardInstance(NpcTemplate template)
  595. +   {
  596. +       super(template);
  597. +   }
  598. +  
  599. +   @Override
  600. +   public void onBypassFeedback(PlayerInstance player, String command)
  601. +   {
  602. +       if (command == null)
  603. +       {
  604. +           return;
  605. +       }
  606. +       String Ordinalsite = command.split(" ")[1];
  607. +       if (!Util.isDigit(Ordinalsite))
  608. +       {
  609. +           return;
  610. +       }
  611. +       int or = Integer.parseInt(Ordinalsite);
  612. +       voteManager.getInatance().getReward(player, or);
  613. +       showChatWindow(player, 0);
  614. +       super.onBypassFeedback(player, command);
  615. +   }
  616. +  
  617. +   @Override
  618. +   public void showChatWindow(PlayerInstance player, int val)
  619. +   {
  620. +      
  621. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  622. +       StringBuilder sb = new StringBuilder();
  623. +       html.setFile(player, getHtmlPath(this.getTemplate().getId(), 0, player));
  624. +       if (Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE)
  625. +       {
  626. +           for (voteSite vs : voteSite.values())
  627. +           {
  628. +               sb.append("<table bgcolor=000000 width=280><tr>");
  629. +               sb.append("<td width=42><img src=\"icon.etc_treasure_box_i08\" width=32 height=32></td>");
  630. +               sb.append("<td width=220><table width=220>");
  631. +               sb.append("<tr><td><table width=220><tr><td width=145>On " + String.format("%s", ReadJson.getInstance().getSiteName(vs.ordinal())) + "</td>");
  632. +               if (voteManager.getInatance().checkIndividualAvailableVote(player, vs.ordinal()))
  633. +               {
  634. +                   sb.append("<td width=75>" + String.format("<button value=\"Get reward\" action=\"bypass -h vote_%s_site %s\" height=17 width=64 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">", getObjectId(), vs.ordinal()) + "</td>");
  635. +               }
  636. +               else
  637. +               {
  638. +                   sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(player, vs.ordinal())));
  639. +               }
  640. +               sb.append("</tr></table></td></tr>");
  641. +               sb.append("<tr><td><table width=220><tr>");
  642. +               int i = 0;
  643. +               for (Reward r : ReadJson.getInstance().getRewards(vs.ordinal()))
  644. +               {
  645. +                   sb.append(String.format("<td width=110 height=32 align=center><font color=BFAF00>%s x%s</font></td>", ItemTable.getInstance().getTemplate(r.getItemId()).getName(), r.getItemCount()));
  646. +                   i++;
  647. +                   if ((i % 2) == 0)
  648. +                   {
  649. +                       sb.append("</tr><tr>");
  650. +                   }
  651. +               }
  652. +               sb.append("</tr></table></td></tr></table></td></tr></table><br>");
  653. +           }
  654. +       }
  655. +       else
  656. +       {
  657. +           sb.append("<table bgcolor=000000 width=280><tr><td><p><font color=#bfb300 >Individual vote system has been disabled for your server owner.</font></p></td></tr></table>");
  658. +       }
  659. +       html.replace("%everyXtime%", Config.INTERVAL_TO_NEXT_VOTE / (3600 * 1000));
  660. +       html.replace("%enablevote%", sb.toString());
  661. +       html.replace("%accountName%", player.getName());
  662. +       player.sendPacket(html);
  663. +   }
  664. +  
  665. +   @Override
  666. +   public String getHtmlPath(int npcId, int val, PlayerInstance player)
  667. +   {
  668. +       String filename = "";
  669. +       if (val == 0)
  670. +       {
  671. +           filename = "" + npcId;
  672. +       }
  673. +       else
  674. +       {
  675. +           filename = npcId + "-" + val;
  676. +       }
  677. +      
  678. +       return "data/html/mods/votesystem/" + filename + ".html";
  679. +   }
  680. +  
  681. +}
  682. \ No newline at end of file
  683. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
  684. index 2be9992..ea42cad 100644
  685. --- a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
  686. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/network/clientpackets/RequestBypassToServer.java
  687. @@ -167,6 +167,30 @@
  688.                
  689.                 player.sendPacket(ActionFailed.STATIC_PACKET);
  690.             }
  691. +           else if (_command.startsWith("vote_"))
  692. +           {
  693. +              
  694. +               int endOfId = _command.indexOf('_', 6);
  695. +               String id;
  696. +               if (endOfId > 0)
  697. +               {
  698. +                   id = _command.substring(5, endOfId);
  699. +               }
  700. +               else
  701. +               {
  702. +                   id = _command.substring(5);
  703. +               }
  704. +              
  705. +               if (_command.split(" ")[1].toString() != null)
  706. +               {
  707. +                   final WorldObject object = World.getInstance().findObject(Integer.parseInt(id));
  708. +                   if ((object != null) && object.isNpc() && (endOfId > 0) && player.isInsideRadius2D(object, Npc.INTERACTION_DISTANCE))
  709. +                   {
  710. +                       ((Npc) object).onBypassFeedback(player, _command.substring(endOfId + 1));
  711. +                   }
  712. +               }
  713. +               player.sendPacket(ActionFailed.STATIC_PACKET);
  714. +           }
  715.             else if (_command.startsWith("item_"))
  716.             {
  717.                 final int endOfId = _command.indexOf('_', 5);
  718. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java
  719. new file mode 100644
  720. index 0000000..899b19c
  721. --- /dev/null
  722. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/DB/globalVoteDB.java
  723. @@ -0,0 +1,123 @@
  724. +package org.l2jmobius.gameserver.votesystem.DB;
  725. +
  726. +import java.sql.Connection;
  727. +import java.sql.PreparedStatement;
  728. +import java.sql.ResultSet;
  729. +import java.sql.SQLException;
  730. +import java.sql.Statement;
  731. +import java.util.logging.Logger;
  732. +
  733. +import org.l2jmobius.commons.database.DatabaseFactory;
  734. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  735. +import org.l2jmobius.gameserver.votesystem.Model.globalVote;
  736. +
  737. +/**
  738. + * @author l2.topgameserver.net
  739. + */
  740. +public class globalVoteDB
  741. +{
  742. +   public static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName());
  743. +   private Statement st;
  744. +   private Connection con;
  745. +   private final globalVote[] _globalVotes;
  746. +  
  747. +   private globalVoteDB()
  748. +   {
  749. +       _globalVotes = new globalVote[voteSite.values().length];
  750. +       loadGlobalVotes();
  751. +   }
  752. +  
  753. +   public void loadGlobalVotes()
  754. +   {
  755. +       con = DatabaseFactory.getConnection();
  756. +       try (PreparedStatement ps = con.prepareStatement("Select voteSite,lastRewardVotes from globalvotes");
  757. +           ResultSet rs = ps.executeQuery();)
  758. +       {
  759. +           if (rs.getRow() == 0)
  760. +           {
  761. +               for (voteSite vs : voteSite.values())
  762. +               {
  763. +                   globalVote gv = new globalVote();
  764. +                   gv.setVoteSite(vs.ordinal());
  765. +                   gv.setVotesLastReward(0);
  766. +                   _globalVotes[gv.getVoyeSite()] = gv;
  767. +               }
  768. +               return;
  769. +           }
  770. +           while (rs.next())
  771. +           {
  772. +               globalVote gv = new globalVote();
  773. +               gv.setVoteSite(rs.getInt("voteSite"));
  774. +               gv.setVotesLastReward(rs.getInt("lastRewardVotes"));
  775. +               _globalVotes[gv.getVoyeSite()] = gv;
  776. +           }
  777. +           ps.close();
  778. +           con.close();
  779. +          
  780. +       }
  781. +       catch (SQLException e)
  782. +       {
  783. +           e.printStackTrace();
  784. +       }
  785. +   }
  786. +  
  787. +   public void saveGlobalVote(globalVote gb)
  788. +   {
  789. +       try (Connection con = DatabaseFactory.getConnection();
  790. +           PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
  791. +      
  792. +       {
  793. +           ps.setInt(1, gb.getVoyeSite());
  794. +           ps.setInt(2, gb.getVotesLastReward());
  795. +           ps.executeUpdate();
  796. +          
  797. +           ps.close();
  798. +           con.close();
  799. +          
  800. +       }
  801. +       catch (SQLException e)
  802. +       {
  803. +           e.printStackTrace();
  804. +       }
  805. +   }
  806. +  
  807. +   public void saveGlobalVotes(globalVote[] globalVotes)
  808. +   {
  809. +       try (Connection con = DatabaseFactory.getConnection();
  810. +           PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
  811. +      
  812. +       {
  813. +           for (voteSite vs : voteSite.values())
  814. +           {
  815. +               globalVote gb = globalVotes[vs.ordinal()];
  816. +               ps.setInt(1, gb.getVoyeSite());
  817. +               ps.setInt(2, gb.getVotesLastReward());
  818. +               ps.addBatch();
  819. +           }
  820. +           ps.executeBatch();
  821. +          
  822. +           ps.close();
  823. +           con.close();
  824. +          
  825. +       }
  826. +       catch (SQLException e)
  827. +       {
  828. +           e.printStackTrace();
  829. +       }
  830. +   }
  831. +  
  832. +   public globalVote[] getGlobalVotes()
  833. +   {
  834. +       return _globalVotes;
  835. +   }
  836. +  
  837. +   public static final globalVoteDB getInstance()
  838. +   {
  839. +       return SingleHolder.INSTANCE;
  840. +   }
  841. +  
  842. +   private static final class SingleHolder
  843. +   {
  844. +       protected static final globalVoteDB INSTANCE = new globalVoteDB();
  845. +   }
  846. +}
  847. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java
  848. new file mode 100644
  849. index 0000000..fa9fbe1
  850. --- /dev/null
  851. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/DB/individualVoteDB.java
  852. @@ -0,0 +1,183 @@
  853. +package org.l2jmobius.gameserver.votesystem.DB;
  854. +
  855. +import java.sql.Connection;
  856. +import java.sql.PreparedStatement;
  857. +import java.sql.ResultSet;
  858. +import java.sql.SQLException;
  859. +import java.sql.Statement;
  860. +import java.util.HashMap;
  861. +import java.util.HashSet;
  862. +import java.util.Map;
  863. +import java.util.logging.Logger;
  864. +
  865. +import org.l2jmobius.commons.database.DatabaseFactory;
  866. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  867. +import org.l2jmobius.gameserver.votesystem.Model.individualVote;
  868. +
  869. +/**
  870. + * @author l2.topgameserver.net
  871. + */
  872. +public class individualVoteDB
  873. +{
  874. +   private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
  875. +   private final Map<String, individualVote[]> _votes;
  876. +   private Statement st;
  877. +   private Connection con;
  878. +  
  879. +   private individualVoteDB()
  880. +   {
  881. +       _votes = new HashMap<>();
  882. +       loadVotes();
  883. +   }
  884. +  
  885. +   public void loadVotes()
  886. +   {
  887. +      
  888. +       _votes.clear();
  889. +       try (Connection con = DatabaseFactory.getConnection();
  890. +           PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualvotes");
  891. +           ResultSet rs = ps.executeQuery();)
  892. +       {
  893. +           individualVote[] ivs = new individualVote[voteSite.values().length];
  894. +           while (rs.next())
  895. +           {
  896. +               individualVote iv = new individualVote();
  897. +               iv.setVoterIp(rs.getString("voterIp"));
  898. +               iv.setVoteSite(rs.getInt("voteSite"));
  899. +               iv.setDiffTime(rs.getLong("diffTime"));
  900. +               iv.setVotingTimeSite(rs.getLong("votingTimeSite"));
  901. +               iv.setAlreadyRewarded(rs.getBoolean("alreadyRewarded"));
  902. +              
  903. +               if (_votes.containsKey(iv.getVoterIp()))
  904. +               {
  905. +                   if (_votes.get(iv.getVoterIp())[iv.getVoteSite()] == null)
  906. +                   {
  907. +                       ivs[iv.getVoteSite()] = iv;
  908. +                       _votes.replace(iv.getVoterIp(), ivs);
  909. +                   }
  910. +               }
  911. +               else
  912. +               {
  913. +                   ivs[iv.getVoteSite()] = iv;
  914. +                   _votes.put(iv.getVoterIp(), ivs);
  915. +                  
  916. +               }
  917. +           }
  918. +          
  919. +       }
  920. +       catch (SQLException e)
  921. +       {
  922. +           e.printStackTrace();
  923. +       }
  924. +      
  925. +   }
  926. +  
  927. +   public void SaveVotes(Map<String, individualVote[]> votes)
  928. +   {
  929. +      
  930. +       if (votes == null)
  931. +       {
  932. +           return;
  933. +       }
  934. +       if (votes.size() == 0)
  935. +       {
  936. +           return;
  937. +       }
  938. +       try (Connection con = DatabaseFactory.getConnection();
  939. +           PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE " + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite),alreadyRewarded = VALUES(alreadyRewarded)");)
  940. +       {
  941. +          
  942. +           for (Map.Entry<String, individualVote[]> ivm : votes.entrySet())
  943. +           {
  944. +               for (individualVote iv : ivm.getValue())
  945. +               {
  946. +                   if (iv == null)
  947. +                   {
  948. +                       continue;
  949. +                   }
  950. +                   ps.setString(1, iv.getVoterIp());
  951. +                   ps.setInt(2, iv.getVoteSite());
  952. +                   ps.setLong(3, iv.getDiffTime());
  953. +                   ps.setLong(4, iv.getVotingTimeSite());
  954. +                   ps.setBoolean(5, iv.getAlreadyRewarded());
  955. +                   ps.addBatch();
  956. +               }
  957. +           }
  958. +           ps.executeBatch();
  959. +       }
  960. +       catch (SQLException e)
  961. +       {
  962. +           e.printStackTrace();
  963. +       }
  964. +   }
  965. +  
  966. +   public void SaveVote(individualVote vote)
  967. +   {
  968. +      
  969. +       if (vote == null)
  970. +       {
  971. +           return;
  972. +       }
  973. +      
  974. +       try (Connection con = DatabaseFactory.getConnection();
  975. +           PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE" + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");)
  976. +       {
  977. +           ps.setString(1, vote.getVoterIp());
  978. +           ps.setInt(2, vote.getVoteSite());
  979. +           ps.setLong(3, vote.getDiffTime());
  980. +           ps.setLong(4, vote.getVotingTimeSite());
  981. +           ps.setBoolean(5, vote.getAlreadyRewarded());
  982. +           ps.executeUpdate();
  983. +       }
  984. +       catch (SQLException e)
  985. +       {
  986. +           e.printStackTrace();
  987. +       }
  988. +   }
  989. +  
  990. +   public void DeleteVotes(HashSet<individualVote> deleteVotes)
  991. +   {
  992. +       if (deleteVotes == null)
  993. +       {
  994. +           return;
  995. +       }
  996. +       if (deleteVotes.size() == 0)
  997. +       {
  998. +           return;
  999. +       }
  1000. +       try
  1001. +       {
  1002. +           con = DatabaseFactory.getConnection();
  1003. +           st = con.createStatement();
  1004. +           for (individualVote iv : deleteVotes)
  1005. +           {
  1006. +               String sql = String.format("Delete from individualvotes where voterIp = '%s' AND voteSite = %s", iv.getVoterIp(), iv.getVoteSite());
  1007. +               st.addBatch(sql);
  1008. +           }
  1009. +           int[] result = st.executeBatch();
  1010. +           st.close();
  1011. +           con.close();
  1012. +           LOGGER.info(result.length + " Innecesary votes has been deleted");
  1013. +          
  1014. +       }
  1015. +       catch (SQLException e)
  1016. +       {
  1017. +           e.printStackTrace();
  1018. +       }
  1019. +   }
  1020. +  
  1021. +   public Map<String, individualVote[]> getVotesDB()
  1022. +   {
  1023. +       return _votes;
  1024. +   }
  1025. +  
  1026. +   public static final individualVoteDB getInstance()
  1027. +   {
  1028. +       return SingleHolder.INSTANCE;
  1029. +   }
  1030. +  
  1031. +   private static final class SingleHolder
  1032. +   {
  1033. +       protected static final individualVoteDB INSTANCE = new individualVoteDB();
  1034. +   }
  1035. +}
  1036. \ No newline at end of file
  1037. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java
  1038. new file mode 100644
  1039. index 0000000..9218452
  1040. --- /dev/null
  1041. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Enum/voteSite.java
  1042. @@ -0,0 +1,19 @@
  1043. +package org.l2jmobius.gameserver.votesystem.Enum;
  1044. +
  1045. +/**
  1046. + * @author l2.topgameserver.net
  1047. + */
  1048. +public enum voteSite
  1049. +{
  1050. +   L2TOPGAMESERVER, // 0
  1051. +   ITOPZ, // 1
  1052. +   L2TOPCO, // 2
  1053. +   L2VOTES, // 3
  1054. +   HOPZONE, // 4
  1055. +   L2NETWORK, // 5
  1056. +   L2TOPSERVERS, // 6
  1057. +   TOPL2JBRASIL, // 7
  1058. +   MMOTOP, // 8
  1059. +   TOPZONE, // 9
  1060. +   L2SERVERS,// 10
  1061. +}
  1062. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java
  1063. new file mode 100644
  1064. index 0000000..3119aa5
  1065. --- /dev/null
  1066. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Handler/voteHandler.java
  1067. @@ -0,0 +1,509 @@
  1068. +package org.l2jmobius.gameserver.votesystem.Handler;
  1069. +
  1070. +import java.io.BufferedReader;
  1071. +import java.io.DataOutputStream;
  1072. +import java.io.InputStreamReader;
  1073. +import java.net.HttpURLConnection;
  1074. +import java.net.URL;
  1075. +import java.nio.charset.Charset;
  1076. +import java.text.ParseException;
  1077. +import java.text.SimpleDateFormat;
  1078. +import java.util.logging.Logger;
  1079. +
  1080. +import org.l2jmobius.Config;
  1081. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  1082. +import org.l2jmobius.gameserver.votesystem.Model.individualVoteResponse;
  1083. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  1084. +import org.l2jmobius.gameserver.votesystem.VoteUtil.VoteUtil;
  1085. +
  1086. +/**
  1087. + * @author l2.topgameserver.net
  1088. + */
  1089. +public class voteHandler
  1090. +{
  1091. +   public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
  1092. +  
  1093. +   protected static String getNetWorkResponse(String URL, int ordinal)
  1094. +   {
  1095. +       if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
  1096. +       {
  1097. +           return "";
  1098. +       }
  1099. +      
  1100. +       StringBuffer response = new StringBuffer();
  1101. +       try
  1102. +       {
  1103. +           String API_URL = Config.VOTE_NETWORK_LINK;
  1104. +           String detail = URL;
  1105. +           String postParameters = "";
  1106. +           postParameters += "apiKey=" + VoteUtil.between("apiKey=", detail, "&type=");
  1107. +           postParameters += "&type=" + VoteUtil.between("&type=", detail, "&player");
  1108. +           String beginIndexPlayer = "&player=";
  1109. +           String player = detail.substring(detail.indexOf(beginIndexPlayer) + beginIndexPlayer.length());
  1110. +          
  1111. +           if ((player != null) && !player.equals(""))
  1112. +           {
  1113. +               postParameters += "&player=" + player;
  1114. +           }
  1115. +          
  1116. +           byte[] postData = postParameters.getBytes(Charset.forName("UTF-8"));
  1117. +           URL url = new URL(API_URL);
  1118. +           HttpURLConnection con = (HttpURLConnection) url.openConnection();
  1119. +           con.setConnectTimeout(5000);
  1120. +           con.setRequestMethod("POST");
  1121. +           con.setRequestProperty("Content-Length", Integer.toString(postData.length));
  1122. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  1123. +           con.setDoOutput(true);
  1124. +          
  1125. +           DataOutputStream os = new DataOutputStream(con.getOutputStream());
  1126. +           os.write(postData);
  1127. +           os.flush();
  1128. +           os.close();
  1129. +          
  1130. +           BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  1131. +           String inputLine;
  1132. +          
  1133. +           while ((inputLine = in.readLine()) != null)
  1134. +           {
  1135. +               response.append(inputLine);
  1136. +           }
  1137. +           in.close();
  1138. +          
  1139. +           return response.toString();
  1140. +          
  1141. +       }
  1142. +       catch (Exception e)
  1143. +       {
  1144. +           LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getCause());
  1145. +           return "";
  1146. +       }
  1147. +   }
  1148. +  
  1149. +   protected static String getResponse(String Url, int ordinal)
  1150. +   {
  1151. +       if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
  1152. +       {
  1153. +           return "";
  1154. +       }
  1155. +      
  1156. +       try
  1157. +       {
  1158. +           int responseCode = 0;
  1159. +           URL objUrl = new URL(Url);
  1160. +           HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
  1161. +           con.setRequestMethod("GET");
  1162. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  1163. +           con.setConnectTimeout(5000);
  1164. +           responseCode = con.getResponseCode();
  1165. +           if (responseCode == HttpURLConnection.HTTP_OK)
  1166. +           {
  1167. +               String inputLine;
  1168. +               StringBuffer response = new StringBuffer();
  1169. +               BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  1170. +               while ((inputLine = in.readLine()) != null)
  1171. +               {
  1172. +                   response.append(inputLine);
  1173. +               }
  1174. +               in.close();
  1175. +               return response.toString();
  1176. +           }
  1177. +          
  1178. +       }
  1179. +       catch (Exception e)
  1180. +       {
  1181. +           LOGGER.warning(ReadJson.getInstance().getSiteName(ordinal) + " Say: An error ocurred " + e.getCause());
  1182. +           return "";
  1183. +       }
  1184. +      
  1185. +       return "";
  1186. +   }
  1187. +  
  1188. +   public static individualVoteResponse getIndividualVoteResponse(int ordinal, String ip, String AccountName)
  1189. +   {
  1190. +       String response = "";
  1191. +       boolean isVoted = false;
  1192. +       long voteSiteTime = 0L, diffTime = 0L;
  1193. +       SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  1194. +       individualVoteResponse ivr = new individualVoteResponse();
  1195. +      
  1196. +       switch (ordinal)
  1197. +       {
  1198. +           case 0:
  1199. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1200. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"already_voted\":", response, ",\"vote_time\""));
  1201. +               if (isVoted)
  1202. +               {
  1203. +                   try
  1204. +                   {
  1205. +                       voteSiteTime = format.parse(VoteUtil.between("\"vote_time\":\"", response, "\",\"server_time\"")).getTime();
  1206. +                       diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"server_time\":\"", response, "\"}")).getTime();
  1207. +                   }
  1208. +                   catch (ParseException e)
  1209. +                   {
  1210. +                       e.printStackTrace();
  1211. +                   }
  1212. +               }
  1213. +               break;
  1214. +          
  1215. +           case 1:
  1216. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1217. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isvoted\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"votetime").replaceAll("\"", ""));
  1218. +               if (isVoted)
  1219. +               {
  1220. +                   try
  1221. +                   {
  1222. +                       voteSiteTime = (Long.parseLong(VoteUtil.between("\"votetime\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"servertime"))) * 1000;
  1223. +                       diffTime = System.currentTimeMillis() - ((Long.parseLong(VoteUtil.between("\"servertime\":", response.toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), "}"))) * 1000);
  1224. +                   }
  1225. +                   catch (Exception e)
  1226. +                   {
  1227. +                       e.printStackTrace();
  1228. +                   }
  1229. +               }
  1230. +               break;
  1231. +          
  1232. +           case 2:
  1233. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1234. +               isVoted = (response == "") ? false : Boolean.parseBoolean(response);
  1235. +               if (isVoted)
  1236. +               {
  1237. +                   voteSiteTime = System.currentTimeMillis();
  1238. +                   diffTime = 0;
  1239. +               }
  1240. +               break;
  1241. +          
  1242. +           case 3:
  1243. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1244. +               isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"date\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"date\"")) == 1)) ? true : false;
  1245. +               if (isVoted)
  1246. +               {
  1247. +                   String dateString = VoteUtil.between("\"date\":\"", response, "\"}]");
  1248. +                   try
  1249. +                   {
  1250. +                       voteSiteTime = System.currentTimeMillis();
  1251. +                       diffTime = 0;
  1252. +                   }
  1253. +                   catch (Exception e)
  1254. +                   {
  1255. +                       e.printStackTrace();
  1256. +                   }
  1257. +                  
  1258. +               }
  1259. +               break;
  1260. +          
  1261. +           case 4:
  1262. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1263. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
  1264. +               if (isVoted)
  1265. +               {
  1266. +                   try
  1267. +                   {
  1268. +                       voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"hopzoneServerTime\"")).getTime();
  1269. +                       diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"hopzoneServerTime\":\"", response, "\",\"status_code\":")).getTime();
  1270. +                   }
  1271. +                   catch (ParseException e)
  1272. +                   {
  1273. +                       e.printStackTrace();
  1274. +                   }
  1275. +               }
  1276. +               break;
  1277. +          
  1278. +           case 5:
  1279. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1280. +               isVoted = (!"".equals(response) && (Integer.parseInt(response) == 1)) ? true : false;
  1281. +               if (isVoted)
  1282. +               {
  1283. +                   voteSiteTime = System.currentTimeMillis();
  1284. +                   diffTime = 0;
  1285. +               }
  1286. +               break;
  1287. +          
  1288. +           case 6:
  1289. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1290. +               isVoted = ("".equals(response)) ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
  1291. +               if (isVoted)
  1292. +               {
  1293. +                   try
  1294. +                   {
  1295. +                       voteSiteTime = System.currentTimeMillis();
  1296. +                       diffTime = 0;
  1297. +                   }
  1298. +                   catch (Exception e)
  1299. +                   {
  1300. +                       e.printStackTrace();
  1301. +                   }
  1302. +                  
  1303. +               }
  1304. +               break;
  1305. +          
  1306. +           case 7:
  1307. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1308. +               isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"server_time\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1)) ? true : false;
  1309. +               if (isVoted)
  1310. +               {
  1311. +                   try
  1312. +                   {
  1313. +                       voteSiteTime = System.currentTimeMillis();
  1314. +                       diffTime = 0;
  1315. +                   }
  1316. +                   catch (Exception e)
  1317. +                   {
  1318. +                       e.printStackTrace();
  1319. +                   }
  1320. +               }
  1321. +               break;
  1322. +          
  1323. +           case 8:
  1324. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1325. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"is_voted\":", response, ",\"vote_time\""));
  1326. +               if (isVoted)
  1327. +               {
  1328. +                   try
  1329. +                   {
  1330. +                       voteSiteTime = (Long.parseLong(VoteUtil.between("\"vote_time\":", response, ",\"server_time\""))) * 1000;
  1331. +                       diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"server_time\":", response, "}}")) * 1000);
  1332. +                   }
  1333. +                   catch (Exception e)
  1334. +                   {
  1335. +                       e.printStackTrace();
  1336. +                   }
  1337. +               }
  1338. +               break;
  1339. +          
  1340. +           case 9:
  1341. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1342. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isVoted\": ", response, ",\"voteTime\""));
  1343. +               if (isVoted)
  1344. +               {
  1345. +                   voteSiteTime = Long.parseLong(VoteUtil.between("\"voteTime\": \"", response, "\",\"serverTime\"")) * 1000;
  1346. +                   diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"serverTime\": ", response, "}}")) * 1000);
  1347. +               }
  1348. +               break;
  1349. +          
  1350. +           case 10:
  1351. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1352. +               isVoted = (response == "") ? false : Boolean.parseBoolean(response);
  1353. +               if (isVoted)
  1354. +               {
  1355. +                   voteSiteTime = System.currentTimeMillis();
  1356. +                   diffTime = 0;
  1357. +               }
  1358. +               break;
  1359. +          
  1360. +       }
  1361. +       if (!response.equals(""))
  1362. +       {
  1363. +           ivr.setIsVoted(isVoted);
  1364. +           ivr.setDiffTime(diffTime);
  1365. +           ivr.setVoteSiteTime(voteSiteTime);
  1366. +           return ivr;
  1367. +       }
  1368. +       return null;
  1369. +   }
  1370. +  
  1371. +   public int getGlobalVotesResponse(int ordinal)
  1372. +   {
  1373. +      
  1374. +       String response = "";
  1375. +       int totalVotes = 0;
  1376. +      
  1377. +       switch (ordinal)
  1378. +       {
  1379. +           case 0:
  1380. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1381. +               response = VoteUtil.between("\"getVotes\":", response, "}");
  1382. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1383. +               break;
  1384. +          
  1385. +           case 1:
  1386. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1387. +               response = VoteUtil.between("server_votes\":", response.replace(" ", ""), ",\"server_rank");
  1388. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1389. +               break;
  1390. +          
  1391. +           case 2:
  1392. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1393. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1394. +               break;
  1395. +          
  1396. +           case 3:
  1397. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1398. +               response = VoteUtil.between("Votes:</th><th><a class='votes'>", response, "</a></th></tr><tr><th>Clicks:");
  1399. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1400. +               break;
  1401. +          
  1402. +           case 4:
  1403. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1404. +               response = VoteUtil.between("\"totalvotes\":", response, ",\"status_code\"");
  1405. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1406. +               break;
  1407. +          
  1408. +           case 5:
  1409. +               String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal), ordinal);
  1410. +               totalVotes = (!"".equals(responseNetwork)) ? Integer.parseInt(responseNetwork) : -1;
  1411. +               break;
  1412. +          
  1413. +           case 6:
  1414. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1415. +               response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>");
  1416. +              
  1417. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1418. +               break;
  1419. +          
  1420. +           case 7:
  1421. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1422. +               response = VoteUtil.between("nicas:</b> ", response, "<br /><br />");
  1423. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1424. +               break;
  1425. +          
  1426. +           case 8:
  1427. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1428. +               response = VoteUtil.between("\"monthly_votes\":", response, "}}");
  1429. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1430. +               break;
  1431. +          
  1432. +           case 9:
  1433. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1434. +               response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\"");
  1435. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1436. +               break;
  1437. +          
  1438. +           case 10:
  1439. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1440. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1441. +               break;
  1442. +       }
  1443. +      
  1444. +       return totalVotes;
  1445. +   }
  1446. +  
  1447. +   public static String getIndividualUrl(int ordinal, String ip, String AccountName)
  1448. +   {
  1449. +       String url = "";
  1450. +       ip = (Config.TEST_IP.equalsIgnoreCase("off") || Config.TEST_IP.equalsIgnoreCase("")) ? ip : Config.TEST_IP;
  1451. +       switch (ordinal)
  1452. +       {
  1453. +           case 0:
  1454. +               // l2.topgameserver.net
  1455. +               url = String.format("%sAPI_KEY=%s/getData/%s", Config.VOTE_LINK_TGS, Config.TGS_API_KEY, ip);
  1456. +               break;
  1457. +          
  1458. +           case 1:
  1459. +               // itopz.com
  1460. +               url = String.format("%s%s/%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID, ip);
  1461. +               break;
  1462. +          
  1463. +           case 2:
  1464. +               // l2top.co
  1465. +               url = String.format("%sVoteCheck.php?id=%s&ip=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID, ip);
  1466. +               break;
  1467. +          
  1468. +           case 3:
  1469. +               // l2votes.com
  1470. +               url = String.format("%sapi.php?apiKey=%s&ip=%s", Config.VOTE_LINK_VTS, Config.VTS_API_KEY, ip);
  1471. +               break;
  1472. +          
  1473. +           case 4:
  1474. +               // hopzone.net
  1475. +               url = String.format("%svote?token=%s&ip_address=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY, ip);
  1476. +               break;
  1477. +          
  1478. +           case 5:
  1479. +               // l2network.eu
  1480. +               url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_USER_NAME, ip);
  1481. +               break;
  1482. +          
  1483. +           case 6:
  1484. +               // l2topservers.com
  1485. +               url = String.format("%stoken=%s&ip=%s", Config.VOTE_LINK_TSS, Config.TSS_API_TOKEN, ip);
  1486. +               break;
  1487. +          
  1488. +           case 7:
  1489. +               // top.l2jbrasil.com
  1490. +               url = String.format("%susername=%s&ip=%s&type=json", Config.BRASIL_VOTE_LINK, Config.BRASIL_USER_NAME, ip);
  1491. +               break;
  1492. +          
  1493. +           case 8:
  1494. +               // mmotop
  1495. +               url = String.format("%s%s/ip/%s", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY, ip);
  1496. +               break;
  1497. +          
  1498. +           case 9:
  1499. +               // topzone.com
  1500. +               url = String.format("%svote?token=%s&ip=%s", Config.VOTE_LINK_TZ, Config.TZ_API_KEY, ip);
  1501. +               break;
  1502. +          
  1503. +           case 10:
  1504. +               // l2servers.com
  1505. +               url = String.format("%scheckip.php?hash=%s&server_id=%s&ip=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_HASH_CODE, Config.SERVERS_SRV_ID, ip);
  1506. +               break;
  1507. +       }
  1508. +      
  1509. +       return url;
  1510. +   }
  1511. +  
  1512. +   public String getGlobalUrl(int ordinal)
  1513. +   {
  1514. +       String url = "";
  1515. +      
  1516. +       switch (ordinal)
  1517. +       {
  1518. +           case 0:
  1519. +               // l2.topgameserver.net
  1520. +               url = String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS, Config.TGS_API_KEY);
  1521. +               break;
  1522. +          
  1523. +           case 1:
  1524. +               // itopz.com
  1525. +               url = String.format("%s%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID);
  1526. +               break;
  1527. +          
  1528. +           case 2:
  1529. +               // l2top.co
  1530. +               url = String.format("%sVoteCheck_Total.php?id=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID);
  1531. +               break;
  1532. +          
  1533. +           case 3:
  1534. +               // l2votes.com
  1535. +               url = String.format("%sserverPage.php?sid=%s", Config.VOTE_LINK_VTS, Config.VTS_SID);
  1536. +               break;
  1537. +          
  1538. +           case 4:
  1539. +               // hopzone.net
  1540. +               url = String.format("%svotes?token=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY);
  1541. +               break;
  1542. +          
  1543. +           case 5:
  1544. +               // l2network.eu
  1545. +               url = String.format("apiKey=%s&type=%s&player=", Config.VOTE_NETWORK_API_KEY, 1);
  1546. +               break;
  1547. +          
  1548. +           case 6:
  1549. +               // l2topservers
  1550. +               url = String.format("https://l2topservers.com/l2top/%s/%s", Config.TS_SRV_ID, Config.TS_DOMAIN_NAME);
  1551. +               break;
  1552. +          
  1553. +           case 7:
  1554. +               // top.l2jbrasil.com
  1555. +               url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s", Config.BRASIL_USER_NAME);
  1556. +               break;
  1557. +          
  1558. +           case 8:
  1559. +               // mmotop.eu/l2/
  1560. +               url = String.format("%s%s/info/", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY);
  1561. +               break;
  1562. +          
  1563. +           case 9:
  1564. +               // l2topzone.com
  1565. +               url = String.format("%sserver_%s/getServerData", Config.VOTE_LINK_TZ, Config.TZ_API_KEY);
  1566. +               break;
  1567. +          
  1568. +           case 10:
  1569. +               // l2servers.com
  1570. +               url = String.format("%syearlyvotes.php?server_id=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_SRV_ID);
  1571. +               break;
  1572. +       }
  1573. +      
  1574. +       return url;
  1575. +   }
  1576. +}
  1577. \ No newline at end of file
  1578. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java
  1579. new file mode 100644
  1580. index 0000000..27aee71
  1581. --- /dev/null
  1582. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Handler/voteManager.java
  1583. @@ -0,0 +1,395 @@
  1584. +package org.l2jmobius.gameserver.votesystem.Handler;
  1585. +
  1586. +import java.util.HashSet;
  1587. +import java.util.Map;
  1588. +import java.util.concurrent.ConcurrentHashMap;
  1589. +import java.util.concurrent.ScheduledFuture;
  1590. +
  1591. +import org.l2jmobius.Config;
  1592. +import org.l2jmobius.commons.concurrent.ThreadPool;
  1593. +import org.l2jmobius.gameserver.model.World;
  1594. +import org.l2jmobius.gameserver.model.actor.instance.PlayerInstance;
  1595. +import org.l2jmobius.gameserver.network.GameClient;
  1596. +import org.l2jmobius.gameserver.network.SystemMessageId;
  1597. +import org.l2jmobius.gameserver.network.serverpackets.ItemList;
  1598. +import org.l2jmobius.gameserver.network.serverpackets.SystemMessage;
  1599. +import org.l2jmobius.gameserver.util.Broadcast;
  1600. +import org.l2jmobius.gameserver.votesystem.DB.globalVoteDB;
  1601. +import org.l2jmobius.gameserver.votesystem.DB.individualVoteDB;
  1602. +import org.l2jmobius.gameserver.votesystem.Enum.voteSite;
  1603. +import org.l2jmobius.gameserver.votesystem.Model.Reward;
  1604. +import org.l2jmobius.gameserver.votesystem.Model.globalVote;
  1605. +import org.l2jmobius.gameserver.votesystem.Model.individualVote;
  1606. +import org.l2jmobius.gameserver.votesystem.Model.individualVoteResponse;
  1607. +import org.l2jmobius.gameserver.votesystem.VoteUtil.ReadJson;
  1608. +import org.l2jmobius.gameserver.votesystem.VoteUtil.VoteUtil;
  1609. +
  1610. +/**
  1611. + * @author l2.topgameserver.net
  1612. + */
  1613. +public final class voteManager extends voteHandler
  1614. +{
  1615. +   private ScheduledFuture<?> _saveGlobalVotes;
  1616. +   private ScheduledFuture<?> _updateIndividualVotes;
  1617. +   private ScheduledFuture<?> _autoGlobalVotesReward;
  1618. +  
  1619. +   private HashSet<individualVote> _votes;
  1620. +   private Map<String, individualVote[]> _foundVoters;
  1621. +   private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
  1622. +  
  1623. +   public voteManager()
  1624. +   {
  1625. +       _foundVoters = new ConcurrentHashMap<>();
  1626. +       loadVotes();
  1627. +       loadGlobalVotes();
  1628. +       checkAllResponseGlobalVotes();
  1629. +       stopAutoTasks();
  1630. +      
  1631. +       if (Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
  1632. +       {
  1633. +           _updateIndividualVotes = ThreadPool.scheduleAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES);
  1634. +       }
  1635. +       if (Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
  1636. +       {
  1637. +           _autoGlobalVotesReward = ThreadPool.scheduleAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD);
  1638. +           _saveGlobalVotes = ThreadPool.scheduleAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE);
  1639. +       }
  1640. +   }
  1641. +  
  1642. +   private void stopAutoTasks()
  1643. +   {
  1644. +       if (_saveGlobalVotes != null)
  1645. +       {
  1646. +           _saveGlobalVotes.cancel(true);
  1647. +           _saveGlobalVotes = null;
  1648. +       }
  1649. +       if (_updateIndividualVotes != null)
  1650. +       {
  1651. +           _updateIndividualVotes.cancel(true);
  1652. +           _updateIndividualVotes = null;
  1653. +       }
  1654. +       if (_autoGlobalVotesReward != null)
  1655. +       {
  1656. +           _autoGlobalVotesReward.cancel(true);
  1657. +           _autoGlobalVotesReward = null;
  1658. +       }
  1659. +   }
  1660. +  
  1661. +   public void getReward(PlayerInstance player, int ordinalSite)
  1662. +   {
  1663. +       String ip = existIp(player);
  1664. +       if (ip == null)
  1665. +       {
  1666. +           return;
  1667. +       }
  1668. +       individualVoteResponse ivr = getIndividualVoteResponse(ordinalSite, ip, player.getAccountName());
  1669. +       if (ivr == null)
  1670. +       {
  1671. +           player.sendMessage("We were unable to verify your vote with: " + ReadJson.getInstance().getSiteName(ordinalSite) + ", please try again");
  1672. +           return;
  1673. +       }
  1674. +
  1675. +       if (getTimeRemaining(new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false)) < 0)
  1676. +       {
  1677. +           player.sendMessage("We were unable to verify your vote with: " + ReadJson.getInstance().getRecordSite(ordinalSite).getSiteName() + ", please try again");
  1678. +           return;
  1679. +       }
  1680. +       if (!ivr.getIsVoted())
  1681. +       {
  1682. +           player.sendMessage(String.format("You haven't vote on %s yet!", ReadJson.getInstance().getSiteName(ordinalSite)));
  1683. +           return;
  1684. +       }
  1685. +       if (!checkIndividualAvailableVote(player, ordinalSite))
  1686. +       {
  1687. +           player.sendMessage(String.format("You can get the reward again on %s at %s", ReadJson.getInstance().getSiteName(ordinalSite), getTimeRemainingWithSampleFormat(player, ordinalSite)));
  1688. +           return;
  1689. +       }
  1690. +       individualVote iv = new individualVote(ip, ivr.getDiffTime(), ivr.getVoteSiteTime(), ordinalSite, false);
  1691. +      
  1692. +       individualVote[] aiv;
  1693. +       if (!_foundVoters.containsKey(ip))
  1694. +       {
  1695. +           aiv = new individualVote[voteSite.values().length];
  1696. +           iv.setAlreadyRewarded(true);
  1697. +           aiv[ordinalSite] = iv;
  1698. +           _foundVoters.put(ip, aiv);
  1699. +       }
  1700. +       else
  1701. +       {
  1702. +           aiv = _foundVoters.get(ip);
  1703. +           iv.setAlreadyRewarded(true);
  1704. +           aiv[ordinalSite] = iv;
  1705. +           _foundVoters.replace(ip, aiv);
  1706. +          
  1707. +       }
  1708. +       for (Reward reward : ReadJson.getInstance().getRewards(ordinalSite))
  1709. +       {
  1710. +           player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null);
  1711. +           player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S).addItemName(reward.getItemId()).addInt(reward.getItemCount()));
  1712. +       }
  1713. +       player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", ReadJson.getInstance().getSiteName(ordinalSite)));
  1714. +       player.sendPacket(new ItemList(1, player));
  1715. +       player.sendPacket(new ItemList(2, player));
  1716. +   }
  1717. +  
  1718. +   public boolean checkIndividualAvailableVote(PlayerInstance player, int ordinalSite)
  1719. +   {
  1720. +       String ip = existIp(player);
  1721. +       if (_foundVoters.containsKey(ip))
  1722. +       {
  1723. +           individualVote[] ivs = _foundVoters.get(ip);
  1724. +           if (ivs[ordinalSite] == null)
  1725. +           {
  1726. +               return true;
  1727. +           }
  1728. +           if (ivs[ordinalSite] != null)
  1729. +           {
  1730. +               individualVote iv = ivs[ordinalSite];
  1731. +               if (getTimeRemaining(iv) < 0)
  1732. +               {
  1733. +                   return true;
  1734. +               }
  1735. +           }
  1736. +       }
  1737. +       else
  1738. +       {
  1739. +           return true;
  1740. +       }
  1741. +      
  1742. +       return false;
  1743. +   }
  1744. +  
  1745. +   public long getTimeRemaining(individualVote iv)
  1746. +   {
  1747. +       long timeRemaining = 0L;
  1748. +       timeRemaining = ((iv.getVotingTimeSite() + Config.INTERVAL_TO_NEXT_VOTE) - ((iv.getDiffTime() > 0) ? (System.currentTimeMillis() + iv.getDiffTime()) : (System.currentTimeMillis() - iv.getDiffTime())));
  1749. +       return timeRemaining;
  1750. +   }
  1751. +  
  1752. +   public String getTimeRemainingWithSampleFormat(PlayerInstance player, int ordinalSite)
  1753. +   {
  1754. +       String ip = existIp(player);
  1755. +       String timeRemainingWithSampleFormat = "";
  1756. +       if (_foundVoters.containsKey(ip))
  1757. +       {
  1758. +           individualVote[] ivs = _foundVoters.get(ip);
  1759. +           if (ivs[ordinalSite] != null)
  1760. +           {
  1761. +               individualVote iv = ivs[ordinalSite];
  1762. +               long timeRemaining = getTimeRemaining(iv);
  1763. +               if (timeRemaining > 0)
  1764. +               {
  1765. +                   timeRemainingWithSampleFormat = CalculateTimeRemainingWithSampleDateFormat(timeRemaining);
  1766. +                   return timeRemainingWithSampleFormat;
  1767. +               }
  1768. +           }
  1769. +       }
  1770. +       return timeRemainingWithSampleFormat;
  1771. +   }
  1772. +  
  1773. +   public String CalculateTimeRemainingWithSampleDateFormat(long timeRemaining)
  1774. +   {
  1775. +       long t = timeRemaining / 1000;
  1776. +       int hours = Math.round(((t / 3600) % 24));
  1777. +       int minutes = Math.round((t / 60) % 60);
  1778. +       int seconds = Math.round(t % 60);
  1779. +       return String.format("%sH:%sm:%ss", hours, minutes, seconds);
  1780. +   }
  1781. +  
  1782. +   public String existIp(PlayerInstance p)
  1783. +   {
  1784. +      
  1785. +       GameClient client = p.getClient();
  1786. +       if ((client.getConnectionAddress() != null) && (client.getPlayer() != null) && !client.isDetached())
  1787. +       {
  1788. +           try
  1789. +           {
  1790. +               return client.getConnectionAddress().getHostAddress();
  1791. +           }
  1792. +           catch (Exception e)
  1793. +           {
  1794. +               e.printStackTrace();
  1795. +           }
  1796. +       }
  1797. +       return null;
  1798. +      
  1799. +   }
  1800. +  
  1801. +   public final void loadVotes()
  1802. +   {
  1803. +       _foundVoters = individualVoteDB.getInstance().getVotesDB();
  1804. +   }
  1805. +  
  1806. +   protected void loadGlobalVotes()
  1807. +   {
  1808. +       _globalVotes = globalVoteDB.getInstance().getGlobalVotes();
  1809. +   }
  1810. +  
  1811. +   public void saveVotes()
  1812. +   {
  1813. +       individualVoteDB.getInstance().SaveVotes(_foundVoters);
  1814. +   }
  1815. +  
  1816. +   protected void AutoGlobalVoteReward()
  1817. +   {
  1818. +       HashSet<String> ipList = new HashSet<>();
  1819. +       for (voteSite vs : voteSite.values())
  1820. +       {
  1821. +          
  1822. +           new Thread(() ->
  1823. +           {
  1824. +               checkNewUpdate(vs.ordinal());
  1825. +               if (_globalVotes[vs.ordinal()].getCurrentVotes() >= (_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)))
  1826. +               {
  1827. +                   _globalVotes[vs.ordinal()].setVotesLastReward(_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD));
  1828. +                   for (PlayerInstance player : World.getInstance().getPlayers())
  1829. +                   {
  1830. +                       String ip = existIp(player);
  1831. +                       if (ip == null)
  1832. +                       {
  1833. +                           continue;
  1834. +                       }
  1835. +                       if (ipList.contains(ip))
  1836. +                       {
  1837. +                           continue;
  1838. +                       }
  1839. +                       for (Reward reward : ReadJson.getInstance().getRewards(11))
  1840. +                       {
  1841. +                           player.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), player, null);
  1842. +                           player.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_EARNED_S2_S1_S).addItemName(reward.getItemId()).addInt(reward.getItemCount()));
  1843. +                       }
  1844. +                       ipList.add(ip);
  1845. +                       player.sendPacket(new ItemList(1, player));
  1846. +                       player.sendPacket(new ItemList(2, player));
  1847. +                   }
  1848. +                   Broadcast.toAllOnlinePlayers(VoteUtil.Sites[vs.ordinal()] + ": All players has been rewarded, please check your inventory", true);
  1849. +               }
  1850. +               else
  1851. +               {
  1852. +                   String encourage = "";
  1853. +                   int nextReward = _globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
  1854. +                   encourage = String.format("Vote for %s current Votes: %s, next quantity of votes to reward : %s, need votes to next reward: %s", VoteUtil.Sites[vs.ordinal()], _globalVotes[vs.ordinal()].getCurrentVotes(), nextReward, nextReward - _globalVotes[vs.ordinal()].getCurrentVotes());
  1855. +                   Broadcast.toAllOnlinePlayers(encourage, true);
  1856. +               }
  1857. +           }).start();
  1858. +          
  1859. +       }
  1860. +   }
  1861. +  
  1862. +   protected void AutoSaveGlobalVotes()
  1863. +   {
  1864. +       globalVoteDB.getInstance().saveGlobalVotes(_globalVotes);
  1865. +   }
  1866. +  
  1867. +   protected synchronized void AutoUpdateIndividualVotes()
  1868. +   {
  1869. +       AutoCleanInnecesaryIndividualVotes();
  1870. +       individualVoteDB.getInstance().SaveVotes(_foundVoters);
  1871. +   }
  1872. +  
  1873. +   protected synchronized void AutoCleanInnecesaryIndividualVotes()
  1874. +   {
  1875. +       HashSet<individualVote> removeVotes = new HashSet<>();
  1876. +       for (Map.Entry<String, individualVote[]> ivs : _foundVoters.entrySet())
  1877. +       {
  1878. +           for (individualVote individualvote : ivs.getValue())
  1879. +           {
  1880. +               if (individualvote == null)
  1881. +               {
  1882. +                   continue;
  1883. +               }
  1884. +               if (getTimeRemaining(individualvote) < 0)
  1885. +               {
  1886. +                   removeVotes.add(individualvote);
  1887. +                   if (_foundVoters.containsKey(individualvote.getVoterIp()))
  1888. +                   {
  1889. +                       if (_foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] != null)
  1890. +                       {
  1891. +                           _foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] = null;
  1892. +                       }
  1893. +                   }
  1894. +               }
  1895. +           }
  1896. +       }
  1897. +       individualVoteDB.getInstance().DeleteVotes(removeVotes);
  1898. +   }
  1899. +  
  1900. +   public void checkAllResponseGlobalVotes()
  1901. +   {
  1902. +       for (voteSite vs : voteSite.values())
  1903. +       {
  1904. +           new Thread(() ->
  1905. +           {
  1906. +               checkNewUpdate(vs.ordinal());
  1907. +           });
  1908. +       }
  1909. +   }
  1910. +  
  1911. +   public void checkNewUpdate(int ordinalSite)
  1912. +   {
  1913. +       int globalVotesResponse = getGlobalVotesResponse(ordinalSite);
  1914. +       if (globalVotesResponse == -1)
  1915. +       {
  1916. +           return;
  1917. +       }
  1918. +       _globalVotes[ordinalSite].setCurrentVotes(globalVotesResponse);
  1919. +       int last = globalVotesResponse - (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
  1920. +       if (last < 0)
  1921. +       {
  1922. +           _globalVotes[ordinalSite].setVotesLastReward(0);
  1923. +           return;
  1924. +       }
  1925. +       if ((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) < globalVotesResponse)
  1926. +       {
  1927. +           _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse);
  1928. +           return;
  1929. +       }
  1930. +   }
  1931. +  
  1932. +   public void Shutdown()
  1933. +   {
  1934. +       AutoSaveGlobalVotes();
  1935. +       AutoCleanInnecesaryIndividualVotes();
  1936. +       AutoUpdateIndividualVotes();
  1937. +   }
  1938. +  
  1939. +   protected class AutoGlobalVoteRewardTask implements Runnable
  1940. +   {
  1941. +      
  1942. +       @Override
  1943. +       public void run()
  1944. +       {
  1945. +           AutoGlobalVoteReward();
  1946. +          
  1947. +       }
  1948. +      
  1949. +   }
  1950. +  
  1951. +   protected class AutoSaveGlobalVotesTask implements Runnable
  1952. +   {
  1953. +      
  1954. +       @Override
  1955. +       public void run()
  1956. +       {
  1957. +           AutoSaveGlobalVotes();
  1958. +          
  1959. +       }
  1960. +      
  1961. +   }
  1962. +  
  1963. +   protected class AutoUpdateIndividualVotesTask implements Runnable
  1964. +   {
  1965. +      
  1966. +       @Override
  1967. +       public void run()
  1968. +       {
  1969. +           AutoUpdateIndividualVotes();
  1970. +          
  1971. +       }
  1972. +      
  1973. +   }
  1974. +  
  1975. +   public static voteManager getInatance()
  1976. +   {
  1977. +       return SingleHolder.INSTANCE;
  1978. +   }
  1979. +  
  1980. +   private static class SingleHolder
  1981. +   {
  1982. +       protected static final voteManager INSTANCE = new voteManager();
  1983. +   }
  1984. +}
  1985. \ No newline at end of file
  1986. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java
  1987. new file mode 100644
  1988. index 0000000..d34f98b
  1989. --- /dev/null
  1990. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/Reward.java
  1991. @@ -0,0 +1,36 @@
  1992. +package org.l2jmobius.gameserver.votesystem.Model;
  1993. +
  1994. +/**
  1995. + * @author l2.topgameserver.net
  1996. + */
  1997. +public class Reward
  1998. +{
  1999. +   private int _itemId;
  2000. +   private int _itemCount;
  2001. +  
  2002. +   public Reward(int itemId, int itemCount)
  2003. +   {
  2004. +       this._itemId = itemId;
  2005. +       this._itemCount = itemCount;
  2006. +   }
  2007. +  
  2008. +   public void setItemId(int itemId)
  2009. +   {
  2010. +       _itemId = itemId;
  2011. +   }
  2012. +  
  2013. +   public void setItemCount(int itemCount)
  2014. +   {
  2015. +       _itemCount = itemCount;
  2016. +   }
  2017. +  
  2018. +   public int getItemId()
  2019. +   {
  2020. +       return _itemId;
  2021. +   }
  2022. +  
  2023. +   public int getItemCount()
  2024. +   {
  2025. +       return _itemCount;
  2026. +   }
  2027. +}
  2028. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java
  2029. new file mode 100644
  2030. index 0000000..0b26c01
  2031. --- /dev/null
  2032. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/VoteSite.java
  2033. @@ -0,0 +1,53 @@
  2034. +package org.l2jmobius.gameserver.votesystem.Model;
  2035. +
  2036. +import java.util.ArrayList;
  2037. +import java.util.List;
  2038. +
  2039. +/**
  2040. + * @author l2.topgameserver.net
  2041. + */
  2042. +public class VoteSite
  2043. +{
  2044. +   private int _siteOrdinal;
  2045. +   private String _siteName;
  2046. +   private final List<Reward> _rewards = new ArrayList<>();
  2047. +  
  2048. +   public VoteSite()
  2049. +   {
  2050. +      
  2051. +   }
  2052. +  
  2053. +   public void setSiteOrdinal(int siteOrdinal)
  2054. +   {
  2055. +       _siteOrdinal = siteOrdinal;
  2056. +   }
  2057. +  
  2058. +   public void setSiteName(String siteName)
  2059. +   {
  2060. +       _siteName = siteName;
  2061. +   }
  2062. +  
  2063. +   public void setRewardList(List<Reward> rewards)
  2064. +   {
  2065. +       for (Reward r : rewards)
  2066. +       {
  2067. +           _rewards.add(r);
  2068. +       }
  2069. +   }
  2070. +  
  2071. +   public int getSiteOrdinal()
  2072. +   {
  2073. +       return _siteOrdinal;
  2074. +   }
  2075. +  
  2076. +   public String getSiteName()
  2077. +   {
  2078. +       return _siteName;
  2079. +   }
  2080. +  
  2081. +   public List<Reward> getRewardList()
  2082. +   {
  2083. +       return _rewards;
  2084. +   }
  2085. +  
  2086. +}
  2087. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java
  2088. new file mode 100644
  2089. index 0000000..6ed7b6b
  2090. --- /dev/null
  2091. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/globalVote.java
  2092. @@ -0,0 +1,53 @@
  2093. +package org.l2jmobius.gameserver.votesystem.Model;
  2094. +
  2095. +/**
  2096. + * @author l2.topgameserver.net
  2097. + */
  2098. +public class globalVote
  2099. +{
  2100. +   private int _voteSite;
  2101. +   private int _votesLastReward;
  2102. +   private int _currentVotes;
  2103. +  
  2104. +   public globalVote()
  2105. +   {
  2106. +      
  2107. +   }
  2108. +  
  2109. +   public globalVote(int voteSite, int votesLastReward)
  2110. +   {
  2111. +       _voteSite = voteSite;
  2112. +       _votesLastReward = votesLastReward;
  2113. +   }
  2114. +  
  2115. +   public void setVoteSite(int voteSite)
  2116. +   {
  2117. +       _voteSite = voteSite;
  2118. +   }
  2119. +  
  2120. +   public void setVotesLastReward(int votesLastReward)
  2121. +   {
  2122. +       _votesLastReward = votesLastReward;
  2123. +   }
  2124. +  
  2125. +   public void setCurrentVotes(int currentVotes)
  2126. +   {
  2127. +       _currentVotes = currentVotes;
  2128. +   }
  2129. +  
  2130. +   public int getVoyeSite()
  2131. +   {
  2132. +       return _voteSite;
  2133. +   }
  2134. +  
  2135. +   public int getVotesLastReward()
  2136. +   {
  2137. +       return _votesLastReward;
  2138. +   }
  2139. +  
  2140. +   public int getCurrentVotes()
  2141. +   {
  2142. +       return _currentVotes;
  2143. +   }
  2144. +  
  2145. +}
  2146. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java
  2147. new file mode 100644
  2148. index 0000000..2b22289
  2149. --- /dev/null
  2150. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/individualVote.java
  2151. @@ -0,0 +1,78 @@
  2152. +package org.l2jmobius.gameserver.votesystem.Model;
  2153. +
  2154. +/**
  2155. + * @author l2.topgameserver.net
  2156. + */
  2157. +public class individualVote
  2158. +{
  2159. +   private String _voterIp;
  2160. +   private long _diffTime;
  2161. +   private long _votingTimeSite;
  2162. +   private int _voteSite;
  2163. +   private boolean _alreadyRewarded;
  2164. +  
  2165. +   public individualVote(String voterIp, long diffTime, long votingTimeSite, int voteSite, boolean alreadyRewarded)
  2166. +   {
  2167. +       _voterIp = voterIp;
  2168. +       _diffTime = diffTime;
  2169. +       _votingTimeSite = votingTimeSite;
  2170. +       _voteSite = voteSite;
  2171. +       _alreadyRewarded = alreadyRewarded;
  2172. +   }
  2173. +  
  2174. +   public individualVote()
  2175. +   {
  2176. +      
  2177. +   }
  2178. +  
  2179. +   public void setVoterIp(String voterIp)
  2180. +   {
  2181. +       _voterIp = voterIp;
  2182. +   }
  2183. +  
  2184. +   public void setDiffTime(long diffTime)
  2185. +   {
  2186. +       _diffTime = diffTime;
  2187. +   }
  2188. +  
  2189. +   public void setVotingTimeSite(long votingTimeSite)
  2190. +   {
  2191. +       _votingTimeSite = votingTimeSite;
  2192. +   }
  2193. +  
  2194. +   public void setVoteSite(int voteSite)
  2195. +   {
  2196. +       _voteSite = voteSite;
  2197. +   }
  2198. +  
  2199. +   public void setAlreadyRewarded(boolean alreadyRewarded)
  2200. +   {
  2201. +       _alreadyRewarded = alreadyRewarded;
  2202. +   }
  2203. +  
  2204. +   public String getVoterIp()
  2205. +   {
  2206. +       return _voterIp;
  2207. +   }
  2208. +  
  2209. +   public long getDiffTime()
  2210. +   {
  2211. +       return _diffTime;
  2212. +   }
  2213. +  
  2214. +   public long getVotingTimeSite()
  2215. +   {
  2216. +       return _votingTimeSite;
  2217. +   }
  2218. +  
  2219. +   public int getVoteSite()
  2220. +   {
  2221. +       return _voteSite;
  2222. +   }
  2223. +  
  2224. +   public boolean getAlreadyRewarded()
  2225. +   {
  2226. +       return _alreadyRewarded;
  2227. +   }
  2228. +  
  2229. +}
  2230. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java
  2231. new file mode 100644
  2232. index 0000000..6707e1b
  2233. --- /dev/null
  2234. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/Model/individualVoteResponse.java
  2235. @@ -0,0 +1,46 @@
  2236. +package org.l2jmobius.gameserver.votesystem.Model;
  2237. +
  2238. +/**
  2239. + * @author l2.topgameserver.net
  2240. + */
  2241. +public class individualVoteResponse
  2242. +{
  2243. +   private boolean _isVoted;
  2244. +   private long _diffTime;
  2245. +   private long _voteSiteTime;
  2246. +  
  2247. +   public individualVoteResponse()
  2248. +   {
  2249. +      
  2250. +   }
  2251. +  
  2252. +   public void setIsVoted(boolean isVoted)
  2253. +   {
  2254. +       _isVoted = isVoted;
  2255. +   }
  2256. +  
  2257. +   public void setDiffTime(long diffTime)
  2258. +   {
  2259. +       _diffTime = diffTime;
  2260. +   }
  2261. +  
  2262. +   public void setVoteSiteTime(long voteSiteTime)
  2263. +   {
  2264. +       _voteSiteTime = voteSiteTime;
  2265. +   }
  2266. +  
  2267. +   public boolean getIsVoted()
  2268. +   {
  2269. +       return _isVoted;
  2270. +   }
  2271. +  
  2272. +   public long getDiffTime()
  2273. +   {
  2274. +       return _diffTime;
  2275. +   }
  2276. +  
  2277. +   public long getVoteSiteTime()
  2278. +   {
  2279. +       return _voteSiteTime;
  2280. +   }
  2281. +}
  2282. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java
  2283. new file mode 100644
  2284. index 0000000..8bedd9c
  2285. --- /dev/null
  2286. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/VoteUtil/ReadJson.java
  2287. @@ -0,0 +1,120 @@
  2288. +/*
  2289. + * This file is part of the L2J Mobius project.
  2290. + *
  2291. + * This program is free software: you can redistribute it and/or modify
  2292. + * it under the terms of the GNU General Public License as published by
  2293. + * the Free Software Foundation, either version 3 of the License, or
  2294. + * (at your option) any later version.
  2295. + *
  2296. + * This program is distributed in the hope that it will be useful,
  2297. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2298. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  2299. + * General Public License for more details.
  2300. + *
  2301. + * You should have received a copy of the GNU General Public License
  2302. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  2303. + */
  2304. +package org.l2jmobius.gameserver.votesystem.VoteUtil;
  2305. +
  2306. +import java.io.FileNotFoundException;
  2307. +import java.io.FileReader;
  2308. +import java.io.IOException;
  2309. +import java.util.Collection;
  2310. +import java.util.HashMap;
  2311. +import java.util.Map;
  2312. +import java.util.logging.Level;
  2313. +import java.util.logging.Logger;
  2314. +
  2315. +import org.json.simple.JSONArray;
  2316. +import org.json.simple.JSONObject;
  2317. +import org.json.simple.parser.JSONParser;
  2318. +import org.json.simple.parser.ParseException;
  2319. +
  2320. +import org.l2jmobius.Config;
  2321. +import org.l2jmobius.gameserver.votesystem.Model.Reward;
  2322. +import org.l2jmobius.gameserver.votesystem.Model.VoteSite;
  2323. +
  2324. +public class ReadJson
  2325. +{
  2326. +   Logger LOGGER = Logger.getLogger(ReadJson.class.getName());
  2327. +   private final static Map<Integer, VoteSite> _voteSites = new HashMap<>();
  2328. +  
  2329. +   public ReadJson()
  2330. +   {
  2331. +       load();
  2332. +   }
  2333. +  
  2334. +   @SuppressWarnings("unchecked")
  2335. +   public void load()
  2336. +   {
  2337. +       JSONParser jsonParser = new JSONParser();
  2338. +      
  2339. +       try (FileReader reader = new FileReader(parseDatapackFile("/data/votesystem.json")))
  2340. +       {
  2341. +           Object obj = jsonParser.parse(reader);
  2342. +          
  2343. +           JSONArray rewardSiteList = (JSONArray) obj;
  2344. +           rewardSiteList.forEach(emp -> parseRewardSites((JSONObject) emp));
  2345. +           LOGGER.log(Level.INFO, "Loaded {} reward sites", _voteSites.size());
  2346. +          
  2347. +       }
  2348. +       catch (FileNotFoundException e)
  2349. +       {
  2350. +           e.printStackTrace();
  2351. +       }
  2352. +       catch (IOException e)
  2353. +       {
  2354. +           e.printStackTrace();
  2355. +       }
  2356. +       catch (ParseException e)
  2357. +       {
  2358. +           e.printStackTrace();
  2359. +       }
  2360. +   }
  2361. +  
  2362. +   private void parseRewardSites(JSONObject site)
  2363. +   {
  2364. +       VoteSite votesite = new VoteSite();
  2365. +       JSONObject rewardsite = (JSONObject) site.get("votesite");
  2366. +      
  2367. +       votesite.setSiteOrdinal(Integer.parseInt((String) rewardsite.get("ordinal")));
  2368. +       votesite.setSiteName((String) rewardsite.get("name"));
  2369. +      
  2370. +       JSONArray rewardList = (JSONArray) rewardsite.get("rewards");
  2371. +       for (int i = 0; i < rewardList.size(); i++)
  2372. +       {
  2373. +           JSONObject object = (JSONObject) rewardList.get(i);
  2374. +           votesite.getRewardList().add(new Reward(Integer.parseInt((String) object.get("item_id")), Integer.parseInt((String) object.get("item_count"))));
  2375. +          
  2376. +       }
  2377. +      
  2378. +       _voteSites.put(votesite.getSiteOrdinal(), votesite);
  2379. +   }
  2380. +  
  2381. +   private String parseDatapackFile(String path)
  2382. +   {
  2383. +       String p = Config.DATAPACK_ROOT + path;
  2384. +       return p;
  2385. +   }
  2386. +  
  2387. +   public String getSiteName(int ordinal)
  2388. +   {
  2389. +       return _voteSites.get(ordinal).getSiteName();
  2390. +   }
  2391. +  
  2392. +   public Collection<Reward> getRewards(int ordinal)
  2393. +   {
  2394. +       return _voteSites.get(ordinal).getRewardList();
  2395. +   }
  2396. +  
  2397. +   public static final ReadJson getInstance()
  2398. +   {
  2399. +       return SingletonHolder.INSTANCE;
  2400. +   }
  2401. +  
  2402. +   private static final class SingletonHolder
  2403. +   {
  2404. +       protected static final ReadJson INSTANCE = new ReadJson();
  2405. +   }
  2406. +  
  2407. +}
  2408. diff --git a/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java
  2409. new file mode 100644
  2410. index 0000000..1a904c1
  2411. --- /dev/null
  2412. +++ b/L2J_Mobius_8.0_Homunculus/java/org/l2jmobius/gameserver/votesystem/VoteUtil/VoteUtil.java
  2413. @@ -0,0 +1,123 @@
  2414. +package org.l2jmobius.gameserver.votesystem.VoteUtil;
  2415. +
  2416. +import java.io.BufferedReader;
  2417. +import java.io.InputStreamReader;
  2418. +import java.net.HttpURLConnection;
  2419. +import java.net.URL;
  2420. +import java.time.LocalDateTime;
  2421. +import java.time.ZoneId;
  2422. +import java.time.ZonedDateTime;
  2423. +import java.util.logging.Logger;
  2424. +
  2425. +import org.l2jmobius.gameserver.votesystem.Handler.voteHandler;
  2426. +
  2427. +/**
  2428. + * @author l2.topgameserver.net
  2429. + */
  2430. +public final class VoteUtil
  2431. +{
  2432. +   public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
  2433. +  
  2434. +   private static String voteTimeZones[] =
  2435. +   {
  2436. +       "topgameserver.net=Europe/Berlin",
  2437. +       "itopz.com=America/New_York",
  2438. +       "l2top.co=Europe/London",
  2439. +       "l2votes.com=GMT",
  2440. +       "hopzone.net=Europe/Athens",
  2441. +       "l2network.eu=America/Chicago",
  2442. +       "l2topservers.com=Europe/Athens",
  2443. +       "top.l2jbrasil.com=America/Sao_Paulo",
  2444. +       "mmotop.eu=America/Chicago",
  2445. +       "l2topzone.com=America/Chicago",
  2446. +       "l2servers.com=America/Chicago",
  2447. +   };
  2448. +  
  2449. +   public static final long getTimeVotingSite(int ordinalSite)
  2450. +   {
  2451. +       LocalDateTime ldt = LocalDateTime.now(ZoneId.of(voteTimeZones[ordinalSite].split("=")[1]));
  2452. +       ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
  2453. +       long millis = zdt.toInstant().toEpochMilli();
  2454. +       return millis;
  2455. +   }
  2456. +  
  2457. +   public static final String Sites[] =
  2458. +   {
  2459. +       "L2.TopGameServer.net",
  2460. +       "ITopZ.com",
  2461. +       "L2Top.co",
  2462. +       "L2Votes.com",
  2463. +       "L2.Hopzone.net",
  2464. +       "L2Network.eu",
  2465. +       "L2TopServers.com",
  2466. +       "top.l2jbrasil.com",
  2467. +       "MMOTOP.eu",
  2468. +       "L2Topzone.com",
  2469. +       "L2Servers.com"
  2470. +   };
  2471. +  
  2472. +   public static final String getResponse(String Url, int ordinal)
  2473. +   {
  2474. +      
  2475. +       try
  2476. +       {
  2477. +           int responseCode = 0;
  2478. +           URL objUrl = new URL(Url);
  2479. +           HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
  2480. +           con.setRequestMethod("GET");
  2481. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  2482. +           con.setConnectTimeout(5000);
  2483. +           responseCode = con.getResponseCode();
  2484. +           if (responseCode == HttpURLConnection.HTTP_OK)
  2485. +           {
  2486. +              
  2487. +               String inputLine;
  2488. +               StringBuffer response = new StringBuffer();
  2489. +               BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  2490. +               while ((inputLine = in.readLine()) != null)
  2491. +               {
  2492. +                   if (ordinal == 3)
  2493. +                   {
  2494. +                       if (inputLine.contains("Votes:"))
  2495. +                       {
  2496. +                           response.append(inputLine);
  2497. +                           break;
  2498. +                       }
  2499. +                   }
  2500. +                   if (ordinal == 7)
  2501. +                   {
  2502. +                       if (inputLine.contains("<b>Entradas "))
  2503. +                       {
  2504. +                           response.append(inputLine);
  2505. +                           break;
  2506. +                       }
  2507. +                   }
  2508. +               }
  2509. +               in.close();
  2510. +               return response.toString();
  2511. +           }
  2512. +          
  2513. +       }
  2514. +       catch (Exception e)
  2515. +       {
  2516. +           LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getStackTrace());
  2517. +           return "";
  2518. +       }
  2519. +      
  2520. +       return "";
  2521. +   }
  2522. +  
  2523. +   public static final String between(String p1, String str, String p2)
  2524. +   {
  2525. +       String returnValue = "";
  2526. +       int i1 = str.indexOf(p1);
  2527. +       int i2 = str.indexOf(p2);
  2528. +       if ((i1 != -1) && (i2 != -1))
  2529. +       {
  2530. +           i1 = i1 + p1.length();
  2531. +           returnValue = str.substring(i1, i2);
  2532. +       }
  2533. +       return returnValue;
  2534. +   }
  2535. +  
  2536. +}
  2537.  
  2538.  
  2539. ==========================================SQL================================
  2540. -- ----------------------------
  2541. -- Table structure for globalvotes
  2542. -- ----------------------------
  2543. DROP TABLE IF EXISTS `globalvotes`;
  2544. CREATE TABLE `globalvotes`  (
  2545.   `voteSite` tinyint(2) NOT NULL,
  2546.   `lastRewardVotes` int(11) NULL DEFAULT NULL,
  2547.   PRIMARY KEY (`voteSite`) USING BTREE
  2548. ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
  2549.  
  2550. -- ----------------------------
  2551. -- Records of globalvotes
  2552. -- ----------------------------
  2553. INSERT INTO `globalvotes` VALUES (0, 13);
  2554. INSERT INTO `globalvotes` VALUES (1, 68);
  2555. INSERT INTO `globalvotes` VALUES (2, 0);
  2556. INSERT INTO `globalvotes` VALUES (3, 3);
  2557. INSERT INTO `globalvotes` VALUES (4, 2);
  2558. INSERT INTO `globalvotes` VALUES (5, 0);
  2559. INSERT INTO `globalvotes` VALUES (6, 0);
  2560. INSERT INTO `globalvotes` VALUES (7, 2);
  2561. INSERT INTO `globalvotes` VALUES (8, 3);
  2562. INSERT INTO `globalvotes` VALUES (9, 0);
  2563. INSERT INTO `globalvotes` VALUES (10, 75);
  2564.  
  2565. -- ----------------------------
  2566. -- Table structure for individualvotes
  2567. -- ----------------------------
  2568. DROP TABLE IF EXISTS `individualvotes`;
  2569. CREATE TABLE `individualvotes`  (
  2570.   `voterIp` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  2571.   `voteSite` tinyint(3) NOT NULL,
  2572.   `diffTime` bigint(20) NULL DEFAULT NULL,
  2573.   `votingTimeSite` bigint(20) NULL DEFAULT NULL,
  2574.   `alreadyRewarded` tinyint(3) NULL DEFAULT NULL,
  2575.   PRIMARY KEY (`voterIp`, `voteSite`) USING BTREE
  2576. ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
  2577.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement