l2TopgameserverNet

L2jMobius-HighFive auto vote reward system - l2.topgameserver.net

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