l2TopgameserverNet

L2JServer H5 vote reward system - l2.topgameserver.net

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