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