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