· 4 years ago · Dec 31, 2020, 11:48 PM
1### Eclipse Workspace Patch 1.0
2#P L2jFrozen_GameServer
3Index: head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java
4===================================================================
5--- head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java (nonexistent)
6+++ head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java (working copy)
7@@ -0,0 +1,123 @@
8+package com.l2jfrozen.gameserver.votesystem.DB;
9+
10+import java.sql.Connection;
11+import java.sql.PreparedStatement;
12+import java.sql.ResultSet;
13+import java.sql.SQLException;
14+import java.sql.Statement;
15+import java.util.logging.Logger;
16+
17+import com.l2jfrozen.gameserver.votesystem.Model.globalVote;
18+import com.l2jfrozen.util.database.L2DatabaseFactory;
19+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
20+
21+/**
22+ * @author l2.topgameserver.net
23+ */
24+public class globalVoteDB
25+{
26+ public static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName());
27+ private Statement st;
28+ private Connection con;
29+ private final globalVote[] _globalVotes;
30+
31+ private globalVoteDB()
32+ {
33+ _globalVotes = new globalVote[voteSite.values().length];
34+ loadGlobalVotes();
35+ }
36+
37+ public void loadGlobalVotes()
38+ {
39+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement ps = con.prepareStatement("Select voteSite,lastRewardVotes from globalvotes");
40+
41+ ResultSet rs = ps.executeQuery();)
42+ {
43+ if (rs.getRow() == 0)
44+ {
45+ for (voteSite vs : voteSite.values())
46+ {
47+ globalVote gv = new globalVote();
48+ gv.setVoteSite(vs.ordinal());
49+ gv.setVotesLastReward(0);
50+ _globalVotes[gv.getVoyeSite()] = gv;
51+ }
52+ return;
53+ }
54+ while (rs.next())
55+ {
56+ globalVote gv = new globalVote();
57+ gv.setVoteSite(rs.getInt("voteSite"));
58+ gv.setVotesLastReward(rs.getInt("lastRewardVotes"));
59+ _globalVotes[gv.getVoyeSite()] = gv;
60+ }
61+ ps.close();
62+ con.close();
63+
64+ }
65+ catch (SQLException e)
66+ {
67+ e.printStackTrace();
68+ }
69+ }
70+
71+ public void saveGlobalVote(globalVote gb)
72+ {
73+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
74+ PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
75+
76+ {
77+ ps.setInt(1, gb.getVoyeSite());
78+ ps.setInt(2, gb.getVotesLastReward());
79+ ps.executeUpdate();
80+
81+ ps.close();
82+ con.close();
83+
84+ }
85+ catch (SQLException e)
86+ {
87+ e.printStackTrace();
88+ }
89+ }
90+
91+ public void saveGlobalVotes(globalVote[] globalVotes)
92+ {
93+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
94+ PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
95+
96+ {
97+ for (voteSite vs : voteSite.values())
98+ {
99+ globalVote gb = globalVotes[vs.ordinal()];
100+ ps.setInt(1, gb.getVoyeSite());
101+ ps.setInt(2, gb.getVotesLastReward());
102+ ps.addBatch();
103+ }
104+ ps.executeBatch();
105+
106+ ps.close();
107+ con.close();
108+
109+ }
110+ catch (SQLException e)
111+ {
112+ e.printStackTrace();
113+ }
114+ }
115+
116+ public globalVote[] getGlobalVotes()
117+ {
118+ return _globalVotes;
119+ }
120+
121+ public static final globalVoteDB getInstance()
122+ {
123+ return SingleHolder.INSTANCE;
124+ }
125+
126+ private static final class SingleHolder
127+ {
128+ protected static final globalVoteDB INSTANCE = new globalVoteDB();
129+ }
130+}
131Index: .classpath
132===================================================================
133--- .classpath (revision 1132)
134+++ .classpath (working copy)
135@@ -1,11 +1,7 @@
136 <?xml version="1.0" encoding="UTF-8"?>
137 <classpath>
138 <classpathentry excluding="**/.svn/*|.svn" kind="src" path="head-src"/>
139- <classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
140- <accessrules>
141- <accessrule kind="accessible" pattern="com/sun/net/httpserver/**"/>
142- </accessrules>
143- </classpathentry>
144+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_13"/>
145 <classpathentry kind="lib" path="lib/bsh-2.0b5.jar"/>
146 <classpathentry kind="lib" path="lib/bsh-engine.jar"/>
147 <classpathentry kind="lib" path="lib/ecj-3.6.1.jar"/>
148@@ -47,5 +43,6 @@
149 <classpathentry kind="lib" path="lib/uMad/xalan-2.7.1.jar"/>
150 <classpathentry kind="lib" path="lib/uMad/xercesImpl-2.11.0.jar"/>
151 <classpathentry kind="lib" path="lib/uMad/xml-apis-1.4.01.jar"/>
152+ <classpathentry kind="lib" path="C:/Users/escor/eclipse-workspace/L2jFrozen_GameServer/lib/glassfish-corba-omgapi-4.2.3.jar"/>
153 <classpathentry kind="output" path="bin"/>
154 </classpath>
155Index: config/votesystem.properties
156===================================================================
157--- config/votesystem.properties (nonexistent)
158+++ config/votesystem.properties (working copy)
159@@ -0,0 +1,95 @@
160+EnableVoteSystem = True
161+
162+EnableGlobalVote = True
163+
164+EnableIndividualVote = True
165+
166+## Time to Update table totalVotes from DB
167+NextTimeToAutoUpdateTotalVote = 2
168+
169+## Time to update table individualVotes
170+NextTimeToAutoUpdateIndividualVotes = 2
171+
172+NextTimeToAutoCleanInnecesaryVotes = 30
173+
174+NextTimeToCheckAutoGlobalVotesReward = 1
175+
176+IntervalToNextVote = 12
177+
178+GlobalVotesAmountToNextReward = 1
179+
180+EnableVotingCommand = True
181+
182+VotingCommand = .getreward
183+
184+## l2.topgameserver.net
185+VoteLinkTgs = http://l2.topgameserver.net/lineage/VoteApi/
186+
187+TgsApiKey =
188+
189+## l2top.co
190+VoteLinkTopCo = https://l2top.co/reward/
191+
192+TopCoSrvId =
193+
194+## ITopz.com
195+VoteLinkItopz = https://itopz.com/check/
196+
197+ItopzZpiKey =
198+
199+ItopzSrvId =
200+
201+## l2votes.com
202+VoteLinkVts = https://l2votes.com/
203+
204+VtsApiKey =
205+
206+VtsSid =
207+
208+## Hopzone.net
209+VoteLinkHz = https://api.hopzone.net/lineage2/
210+
211+HzApiKey =
212+
213+## l2network.eu
214+VoteNetworkLink = https://l2network.eu/api.php
215+
216+VoteNetworkUserName =
217+
218+VoteNetworkApiKey =
219+
220+## L2TopServer.com
221+VoteLinkTss = https://l2topservers.com/votes?
222+
223+TssApiToken =
224+
225+TsSrvId = 453
226+
227+TsDomainName= l2catgang
228+
229+## top.l2jbrasil.com
230+BrasilVoteLink = https://top.l2jbrasil.com/votesystem/index.php?
231+
232+BrasilUserName = julioguzman
233+
234+## Mmotop.eu
235+VoteLinkMmotop = https://mmotop.eu/l2/data/
236+
237+MmotopApiKey =
238+
239+## L2TopZone.com
240+VoteLinkTz = https://api.l2topzone.com/v1/
241+
242+TzApiKey =
243+
244+## L2Servers.com
245+VoteLinkServers = https://www.l2servers.com/api/
246+
247+ServersHashCode =
248+
249+ServersSrvId =
250+
251+
252+## for local test
253+TestIp =
254+
255Index: head-src/com/l2jfrozen/gameserver/network/serverpackets/Snoop.java
256===================================================================
257--- head-src/com/l2jfrozen/gameserver/network/serverpackets/Snoop.java (revision 1132)
258+++ head-src/com/l2jfrozen/gameserver/network/serverpackets/Snoop.java (working copy)
259@@ -20,6 +20,8 @@
260 */
261 package com.l2jfrozen.gameserver.network.serverpackets;
262
263+
264+import com.l2jfrozen.gameserver.enums.ChatType;
265 import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
266
267 /**
268@@ -31,13 +33,23 @@
269 private static final String _S__D5_SNOOP = "[S] D5 Snoop";
270 private final L2PcInstance _snooped;
271 private final int _type;
272+ private final ChatType _ctype;
273 private final String _speaker;
274 private final String _msg;
275
276+ public Snoop(L2PcInstance snooped, ChatType _cType, String speaker, String msg)
277+ {
278+ _snooped = snooped;
279+ this._type = 0;
280+ _ctype = _cType;
281+ _speaker = speaker;
282+ _msg = msg;
283+ }
284 public Snoop(final L2PcInstance snooped, final int type, final String speaker, final String msg)
285 {
286 _snooped = snooped;
287 _type = type;
288+ this._ctype = null;
289 _speaker = speaker;
290 _msg = msg;
291 }
292Index: head-src/com/l2jfrozen/gameserver/network/serverpackets/CreatureSay.java
293===================================================================
294--- head-src/com/l2jfrozen/gameserver/network/serverpackets/CreatureSay.java (revision 1132)
295+++ head-src/com/l2jfrozen/gameserver/network/serverpackets/CreatureSay.java (working copy)
296@@ -20,6 +20,8 @@
297 */
298 package com.l2jfrozen.gameserver.network.serverpackets;
299
300+
301+import com.l2jfrozen.gameserver.enums.ChatType;
302 import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
303
304 /**
305@@ -31,23 +33,30 @@
306 // ddSS
307 private static final String _S__4A_CREATURESAY = "[S] 4A CreatureSay";
308 private final int _objectId;
309- private final int _textType;
310+ private final int _chatType;
311 private final String _charName;
312 private final String _text;
313
314 /**
315 * @param objectId
316- * @param messageType
317+ * @param chatType
318 * @param charName
319 * @param text
320 */
321- public CreatureSay(final int objectId, final int messageType, final String charName, final String text)
322+ public CreatureSay(int objectId, ChatType chatType, String charName, String text)
323 {
324 _objectId = objectId;
325- _textType = messageType;
326+ _chatType = chatType.getClientId();
327 _charName = charName;
328 _text = text;
329- // setLifeTime(0);
330+ }
331+
332+ public CreatureSay(int objectId, int chatType, String charName, String text)
333+ {
334+ _objectId = objectId;
335+ _chatType = chatType;
336+ _charName = charName;
337+ _text = text;
338 }
339
340 @Override
341@@ -55,14 +64,14 @@
342 {
343 writeC(0x4a);
344 writeD(_objectId);
345- writeD(_textType);
346+ writeD(_chatType);
347 writeS(_charName);
348 writeS(_text);
349
350- final L2PcInstance _pci = getClient().getActiveChar();
351- if (_pci != null)
352+ final L2PcInstance player = getClient().getActiveChar();
353+ if (player != null)
354 {
355- _pci.broadcastSnoop(_textType, _charName, _text, this);
356+ player.broadcastSnoop(ChatType.values()[_chatType], _charName, _text, this);
357 }
358 }
359
360Index: head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java
361===================================================================
362--- head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java (nonexistent)
363+++ head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java (working copy)
364@@ -0,0 +1,127 @@
365+package com.l2jfrozen.gameserver.votesystem.VoteUtil;
366+
367+import java.io.File;
368+import java.util.Collection;
369+import java.util.HashMap;
370+import java.util.Map;
371+import java.util.logging.Level;
372+
373+import javax.xml.parsers.DocumentBuilderFactory;
374+
375+import org.apache.log4j.Logger;
376+
377+import org.w3c.dom.Document;
378+import org.w3c.dom.NamedNodeMap;
379+import org.w3c.dom.Node;
380+
381+import com.l2jfrozen.Config;
382+import com.l2jfrozen.gameserver.datatables.xml.ExperienceData;
383+import com.l2jfrozen.gameserver.datatables.xml.AugmentationData.augmentationSkill;
384+import com.l2jfrozen.gameserver.votesystem.Model.Reward;
385+import com.l2jfrozen.gameserver.votesystem.Model.VoteSite;
386+
387+
388+/**
389+ * @author l2.topgameserver.net
390+ */
391+public class VoteSiteXml
392+{
393+
394+ private final Map<Integer, VoteSite> _voteSites = new HashMap<>();
395+ private static Logger LOGGER = Logger.getLogger(ExperienceData.class);
396+
397+ private VoteSiteXml()
398+ {
399+ load();
400+ }
401+
402+
403+ public void load()
404+ {
405+ try
406+ {
407+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
408+ factory.setValidating(false);
409+ factory.setIgnoringComments(true);
410+
411+ File file = new File(Config.DATAPACK_ROOT + "/data/stats/votesystem.xml");
412+ if (!file.exists())
413+ {
414+ if (Config.DEBUG)
415+ {
416+ LOGGER.info("The votesystem file is missing.");
417+ }
418+ return;
419+ }
420+
421+ Document doc = factory.newDocumentBuilder().parse(file);
422+
423+ for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
424+ {
425+ if ("list".equalsIgnoreCase(n.getNodeName()))
426+ {
427+ for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
428+ {
429+ final VoteSite votesite = new VoteSite();
430+ if ("votesite".equalsIgnoreCase(d.getNodeName()))
431+ {
432+ NamedNodeMap attrs = d.getAttributes();
433+ String name = attrs.getNamedItem("name").getNodeValue();
434+ int ordinal = Integer.parseInt(attrs.getNamedItem("ordinal").getNodeValue());
435+ votesite.setSiteName(name);
436+ votesite.setSiteOrdinal(ordinal);
437+ for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
438+ {
439+ if ("item".equalsIgnoreCase(cd.getNodeName()))
440+ {
441+ attrs = cd.getAttributes();
442+ int itemId = Integer.parseInt(attrs.getNamedItem("itemId").getNodeValue());
443+ int itemCount = Integer.parseInt(attrs.getNamedItem("itemCount").getNodeValue());
444+ votesite.getRewardList().add(new Reward(itemId,itemCount));
445+ }
446+
447+ }
448+ _voteSites.put(votesite.getSiteOrdinal(), votesite);
449+ attrs = null;
450+ }
451+ }
452+ }
453+ }
454+
455+
456+ doc = null;
457+ file = null;
458+ }
459+ catch (final Exception e)
460+ {
461+ if (Config.ENABLE_ALL_EXCEPTIONS)
462+ e.printStackTrace();
463+
464+ LOGGER.error("Error parsing votesystem.xml", e);
465+
466+ return;
467+ }
468+ }
469+
470+
471+ public String getSiteName(int ordinal)
472+ {
473+ return _voteSites.get(ordinal).getSiteName();
474+ }
475+
476+ public Collection<Reward> getRewards(int ordinal)
477+ {
478+ return _voteSites.get(ordinal).getRewardList();
479+ }
480+
481+ public static final VoteSiteXml getInstance()
482+ {
483+ return SingletonHolder.INSTANCE;
484+ }
485+
486+ private static final class SingletonHolder
487+ {
488+ protected static final VoteSiteXml INSTANCE = new VoteSiteXml();
489+ }
490+
491+}
492Index: head-src/com/l2jfrozen/gameserver/enums/ChatType.java
493===================================================================
494--- head-src/com/l2jfrozen/gameserver/enums/ChatType.java (nonexistent)
495+++ head-src/com/l2jfrozen/gameserver/enums/ChatType.java (working copy)
496@@ -0,0 +1,60 @@
497+
498+package com.l2jfrozen.gameserver.enums;
499+
500+/**
501+ * @author St3eT
502+ */
503+public enum ChatType
504+{
505+ GENERAL(0),
506+ SHOUT(1),
507+ WHISPER(2),
508+ PARTY(3),
509+ CLAN(4),
510+ GM(5),
511+ PETITION_PLAYER(6),
512+ PETITION_GM(7),
513+ TRADE(8),
514+ ALLIANCE(9),
515+ ANNOUNCEMENT(10),
516+ BOAT(11),
517+ FRIEND(12),
518+ MSNCHAT(13),
519+ PARTYMATCH_ROOM(14),
520+ PARTYROOM_COMMANDER(15),
521+ PARTYROOM_ALL(16),
522+ HERO_VOICE(17),
523+ CRITICAL_ANNOUNCE(18);
524+
525+ private final int _clientId;
526+
527+ private ChatType(int clientId)
528+ {
529+ _clientId = clientId;
530+ }
531+
532+ /**
533+ * @return the client id.
534+ */
535+ public int getClientId()
536+ {
537+ return _clientId;
538+ }
539+
540+ /**
541+ * Finds the {@code ChatType} by its clientId
542+ * @param clientId the clientId
543+ * @return the {@code ChatType} if its found, {@code null} otherwise.
544+ */
545+ public static ChatType findByClientId(int clientId)
546+ {
547+ for (ChatType ChatType : values())
548+ {
549+ if (ChatType.getClientId() == clientId)
550+ {
551+ return ChatType;
552+ }
553+ }
554+ return null;
555+ }
556+}
557\ No newline at end of file
558Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java
559===================================================================
560--- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (revision 1132)
561+++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2PcInstance.java (working copy)
562@@ -77,6 +77,7 @@
563 import com.l2jfrozen.gameserver.datatables.sql.NpcTable;
564 import com.l2jfrozen.gameserver.datatables.sql.SkillTreeTable;
565 import com.l2jfrozen.gameserver.datatables.xml.ExperienceData;
566+import com.l2jfrozen.gameserver.enums.ChatType;
567 import com.l2jfrozen.gameserver.geo.GeoData;
568 import com.l2jfrozen.gameserver.handler.IItemHandler;
569 import com.l2jfrozen.gameserver.handler.ItemHandler;
570@@ -16024,7 +16025,21 @@
571 }
572 }
573 }
574-
575+ public void broadcastSnoop(ChatType _chatType, String name, String text, CreatureSay cs)
576+ {
577+ if (!_snoopListener.isEmpty())
578+ {
579+ final Snoop sn = new Snoop(this, _chatType, name, text);
580+ for (L2PcInstance pci : _snoopListener)
581+ {
582+ if (pci != null)
583+ {
584+ pci.sendPacket(cs);
585+ pci.sendPacket(sn);
586+ }
587+ }
588+ }
589+ }
590 public void addSnooper(final L2PcInstance pci)
591 {
592 if (!_snoopListener.contains(pci))
593Index: head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoteReward.java
594===================================================================
595--- head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoteReward.java (nonexistent)
596+++ head-src/com/l2jfrozen/gameserver/handler/voicedcommandhandlers/VoteReward.java (working copy)
597@@ -0,0 +1,92 @@
598+/*
599+ * This program is free software: you can redistribute it and/or modify it under
600+ * the terms of the GNU General Public License as published by the Free Software
601+ * Foundation, either version 3 of the License, or (at your option) any later
602+ * version.
603+ *
604+ * This program is distributed in the hope that it will be useful, but WITHOUT
605+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
606+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
607+ * details.
608+ *
609+ * You should have received a copy of the GNU General Public License along with
610+ * this program. If not, see <http://www.gnu.org/licenses/>.
611+ */
612+package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;
613+
614+import com.l2jfrozen.Config;
615+import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
616+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
617+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
618+import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
619+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
620+
621+/**
622+ * @author escor
623+ *
624+ */
625+public class VoteReward implements IVoicedCommandHandler
626+{
627+ @Override
628+ public boolean useVoicedCommand(String command, L2PcInstance player, String params)
629+ {
630+ final L2PcInstance _player = player;
631+ if (command.equalsIgnoreCase(Config.VOTING_COMMAND))
632+ {
633+ if (player.isInJail())
634+ {
635+ player.sendMessage("You cannot use this function while you are jailed");
636+ return false;
637+ }
638+ if (!Config.ENABLE_VOTE_SYSTEM)
639+ {
640+ player.sendMessage("The rewards system has been disabled by your administrator");
641+ return false;
642+ }
643+ if (!Config.ENABLE_INDIVIDUAL_VOTE)
644+ {
645+ player.sendMessage("The individual reward system is disabled");
646+ return false;
647+ }
648+ if (!Config.ENABLE_VOTING_COMMAND)
649+ {
650+ player.sendMessage("Voting command reward is disabled");
651+ return false;
652+ }
653+
654+ for (final voteSite vs : voteSite.values())
655+ {
656+ new Thread(new Runnable() {
657+
658+ @Override
659+ public void run()
660+ {
661+ voteManager.getInatance().getReward(_player, vs.ordinal());
662+
663+ }
664+
665+ }).start();
666+ }
667+
668+ return true;
669+
670+ }
671+ if(command.equalsIgnoreCase("reloadrewards") && player.isGM()) {
672+ VoteSiteXml.getInstance().load();
673+ player.sendMessage("=============All reward has been reloaded=============");
674+ return true;
675+ }
676+ return false;
677+ }
678+
679+ @Override
680+ public String[] getVoicedCommandList()
681+ {
682+ return new String[]
683+ {
684+ Config.VOTING_COMMAND,
685+ "reloadrewards",
686+ };
687+ }
688+
689+}
690\ No newline at end of file
691Index: head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java
692===================================================================
693--- head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java (revision 1132)
694+++ head-src/com/l2jfrozen/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
695@@ -125,6 +125,30 @@
696 {
697 playerHelp(activeChar, _command.substring(12));
698 }
699+ else if (_command.startsWith("vote_"))
700+ {
701+
702+ int endOfId = _command.indexOf('_', 6);
703+ String id;
704+ if (endOfId > 0)
705+ {
706+ id = _command.substring(5, endOfId);
707+ }
708+ else
709+ {
710+ id = _command.substring(5);
711+ }
712+
713+ if (_command.split(" ")[1].toString() != null)
714+ {
715+ final L2Object object = L2World.getInstance().findObject(Integer.parseInt(id));
716+ if ((Config.ALLOW_CLASS_MASTERS && Config.ALLOW_REMOTE_CLASS_MASTERS && (object instanceof L2ClassMasterInstance)) //
717+ || ((object instanceof L2NpcInstance) && (endOfId > 0) && activeChar.isInsideRadius(object, L2NpcInstance.INTERACTION_DISTANCE, false, false)))
718+ {
719+ ((L2NpcInstance) object).onBypassFeedback(activeChar, _command.split(" ")[1].toString());
720+ }
721+ }
722+ }
723 else if (_command.startsWith("npc_"))
724 {
725 if (!activeChar.validateBypass(_command))
726Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java
727===================================================================
728--- head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java (nonexistent)
729+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java (working copy)
730@@ -0,0 +1,78 @@
731+package com.l2jfrozen.gameserver.votesystem.Model;
732+
733+/**
734+ * @author l2.topgameserver.net
735+ */
736+public class individualVote
737+{
738+ private String _voterIp;
739+ private long _diffTime;
740+ private long _votingTimeSite;
741+ private int _voteSite;
742+ private boolean _alreadyRewarded;
743+
744+ public individualVote(String voterIp, long diffTime, long votingTimeSite, int voteSite, boolean alreadyRewarded)
745+ {
746+ _voterIp = voterIp;
747+ _diffTime = diffTime;
748+ _votingTimeSite = votingTimeSite;
749+ _voteSite = voteSite;
750+ _alreadyRewarded = alreadyRewarded;
751+ }
752+
753+ public individualVote()
754+ {
755+
756+ }
757+
758+ public void setVoterIp(String voterIp)
759+ {
760+ _voterIp = voterIp;
761+ }
762+
763+ public void setDiffTime(long diffTime)
764+ {
765+ _diffTime = diffTime;
766+ }
767+
768+ public void setVotingTimeSite(long votingTimeSite)
769+ {
770+ _votingTimeSite = votingTimeSite;
771+ }
772+
773+ public void setVoteSite(int voteSite)
774+ {
775+ _voteSite = voteSite;
776+ }
777+
778+ public void setAlreadyRewarded(boolean alreadyRewarded)
779+ {
780+ _alreadyRewarded = alreadyRewarded;
781+ }
782+
783+ public String getVoterIp()
784+ {
785+ return _voterIp;
786+ }
787+
788+ public long getDiffTime()
789+ {
790+ return _diffTime;
791+ }
792+
793+ public long getVotingTimeSite()
794+ {
795+ return _votingTimeSite;
796+ }
797+
798+ public int getVoteSite()
799+ {
800+ return _voteSite;
801+ }
802+
803+ public boolean getAlreadyRewarded()
804+ {
805+ return _alreadyRewarded;
806+ }
807+
808+}
809Index: head-src/com/l2jfrozen/gameserver/Shutdown.java
810===================================================================
811--- head-src/com/l2jfrozen/gameserver/Shutdown.java (revision 1132)
812+++ head-src/com/l2jfrozen/gameserver/Shutdown.java (working copy)
813@@ -47,6 +47,7 @@
814 import com.l2jfrozen.gameserver.thread.LoginServerThread;
815 import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
816 import com.l2jfrozen.gameserver.util.sql.SQLQueue;
817+import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
818 import com.l2jfrozen.util.database.L2DatabaseFactory;
819 import com.l2jfrozen.util.database.SqlUtils;
820
821@@ -679,6 +680,12 @@
822 GrandBossManager.getInstance().cleanUp();
823 LOGGER.info("GrandBossManager: All Grand Boss info saved!!");
824
825+ if (Config.ENABLE_VOTE_SYSTEM)
826+ {
827+ voteManager.getInatance().Shutdown();
828+ LOGGER.info("Vote data have been saved!!");
829+ }
830+
831 // Save data CountStore
832 TradeController.getInstance().dataCountStore();
833 LOGGER.info("TradeController: All count Item Saved");
834Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java
835===================================================================
836--- head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java (nonexistent)
837+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java (working copy)
838@@ -0,0 +1,44 @@
839+package com.l2jfrozen.gameserver.votesystem.Model;
840+
841+import com.l2jfrozen.gameserver.templates.StatsSet;
842+
843+/**
844+ * @author l2.topgameserver.net
845+ */
846+public class Reward
847+{
848+ private int _itemId;
849+ private int _itemCount;
850+
851+ public Reward(int itemId, int itemCount)
852+ {
853+ this._itemId = itemId;
854+ this._itemCount = itemCount;
855+ }
856+
857+ public Reward(StatsSet set)
858+ {
859+ _itemId = set.getInteger("itemId");
860+ _itemCount = set.getInteger("itemCount");
861+ }
862+
863+ public void setItemId(int itemId)
864+ {
865+ _itemId = itemId;
866+ }
867+
868+ public void setItemCount(int itemCount)
869+ {
870+ _itemCount = itemCount;
871+ }
872+
873+ public int getItemId()
874+ {
875+ return _itemId;
876+ }
877+
878+ public int getItemCount()
879+ {
880+ return _itemCount;
881+ }
882+}
883Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java
884===================================================================
885--- head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java (nonexistent)
886+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java (working copy)
887@@ -0,0 +1,53 @@
888+package com.l2jfrozen.gameserver.votesystem.Model;
889+
890+/**
891+ * @author l2.topgameserver.net
892+ */
893+public class globalVote
894+{
895+ private int _voteSite;
896+ private int _votesLastReward;
897+ private int _currentVotes;
898+
899+ public globalVote()
900+ {
901+
902+ }
903+
904+ public globalVote(int voteSite, int votesLastReward)
905+ {
906+ _voteSite = voteSite;
907+ _votesLastReward = votesLastReward;
908+ }
909+
910+ public void setVoteSite(int voteSite)
911+ {
912+ _voteSite = voteSite;
913+ }
914+
915+ public void setVotesLastReward(int votesLastReward)
916+ {
917+ _votesLastReward = votesLastReward;
918+ }
919+
920+ public void setCurrentVotes(int currentVotes)
921+ {
922+ _currentVotes = currentVotes;
923+ }
924+
925+ public int getVoyeSite()
926+ {
927+ return _voteSite;
928+ }
929+
930+ public int getVotesLastReward()
931+ {
932+ return _votesLastReward;
933+ }
934+
935+ public int getCurrentVotes()
936+ {
937+ return _currentVotes;
938+ }
939+
940+}
941Index: head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java
942===================================================================
943--- head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java (nonexistent)
944+++ head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java (working copy)
945@@ -0,0 +1,122 @@
946+package com.l2jfrozen.gameserver.votesystem.VoteUtil;
947+
948+import java.io.BufferedReader;
949+import java.io.InputStreamReader;
950+import java.net.HttpURLConnection;
951+import java.net.URL;
952+
953+import java.util.logging.Logger;
954+
955+import com.l2jfrozen.gameserver.votesystem.Handler.voteHandler;
956+
957+
958+/**
959+ * @author l2.topgameserver.net
960+ */
961+public final class VoteUtil
962+{
963+ public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
964+
965+ private static String voteTimeZones[] =
966+ {
967+ "topgameserver.net=Europe/Berlin",
968+ "itopz.com=America/New_York",
969+ "l2top.co=Europe/London",
970+ "l2votes.com=GMT",
971+ "hopzone.net=Europe/Athens",
972+ "l2network.eu=America/Chicago",
973+ "l2topservers.com=Europe/Athens",
974+ "top.l2jbrasil.com=America/Sao_Paulo",
975+ "mmotop.eu=America/Chicago",
976+ "l2topzone.com=America/Chicago",
977+ "l2servers.com=America/Chicago",
978+ };
979+
980+ /*public static final long getTimeVotingSite(int ordinalSite)
981+ {
982+ LocalDateTime ldt = LocalDateTime.now(ZoneId.of(voteTimeZones[ordinalSite].split("=")[1]));
983+ ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
984+ long millis = zdt.toInstant().toEpochMilli();
985+ return millis;
986+ }*/
987+
988+ public static final String Sites[] =
989+ {
990+ "L2.TopGameServer.net",
991+ "ITopZ.com",
992+ "L2Top.co",
993+ "L2Votes.com",
994+ "L2.Hopzone.net",
995+ "L2Network.eu",
996+ "L2TopServers.com",
997+ "top.l2jbrasil.com",
998+ "MMOTOP.eu",
999+ "L2Topzone.com",
1000+ "L2Servers.com"
1001+ };
1002+
1003+ public static final String getResponse(String Url, int ordinal)
1004+ {
1005+
1006+ try
1007+ {
1008+ int responseCode = 0;
1009+ URL objUrl = new URL(Url);
1010+ HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
1011+ con.setRequestMethod("GET");
1012+ con.setRequestProperty("User-Agent", "Mozilla/5.0");
1013+ con.setConnectTimeout(5000);
1014+ responseCode = con.getResponseCode();
1015+ if (responseCode == HttpURLConnection.HTTP_OK)
1016+ {
1017+
1018+ String inputLine;
1019+ StringBuffer response = new StringBuffer();
1020+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
1021+ while ((inputLine = in.readLine()) != null)
1022+ {
1023+ if (ordinal == 3)
1024+ {
1025+ if (inputLine.contains("Votes:"))
1026+ {
1027+ response.append(inputLine);
1028+ break;
1029+ }
1030+ }
1031+ if (ordinal == 7)
1032+ {
1033+ if (inputLine.contains("<b>Entradas "))
1034+ {
1035+ response.append(inputLine);
1036+ break;
1037+ }
1038+ }
1039+ }
1040+ in.close();
1041+ return response.toString();
1042+ }
1043+
1044+ }
1045+ catch (Exception e)
1046+ {
1047+ LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getStackTrace());
1048+ return "";
1049+ }
1050+
1051+ return "";
1052+ }
1053+
1054+ public static final String between(String p1, String str, String p2)
1055+ {
1056+ String returnValue = "";
1057+ int i1 = str.indexOf(p1);
1058+ int i2 = str.indexOf(p2);
1059+ if ((i1 != -1) && (i2 != -1))
1060+ {
1061+ i1 = i1 + p1.length();
1062+ returnValue = str.substring(i1, i2);
1063+ }
1064+ return returnValue;
1065+ }
1066+
1067+}
1068Index: head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java
1069===================================================================
1070--- head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java (nonexistent)
1071+++ head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java (working copy)
1072@@ -0,0 +1,19 @@
1073+package com.l2jfrozen.gameserver.votesystem.Enum;
1074+
1075+/**
1076+ * @author l2.topgameserver.net
1077+ */
1078+public enum voteSite
1079+{
1080+ L2TOPGAMESERVER, // 0
1081+ ITOPZ, // 1
1082+ L2TOPCO, // 2
1083+ L2VOTES, // 3
1084+ HOPZONE, // 4
1085+ L2NETWORK, // 5
1086+ L2TOPSERVERS, // 6
1087+ TOPL2JBRASIL, // 7
1088+ MMOTOP, // 8
1089+ TOPZONE, // 9
1090+ L2SERVERS,// 10
1091+}
1092Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java
1093===================================================================
1094--- head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java (nonexistent)
1095+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java (working copy)
1096@@ -0,0 +1,46 @@
1097+package com.l2jfrozen.gameserver.votesystem.Model;
1098+
1099+/**
1100+ * @author l2.topgameserver.net
1101+ */
1102+public class individualVoteResponse
1103+{
1104+ private boolean _isVoted;
1105+ private long _diffTime;
1106+ private long _voteSiteTime;
1107+
1108+ public individualVoteResponse()
1109+ {
1110+
1111+ }
1112+
1113+ public void setIsVoted(boolean isVoted)
1114+ {
1115+ _isVoted = isVoted;
1116+ }
1117+
1118+ public void setDiffTime(long diffTime)
1119+ {
1120+ _diffTime = diffTime;
1121+ }
1122+
1123+ public void setVoteSiteTime(long voteSiteTime)
1124+ {
1125+ _voteSiteTime = voteSiteTime;
1126+ }
1127+
1128+ public boolean getIsVoted()
1129+ {
1130+ return _isVoted;
1131+ }
1132+
1133+ public long getDiffTime()
1134+ {
1135+ return _diffTime;
1136+ }
1137+
1138+ public long getVoteSiteTime()
1139+ {
1140+ return _voteSiteTime;
1141+ }
1142+}
1143Index: lib/glassfish-corba-omgapi-4.2.3.jar
1144===================================================================
1145Cannot display: file marked as a binary type.
1146svn:mime-type = application/octet-stream
1147
1148Property changes on: lib\glassfish-corba-omgapi-4.2.3.jar
1149___________________________________________________________________
1150Added: svn:mime-type
1151## -0,0 +1 ##
1152+application/octet-stream
1153Index: head-src/com/l2jfrozen/FService.java
1154===================================================================
1155--- head-src/com/l2jfrozen/FService.java (revision 1132)
1156+++ head-src/com/l2jfrozen/FService.java (working copy)
1157@@ -34,6 +34,7 @@
1158 public static final String QUESTION_FILE = "./config/questionwords.txt";
1159 public static final String HEXID_FILE = "./config/hexid.txt";
1160 public static final String TELNET_FILE = "./config/telnet.properties";
1161+ public static final String VOTE_SYSTEM_FILE = "./config/votesystem.properties";
1162
1163 // head
1164 public static final String ALT_SETTINGS_FILE = "./config/head/altsettings.properties";
1165Index: head-src/com/l2jfrozen/gameserver/util/Broadcast.java
1166===================================================================
1167--- head-src/com/l2jfrozen/gameserver/util/Broadcast.java (revision 1132)
1168+++ head-src/com/l2jfrozen/gameserver/util/Broadcast.java (working copy)
1169@@ -35,10 +35,12 @@
1170 import org.apache.log4j.Logger;
1171
1172 import com.l2jfrozen.Config;
1173+import com.l2jfrozen.gameserver.enums.ChatType;
1174 import com.l2jfrozen.gameserver.model.L2Character;
1175 import com.l2jfrozen.gameserver.model.L2World;
1176 import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
1177 import com.l2jfrozen.gameserver.network.serverpackets.CharInfo;
1178+import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
1179 import com.l2jfrozen.gameserver.network.serverpackets.L2GameServerPacket;
1180 import com.l2jfrozen.gameserver.network.serverpackets.RelationChanged;
1181
1182@@ -237,4 +239,8 @@
1183 onlinePlayer.sendPacket(mov);
1184 }
1185 }
1186+ public static void toAllOnlinePlayers(String text, boolean isCritical)
1187+ {
1188+ toAllOnlinePlayers(new CreatureSay(0, isCritical ? ChatType.CRITICAL_ANNOUNCE.ordinal() : ChatType.ANNOUNCEMENT.ordinal(), "", text));
1189+ }
1190 }
1191Index: head-src/com/l2jfrozen/gameserver/model/actor/instance/L2NpcVoteRewardInstance.java
1192===================================================================
1193--- head-src/com/l2jfrozen/gameserver/model/actor/instance/L2NpcVoteRewardInstance.java (nonexistent)
1194+++ head-src/com/l2jfrozen/gameserver/model/actor/instance/L2NpcVoteRewardInstance.java (working copy)
1195@@ -0,0 +1,114 @@
1196+/*
1197+ * This program is free software: you can redistribute it and/or modify it under
1198+ * the terms of the GNU General Public License as published by the Free Software
1199+ * Foundation, either version 3 of the License, or (at your option) any later
1200+ * version.
1201+ *
1202+ * This program is distributed in the hope that it will be useful, but WITHOUT
1203+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1204+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1205+ * details.
1206+ *
1207+ * You should have received a copy of the GNU General Public License along with
1208+ * this program. If not, see <http://www.gnu.org/licenses/>.
1209+ */
1210+package com.l2jfrozen.gameserver.model.actor.instance;
1211+
1212+import com.l2jfrozen.Config;
1213+import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
1214+import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
1215+import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
1216+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
1217+import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
1218+import com.l2jfrozen.gameserver.votesystem.Model.Reward;
1219+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
1220+
1221+/**
1222+ * @author escor
1223+ *
1224+ */
1225+public class L2NpcVoteRewardInstance extends L2NpcInstance
1226+{
1227+
1228+ /**
1229+ * @param objectId
1230+ * @param template
1231+ */
1232+ public L2NpcVoteRewardInstance(int objectId, L2NpcTemplate template)
1233+ {
1234+ super(objectId, template);
1235+ // TODO Auto-generated constructor stub
1236+ }
1237+
1238+
1239+
1240+ @Override
1241+ public void onBypassFeedback(L2PcInstance player, String command)
1242+ {
1243+ if (command == null)
1244+ {
1245+ return;
1246+ }
1247+ int Ordinalsite = Integer.parseInt(command);
1248+ voteManager.getInatance().getReward(player, Ordinalsite);
1249+ showChatWindow(player, 0);
1250+ super.onBypassFeedback(player, command);
1251+ }
1252+
1253+ @Override
1254+ public void showChatWindow(L2PcInstance player, int val)
1255+ {
1256+ final NpcHtmlMessage html = new NpcHtmlMessage(0);
1257+ StringBuilder sb = new StringBuilder();
1258+ html.setFile(getHtmlPath(getNpcId(), 0));
1259+ for (voteSite vs : voteSite.values())
1260+ {
1261+ sb.append("<table bgcolor=000000 width=280><tr>");
1262+ sb.append("<td width=42><img src=\"icon.etc_treasure_box_i08\" width=32 height=32></td>");
1263+ sb.append("<td width=220><table width=220>");
1264+ sb.append("<tr><td><table width=220><tr><td width=145>On " + String.format("%s", VoteSiteXml.getInstance().getSiteName(vs.ordinal())) + "</td>");
1265+ if (voteManager.getInatance().checkIndividualAvailableVote(player, vs.ordinal()))
1266+ {
1267+ 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>");
1268+ }
1269+ else
1270+ {
1271+ sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(player, vs.ordinal())));
1272+ }
1273+ sb.append("</tr></table></td></tr>");
1274+ sb.append("<tr><td><table width=220><tr>");
1275+ int i = 0;
1276+ for (Reward r : VoteSiteXml.getInstance().getRewards(vs.ordinal()))
1277+ {
1278+ 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()));
1279+ i++;
1280+ if ((i % 2) == 0)
1281+ {
1282+ sb.append("</tr><tr>");
1283+ }
1284+ }
1285+ sb.append("</tr></table></td></tr></table></td></tr></table><br>");
1286+ }
1287+ html.replace("%everyXtime%", Config.INTERVAL_TO_NEXT_VOTE / (3600 * 1000));
1288+ html.replace("%enablevote%", sb.toString());
1289+ html.replace("%accountName%", player.getName());
1290+ player.sendPacket(html);
1291+ }
1292+
1293+ @Override
1294+ public String getHtmlPath(int npcId, int val)
1295+ {
1296+ String filename = "";
1297+ if (val == 0)
1298+ {
1299+ filename = "" + npcId;
1300+ }
1301+ else
1302+ {
1303+ filename = npcId + "-" + val;
1304+ }
1305+
1306+ return "data/html/mods/votesystem/" + filename + ".htm";
1307+ }
1308+
1309+}
1310Index: head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java
1311===================================================================
1312--- head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java (nonexistent)
1313+++ head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java (working copy)
1314@@ -0,0 +1,417 @@
1315+package com.l2jfrozen.gameserver.votesystem.Handler;
1316+
1317+import java.util.HashSet;
1318+import java.util.Map;
1319+import java.util.concurrent.ConcurrentHashMap;
1320+import java.util.concurrent.ScheduledFuture;
1321+
1322+import com.l2jfrozen.gameserver.votesystem.Model.Reward;
1323+import com.l2jfrozen.gameserver.votesystem.Model.globalVote;
1324+import com.l2jfrozen.gameserver.votesystem.Model.individualVote;
1325+import com.l2jfrozen.gameserver.votesystem.Model.individualVoteResponse;
1326+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
1327+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteUtil;
1328+import com.l2jfrozen.Config;
1329+import com.l2jfrozen.gameserver.model.L2World;
1330+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
1331+import com.l2jfrozen.gameserver.network.L2GameClient;
1332+import com.l2jfrozen.gameserver.network.SystemMessageId;
1333+import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
1334+import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
1335+import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
1336+import com.l2jfrozen.gameserver.util.Broadcast;
1337+import com.l2jfrozen.gameserver.votesystem.DB.globalVoteDB;
1338+import com.l2jfrozen.gameserver.votesystem.DB.individualVoteDB;
1339+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
1340+
1341+
1342+/**
1343+ * @author l2.topgameserver.net
1344+ */
1345+public final class voteManager extends voteHandler
1346+{
1347+ private ScheduledFuture<?> _saveGlobalVotes;
1348+ private ScheduledFuture<?> _updateIndividualVotes;
1349+ private ScheduledFuture<?> _autoGlobalVotesReward;
1350+
1351+ private Map<String, individualVote[]> _foundVoters;
1352+ private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
1353+
1354+ public voteManager()
1355+ {
1356+ _foundVoters = new ConcurrentHashMap<>();
1357+ loadVotes();
1358+ loadGlobalVotes();
1359+ checkAllResponseGlobalVotes();
1360+ stopAutoTasks();
1361+
1362+ if (Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
1363+ {
1364+ _updateIndividualVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES);
1365+ }
1366+ if (Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
1367+ {
1368+ _autoGlobalVotesReward = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD);
1369+ _saveGlobalVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE);
1370+ }
1371+ }
1372+
1373+ private void stopAutoTasks()
1374+ {
1375+ if (_saveGlobalVotes != null)
1376+ {
1377+ _saveGlobalVotes.cancel(true);
1378+ _saveGlobalVotes = null;
1379+ }
1380+ if (_updateIndividualVotes != null)
1381+ {
1382+ _updateIndividualVotes.cancel(true);
1383+ _updateIndividualVotes = null;
1384+ }
1385+ if (_autoGlobalVotesReward != null)
1386+ {
1387+ _autoGlobalVotesReward.cancel(true);
1388+ _autoGlobalVotesReward = null;
1389+ }
1390+ }
1391+
1392+ public void getReward(L2PcInstance player, int ordinalSite)
1393+ {
1394+ String ip = existIp(player);
1395+ if (ip == null)
1396+ {
1397+ return;
1398+ }
1399+ individualVoteResponse ivr = getIndividualVoteResponse(ordinalSite, ip, player.getAccountName());
1400+ if (ivr == null)
1401+ {
1402+ player.sendMessage("We were unable to verify your vote with: " + VoteSiteXml.getInstance().getSiteName(ordinalSite) + ", please try again");
1403+ return;
1404+ }
1405+ if (!ivr.getIsVoted())
1406+ {
1407+ player.sendMessage(String.format("You haven't vote on %s yet!", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
1408+ return;
1409+ }
1410+ if (!checkIndividualAvailableVote(player, ordinalSite))
1411+ {
1412+ player.sendMessage(String.format("You can get the reward again on %s at %s", VoteSiteXml.getInstance().getSiteName(ordinalSite), getTimeRemainingWithSampleFormat(player, ordinalSite)));
1413+ return;
1414+ }
1415+ individualVote iv = new individualVote(ip, ivr.getDiffTime(), ivr.getVoteSiteTime(), ordinalSite, false);
1416+
1417+ individualVote[] aiv;
1418+ if (!_foundVoters.containsKey(ip))
1419+ {
1420+ aiv = new individualVote[voteSite.values().length];
1421+ iv.setAlreadyRewarded(true);
1422+ aiv[ordinalSite] = iv;
1423+ _foundVoters.put(ip, aiv);
1424+ }
1425+ else
1426+ {
1427+ aiv = _foundVoters.get(ip);
1428+ iv.setAlreadyRewarded(true);
1429+ aiv[ordinalSite] = iv;
1430+ _foundVoters.put(ip, aiv);
1431+
1432+ }
1433+ for (Reward reward : VoteSiteXml.getInstance().getRewards(ordinalSite))
1434+ {
1435+ player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null);
1436+ player.sendPacket(new SystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
1437+ }
1438+ player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
1439+ player.sendPacket(new ItemList(player, true));
1440+ return;
1441+ }
1442+
1443+ public boolean checkIndividualAvailableVote(L2PcInstance player, int ordinalSite)
1444+ {
1445+ String ip = existIp(player);
1446+ if (_foundVoters.containsKey(ip))
1447+ {
1448+ individualVote[] ivs = _foundVoters.get(ip);
1449+ if (ivs[ordinalSite] == null)
1450+ {
1451+ return true;
1452+ }
1453+ if (ivs[ordinalSite] != null)
1454+ {
1455+ individualVote iv = ivs[ordinalSite];
1456+ if (getTimeRemaining(iv) < 0)
1457+ {
1458+ return true;
1459+ }
1460+ }
1461+ }
1462+ else
1463+ {
1464+ return true;
1465+ }
1466+
1467+ return false;
1468+ }
1469+
1470+ public long getTimeRemaining(individualVote iv)
1471+ {
1472+ long timeRemaining = 0L;
1473+ timeRemaining = ((iv.getVotingTimeSite() + Config.INTERVAL_TO_NEXT_VOTE) - (iv.getDiffTime() > 0 ? iv.getDiffTime() : -1 * iv.getDiffTime())) - System.currentTimeMillis();
1474+ return timeRemaining;
1475+ }
1476+
1477+ public String getTimeRemainingWithSampleFormat(L2PcInstance player, int ordinalSite)
1478+ {
1479+ String ip = existIp(player);
1480+ String timeRemainingWithSampleFormat = "";
1481+ if (_foundVoters.containsKey(ip))
1482+ {
1483+ individualVote[] ivs = _foundVoters.get(ip);
1484+ if (ivs[ordinalSite] != null)
1485+ {
1486+ individualVote iv = ivs[ordinalSite];
1487+ long timeRemaining = getTimeRemaining(iv);
1488+ if (timeRemaining > 0)
1489+ {
1490+ timeRemainingWithSampleFormat = CalculateTimeRemainingWithSampleDateFormat(timeRemaining);
1491+ return timeRemainingWithSampleFormat;
1492+ }
1493+ }
1494+ }
1495+ return timeRemainingWithSampleFormat;
1496+ }
1497+
1498+ public String CalculateTimeRemainingWithSampleDateFormat(long timeRemaining)
1499+ {
1500+ long t = timeRemaining / 1000;
1501+ int hours = Math.round(((t / 3600) % 24));
1502+ int minutes = Math.round((t / 60) % 60);
1503+ int seconds = Math.round(t % 60);
1504+ return String.format("%sH:%sm:%ss", hours, minutes, seconds);
1505+ }
1506+
1507+ public String existIp(L2PcInstance p)
1508+ {
1509+
1510+ L2GameClient client = p.getClient();
1511+ if ((client.getConnection().getInetAddress() != null) && (client.getActiveChar() != null) && !client.isDetached())
1512+ {
1513+ try
1514+ {
1515+ return client.getConnection().getInetAddress().getHostAddress();
1516+ }
1517+ catch (Exception e)
1518+ {
1519+ e.printStackTrace();
1520+ }
1521+ }
1522+ return null;
1523+
1524+ }
1525+
1526+ public final void loadVotes()
1527+ {
1528+ _foundVoters = individualVoteDB.getInstance().getVotesDB();
1529+ }
1530+
1531+ protected void loadGlobalVotes()
1532+ {
1533+ _globalVotes = globalVoteDB.getInstance().getGlobalVotes();
1534+ }
1535+
1536+ public void saveVotes()
1537+ {
1538+ individualVoteDB.getInstance().SaveVotes(_foundVoters);
1539+ }
1540+
1541+ protected void AutoGlobalVoteReward()
1542+ {
1543+ final HashSet<String> ipList = new HashSet<>();
1544+ for (final voteSite vs : voteSite.values())
1545+ {
1546+
1547+ new Thread(new Runnable() {
1548+
1549+ @Override
1550+ public void run()
1551+ {
1552+ AutoGlobalVoteRewardCheck(vs.ordinal(),ipList);
1553+
1554+ }
1555+
1556+ }
1557+
1558+ ).start();
1559+
1560+ }
1561+ }
1562+
1563+ /**
1564+ * @param ordinal
1565+ * @param ipList
1566+ */
1567+ protected void AutoGlobalVoteRewardCheck(int ordinal, HashSet<String> ipList)
1568+ {
1569+ checkNewUpdate(ordinal);
1570+ if (_globalVotes[ordinal].getCurrentVotes() >= (_globalVotes[ordinal].getVotesLastReward() + (ordinal == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)))
1571+ {
1572+ _globalVotes[ordinal].setVotesLastReward(_globalVotes[ordinal].getVotesLastReward() + (ordinal == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD));
1573+ for (L2PcInstance player : L2World.getInstance().getAllPlayers())
1574+ {
1575+ String ip = existIp(player);
1576+ if (ip == null)
1577+ {
1578+ continue;
1579+ }
1580+ if (ipList.contains(ip))
1581+ {
1582+ continue;
1583+ }
1584+ for (Reward reward : VoteSiteXml.getInstance().getRewards(11))
1585+ {
1586+ player.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), player, null);
1587+ player.sendPacket(new SystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
1588+ }
1589+ ipList.add(ip);
1590+ player.sendPacket(new ItemList(player, true));
1591+ }
1592+ Broadcast.toAllOnlinePlayers(VoteUtil.Sites[ordinal] + ": All players has been rewarded, please check your inventory",true);
1593+ }
1594+ else
1595+ {
1596+ String encourage = "";
1597+ int nextReward = _globalVotes[ordinal].getVotesLastReward() + (ordinal == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
1598+ encourage = String.format("Vote for %s current Votes: %s, next quantity of votes to reward : %s, need votes to next reward: %s", VoteUtil.Sites[ordinal], _globalVotes[ordinal].getCurrentVotes(), nextReward, nextReward - _globalVotes[ordinal].getCurrentVotes());
1599+ Broadcast.toAllOnlinePlayers(encourage,true);
1600+ }
1601+
1602+ }
1603+
1604+ protected void AutoSaveGlobalVotes()
1605+ {
1606+ globalVoteDB.getInstance().saveGlobalVotes(_globalVotes);
1607+ }
1608+
1609+ protected synchronized void AutoUpdateIndividualVotes()
1610+ {
1611+ AutoCleanInnecesaryIndividualVotes();
1612+ individualVoteDB.getInstance().SaveVotes(_foundVoters);
1613+ }
1614+
1615+ protected synchronized void AutoCleanInnecesaryIndividualVotes()
1616+ {
1617+ HashSet<individualVote> removeVotes = new HashSet<>();
1618+ for (Map.Entry<String, individualVote[]> ivs : _foundVoters.entrySet())
1619+ {
1620+ for (individualVote individualvote : ivs.getValue())
1621+ {
1622+ if (individualvote == null)
1623+ {
1624+ continue;
1625+ }
1626+ if (getTimeRemaining(individualvote) < 0)
1627+ {
1628+ removeVotes.add(individualvote);
1629+ if (_foundVoters.containsKey(individualvote.getVoterIp()))
1630+ {
1631+ if (_foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] != null)
1632+ {
1633+ _foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] = null;
1634+ }
1635+ }
1636+ }
1637+ }
1638+ }
1639+ individualVoteDB.getInstance().DeleteVotes(removeVotes);
1640+ }
1641+
1642+ public void checkAllResponseGlobalVotes()
1643+ {
1644+ for (final voteSite vs : voteSite.values())
1645+ {
1646+ new Thread(new Runnable() {
1647+
1648+ @Override
1649+ public void run()
1650+ {
1651+ checkNewUpdate(vs.ordinal());
1652+
1653+ }
1654+
1655+ }).start();
1656+ }
1657+ }
1658+
1659+
1660+ public void checkNewUpdate(int ordinalSite)
1661+ {
1662+ int globalVotesResponse = getGlobalVotesResponse(ordinalSite);
1663+ if (globalVotesResponse == -1)
1664+ {
1665+ }
1666+ _globalVotes[ordinalSite].setCurrentVotes(globalVotesResponse);
1667+ int last = globalVotesResponse - (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
1668+ if (last < 0)
1669+ {
1670+ _globalVotes[ordinalSite].setVotesLastReward(0);
1671+ }
1672+ if ((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) < globalVotesResponse)
1673+ {
1674+ _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse);
1675+ }
1676+ return;
1677+ }
1678+
1679+ public void Shutdown()
1680+ {
1681+ AutoSaveGlobalVotes();
1682+ AutoCleanInnecesaryIndividualVotes();
1683+ AutoUpdateIndividualVotes();
1684+ }
1685+
1686+ protected class AutoGlobalVoteRewardTask implements Runnable
1687+ {
1688+
1689+ @Override
1690+ public void run()
1691+ {
1692+ AutoGlobalVoteReward();
1693+
1694+ }
1695+
1696+ }
1697+
1698+ protected class AutoSaveGlobalVotesTask implements Runnable
1699+ {
1700+
1701+ @Override
1702+ public void run()
1703+ {
1704+ AutoSaveGlobalVotes();
1705+
1706+ }
1707+
1708+ }
1709+
1710+ protected class AutoUpdateIndividualVotesTask implements Runnable
1711+ {
1712+
1713+ @Override
1714+ public void run()
1715+ {
1716+ AutoUpdateIndividualVotes();
1717+
1718+ }
1719+
1720+ }
1721+
1722+ public static voteManager getInatance()
1723+ {
1724+ return SingleHolder.INSTANCE;
1725+ }
1726+
1727+ private static class SingleHolder
1728+ {
1729+ protected static final voteManager INSTANCE = new voteManager();
1730+ }
1731+}
1732\ No newline at end of file
1733Index: head-src/com/l2jfrozen/gameserver/GameServer.java
1734===================================================================
1735--- head-src/com/l2jfrozen/gameserver/GameServer.java (revision 1132)
1736+++ head-src/com/l2jfrozen/gameserver/GameServer.java (working copy)
1737@@ -146,6 +146,8 @@
1738 import com.l2jfrozen.gameserver.thread.daemons.PcPoint;
1739 import com.l2jfrozen.gameserver.util.DynamicExtension;
1740 import com.l2jfrozen.gameserver.util.sql.SQLQueue;
1741+import com.l2jfrozen.gameserver.votesystem.Handler.voteManager;
1742+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
1743 import com.l2jfrozen.netcore.NetcoreConfig;
1744 import com.l2jfrozen.netcore.SelectorConfig;
1745 import com.l2jfrozen.netcore.SelectorThread;
1746@@ -430,6 +432,18 @@
1747 UserCommandHandler.getInstance();
1748 VoicedCommandHandler.getInstance();
1749
1750+ Util.printSection("Vote Reward System");
1751+ if (Config.ENABLE_VOTE_SYSTEM)
1752+ {
1753+ voteManager.getInatance();
1754+ LOGGER.info("======================Vote System Enabled=========================");
1755+ VoteSiteXml.getInstance();
1756+ }
1757+ else
1758+ {
1759+ LOGGER.info("======================Vote System Disabled=========================");
1760+ }
1761+
1762 LOGGER.info("AutoChatHandler : Loaded " + AutoChatHandler.getInstance().size() + " handlers in total.");
1763 LOGGER.info("AutoSpawnHandler : Loaded " + AutoSpawn.getInstance().size() + " handlers in total.");
1764
1765Index: head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java
1766===================================================================
1767--- head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java (nonexistent)
1768+++ head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java (working copy)
1769@@ -0,0 +1,509 @@
1770+package com.l2jfrozen.gameserver.votesystem.Handler;
1771+
1772+import java.io.BufferedReader;
1773+import java.io.DataOutputStream;
1774+import java.io.InputStreamReader;
1775+import java.net.HttpURLConnection;
1776+import java.net.URL;
1777+import java.nio.charset.Charset;
1778+import java.text.ParseException;
1779+import java.text.SimpleDateFormat;
1780+import java.util.logging.Logger;
1781+
1782+import com.l2jfrozen.Config;
1783+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
1784+import com.l2jfrozen.gameserver.votesystem.Model.individualVoteResponse;
1785+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
1786+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteUtil;
1787+
1788+/**
1789+ * @author l2.topgameserver.net
1790+ */
1791+public class voteHandler
1792+{
1793+ public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
1794+
1795+ protected static String getNetWorkResponse(String URL, int ordinal)
1796+ {
1797+ if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
1798+ {
1799+ return "";
1800+ }
1801+
1802+ StringBuffer response = new StringBuffer();
1803+ try
1804+ {
1805+ String API_URL = Config.VOTE_NETWORK_LINK;
1806+ String detail = URL;
1807+ String postParameters = "";
1808+ postParameters += "apiKey=" + VoteUtil.between("apiKey=", detail, "&type=");
1809+ postParameters += "&type=" + VoteUtil.between("&type=", detail, "&player");
1810+ String beginIndexPlayer = "&player=";
1811+ String player = detail.substring(detail.indexOf(beginIndexPlayer) + beginIndexPlayer.length());
1812+
1813+ if ((player != null) && !player.equals(""))
1814+ {
1815+ postParameters += "&player=" + player;
1816+ }
1817+
1818+ byte[] postData = postParameters.getBytes(Charset.forName("UTF-8"));
1819+ URL url = new URL(API_URL);
1820+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
1821+ con.setConnectTimeout(5000);
1822+ con.setRequestMethod("POST");
1823+ con.setRequestProperty("Content-Length", Integer.toString(postData.length));
1824+ con.setRequestProperty("User-Agent", "Mozilla/5.0");
1825+ con.setDoOutput(true);
1826+
1827+ DataOutputStream os = new DataOutputStream(con.getOutputStream());
1828+ os.write(postData);
1829+ os.flush();
1830+ os.close();
1831+
1832+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
1833+ String inputLine;
1834+
1835+ while ((inputLine = in.readLine()) != null)
1836+ {
1837+ response.append(inputLine);
1838+ }
1839+ in.close();
1840+
1841+ return response.toString();
1842+
1843+ }
1844+ catch (Exception e)
1845+ {
1846+ LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getCause());
1847+ return "";
1848+ }
1849+ }
1850+
1851+ protected static String getResponse(String Url, int ordinal)
1852+ {
1853+ if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
1854+ {
1855+ return "";
1856+ }
1857+
1858+ try
1859+ {
1860+ int responseCode = 0;
1861+ URL objUrl = new URL(Url);
1862+ HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
1863+ con.setRequestMethod("GET");
1864+ con.setRequestProperty("User-Agent", "Mozilla/5.0");
1865+ con.setConnectTimeout(5000);
1866+ responseCode = con.getResponseCode();
1867+ if (responseCode == HttpURLConnection.HTTP_OK)
1868+ {
1869+ String inputLine;
1870+ StringBuffer response = new StringBuffer();
1871+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
1872+ while ((inputLine = in.readLine()) != null)
1873+ {
1874+ response.append(inputLine);
1875+ }
1876+ in.close();
1877+ return response.toString();
1878+ }
1879+
1880+ }
1881+ catch (Exception e)
1882+ {
1883+ LOGGER.warning(VoteSiteXml.getInstance().getSiteName(ordinal) + " Say: An error ocurred " + e.getCause());
1884+ return "";
1885+ }
1886+
1887+ return "";
1888+ }
1889+
1890+ public static individualVoteResponse getIndividualVoteResponse(int ordinal, String ip, String AccountName)
1891+ {
1892+ String response = "";
1893+ boolean isVoted = false;
1894+ long voteSiteTime = 0L, diffTime = 0L;
1895+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
1896+ individualVoteResponse ivr = new individualVoteResponse();
1897+
1898+ switch (ordinal)
1899+ {
1900+ case 0:
1901+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
1902+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"already_voted\":", response, ",\"vote_time\""));
1903+ if (isVoted)
1904+ {
1905+ try
1906+ {
1907+ voteSiteTime = format.parse(VoteUtil.between("\"vote_time\":\"", response, "\",\"server_time\"")).getTime();
1908+ diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"server_time\":\"", response, "\"}")).getTime();
1909+ }
1910+ catch (ParseException e)
1911+ {
1912+ e.printStackTrace();
1913+ }
1914+ }
1915+ break;
1916+
1917+ case 1:
1918+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
1919+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isvoted\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"votetime").replaceAll("\"", ""));
1920+ if (isVoted)
1921+ {
1922+ try
1923+ {
1924+ voteSiteTime = (Long.parseLong(VoteUtil.between("\"votetime\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"servertime"))) * 1000;
1925+ diffTime = System.currentTimeMillis() - ((Long.parseLong(VoteUtil.between("\"servertime\":", response.toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), "}"))) * 1000);
1926+ }
1927+ catch (Exception e)
1928+ {
1929+ e.printStackTrace();
1930+ }
1931+ }
1932+ break;
1933+
1934+ case 2:
1935+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
1936+ isVoted = (response == "") ? false : Boolean.parseBoolean(response);
1937+ if (isVoted)
1938+ {
1939+ voteSiteTime = System.currentTimeMillis();
1940+ diffTime = 0;
1941+ }
1942+ break;
1943+
1944+ case 3:
1945+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
1946+ isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"date\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"date\"")) == 1)) ? true : false;
1947+ if (isVoted)
1948+ {
1949+ String dateString = VoteUtil.between("\"date\":\"", response, "\"}]");
1950+ try
1951+ {
1952+ voteSiteTime = System.currentTimeMillis();
1953+ diffTime = 0;
1954+ }
1955+ catch (Exception e)
1956+ {
1957+ e.printStackTrace();
1958+ }
1959+
1960+ }
1961+ break;
1962+
1963+ case 4:
1964+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
1965+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
1966+ if (isVoted)
1967+ {
1968+ try
1969+ {
1970+ voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"hopzoneServerTime\"")).getTime();
1971+ diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"hopzoneServerTime\":\"", response, "\",\"status_code\":")).getTime();
1972+ }
1973+ catch (ParseException e)
1974+ {
1975+ e.printStackTrace();
1976+ }
1977+ }
1978+ break;
1979+
1980+ case 5:
1981+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
1982+ isVoted = (!"".equals(response) && (Integer.parseInt(response) == 1)) ? true : false;
1983+ if (isVoted)
1984+ {
1985+ voteSiteTime = System.currentTimeMillis();
1986+ diffTime = 0;
1987+ }
1988+ break;
1989+
1990+ case 6:
1991+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
1992+ isVoted = ("".equals(response)) ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
1993+ if (isVoted)
1994+ {
1995+ try
1996+ {
1997+ voteSiteTime = System.currentTimeMillis();
1998+ diffTime = 0;
1999+ }
2000+ catch (Exception e)
2001+ {
2002+ e.printStackTrace();
2003+ }
2004+
2005+ }
2006+ break;
2007+
2008+ case 7:
2009+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
2010+ isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"server_time\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1)) ? true : false;
2011+ if (isVoted)
2012+ {
2013+ try
2014+ {
2015+ voteSiteTime = System.currentTimeMillis();
2016+ diffTime = 0;
2017+ }
2018+ catch (Exception e)
2019+ {
2020+ e.printStackTrace();
2021+ }
2022+ }
2023+ break;
2024+
2025+ case 8:
2026+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
2027+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"is_voted\":", response, ",\"vote_time\""));
2028+ if (isVoted)
2029+ {
2030+ try
2031+ {
2032+ voteSiteTime = (Long.parseLong(VoteUtil.between("\"vote_time\":", response, ",\"server_time\""))) * 1000;
2033+ diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"server_time\":", response, "}}")) * 1000);
2034+ }
2035+ catch (Exception e)
2036+ {
2037+ e.printStackTrace();
2038+ }
2039+ }
2040+ break;
2041+
2042+ case 9:
2043+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
2044+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isVoted\": ", response, ",\"voteTime\""));
2045+ if (isVoted)
2046+ {
2047+ voteSiteTime = Long.parseLong(VoteUtil.between("\"voteTime\": \"", response, "\",\"serverTime\"")) * 1000;
2048+ diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"serverTime\": ", response, "}}")) * 1000);
2049+ }
2050+ break;
2051+
2052+ case 10:
2053+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
2054+ isVoted = (response == "") ? false : Boolean.parseBoolean(response);
2055+ if (isVoted)
2056+ {
2057+ voteSiteTime = System.currentTimeMillis();
2058+ diffTime = 0;
2059+ }
2060+ break;
2061+
2062+ }
2063+ if (!response.equals(""))
2064+ {
2065+ ivr.setIsVoted(isVoted);
2066+ ivr.setDiffTime(diffTime);
2067+ ivr.setVoteSiteTime(voteSiteTime);
2068+ return ivr;
2069+ }
2070+ return null;
2071+ }
2072+
2073+ public int getGlobalVotesResponse(int ordinal)
2074+ {
2075+
2076+ String response = "";
2077+ int totalVotes = 0;
2078+
2079+ switch (ordinal)
2080+ {
2081+ case 0:
2082+ response = getResponse(getGlobalUrl(ordinal), ordinal);
2083+ response = VoteUtil.between("\"getVotes\":", response, "}");
2084+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2085+ break;
2086+
2087+ case 1:
2088+ response = getResponse(getGlobalUrl(ordinal), ordinal);
2089+ response = VoteUtil.between("server_votes\":", response.replace(" ", ""), ",\"server_rank");
2090+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2091+ break;
2092+
2093+ case 2:
2094+ response = getResponse(getGlobalUrl(ordinal), ordinal);
2095+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2096+ break;
2097+
2098+ case 3:
2099+ response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
2100+ response = VoteUtil.between("Votes:</th><th><a class='votes'>", response, "</a></th></tr><tr><th>Clicks:");
2101+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2102+ break;
2103+
2104+ case 4:
2105+ response = getResponse(getGlobalUrl(ordinal), ordinal);
2106+ response = VoteUtil.between("\"totalvotes\":", response, ",\"status_code\"");
2107+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2108+ break;
2109+
2110+ case 5:
2111+ String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal), ordinal);
2112+ totalVotes = (!"".equals(responseNetwork)) ? Integer.parseInt(responseNetwork) : -1;
2113+ break;
2114+
2115+ case 6:
2116+ response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
2117+ response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>");
2118+
2119+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2120+ break;
2121+
2122+ case 7:
2123+ response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
2124+ response = VoteUtil.between("nicas:</b> ", response, "<br /><br />");
2125+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2126+ break;
2127+
2128+ case 8:
2129+ response = getResponse(getGlobalUrl(ordinal), ordinal);
2130+ response = VoteUtil.between("\"monthly_votes\":", response, "}}");
2131+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2132+ break;
2133+
2134+ case 9:
2135+ response = getResponse(getGlobalUrl(ordinal), ordinal);
2136+ response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\"");
2137+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2138+ break;
2139+
2140+ case 10:
2141+ response = getResponse(getGlobalUrl(ordinal), ordinal);
2142+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
2143+ break;
2144+ }
2145+
2146+ return totalVotes;
2147+ }
2148+
2149+ public static String getIndividualUrl(int ordinal, String ip, String AccountName)
2150+ {
2151+ String url = "";
2152+ ip = (Config.TEST_IP.equalsIgnoreCase("off") || Config.TEST_IP.equalsIgnoreCase("")) ? ip : Config.TEST_IP;
2153+ switch (ordinal)
2154+ {
2155+ case 0:
2156+ // l2.topgameserver.net
2157+ url = String.format("%sAPI_KEY=%s/getData/%s", Config.VOTE_LINK_TGS, Config.TGS_API_KEY, ip);
2158+ break;
2159+
2160+ case 1:
2161+ // itopz.com
2162+ url = String.format("%s%s/%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID, ip);
2163+ break;
2164+
2165+ case 2:
2166+ // l2top.co
2167+ url = String.format("%sVoteCheck.php?id=%s&ip=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID, ip);
2168+ break;
2169+
2170+ case 3:
2171+ // l2votes.com
2172+ url = String.format("%sapi.php?apiKey=%s&ip=%s", Config.VOTE_LINK_VTS, Config.VTS_API_KEY, ip);
2173+ break;
2174+
2175+ case 4:
2176+ // hopzone.net
2177+ url = String.format("%svote?token=%s&ip_address=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY, ip);
2178+ break;
2179+
2180+ case 5:
2181+ // l2network.eu
2182+ url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_USER_NAME, ip);
2183+ break;
2184+
2185+ case 6:
2186+ // l2topservers.com
2187+ url = String.format("%stoken=%s&ip=%s", Config.VOTE_LINK_TSS, Config.TSS_API_TOKEN, ip);
2188+ break;
2189+
2190+ case 7:
2191+ // top.l2jbrasil.com
2192+ url = String.format("%susername=%s&ip=%s&type=json", Config.BRASIL_VOTE_LINK, Config.BRASIL_USER_NAME, ip);
2193+ break;
2194+
2195+ case 8:
2196+ // mmotop
2197+ url = String.format("%s%s/%s", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY, ip);
2198+ break;
2199+
2200+ case 9:
2201+ // topzone.com
2202+ url = String.format("%svote?token=%s&ip=%s", Config.VOTE_LINK_TZ, Config.TZ_API_KEY, ip);
2203+ break;
2204+
2205+ case 10:
2206+ // l2servers.com
2207+ 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);
2208+ break;
2209+ }
2210+
2211+ return url;
2212+ }
2213+
2214+ public String getGlobalUrl(int ordinal)
2215+ {
2216+ String url = "";
2217+
2218+ switch (ordinal)
2219+ {
2220+ case 0:
2221+ // l2.topgameserver.net
2222+ url = String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS, Config.TGS_API_KEY);
2223+ break;
2224+
2225+ case 1:
2226+ // itopz.com
2227+ url = String.format("%s%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID);
2228+ break;
2229+
2230+ case 2:
2231+ // l2top.co
2232+ url = String.format("%sVoteCheck_Total.php?id=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID);
2233+ break;
2234+
2235+ case 3:
2236+ // l2votes.com
2237+ url = String.format("%sserverPage.php?sid=%s", Config.VOTE_LINK_VTS, Config.VTS_SID);
2238+ break;
2239+
2240+ case 4:
2241+ // hopzone.net
2242+ url = String.format("%svotes?token=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY);
2243+ break;
2244+
2245+ case 5:
2246+ // l2network.eu
2247+ url = String.format("apiKey=%s&type=%s&player=", Config.VOTE_NETWORK_API_KEY, 1);
2248+ break;
2249+
2250+ case 6:
2251+ // l2topservers
2252+ url = String.format("https://l2topservers.com/l2top/%s/%s", Config.TS_SRV_ID, Config.TS_DOMAIN_NAME);
2253+ break;
2254+
2255+ case 7:
2256+ // top.l2jbrasil.com
2257+ url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s", Config.BRASIL_USER_NAME);
2258+ break;
2259+
2260+ case 8:
2261+ // mmotop.eu/l2/
2262+ url = String.format("%s%s/info/", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY);
2263+ break;
2264+
2265+ case 9:
2266+ // l2topzone.com
2267+ url = String.format("%sserver_%s/getServerData", Config.VOTE_LINK_TZ, Config.TZ_API_KEY);
2268+ break;
2269+
2270+ case 10:
2271+ // l2servers.com
2272+ url = String.format("%syearlyvotes.php?server_id=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_SRV_ID);
2273+ break;
2274+ }
2275+
2276+ return url;
2277+ }
2278+}
2279\ No newline at end of file
2280Index: head-src/com/l2jfrozen/Config.java
2281===================================================================
2282--- head-src/com/l2jfrozen/Config.java (revision 1132)
2283+++ head-src/com/l2jfrozen/Config.java (working copy)
2284@@ -55,6 +55,111 @@
2285 {
2286 private static final Logger LOGGER = Logger.getLogger(Config.class);
2287
2288+
2289+
2290+ // ---------------------------------------------------
2291+ // VOTE SYSTEM
2292+ // ---------------------------------------------------
2293+ public static boolean ENABLE_VOTE_SYSTEM;
2294+ public static boolean ENABLE_INDIVIDUAL_VOTE;
2295+ public static boolean ENABLE_GLOBAL_VOTE;
2296+ public static int NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE;
2297+ public static int NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES;
2298+ public static int NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES;
2299+ public static int NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD;
2300+ public static int INTERVAL_TO_NEXT_VOTE;
2301+ public static int GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD;
2302+ public static boolean ENABLE_VOTING_COMMAND;
2303+ public static String VOTING_COMMAND;
2304+ public static String VOTE_LINK_TGS;
2305+ public static String TGS_API_KEY;
2306+ public static String VOTE_LINK_TOP_CO;
2307+ public static String TOP_CO_SRV_ID;
2308+ public static String VOTE_LINK_ITOPZ;
2309+ public static String ITOPZ_API_KEY;
2310+ public static String ITOPZ_SRV_ID;
2311+ public static String VOTE_LINK_VTS;
2312+ public static String VTS_API_KEY;
2313+ public static String VTS_SID;
2314+ public static String VOTE_LINK_HZ;
2315+ public static String HZ_API_KEY;
2316+ public static String VOTE_NETWORK_LINK;
2317+ public static String VOTE_NETWORK_USER_NAME;
2318+ public static String VOTE_NETWORK_API_KEY;
2319+ public static String VOTE_LINK_TSS;
2320+ public static String TSS_API_TOKEN;
2321+ public static String TS_SRV_ID;
2322+ public static String TS_DOMAIN_NAME;
2323+ public static String BRASIL_VOTE_LINK;
2324+ public static String BRASIL_USER_NAME;
2325+ public static String VOTE_LINK_MMOTOP;
2326+ public static String MMOTOP_API_KEY;
2327+ public static String VOTE_LINK_TZ;
2328+ public static String TZ_API_KEY;
2329+ public static String VOTE_LINK_SERVERS;
2330+ public static String SERVERS_HASH_CODE;
2331+ public static String SERVERS_SRV_ID;
2332+ public static String TEST_IP;
2333+
2334+ public static void loadVoteConfig() {
2335+ final String VOTE = FService.VOTE_SYSTEM_FILE;
2336+
2337+ try {
2338+ final Properties VoteSettings = new Properties();
2339+ final InputStream is = new FileInputStream(new File(VOTE));
2340+ VoteSettings.load(is);
2341+ is.close();
2342+ // ===============================================================
2343+
2344+ ENABLE_VOTE_SYSTEM = Boolean.parseBoolean(VoteSettings.getProperty("EnableVoteSettings", "true"));
2345+ ENABLE_INDIVIDUAL_VOTE = Boolean.parseBoolean(VoteSettings.getProperty("EnableIndividualVote", "true"));
2346+ ENABLE_GLOBAL_VOTE = Boolean.parseBoolean(VoteSettings.getProperty("EnableGlobalVote", "true"));
2347+ NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = Integer.parseInt(VoteSettings.getProperty("NextTimeToAutoUpdateTotalVote", "60")) * 60 * 1000; // -> minutes
2348+ NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = Integer.parseInt(VoteSettings.getProperty("NextTimeToAutoUpdateIndividualVotes", "60")) * 60 * 1000; // -> minutes
2349+ NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = Integer.parseInt(VoteSettings.getProperty("NextTimeToAutoCleanInnecesaryVotes", "30")) * 60 * 1000; // -> minutes
2350+ NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = Integer.parseInt(VoteSettings.getProperty("NextTimeToCheckAutoGlobalVotesReward", "5")) * 60 * 1000; // -> minutes
2351+ INTERVAL_TO_NEXT_VOTE = Integer.parseInt(VoteSettings.getProperty("IntervalTimeToNextVote", "12")) * 3600 * 1000; // -> hours
2352+ GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = Integer.parseInt(VoteSettings.getProperty("GlobalVotesAmountToNextReward", "50"));
2353+ ENABLE_VOTING_COMMAND = Boolean.parseBoolean(VoteSettings.getProperty("EnableVotingCommand", "true"));
2354+ VOTING_COMMAND = VoteSettings.getProperty("VotingCommand", "getreward");
2355+ VOTE_LINK_TGS = VoteSettings.getProperty("VoteLinkTgs", "");
2356+ TGS_API_KEY = VoteSettings.getProperty("TgsApiKey", "");
2357+ VOTE_LINK_TOP_CO = VoteSettings.getProperty("VoteLinkTopCo", "");
2358+ TOP_CO_SRV_ID = VoteSettings.getProperty("TopCoSrvId", "");
2359+ VOTE_LINK_ITOPZ = VoteSettings.getProperty("VoteLinkItopz", "");
2360+ ITOPZ_API_KEY = VoteSettings.getProperty("ItopzZpiKey", "");
2361+ ITOPZ_SRV_ID = VoteSettings.getProperty("ItopzSrvId", "");
2362+ VOTE_LINK_VTS = VoteSettings.getProperty("VoteLinkVts", "");
2363+ VTS_API_KEY = VoteSettings.getProperty("VtsApiKey", "");
2364+ VTS_SID = VoteSettings.getProperty("VtsSid", "");
2365+ VOTE_LINK_HZ = VoteSettings.getProperty("VoteLinkHz", "");
2366+ HZ_API_KEY = VoteSettings.getProperty("HzApiKey", "");
2367+ VOTE_NETWORK_LINK = VoteSettings.getProperty("VoteNetworkLink", "");
2368+ VOTE_NETWORK_USER_NAME = VoteSettings.getProperty("VoteNetworkUserName", "");
2369+ VOTE_NETWORK_API_KEY = VoteSettings.getProperty("VoteNetworkApiKey", "");
2370+ VOTE_LINK_TSS = VoteSettings.getProperty("VoteLinkTss", "");
2371+ TSS_API_TOKEN = VoteSettings.getProperty("TssApiToken", "");
2372+ TS_SRV_ID = VoteSettings.getProperty("TsSrvId", "");
2373+ TS_DOMAIN_NAME = VoteSettings.getProperty("TsDomainName", "");
2374+ BRASIL_VOTE_LINK = VoteSettings.getProperty("BrasilVoteLink", "");
2375+ BRASIL_USER_NAME = VoteSettings.getProperty("BrasilUserName", "");
2376+ VOTE_LINK_MMOTOP = VoteSettings.getProperty("VoteLinkMmotop", "");
2377+ MMOTOP_API_KEY = VoteSettings.getProperty("MmotopApiKey", "");
2378+ VOTE_LINK_TZ = VoteSettings.getProperty("VoteLinkTz", "");
2379+ TZ_API_KEY = VoteSettings.getProperty("TzApiKey", "");
2380+ VOTE_LINK_SERVERS = VoteSettings.getProperty("VoteLinkServers", "");
2381+ SERVERS_HASH_CODE = VoteSettings.getProperty("ServersHashCode", "");
2382+ SERVERS_SRV_ID = VoteSettings.getProperty("ServersSrvId", "");
2383+ TEST_IP = VoteSettings.getProperty("TestIp", "");
2384+
2385+ }
2386+ catch (final Exception e)
2387+ {
2388+ e.printStackTrace();
2389+ throw new Error("Failed to Load " + VOTE + " File.");
2390+ }
2391+ }
2392+
2393 // ============================================================
2394 public static boolean EVERYBODY_HAS_ADMIN_RIGHTS;
2395 public static boolean SHOW_GM_LOGIN;
2396@@ -4531,6 +4636,7 @@
2397 // Head functions
2398 loadL2JFrozenConfig();
2399 loadPHYSICSConfig();
2400+ loadVoteConfig();
2401 loadAccessConfig();
2402 loadPvpConfig();
2403 loadCraftConfig();
2404Index: head-src/com/l2jfrozen/gameserver/enums/ChatType.java
2405===================================================================
2406--- head-src/com/l2jfrozen/gameserver/enums/ChatType.java (nonexistent)
2407+++ head-src/com/l2jfrozen/gameserver/enums/ChatType.java (working copy)
2408@@ -0,0 +1,60 @@
2409+
2410+package com.l2jfrozen.gameserver.enums;
2411+
2412+/**
2413+ * @author St3eT
2414+ */
2415+public enum ChatType
2416+{
2417+ GENERAL(0),
2418+ SHOUT(1),
2419+ WHISPER(2),
2420+ PARTY(3),
2421+ CLAN(4),
2422+ GM(5),
2423+ PETITION_PLAYER(6),
2424+ PETITION_GM(7),
2425+ TRADE(8),
2426+ ALLIANCE(9),
2427+ ANNOUNCEMENT(10),
2428+ BOAT(11),
2429+ FRIEND(12),
2430+ MSNCHAT(13),
2431+ PARTYMATCH_ROOM(14),
2432+ PARTYROOM_COMMANDER(15),
2433+ PARTYROOM_ALL(16),
2434+ HERO_VOICE(17),
2435+ CRITICAL_ANNOUNCE(18);
2436+
2437+ private final int _clientId;
2438+
2439+ private ChatType(int clientId)
2440+ {
2441+ _clientId = clientId;
2442+ }
2443+
2444+ /**
2445+ * @return the client id.
2446+ */
2447+ public int getClientId()
2448+ {
2449+ return _clientId;
2450+ }
2451+
2452+ /**
2453+ * Finds the {@code ChatType} by its clientId
2454+ * @param clientId the clientId
2455+ * @return the {@code ChatType} if its found, {@code null} otherwise.
2456+ */
2457+ public static ChatType findByClientId(int clientId)
2458+ {
2459+ for (ChatType ChatType : values())
2460+ {
2461+ if (ChatType.getClientId() == clientId)
2462+ {
2463+ return ChatType;
2464+ }
2465+ }
2466+ return null;
2467+ }
2468+}
2469\ No newline at end of file
2470Index: head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java
2471===================================================================
2472--- head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (revision 1132)
2473+++ head-src/com/l2jfrozen/gameserver/handler/VoicedCommandHandler.java (working copy)
2474@@ -38,6 +38,7 @@
2475 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.StatsCmd;
2476 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.TvTCmd;
2477 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.VersionCmd;
2478+import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.VoteReward;
2479 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Voting;
2480 import com.l2jfrozen.gameserver.handler.voicedcommandhandlers.Wedding;
2481
2482@@ -121,6 +122,11 @@
2483 registerVoicedCommandHandler(new OfflineShop());
2484 }
2485
2486+ if (Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTING_COMMAND)
2487+ {
2488+ registerVoicedCommandHandler(new VoteReward());
2489+ }
2490+
2491 LOGGER.info("VoicedCommandHandler: Loaded " + _datatable.size() + " handlers.");
2492
2493 }
2494Index: head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java
2495===================================================================
2496--- head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java (nonexistent)
2497+++ head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java (working copy)
2498@@ -0,0 +1,183 @@
2499+package com.l2jfrozen.gameserver.votesystem.DB;
2500+
2501+import java.sql.Connection;
2502+import java.sql.PreparedStatement;
2503+import java.sql.ResultSet;
2504+import java.sql.SQLException;
2505+import java.sql.Statement;
2506+import java.util.HashMap;
2507+import java.util.HashSet;
2508+import java.util.Map;
2509+import java.util.logging.Logger;
2510+
2511+import com.l2jfrozen.gameserver.votesystem.Model.individualVote;
2512+import com.l2jfrozen.util.database.L2DatabaseFactory;
2513+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
2514+
2515+
2516+/**
2517+ * @author l2.topgameserver.net
2518+ */
2519+public class individualVoteDB
2520+{
2521+ private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
2522+ private final Map<String, individualVote[]> _votes;
2523+ private Statement st;
2524+ private Connection con;
2525+
2526+ private individualVoteDB()
2527+ {
2528+ _votes = new HashMap<>();
2529+ loadVotes();
2530+ }
2531+
2532+ public void loadVotes()
2533+ {
2534+
2535+ _votes.clear();
2536+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2537+ PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualvotes");
2538+ ResultSet rs = ps.executeQuery();)
2539+ {
2540+ individualVote[] ivs = new individualVote[voteSite.values().length];
2541+ while (rs.next())
2542+ {
2543+ individualVote iv = new individualVote();
2544+ iv.setVoterIp(rs.getString("voterIp"));
2545+ iv.setVoteSite(rs.getInt("voteSite"));
2546+ iv.setDiffTime(rs.getLong("diffTime"));
2547+ iv.setVotingTimeSite(rs.getLong("votingTimeSite"));
2548+ iv.setAlreadyRewarded(rs.getBoolean("alreadyRewarded"));
2549+
2550+ if (_votes.containsKey(iv.getVoterIp()))
2551+ {
2552+ if (_votes.get(iv.getVoterIp())[iv.getVoteSite()] == null)
2553+ {
2554+ ivs[iv.getVoteSite()] = iv;
2555+ _votes.put(iv.getVoterIp(), ivs);
2556+ }
2557+ }
2558+ else
2559+ {
2560+ ivs[iv.getVoteSite()] = iv;
2561+ _votes.put(iv.getVoterIp(), ivs);
2562+
2563+ }
2564+ }
2565+
2566+ }
2567+ catch (SQLException e)
2568+ {
2569+ e.printStackTrace();
2570+ }
2571+
2572+ }
2573+
2574+ public void SaveVotes(Map<String, individualVote[]> votes)
2575+ {
2576+
2577+ if (votes == null)
2578+ {
2579+ return;
2580+ }
2581+ if (votes.size() == 0)
2582+ {
2583+ return;
2584+ }
2585+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2586+ PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE " + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite),alreadyRewarded = VALUES(alreadyRewarded)");)
2587+ {
2588+
2589+ for (Map.Entry<String, individualVote[]> ivm : votes.entrySet())
2590+ {
2591+ for (individualVote iv : ivm.getValue())
2592+ {
2593+ if (iv == null)
2594+ {
2595+ continue;
2596+ }
2597+ ps.setString(1, iv.getVoterIp());
2598+ ps.setInt(2, iv.getVoteSite());
2599+ ps.setLong(3, iv.getDiffTime());
2600+ ps.setLong(4, iv.getVotingTimeSite());
2601+ ps.setBoolean(5, iv.getAlreadyRewarded());
2602+ ps.addBatch();
2603+ }
2604+ }
2605+ ps.executeBatch();
2606+ }
2607+ catch (SQLException e)
2608+ {
2609+ e.printStackTrace();
2610+ }
2611+ }
2612+
2613+ public void SaveVote(individualVote vote)
2614+ {
2615+
2616+ if (vote == null)
2617+ {
2618+ return;
2619+ }
2620+
2621+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2622+ PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE" + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");)
2623+ {
2624+ ps.setString(1, vote.getVoterIp());
2625+ ps.setInt(2, vote.getVoteSite());
2626+ ps.setLong(3, vote.getDiffTime());
2627+ ps.setLong(4, vote.getVotingTimeSite());
2628+ ps.setBoolean(5, vote.getAlreadyRewarded());
2629+ ps.executeUpdate();
2630+ }
2631+ catch (SQLException e)
2632+ {
2633+ e.printStackTrace();
2634+ }
2635+ }
2636+
2637+ public void DeleteVotes(HashSet<individualVote> deleteVotes)
2638+ {
2639+ if (deleteVotes == null)
2640+ {
2641+ return;
2642+ }
2643+ if (deleteVotes.size() == 0)
2644+ {
2645+ return;
2646+ }
2647+ try(Connection con = L2DatabaseFactory.getInstance().getConnection();Statement st = con.createStatement();)
2648+ {
2649+
2650+ for (individualVote iv : deleteVotes)
2651+ {
2652+ String sql = String.format("Delete from individualvotes where voterIp = '%s' AND voteSite = %s", iv.getVoterIp(), iv.getVoteSite());
2653+ st.addBatch(sql);
2654+ }
2655+ int[] result = st.executeBatch();
2656+ st.close();
2657+ con.close();
2658+ LOGGER.info(result.length + " Innecesary votes has been deleted");
2659+
2660+ }
2661+ catch (SQLException e)
2662+ {
2663+ e.printStackTrace();
2664+ }
2665+ }
2666+
2667+ public Map<String, individualVote[]> getVotesDB()
2668+ {
2669+ return _votes;
2670+ }
2671+
2672+ public static final individualVoteDB getInstance()
2673+ {
2674+ return SingleHolder.INSTANCE;
2675+ }
2676+
2677+ private static final class SingleHolder
2678+ {
2679+ protected static final individualVoteDB INSTANCE = new individualVoteDB();
2680+ }
2681+}
2682\ No newline at end of file
2683Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java
2684===================================================================
2685--- head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java (nonexistent)
2686+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java (working copy)
2687@@ -0,0 +1,53 @@
2688+package com.l2jfrozen.gameserver.votesystem.Model;
2689+
2690+import java.util.ArrayList;
2691+import java.util.List;
2692+
2693+/**
2694+ * @author l2.topgameserver.net
2695+ */
2696+public class VoteSite
2697+{
2698+ private int _siteOrdinal;
2699+ private String _siteName;
2700+ private final List<Reward> _rewards = new ArrayList<>();
2701+
2702+ public VoteSite()
2703+ {
2704+
2705+ }
2706+
2707+ public void setSiteOrdinal(int siteOrdinal)
2708+ {
2709+ _siteOrdinal = siteOrdinal;
2710+ }
2711+
2712+ public void setSiteName(String siteName)
2713+ {
2714+ _siteName = siteName;
2715+ }
2716+
2717+ public void setRewardList(List<Reward> rewards)
2718+ {
2719+ for (Reward r : rewards)
2720+ {
2721+ _rewards.add(r);
2722+ }
2723+ }
2724+
2725+ public int getSiteOrdinal()
2726+ {
2727+ return _siteOrdinal;
2728+ }
2729+
2730+ public String getSiteName()
2731+ {
2732+ return _siteName;
2733+ }
2734+
2735+ public List<Reward> getRewardList()
2736+ {
2737+ return _rewards;
2738+ }
2739+
2740+}
2741Index: head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java
2742===================================================================
2743--- head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java (nonexistent)
2744+++ head-src/com/l2jfrozen/gameserver/votesystem/DB/globalVoteDB.java (working copy)
2745@@ -0,0 +1,123 @@
2746+package com.l2jfrozen.gameserver.votesystem.DB;
2747+
2748+import java.sql.Connection;
2749+import java.sql.PreparedStatement;
2750+import java.sql.ResultSet;
2751+import java.sql.SQLException;
2752+import java.sql.Statement;
2753+import java.util.logging.Logger;
2754+
2755+import com.l2jfrozen.gameserver.votesystem.Model.globalVote;
2756+import com.l2jfrozen.util.database.L2DatabaseFactory;
2757+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
2758+
2759+/**
2760+ * @author l2.topgameserver.net
2761+ */
2762+public class globalVoteDB
2763+{
2764+ public static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName());
2765+ private Statement st;
2766+ private Connection con;
2767+ private final globalVote[] _globalVotes;
2768+
2769+ private globalVoteDB()
2770+ {
2771+ _globalVotes = new globalVote[voteSite.values().length];
2772+ loadGlobalVotes();
2773+ }
2774+
2775+ public void loadGlobalVotes()
2776+ {
2777+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();PreparedStatement ps = con.prepareStatement("Select voteSite,lastRewardVotes from globalvotes");
2778+
2779+ ResultSet rs = ps.executeQuery();)
2780+ {
2781+ if (rs.getRow() == 0)
2782+ {
2783+ for (voteSite vs : voteSite.values())
2784+ {
2785+ globalVote gv = new globalVote();
2786+ gv.setVoteSite(vs.ordinal());
2787+ gv.setVotesLastReward(0);
2788+ _globalVotes[gv.getVoyeSite()] = gv;
2789+ }
2790+ return;
2791+ }
2792+ while (rs.next())
2793+ {
2794+ globalVote gv = new globalVote();
2795+ gv.setVoteSite(rs.getInt("voteSite"));
2796+ gv.setVotesLastReward(rs.getInt("lastRewardVotes"));
2797+ _globalVotes[gv.getVoyeSite()] = gv;
2798+ }
2799+ ps.close();
2800+ con.close();
2801+
2802+ }
2803+ catch (SQLException e)
2804+ {
2805+ e.printStackTrace();
2806+ }
2807+ }
2808+
2809+ public void saveGlobalVote(globalVote gb)
2810+ {
2811+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2812+ PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
2813+
2814+ {
2815+ ps.setInt(1, gb.getVoyeSite());
2816+ ps.setInt(2, gb.getVotesLastReward());
2817+ ps.executeUpdate();
2818+
2819+ ps.close();
2820+ con.close();
2821+
2822+ }
2823+ catch (SQLException e)
2824+ {
2825+ e.printStackTrace();
2826+ }
2827+ }
2828+
2829+ public void saveGlobalVotes(globalVote[] globalVotes)
2830+ {
2831+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2832+ PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
2833+
2834+ {
2835+ for (voteSite vs : voteSite.values())
2836+ {
2837+ globalVote gb = globalVotes[vs.ordinal()];
2838+ ps.setInt(1, gb.getVoyeSite());
2839+ ps.setInt(2, gb.getVotesLastReward());
2840+ ps.addBatch();
2841+ }
2842+ ps.executeBatch();
2843+
2844+ ps.close();
2845+ con.close();
2846+
2847+ }
2848+ catch (SQLException e)
2849+ {
2850+ e.printStackTrace();
2851+ }
2852+ }
2853+
2854+ public globalVote[] getGlobalVotes()
2855+ {
2856+ return _globalVotes;
2857+ }
2858+
2859+ public static final globalVoteDB getInstance()
2860+ {
2861+ return SingleHolder.INSTANCE;
2862+ }
2863+
2864+ private static final class SingleHolder
2865+ {
2866+ protected static final globalVoteDB INSTANCE = new globalVoteDB();
2867+ }
2868+}
2869Index: head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java
2870===================================================================
2871--- head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java (nonexistent)
2872+++ head-src/com/l2jfrozen/gameserver/votesystem/DB/individualVoteDB.java (working copy)
2873@@ -0,0 +1,183 @@
2874+package com.l2jfrozen.gameserver.votesystem.DB;
2875+
2876+import java.sql.Connection;
2877+import java.sql.PreparedStatement;
2878+import java.sql.ResultSet;
2879+import java.sql.SQLException;
2880+import java.sql.Statement;
2881+import java.util.HashMap;
2882+import java.util.HashSet;
2883+import java.util.Map;
2884+import java.util.logging.Logger;
2885+
2886+import com.l2jfrozen.gameserver.votesystem.Model.individualVote;
2887+import com.l2jfrozen.util.database.L2DatabaseFactory;
2888+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
2889+
2890+
2891+/**
2892+ * @author l2.topgameserver.net
2893+ */
2894+public class individualVoteDB
2895+{
2896+ private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
2897+ private final Map<String, individualVote[]> _votes;
2898+ private Statement st;
2899+ private Connection con;
2900+
2901+ private individualVoteDB()
2902+ {
2903+ _votes = new HashMap<>();
2904+ loadVotes();
2905+ }
2906+
2907+ public void loadVotes()
2908+ {
2909+
2910+ _votes.clear();
2911+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2912+ PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualvotes");
2913+ ResultSet rs = ps.executeQuery();)
2914+ {
2915+ individualVote[] ivs = new individualVote[voteSite.values().length];
2916+ while (rs.next())
2917+ {
2918+ individualVote iv = new individualVote();
2919+ iv.setVoterIp(rs.getString("voterIp"));
2920+ iv.setVoteSite(rs.getInt("voteSite"));
2921+ iv.setDiffTime(rs.getLong("diffTime"));
2922+ iv.setVotingTimeSite(rs.getLong("votingTimeSite"));
2923+ iv.setAlreadyRewarded(rs.getBoolean("alreadyRewarded"));
2924+
2925+ if (_votes.containsKey(iv.getVoterIp()))
2926+ {
2927+ if (_votes.get(iv.getVoterIp())[iv.getVoteSite()] == null)
2928+ {
2929+ ivs[iv.getVoteSite()] = iv;
2930+ _votes.put(iv.getVoterIp(), ivs);
2931+ }
2932+ }
2933+ else
2934+ {
2935+ ivs[iv.getVoteSite()] = iv;
2936+ _votes.put(iv.getVoterIp(), ivs);
2937+
2938+ }
2939+ }
2940+
2941+ }
2942+ catch (SQLException e)
2943+ {
2944+ e.printStackTrace();
2945+ }
2946+
2947+ }
2948+
2949+ public void SaveVotes(Map<String, individualVote[]> votes)
2950+ {
2951+
2952+ if (votes == null)
2953+ {
2954+ return;
2955+ }
2956+ if (votes.size() == 0)
2957+ {
2958+ return;
2959+ }
2960+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2961+ PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE " + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite),alreadyRewarded = VALUES(alreadyRewarded)");)
2962+ {
2963+
2964+ for (Map.Entry<String, individualVote[]> ivm : votes.entrySet())
2965+ {
2966+ for (individualVote iv : ivm.getValue())
2967+ {
2968+ if (iv == null)
2969+ {
2970+ continue;
2971+ }
2972+ ps.setString(1, iv.getVoterIp());
2973+ ps.setInt(2, iv.getVoteSite());
2974+ ps.setLong(3, iv.getDiffTime());
2975+ ps.setLong(4, iv.getVotingTimeSite());
2976+ ps.setBoolean(5, iv.getAlreadyRewarded());
2977+ ps.addBatch();
2978+ }
2979+ }
2980+ ps.executeBatch();
2981+ }
2982+ catch (SQLException e)
2983+ {
2984+ e.printStackTrace();
2985+ }
2986+ }
2987+
2988+ public void SaveVote(individualVote vote)
2989+ {
2990+
2991+ if (vote == null)
2992+ {
2993+ return;
2994+ }
2995+
2996+ try (Connection con = L2DatabaseFactory.getInstance().getConnection();
2997+ PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE" + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");)
2998+ {
2999+ ps.setString(1, vote.getVoterIp());
3000+ ps.setInt(2, vote.getVoteSite());
3001+ ps.setLong(3, vote.getDiffTime());
3002+ ps.setLong(4, vote.getVotingTimeSite());
3003+ ps.setBoolean(5, vote.getAlreadyRewarded());
3004+ ps.executeUpdate();
3005+ }
3006+ catch (SQLException e)
3007+ {
3008+ e.printStackTrace();
3009+ }
3010+ }
3011+
3012+ public void DeleteVotes(HashSet<individualVote> deleteVotes)
3013+ {
3014+ if (deleteVotes == null)
3015+ {
3016+ return;
3017+ }
3018+ if (deleteVotes.size() == 0)
3019+ {
3020+ return;
3021+ }
3022+ try(Connection con = L2DatabaseFactory.getInstance().getConnection();Statement st = con.createStatement();)
3023+ {
3024+
3025+ for (individualVote iv : deleteVotes)
3026+ {
3027+ String sql = String.format("Delete from individualvotes where voterIp = '%s' AND voteSite = %s", iv.getVoterIp(), iv.getVoteSite());
3028+ st.addBatch(sql);
3029+ }
3030+ int[] result = st.executeBatch();
3031+ st.close();
3032+ con.close();
3033+ LOGGER.info(result.length + " Innecesary votes has been deleted");
3034+
3035+ }
3036+ catch (SQLException e)
3037+ {
3038+ e.printStackTrace();
3039+ }
3040+ }
3041+
3042+ public Map<String, individualVote[]> getVotesDB()
3043+ {
3044+ return _votes;
3045+ }
3046+
3047+ public static final individualVoteDB getInstance()
3048+ {
3049+ return SingleHolder.INSTANCE;
3050+ }
3051+
3052+ private static final class SingleHolder
3053+ {
3054+ protected static final individualVoteDB INSTANCE = new individualVoteDB();
3055+ }
3056+}
3057\ No newline at end of file
3058Index: head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java
3059===================================================================
3060--- head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java (nonexistent)
3061+++ head-src/com/l2jfrozen/gameserver/votesystem/Enum/voteSite.java (working copy)
3062@@ -0,0 +1,19 @@
3063+package com.l2jfrozen.gameserver.votesystem.Enum;
3064+
3065+/**
3066+ * @author l2.topgameserver.net
3067+ */
3068+public enum voteSite
3069+{
3070+ L2TOPGAMESERVER, // 0
3071+ ITOPZ, // 1
3072+ L2TOPCO, // 2
3073+ L2VOTES, // 3
3074+ HOPZONE, // 4
3075+ L2NETWORK, // 5
3076+ L2TOPSERVERS, // 6
3077+ TOPL2JBRASIL, // 7
3078+ MMOTOP, // 8
3079+ TOPZONE, // 9
3080+ L2SERVERS,// 10
3081+}
3082Index: head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java
3083===================================================================
3084--- head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java (nonexistent)
3085+++ head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteHandler.java (working copy)
3086@@ -0,0 +1,509 @@
3087+package com.l2jfrozen.gameserver.votesystem.Handler;
3088+
3089+import java.io.BufferedReader;
3090+import java.io.DataOutputStream;
3091+import java.io.InputStreamReader;
3092+import java.net.HttpURLConnection;
3093+import java.net.URL;
3094+import java.nio.charset.Charset;
3095+import java.text.ParseException;
3096+import java.text.SimpleDateFormat;
3097+import java.util.logging.Logger;
3098+
3099+import com.l2jfrozen.Config;
3100+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
3101+import com.l2jfrozen.gameserver.votesystem.Model.individualVoteResponse;
3102+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
3103+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteUtil;
3104+
3105+/**
3106+ * @author l2.topgameserver.net
3107+ */
3108+public class voteHandler
3109+{
3110+ public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
3111+
3112+ protected static String getNetWorkResponse(String URL, int ordinal)
3113+ {
3114+ if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
3115+ {
3116+ return "";
3117+ }
3118+
3119+ StringBuffer response = new StringBuffer();
3120+ try
3121+ {
3122+ String API_URL = Config.VOTE_NETWORK_LINK;
3123+ String detail = URL;
3124+ String postParameters = "";
3125+ postParameters += "apiKey=" + VoteUtil.between("apiKey=", detail, "&type=");
3126+ postParameters += "&type=" + VoteUtil.between("&type=", detail, "&player");
3127+ String beginIndexPlayer = "&player=";
3128+ String player = detail.substring(detail.indexOf(beginIndexPlayer) + beginIndexPlayer.length());
3129+
3130+ if ((player != null) && !player.equals(""))
3131+ {
3132+ postParameters += "&player=" + player;
3133+ }
3134+
3135+ byte[] postData = postParameters.getBytes(Charset.forName("UTF-8"));
3136+ URL url = new URL(API_URL);
3137+ HttpURLConnection con = (HttpURLConnection) url.openConnection();
3138+ con.setConnectTimeout(5000);
3139+ con.setRequestMethod("POST");
3140+ con.setRequestProperty("Content-Length", Integer.toString(postData.length));
3141+ con.setRequestProperty("User-Agent", "Mozilla/5.0");
3142+ con.setDoOutput(true);
3143+
3144+ DataOutputStream os = new DataOutputStream(con.getOutputStream());
3145+ os.write(postData);
3146+ os.flush();
3147+ os.close();
3148+
3149+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
3150+ String inputLine;
3151+
3152+ while ((inputLine = in.readLine()) != null)
3153+ {
3154+ response.append(inputLine);
3155+ }
3156+ in.close();
3157+
3158+ return response.toString();
3159+
3160+ }
3161+ catch (Exception e)
3162+ {
3163+ LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getCause());
3164+ return "";
3165+ }
3166+ }
3167+
3168+ protected static String getResponse(String Url, int ordinal)
3169+ {
3170+ if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
3171+ {
3172+ return "";
3173+ }
3174+
3175+ try
3176+ {
3177+ int responseCode = 0;
3178+ URL objUrl = new URL(Url);
3179+ HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
3180+ con.setRequestMethod("GET");
3181+ con.setRequestProperty("User-Agent", "Mozilla/5.0");
3182+ con.setConnectTimeout(5000);
3183+ responseCode = con.getResponseCode();
3184+ if (responseCode == HttpURLConnection.HTTP_OK)
3185+ {
3186+ String inputLine;
3187+ StringBuffer response = new StringBuffer();
3188+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
3189+ while ((inputLine = in.readLine()) != null)
3190+ {
3191+ response.append(inputLine);
3192+ }
3193+ in.close();
3194+ return response.toString();
3195+ }
3196+
3197+ }
3198+ catch (Exception e)
3199+ {
3200+ LOGGER.warning(VoteSiteXml.getInstance().getSiteName(ordinal) + " Say: An error ocurred " + e.getCause());
3201+ return "";
3202+ }
3203+
3204+ return "";
3205+ }
3206+
3207+ public static individualVoteResponse getIndividualVoteResponse(int ordinal, String ip, String AccountName)
3208+ {
3209+ String response = "";
3210+ boolean isVoted = false;
3211+ long voteSiteTime = 0L, diffTime = 0L;
3212+ SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
3213+ individualVoteResponse ivr = new individualVoteResponse();
3214+
3215+ switch (ordinal)
3216+ {
3217+ case 0:
3218+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3219+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"already_voted\":", response, ",\"vote_time\""));
3220+ if (isVoted)
3221+ {
3222+ try
3223+ {
3224+ voteSiteTime = format.parse(VoteUtil.between("\"vote_time\":\"", response, "\",\"server_time\"")).getTime();
3225+ diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"server_time\":\"", response, "\"}")).getTime();
3226+ }
3227+ catch (ParseException e)
3228+ {
3229+ e.printStackTrace();
3230+ }
3231+ }
3232+ break;
3233+
3234+ case 1:
3235+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3236+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isvoted\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"votetime").replaceAll("\"", ""));
3237+ if (isVoted)
3238+ {
3239+ try
3240+ {
3241+ voteSiteTime = (Long.parseLong(VoteUtil.between("\"votetime\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"servertime"))) * 1000;
3242+ diffTime = System.currentTimeMillis() - ((Long.parseLong(VoteUtil.between("\"servertime\":", response.toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), "}"))) * 1000);
3243+ }
3244+ catch (Exception e)
3245+ {
3246+ e.printStackTrace();
3247+ }
3248+ }
3249+ break;
3250+
3251+ case 2:
3252+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3253+ isVoted = (response == "") ? false : Boolean.parseBoolean(response);
3254+ if (isVoted)
3255+ {
3256+ voteSiteTime = System.currentTimeMillis();
3257+ diffTime = 0;
3258+ }
3259+ break;
3260+
3261+ case 3:
3262+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3263+ isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"date\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"date\"")) == 1)) ? true : false;
3264+ if (isVoted)
3265+ {
3266+ String dateString = VoteUtil.between("\"date\":\"", response, "\"}]");
3267+ try
3268+ {
3269+ voteSiteTime = System.currentTimeMillis();
3270+ diffTime = 0;
3271+ }
3272+ catch (Exception e)
3273+ {
3274+ e.printStackTrace();
3275+ }
3276+
3277+ }
3278+ break;
3279+
3280+ case 4:
3281+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3282+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
3283+ if (isVoted)
3284+ {
3285+ try
3286+ {
3287+ voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"hopzoneServerTime\"")).getTime();
3288+ diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"hopzoneServerTime\":\"", response, "\",\"status_code\":")).getTime();
3289+ }
3290+ catch (ParseException e)
3291+ {
3292+ e.printStackTrace();
3293+ }
3294+ }
3295+ break;
3296+
3297+ case 5:
3298+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3299+ isVoted = (!"".equals(response) && (Integer.parseInt(response) == 1)) ? true : false;
3300+ if (isVoted)
3301+ {
3302+ voteSiteTime = System.currentTimeMillis();
3303+ diffTime = 0;
3304+ }
3305+ break;
3306+
3307+ case 6:
3308+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3309+ isVoted = ("".equals(response)) ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
3310+ if (isVoted)
3311+ {
3312+ try
3313+ {
3314+ voteSiteTime = System.currentTimeMillis();
3315+ diffTime = 0;
3316+ }
3317+ catch (Exception e)
3318+ {
3319+ e.printStackTrace();
3320+ }
3321+
3322+ }
3323+ break;
3324+
3325+ case 7:
3326+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3327+ isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"server_time\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1)) ? true : false;
3328+ if (isVoted)
3329+ {
3330+ try
3331+ {
3332+ voteSiteTime = System.currentTimeMillis();
3333+ diffTime = 0;
3334+ }
3335+ catch (Exception e)
3336+ {
3337+ e.printStackTrace();
3338+ }
3339+ }
3340+ break;
3341+
3342+ case 8:
3343+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3344+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"is_voted\":", response, ",\"vote_time\""));
3345+ if (isVoted)
3346+ {
3347+ try
3348+ {
3349+ voteSiteTime = (Long.parseLong(VoteUtil.between("\"vote_time\":", response, ",\"server_time\""))) * 1000;
3350+ diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"server_time\":", response, "}}")) * 1000);
3351+ }
3352+ catch (Exception e)
3353+ {
3354+ e.printStackTrace();
3355+ }
3356+ }
3357+ break;
3358+
3359+ case 9:
3360+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3361+ isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isVoted\": ", response, ",\"voteTime\""));
3362+ if (isVoted)
3363+ {
3364+ voteSiteTime = Long.parseLong(VoteUtil.between("\"voteTime\": \"", response, "\",\"serverTime\"")) * 1000;
3365+ diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"serverTime\": ", response, "}}")) * 1000);
3366+ }
3367+ break;
3368+
3369+ case 10:
3370+ response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
3371+ isVoted = (response == "") ? false : Boolean.parseBoolean(response);
3372+ if (isVoted)
3373+ {
3374+ voteSiteTime = System.currentTimeMillis();
3375+ diffTime = 0;
3376+ }
3377+ break;
3378+
3379+ }
3380+ if (!response.equals(""))
3381+ {
3382+ ivr.setIsVoted(isVoted);
3383+ ivr.setDiffTime(diffTime);
3384+ ivr.setVoteSiteTime(voteSiteTime);
3385+ return ivr;
3386+ }
3387+ return null;
3388+ }
3389+
3390+ public int getGlobalVotesResponse(int ordinal)
3391+ {
3392+
3393+ String response = "";
3394+ int totalVotes = 0;
3395+
3396+ switch (ordinal)
3397+ {
3398+ case 0:
3399+ response = getResponse(getGlobalUrl(ordinal), ordinal);
3400+ response = VoteUtil.between("\"getVotes\":", response, "}");
3401+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3402+ break;
3403+
3404+ case 1:
3405+ response = getResponse(getGlobalUrl(ordinal), ordinal);
3406+ response = VoteUtil.between("server_votes\":", response.replace(" ", ""), ",\"server_rank");
3407+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3408+ break;
3409+
3410+ case 2:
3411+ response = getResponse(getGlobalUrl(ordinal), ordinal);
3412+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3413+ break;
3414+
3415+ case 3:
3416+ response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
3417+ response = VoteUtil.between("Votes:</th><th><a class='votes'>", response, "</a></th></tr><tr><th>Clicks:");
3418+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3419+ break;
3420+
3421+ case 4:
3422+ response = getResponse(getGlobalUrl(ordinal), ordinal);
3423+ response = VoteUtil.between("\"totalvotes\":", response, ",\"status_code\"");
3424+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3425+ break;
3426+
3427+ case 5:
3428+ String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal), ordinal);
3429+ totalVotes = (!"".equals(responseNetwork)) ? Integer.parseInt(responseNetwork) : -1;
3430+ break;
3431+
3432+ case 6:
3433+ response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
3434+ response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>");
3435+
3436+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3437+ break;
3438+
3439+ case 7:
3440+ response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
3441+ response = VoteUtil.between("nicas:</b> ", response, "<br /><br />");
3442+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3443+ break;
3444+
3445+ case 8:
3446+ response = getResponse(getGlobalUrl(ordinal), ordinal);
3447+ response = VoteUtil.between("\"monthly_votes\":", response, "}}");
3448+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3449+ break;
3450+
3451+ case 9:
3452+ response = getResponse(getGlobalUrl(ordinal), ordinal);
3453+ response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\"");
3454+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3455+ break;
3456+
3457+ case 10:
3458+ response = getResponse(getGlobalUrl(ordinal), ordinal);
3459+ totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
3460+ break;
3461+ }
3462+
3463+ return totalVotes;
3464+ }
3465+
3466+ public static String getIndividualUrl(int ordinal, String ip, String AccountName)
3467+ {
3468+ String url = "";
3469+ ip = (Config.TEST_IP.equalsIgnoreCase("off") || Config.TEST_IP.equalsIgnoreCase("")) ? ip : Config.TEST_IP;
3470+ switch (ordinal)
3471+ {
3472+ case 0:
3473+ // l2.topgameserver.net
3474+ url = String.format("%sAPI_KEY=%s/getData/%s", Config.VOTE_LINK_TGS, Config.TGS_API_KEY, ip);
3475+ break;
3476+
3477+ case 1:
3478+ // itopz.com
3479+ url = String.format("%s%s/%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID, ip);
3480+ break;
3481+
3482+ case 2:
3483+ // l2top.co
3484+ url = String.format("%sVoteCheck.php?id=%s&ip=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID, ip);
3485+ break;
3486+
3487+ case 3:
3488+ // l2votes.com
3489+ url = String.format("%sapi.php?apiKey=%s&ip=%s", Config.VOTE_LINK_VTS, Config.VTS_API_KEY, ip);
3490+ break;
3491+
3492+ case 4:
3493+ // hopzone.net
3494+ url = String.format("%svote?token=%s&ip_address=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY, ip);
3495+ break;
3496+
3497+ case 5:
3498+ // l2network.eu
3499+ url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_USER_NAME, ip);
3500+ break;
3501+
3502+ case 6:
3503+ // l2topservers.com
3504+ url = String.format("%stoken=%s&ip=%s", Config.VOTE_LINK_TSS, Config.TSS_API_TOKEN, ip);
3505+ break;
3506+
3507+ case 7:
3508+ // top.l2jbrasil.com
3509+ url = String.format("%susername=%s&ip=%s&type=json", Config.BRASIL_VOTE_LINK, Config.BRASIL_USER_NAME, ip);
3510+ break;
3511+
3512+ case 8:
3513+ // mmotop
3514+ url = String.format("%s%s/%s", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY, ip);
3515+ break;
3516+
3517+ case 9:
3518+ // topzone.com
3519+ url = String.format("%svote?token=%s&ip=%s", Config.VOTE_LINK_TZ, Config.TZ_API_KEY, ip);
3520+ break;
3521+
3522+ case 10:
3523+ // l2servers.com
3524+ 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);
3525+ break;
3526+ }
3527+
3528+ return url;
3529+ }
3530+
3531+ public String getGlobalUrl(int ordinal)
3532+ {
3533+ String url = "";
3534+
3535+ switch (ordinal)
3536+ {
3537+ case 0:
3538+ // l2.topgameserver.net
3539+ url = String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS, Config.TGS_API_KEY);
3540+ break;
3541+
3542+ case 1:
3543+ // itopz.com
3544+ url = String.format("%s%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID);
3545+ break;
3546+
3547+ case 2:
3548+ // l2top.co
3549+ url = String.format("%sVoteCheck_Total.php?id=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID);
3550+ break;
3551+
3552+ case 3:
3553+ // l2votes.com
3554+ url = String.format("%sserverPage.php?sid=%s", Config.VOTE_LINK_VTS, Config.VTS_SID);
3555+ break;
3556+
3557+ case 4:
3558+ // hopzone.net
3559+ url = String.format("%svotes?token=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY);
3560+ break;
3561+
3562+ case 5:
3563+ // l2network.eu
3564+ url = String.format("apiKey=%s&type=%s&player=", Config.VOTE_NETWORK_API_KEY, 1);
3565+ break;
3566+
3567+ case 6:
3568+ // l2topservers
3569+ url = String.format("https://l2topservers.com/l2top/%s/%s", Config.TS_SRV_ID, Config.TS_DOMAIN_NAME);
3570+ break;
3571+
3572+ case 7:
3573+ // top.l2jbrasil.com
3574+ url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s", Config.BRASIL_USER_NAME);
3575+ break;
3576+
3577+ case 8:
3578+ // mmotop.eu/l2/
3579+ url = String.format("%s%s/info/", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY);
3580+ break;
3581+
3582+ case 9:
3583+ // l2topzone.com
3584+ url = String.format("%sserver_%s/getServerData", Config.VOTE_LINK_TZ, Config.TZ_API_KEY);
3585+ break;
3586+
3587+ case 10:
3588+ // l2servers.com
3589+ url = String.format("%syearlyvotes.php?server_id=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_SRV_ID);
3590+ break;
3591+ }
3592+
3593+ return url;
3594+ }
3595+}
3596\ No newline at end of file
3597Index: head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java
3598===================================================================
3599--- head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java (nonexistent)
3600+++ head-src/com/l2jfrozen/gameserver/votesystem/Handler/voteManager.java (working copy)
3601@@ -0,0 +1,417 @@
3602+package com.l2jfrozen.gameserver.votesystem.Handler;
3603+
3604+import java.util.HashSet;
3605+import java.util.Map;
3606+import java.util.concurrent.ConcurrentHashMap;
3607+import java.util.concurrent.ScheduledFuture;
3608+
3609+import com.l2jfrozen.gameserver.votesystem.Model.Reward;
3610+import com.l2jfrozen.gameserver.votesystem.Model.globalVote;
3611+import com.l2jfrozen.gameserver.votesystem.Model.individualVote;
3612+import com.l2jfrozen.gameserver.votesystem.Model.individualVoteResponse;
3613+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteSiteXml;
3614+import com.l2jfrozen.gameserver.votesystem.VoteUtil.VoteUtil;
3615+import com.l2jfrozen.Config;
3616+import com.l2jfrozen.gameserver.model.L2World;
3617+import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
3618+import com.l2jfrozen.gameserver.network.L2GameClient;
3619+import com.l2jfrozen.gameserver.network.SystemMessageId;
3620+import com.l2jfrozen.gameserver.network.serverpackets.ItemList;
3621+import com.l2jfrozen.gameserver.network.serverpackets.SystemMessage;
3622+import com.l2jfrozen.gameserver.thread.ThreadPoolManager;
3623+import com.l2jfrozen.gameserver.util.Broadcast;
3624+import com.l2jfrozen.gameserver.votesystem.DB.globalVoteDB;
3625+import com.l2jfrozen.gameserver.votesystem.DB.individualVoteDB;
3626+import com.l2jfrozen.gameserver.votesystem.Enum.voteSite;
3627+
3628+
3629+/**
3630+ * @author l2.topgameserver.net
3631+ */
3632+public final class voteManager extends voteHandler
3633+{
3634+ private ScheduledFuture<?> _saveGlobalVotes;
3635+ private ScheduledFuture<?> _updateIndividualVotes;
3636+ private ScheduledFuture<?> _autoGlobalVotesReward;
3637+
3638+ private Map<String, individualVote[]> _foundVoters;
3639+ private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
3640+
3641+ public voteManager()
3642+ {
3643+ _foundVoters = new ConcurrentHashMap<>();
3644+ loadVotes();
3645+ loadGlobalVotes();
3646+ checkAllResponseGlobalVotes();
3647+ stopAutoTasks();
3648+
3649+ if (Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
3650+ {
3651+ _updateIndividualVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES);
3652+ }
3653+ if (Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
3654+ {
3655+ _autoGlobalVotesReward = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD);
3656+ _saveGlobalVotes = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE);
3657+ }
3658+ }
3659+
3660+ private void stopAutoTasks()
3661+ {
3662+ if (_saveGlobalVotes != null)
3663+ {
3664+ _saveGlobalVotes.cancel(true);
3665+ _saveGlobalVotes = null;
3666+ }
3667+ if (_updateIndividualVotes != null)
3668+ {
3669+ _updateIndividualVotes.cancel(true);
3670+ _updateIndividualVotes = null;
3671+ }
3672+ if (_autoGlobalVotesReward != null)
3673+ {
3674+ _autoGlobalVotesReward.cancel(true);
3675+ _autoGlobalVotesReward = null;
3676+ }
3677+ }
3678+
3679+ public void getReward(L2PcInstance player, int ordinalSite)
3680+ {
3681+ String ip = existIp(player);
3682+ if (ip == null)
3683+ {
3684+ return;
3685+ }
3686+ individualVoteResponse ivr = getIndividualVoteResponse(ordinalSite, ip, player.getAccountName());
3687+ if (ivr == null)
3688+ {
3689+ player.sendMessage("We were unable to verify your vote with: " + VoteSiteXml.getInstance().getSiteName(ordinalSite) + ", please try again");
3690+ return;
3691+ }
3692+ if (!ivr.getIsVoted())
3693+ {
3694+ player.sendMessage(String.format("You haven't vote on %s yet!", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
3695+ return;
3696+ }
3697+ if (!checkIndividualAvailableVote(player, ordinalSite))
3698+ {
3699+ player.sendMessage(String.format("You can get the reward again on %s at %s", VoteSiteXml.getInstance().getSiteName(ordinalSite), getTimeRemainingWithSampleFormat(player, ordinalSite)));
3700+ return;
3701+ }
3702+ individualVote iv = new individualVote(ip, ivr.getDiffTime(), ivr.getVoteSiteTime(), ordinalSite, false);
3703+
3704+ individualVote[] aiv;
3705+ if (!_foundVoters.containsKey(ip))
3706+ {
3707+ aiv = new individualVote[voteSite.values().length];
3708+ iv.setAlreadyRewarded(true);
3709+ aiv[ordinalSite] = iv;
3710+ _foundVoters.put(ip, aiv);
3711+ }
3712+ else
3713+ {
3714+ aiv = _foundVoters.get(ip);
3715+ iv.setAlreadyRewarded(true);
3716+ aiv[ordinalSite] = iv;
3717+ _foundVoters.put(ip, aiv);
3718+
3719+ }
3720+ for (Reward reward : VoteSiteXml.getInstance().getRewards(ordinalSite))
3721+ {
3722+ player.getInventory().addItem("VoteSystem", reward.getItemId(), reward.getItemCount(), player, null);
3723+ player.sendPacket(new SystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
3724+ }
3725+ player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
3726+ player.sendPacket(new ItemList(player, true));
3727+ return;
3728+ }
3729+
3730+ public boolean checkIndividualAvailableVote(L2PcInstance player, int ordinalSite)
3731+ {
3732+ String ip = existIp(player);
3733+ if (_foundVoters.containsKey(ip))
3734+ {
3735+ individualVote[] ivs = _foundVoters.get(ip);
3736+ if (ivs[ordinalSite] == null)
3737+ {
3738+ return true;
3739+ }
3740+ if (ivs[ordinalSite] != null)
3741+ {
3742+ individualVote iv = ivs[ordinalSite];
3743+ if (getTimeRemaining(iv) < 0)
3744+ {
3745+ return true;
3746+ }
3747+ }
3748+ }
3749+ else
3750+ {
3751+ return true;
3752+ }
3753+
3754+ return false;
3755+ }
3756+
3757+ public long getTimeRemaining(individualVote iv)
3758+ {
3759+ long timeRemaining = 0L;
3760+ timeRemaining = ((iv.getVotingTimeSite() + Config.INTERVAL_TO_NEXT_VOTE) - (iv.getDiffTime() > 0 ? iv.getDiffTime() : -1 * iv.getDiffTime())) - System.currentTimeMillis();
3761+ return timeRemaining;
3762+ }
3763+
3764+ public String getTimeRemainingWithSampleFormat(L2PcInstance player, int ordinalSite)
3765+ {
3766+ String ip = existIp(player);
3767+ String timeRemainingWithSampleFormat = "";
3768+ if (_foundVoters.containsKey(ip))
3769+ {
3770+ individualVote[] ivs = _foundVoters.get(ip);
3771+ if (ivs[ordinalSite] != null)
3772+ {
3773+ individualVote iv = ivs[ordinalSite];
3774+ long timeRemaining = getTimeRemaining(iv);
3775+ if (timeRemaining > 0)
3776+ {
3777+ timeRemainingWithSampleFormat = CalculateTimeRemainingWithSampleDateFormat(timeRemaining);
3778+ return timeRemainingWithSampleFormat;
3779+ }
3780+ }
3781+ }
3782+ return timeRemainingWithSampleFormat;
3783+ }
3784+
3785+ public String CalculateTimeRemainingWithSampleDateFormat(long timeRemaining)
3786+ {
3787+ long t = timeRemaining / 1000;
3788+ int hours = Math.round(((t / 3600) % 24));
3789+ int minutes = Math.round((t / 60) % 60);
3790+ int seconds = Math.round(t % 60);
3791+ return String.format("%sH:%sm:%ss", hours, minutes, seconds);
3792+ }
3793+
3794+ public String existIp(L2PcInstance p)
3795+ {
3796+
3797+ L2GameClient client = p.getClient();
3798+ if ((client.getConnection().getInetAddress() != null) && (client.getActiveChar() != null) && !client.isDetached())
3799+ {
3800+ try
3801+ {
3802+ return client.getConnection().getInetAddress().getHostAddress();
3803+ }
3804+ catch (Exception e)
3805+ {
3806+ e.printStackTrace();
3807+ }
3808+ }
3809+ return null;
3810+
3811+ }
3812+
3813+ public final void loadVotes()
3814+ {
3815+ _foundVoters = individualVoteDB.getInstance().getVotesDB();
3816+ }
3817+
3818+ protected void loadGlobalVotes()
3819+ {
3820+ _globalVotes = globalVoteDB.getInstance().getGlobalVotes();
3821+ }
3822+
3823+ public void saveVotes()
3824+ {
3825+ individualVoteDB.getInstance().SaveVotes(_foundVoters);
3826+ }
3827+
3828+ protected void AutoGlobalVoteReward()
3829+ {
3830+ final HashSet<String> ipList = new HashSet<>();
3831+ for (final voteSite vs : voteSite.values())
3832+ {
3833+
3834+ new Thread(new Runnable() {
3835+
3836+ @Override
3837+ public void run()
3838+ {
3839+ AutoGlobalVoteRewardCheck(vs.ordinal(),ipList);
3840+
3841+ }
3842+
3843+ }
3844+
3845+ ).start();
3846+
3847+ }
3848+ }
3849+
3850+ /**
3851+ * @param ordinal
3852+ * @param ipList
3853+ */
3854+ protected void AutoGlobalVoteRewardCheck(int ordinal, HashSet<String> ipList)
3855+ {
3856+ checkNewUpdate(ordinal);
3857+ if (_globalVotes[ordinal].getCurrentVotes() >= (_globalVotes[ordinal].getVotesLastReward() + (ordinal == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)))
3858+ {
3859+ _globalVotes[ordinal].setVotesLastReward(_globalVotes[ordinal].getVotesLastReward() + (ordinal == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD));
3860+ for (L2PcInstance player : L2World.getInstance().getAllPlayers())
3861+ {
3862+ String ip = existIp(player);
3863+ if (ip == null)
3864+ {
3865+ continue;
3866+ }
3867+ if (ipList.contains(ip))
3868+ {
3869+ continue;
3870+ }
3871+ for (Reward reward : VoteSiteXml.getInstance().getRewards(11))
3872+ {
3873+ player.getInventory().addItem("VoteSystem: ", reward.getItemId(), reward.getItemCount(), player, null);
3874+ player.sendPacket(new SystemMessage(SystemMessageId.EARNED_S2_S1_S).addItemName(reward.getItemId()).addNumber(reward.getItemCount()));
3875+ }
3876+ ipList.add(ip);
3877+ player.sendPacket(new ItemList(player, true));
3878+ }
3879+ Broadcast.toAllOnlinePlayers(VoteUtil.Sites[ordinal] + ": All players has been rewarded, please check your inventory",true);
3880+ }
3881+ else
3882+ {
3883+ String encourage = "";
3884+ int nextReward = _globalVotes[ordinal].getVotesLastReward() + (ordinal == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
3885+ encourage = String.format("Vote for %s current Votes: %s, next quantity of votes to reward : %s, need votes to next reward: %s", VoteUtil.Sites[ordinal], _globalVotes[ordinal].getCurrentVotes(), nextReward, nextReward - _globalVotes[ordinal].getCurrentVotes());
3886+ Broadcast.toAllOnlinePlayers(encourage,true);
3887+ }
3888+
3889+ }
3890+
3891+ protected void AutoSaveGlobalVotes()
3892+ {
3893+ globalVoteDB.getInstance().saveGlobalVotes(_globalVotes);
3894+ }
3895+
3896+ protected synchronized void AutoUpdateIndividualVotes()
3897+ {
3898+ AutoCleanInnecesaryIndividualVotes();
3899+ individualVoteDB.getInstance().SaveVotes(_foundVoters);
3900+ }
3901+
3902+ protected synchronized void AutoCleanInnecesaryIndividualVotes()
3903+ {
3904+ HashSet<individualVote> removeVotes = new HashSet<>();
3905+ for (Map.Entry<String, individualVote[]> ivs : _foundVoters.entrySet())
3906+ {
3907+ for (individualVote individualvote : ivs.getValue())
3908+ {
3909+ if (individualvote == null)
3910+ {
3911+ continue;
3912+ }
3913+ if (getTimeRemaining(individualvote) < 0)
3914+ {
3915+ removeVotes.add(individualvote);
3916+ if (_foundVoters.containsKey(individualvote.getVoterIp()))
3917+ {
3918+ if (_foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] != null)
3919+ {
3920+ _foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] = null;
3921+ }
3922+ }
3923+ }
3924+ }
3925+ }
3926+ individualVoteDB.getInstance().DeleteVotes(removeVotes);
3927+ }
3928+
3929+ public void checkAllResponseGlobalVotes()
3930+ {
3931+ for (final voteSite vs : voteSite.values())
3932+ {
3933+ new Thread(new Runnable() {
3934+
3935+ @Override
3936+ public void run()
3937+ {
3938+ checkNewUpdate(vs.ordinal());
3939+
3940+ }
3941+
3942+ }).start();
3943+ }
3944+ }
3945+
3946+
3947+ public void checkNewUpdate(int ordinalSite)
3948+ {
3949+ int globalVotesResponse = getGlobalVotesResponse(ordinalSite);
3950+ if (globalVotesResponse == -1)
3951+ {
3952+ }
3953+ _globalVotes[ordinalSite].setCurrentVotes(globalVotesResponse);
3954+ int last = globalVotesResponse - (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
3955+ if (last < 0)
3956+ {
3957+ _globalVotes[ordinalSite].setVotesLastReward(0);
3958+ }
3959+ if ((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) < globalVotesResponse)
3960+ {
3961+ _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse);
3962+ }
3963+ return;
3964+ }
3965+
3966+ public void Shutdown()
3967+ {
3968+ AutoSaveGlobalVotes();
3969+ AutoCleanInnecesaryIndividualVotes();
3970+ AutoUpdateIndividualVotes();
3971+ }
3972+
3973+ protected class AutoGlobalVoteRewardTask implements Runnable
3974+ {
3975+
3976+ @Override
3977+ public void run()
3978+ {
3979+ AutoGlobalVoteReward();
3980+
3981+ }
3982+
3983+ }
3984+
3985+ protected class AutoSaveGlobalVotesTask implements Runnable
3986+ {
3987+
3988+ @Override
3989+ public void run()
3990+ {
3991+ AutoSaveGlobalVotes();
3992+
3993+ }
3994+
3995+ }
3996+
3997+ protected class AutoUpdateIndividualVotesTask implements Runnable
3998+ {
3999+
4000+ @Override
4001+ public void run()
4002+ {
4003+ AutoUpdateIndividualVotes();
4004+
4005+ }
4006+
4007+ }
4008+
4009+ public static voteManager getInatance()
4010+ {
4011+ return SingleHolder.INSTANCE;
4012+ }
4013+
4014+ private static class SingleHolder
4015+ {
4016+ protected static final voteManager INSTANCE = new voteManager();
4017+ }
4018+}
4019\ No newline at end of file
4020Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java
4021===================================================================
4022--- head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java (nonexistent)
4023+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/Reward.java (working copy)
4024@@ -0,0 +1,44 @@
4025+package com.l2jfrozen.gameserver.votesystem.Model;
4026+
4027+import com.l2jfrozen.gameserver.templates.StatsSet;
4028+
4029+/**
4030+ * @author l2.topgameserver.net
4031+ */
4032+public class Reward
4033+{
4034+ private int _itemId;
4035+ private int _itemCount;
4036+
4037+ public Reward(int itemId, int itemCount)
4038+ {
4039+ this._itemId = itemId;
4040+ this._itemCount = itemCount;
4041+ }
4042+
4043+ public Reward(StatsSet set)
4044+ {
4045+ _itemId = set.getInteger("itemId");
4046+ _itemCount = set.getInteger("itemCount");
4047+ }
4048+
4049+ public void setItemId(int itemId)
4050+ {
4051+ _itemId = itemId;
4052+ }
4053+
4054+ public void setItemCount(int itemCount)
4055+ {
4056+ _itemCount = itemCount;
4057+ }
4058+
4059+ public int getItemId()
4060+ {
4061+ return _itemId;
4062+ }
4063+
4064+ public int getItemCount()
4065+ {
4066+ return _itemCount;
4067+ }
4068+}
4069Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java
4070===================================================================
4071--- head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java (nonexistent)
4072+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/VoteSite.java (working copy)
4073@@ -0,0 +1,53 @@
4074+package com.l2jfrozen.gameserver.votesystem.Model;
4075+
4076+import java.util.ArrayList;
4077+import java.util.List;
4078+
4079+/**
4080+ * @author l2.topgameserver.net
4081+ */
4082+public class VoteSite
4083+{
4084+ private int _siteOrdinal;
4085+ private String _siteName;
4086+ private final List<Reward> _rewards = new ArrayList<>();
4087+
4088+ public VoteSite()
4089+ {
4090+
4091+ }
4092+
4093+ public void setSiteOrdinal(int siteOrdinal)
4094+ {
4095+ _siteOrdinal = siteOrdinal;
4096+ }
4097+
4098+ public void setSiteName(String siteName)
4099+ {
4100+ _siteName = siteName;
4101+ }
4102+
4103+ public void setRewardList(List<Reward> rewards)
4104+ {
4105+ for (Reward r : rewards)
4106+ {
4107+ _rewards.add(r);
4108+ }
4109+ }
4110+
4111+ public int getSiteOrdinal()
4112+ {
4113+ return _siteOrdinal;
4114+ }
4115+
4116+ public String getSiteName()
4117+ {
4118+ return _siteName;
4119+ }
4120+
4121+ public List<Reward> getRewardList()
4122+ {
4123+ return _rewards;
4124+ }
4125+
4126+}
4127Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java
4128===================================================================
4129--- head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java (nonexistent)
4130+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/globalVote.java (working copy)
4131@@ -0,0 +1,53 @@
4132+package com.l2jfrozen.gameserver.votesystem.Model;
4133+
4134+/**
4135+ * @author l2.topgameserver.net
4136+ */
4137+public class globalVote
4138+{
4139+ private int _voteSite;
4140+ private int _votesLastReward;
4141+ private int _currentVotes;
4142+
4143+ public globalVote()
4144+ {
4145+
4146+ }
4147+
4148+ public globalVote(int voteSite, int votesLastReward)
4149+ {
4150+ _voteSite = voteSite;
4151+ _votesLastReward = votesLastReward;
4152+ }
4153+
4154+ public void setVoteSite(int voteSite)
4155+ {
4156+ _voteSite = voteSite;
4157+ }
4158+
4159+ public void setVotesLastReward(int votesLastReward)
4160+ {
4161+ _votesLastReward = votesLastReward;
4162+ }
4163+
4164+ public void setCurrentVotes(int currentVotes)
4165+ {
4166+ _currentVotes = currentVotes;
4167+ }
4168+
4169+ public int getVoyeSite()
4170+ {
4171+ return _voteSite;
4172+ }
4173+
4174+ public int getVotesLastReward()
4175+ {
4176+ return _votesLastReward;
4177+ }
4178+
4179+ public int getCurrentVotes()
4180+ {
4181+ return _currentVotes;
4182+ }
4183+
4184+}
4185Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java
4186===================================================================
4187--- head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java (nonexistent)
4188+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVote.java (working copy)
4189@@ -0,0 +1,78 @@
4190+package com.l2jfrozen.gameserver.votesystem.Model;
4191+
4192+/**
4193+ * @author l2.topgameserver.net
4194+ */
4195+public class individualVote
4196+{
4197+ private String _voterIp;
4198+ private long _diffTime;
4199+ private long _votingTimeSite;
4200+ private int _voteSite;
4201+ private boolean _alreadyRewarded;
4202+
4203+ public individualVote(String voterIp, long diffTime, long votingTimeSite, int voteSite, boolean alreadyRewarded)
4204+ {
4205+ _voterIp = voterIp;
4206+ _diffTime = diffTime;
4207+ _votingTimeSite = votingTimeSite;
4208+ _voteSite = voteSite;
4209+ _alreadyRewarded = alreadyRewarded;
4210+ }
4211+
4212+ public individualVote()
4213+ {
4214+
4215+ }
4216+
4217+ public void setVoterIp(String voterIp)
4218+ {
4219+ _voterIp = voterIp;
4220+ }
4221+
4222+ public void setDiffTime(long diffTime)
4223+ {
4224+ _diffTime = diffTime;
4225+ }
4226+
4227+ public void setVotingTimeSite(long votingTimeSite)
4228+ {
4229+ _votingTimeSite = votingTimeSite;
4230+ }
4231+
4232+ public void setVoteSite(int voteSite)
4233+ {
4234+ _voteSite = voteSite;
4235+ }
4236+
4237+ public void setAlreadyRewarded(boolean alreadyRewarded)
4238+ {
4239+ _alreadyRewarded = alreadyRewarded;
4240+ }
4241+
4242+ public String getVoterIp()
4243+ {
4244+ return _voterIp;
4245+ }
4246+
4247+ public long getDiffTime()
4248+ {
4249+ return _diffTime;
4250+ }
4251+
4252+ public long getVotingTimeSite()
4253+ {
4254+ return _votingTimeSite;
4255+ }
4256+
4257+ public int getVoteSite()
4258+ {
4259+ return _voteSite;
4260+ }
4261+
4262+ public boolean getAlreadyRewarded()
4263+ {
4264+ return _alreadyRewarded;
4265+ }
4266+
4267+}
4268Index: head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java
4269===================================================================
4270--- head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java (nonexistent)
4271+++ head-src/com/l2jfrozen/gameserver/votesystem/Model/individualVoteResponse.java (working copy)
4272@@ -0,0 +1,46 @@
4273+package com.l2jfrozen.gameserver.votesystem.Model;
4274+
4275+/**
4276+ * @author l2.topgameserver.net
4277+ */
4278+public class individualVoteResponse
4279+{
4280+ private boolean _isVoted;
4281+ private long _diffTime;
4282+ private long _voteSiteTime;
4283+
4284+ public individualVoteResponse()
4285+ {
4286+
4287+ }
4288+
4289+ public void setIsVoted(boolean isVoted)
4290+ {
4291+ _isVoted = isVoted;
4292+ }
4293+
4294+ public void setDiffTime(long diffTime)
4295+ {
4296+ _diffTime = diffTime;
4297+ }
4298+
4299+ public void setVoteSiteTime(long voteSiteTime)
4300+ {
4301+ _voteSiteTime = voteSiteTime;
4302+ }
4303+
4304+ public boolean getIsVoted()
4305+ {
4306+ return _isVoted;
4307+ }
4308+
4309+ public long getDiffTime()
4310+ {
4311+ return _diffTime;
4312+ }
4313+
4314+ public long getVoteSiteTime()
4315+ {
4316+ return _voteSiteTime;
4317+ }
4318+}
4319Index: head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java
4320===================================================================
4321--- head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java (nonexistent)
4322+++ head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteSiteXml.java (working copy)
4323@@ -0,0 +1,127 @@
4324+package com.l2jfrozen.gameserver.votesystem.VoteUtil;
4325+
4326+import java.io.File;
4327+import java.util.Collection;
4328+import java.util.HashMap;
4329+import java.util.Map;
4330+import java.util.logging.Level;
4331+
4332+import javax.xml.parsers.DocumentBuilderFactory;
4333+
4334+import org.apache.log4j.Logger;
4335+
4336+import org.w3c.dom.Document;
4337+import org.w3c.dom.NamedNodeMap;
4338+import org.w3c.dom.Node;
4339+
4340+import com.l2jfrozen.Config;
4341+import com.l2jfrozen.gameserver.datatables.xml.ExperienceData;
4342+import com.l2jfrozen.gameserver.datatables.xml.AugmentationData.augmentationSkill;
4343+import com.l2jfrozen.gameserver.votesystem.Model.Reward;
4344+import com.l2jfrozen.gameserver.votesystem.Model.VoteSite;
4345+
4346+
4347+/**
4348+ * @author l2.topgameserver.net
4349+ */
4350+public class VoteSiteXml
4351+{
4352+
4353+ private final Map<Integer, VoteSite> _voteSites = new HashMap<>();
4354+ private static Logger LOGGER = Logger.getLogger(ExperienceData.class);
4355+
4356+ private VoteSiteXml()
4357+ {
4358+ load();
4359+ }
4360+
4361+
4362+ public void load()
4363+ {
4364+ try
4365+ {
4366+ final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
4367+ factory.setValidating(false);
4368+ factory.setIgnoringComments(true);
4369+
4370+ File file = new File(Config.DATAPACK_ROOT + "/data/stats/votesystem.xml");
4371+ if (!file.exists())
4372+ {
4373+ if (Config.DEBUG)
4374+ {
4375+ LOGGER.info("The votesystem file is missing.");
4376+ }
4377+ return;
4378+ }
4379+
4380+ Document doc = factory.newDocumentBuilder().parse(file);
4381+
4382+ for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
4383+ {
4384+ if ("list".equalsIgnoreCase(n.getNodeName()))
4385+ {
4386+ for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
4387+ {
4388+ final VoteSite votesite = new VoteSite();
4389+ if ("votesite".equalsIgnoreCase(d.getNodeName()))
4390+ {
4391+ NamedNodeMap attrs = d.getAttributes();
4392+ String name = attrs.getNamedItem("name").getNodeValue();
4393+ int ordinal = Integer.parseInt(attrs.getNamedItem("ordinal").getNodeValue());
4394+ votesite.setSiteName(name);
4395+ votesite.setSiteOrdinal(ordinal);
4396+ for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
4397+ {
4398+ if ("item".equalsIgnoreCase(cd.getNodeName()))
4399+ {
4400+ attrs = cd.getAttributes();
4401+ int itemId = Integer.parseInt(attrs.getNamedItem("itemId").getNodeValue());
4402+ int itemCount = Integer.parseInt(attrs.getNamedItem("itemCount").getNodeValue());
4403+ votesite.getRewardList().add(new Reward(itemId,itemCount));
4404+ }
4405+
4406+ }
4407+ _voteSites.put(votesite.getSiteOrdinal(), votesite);
4408+ attrs = null;
4409+ }
4410+ }
4411+ }
4412+ }
4413+
4414+
4415+ doc = null;
4416+ file = null;
4417+ }
4418+ catch (final Exception e)
4419+ {
4420+ if (Config.ENABLE_ALL_EXCEPTIONS)
4421+ e.printStackTrace();
4422+
4423+ LOGGER.error("Error parsing votesystem.xml", e);
4424+
4425+ return;
4426+ }
4427+ }
4428+
4429+
4430+ public String getSiteName(int ordinal)
4431+ {
4432+ return _voteSites.get(ordinal).getSiteName();
4433+ }
4434+
4435+ public Collection<Reward> getRewards(int ordinal)
4436+ {
4437+ return _voteSites.get(ordinal).getRewardList();
4438+ }
4439+
4440+ public static final VoteSiteXml getInstance()
4441+ {
4442+ return SingletonHolder.INSTANCE;
4443+ }
4444+
4445+ private static final class SingletonHolder
4446+ {
4447+ protected static final VoteSiteXml INSTANCE = new VoteSiteXml();
4448+ }
4449+
4450+}
4451Index: head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java
4452===================================================================
4453--- head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java (nonexistent)
4454+++ head-src/com/l2jfrozen/gameserver/votesystem/VoteUtil/VoteUtil.java (working copy)
4455@@ -0,0 +1,122 @@
4456+package com.l2jfrozen.gameserver.votesystem.VoteUtil;
4457+
4458+import java.io.BufferedReader;
4459+import java.io.InputStreamReader;
4460+import java.net.HttpURLConnection;
4461+import java.net.URL;
4462+
4463+import java.util.logging.Logger;
4464+
4465+import com.l2jfrozen.gameserver.votesystem.Handler.voteHandler;
4466+
4467+
4468+/**
4469+ * @author l2.topgameserver.net
4470+ */
4471+public final class VoteUtil
4472+{
4473+ public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
4474+
4475+ private static String voteTimeZones[] =
4476+ {
4477+ "topgameserver.net=Europe/Berlin",
4478+ "itopz.com=America/New_York",
4479+ "l2top.co=Europe/London",
4480+ "l2votes.com=GMT",
4481+ "hopzone.net=Europe/Athens",
4482+ "l2network.eu=America/Chicago",
4483+ "l2topservers.com=Europe/Athens",
4484+ "top.l2jbrasil.com=America/Sao_Paulo",
4485+ "mmotop.eu=America/Chicago",
4486+ "l2topzone.com=America/Chicago",
4487+ "l2servers.com=America/Chicago",
4488+ };
4489+
4490+ /*public static final long getTimeVotingSite(int ordinalSite)
4491+ {
4492+ LocalDateTime ldt = LocalDateTime.now(ZoneId.of(voteTimeZones[ordinalSite].split("=")[1]));
4493+ ZonedDateTime zdt = ldt.atZone(ZoneId.systemDefault());
4494+ long millis = zdt.toInstant().toEpochMilli();
4495+ return millis;
4496+ }*/
4497+
4498+ public static final String Sites[] =
4499+ {
4500+ "L2.TopGameServer.net",
4501+ "ITopZ.com",
4502+ "L2Top.co",
4503+ "L2Votes.com",
4504+ "L2.Hopzone.net",
4505+ "L2Network.eu",
4506+ "L2TopServers.com",
4507+ "top.l2jbrasil.com",
4508+ "MMOTOP.eu",
4509+ "L2Topzone.com",
4510+ "L2Servers.com"
4511+ };
4512+
4513+ public static final String getResponse(String Url, int ordinal)
4514+ {
4515+
4516+ try
4517+ {
4518+ int responseCode = 0;
4519+ URL objUrl = new URL(Url);
4520+ HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
4521+ con.setRequestMethod("GET");
4522+ con.setRequestProperty("User-Agent", "Mozilla/5.0");
4523+ con.setConnectTimeout(5000);
4524+ responseCode = con.getResponseCode();
4525+ if (responseCode == HttpURLConnection.HTTP_OK)
4526+ {
4527+
4528+ String inputLine;
4529+ StringBuffer response = new StringBuffer();
4530+ BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
4531+ while ((inputLine = in.readLine()) != null)
4532+ {
4533+ if (ordinal == 3)
4534+ {
4535+ if (inputLine.contains("Votes:"))
4536+ {
4537+ response.append(inputLine);
4538+ break;
4539+ }
4540+ }
4541+ if (ordinal == 7)
4542+ {
4543+ if (inputLine.contains("<b>Entradas "))
4544+ {
4545+ response.append(inputLine);
4546+ break;
4547+ }
4548+ }
4549+ }
4550+ in.close();
4551+ return response.toString();
4552+ }
4553+
4554+ }
4555+ catch (Exception e)
4556+ {
4557+ LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getStackTrace());
4558+ return "";
4559+ }
4560+
4561+ return "";
4562+ }
4563+
4564+ public static final String between(String p1, String str, String p2)
4565+ {
4566+ String returnValue = "";
4567+ int i1 = str.indexOf(p1);
4568+ int i2 = str.indexOf(p2);
4569+ if ((i1 != -1) && (i2 != -1))
4570+ {
4571+ i1 = i1 + p1.length();
4572+ returnValue = str.substring(i1, i2);
4573+ }
4574+ return returnValue;
4575+ }
4576+
4577+}
4578
4579
4580
4581========================================================= DP ================================================
4582Index: data/html/mods/votesystem/50009.htm
4583===================================================================
4584--- data/html/mods/votesystem/50009.htm (nonexistent)
4585+++ data/html/mods/votesystem/50009.htm (working copy)
4586@@ -0,0 +1,19 @@
4587+<html>
4588+<title>Voting panel</title>
4589+<body><center>
4590+ <br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
4591+ <table cellpadding=2 width=280>
4592+ <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>
4593+ </table>
4594+ <table width="290"><tr><td width="290" align="center">You can vote: </td></tr></table>
4595+ <br><img src="l2ui.SquareWhite" width=290 height=1><br>
4596+
4597+ %enablevote%
4598+
4599+ <br>
4600+ <img src="l2ui.SquareWhite" width=290 height=1><br>
4601+
4602+
4603+
4604+</center></body>
4605+</html>
4606\ No newline at end of file
4607Index: data/stats/votesystem.xml
4608===================================================================
4609--- data/stats/votesystem.xml (nonexistent)
4610+++ data/stats/votesystem.xml (working copy)
4611@@ -0,0 +1,70 @@
4612+<?xml version="1.0" encoding="UTF-8"?>
4613+<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/votesystem.xsd">
4614+ <votesite name="l2.topgameserver.net" ordinal="0">
4615+ <items>
4616+ <item itemId="57" itemCount="100000" />
4617+ </items>
4618+ </votesite>
4619+ <votesite name="ItopZ.com" ordinal="1">
4620+ <items>
4621+ <item itemId="57" itemCount="100000" />
4622+ </items>
4623+ </votesite>
4624+ <votesite name="L2Top.co" ordinal="2">
4625+ <items>
4626+ <item itemId="57" itemCount="100000" />
4627+ <item itemId="6673" itemCount="1"/>
4628+ </items>
4629+ </votesite>
4630+ <votesite name="L2Votes.com" ordinal="3">
4631+ <items>
4632+ <item itemId="57" itemCount="100000" />
4633+ </items>
4634+ </votesite>
4635+ <votesite name="Hopzone.net" ordinal="4">
4636+ <items>
4637+ <item itemId="57" itemCount="100000" />
4638+ </items>
4639+ </votesite>
4640+ <votesite name="L2Network.eu" ordinal="5">
4641+ <items>
4642+ <item itemId="57" itemCount="100000" />
4643+ <item itemId="6673" itemCount="1"/>
4644+ </items>
4645+ </votesite>
4646+ <votesite name="L2Topservers.com" ordinal="6">
4647+ <items>
4648+ <item itemId="57" itemCount="100000" />
4649+ <item itemId="6673" itemCount="1"/>
4650+ </items>
4651+ </votesite>
4652+ <votesite name="top.l2jbrasil.com" ordinal="7">
4653+ <items>
4654+ <item itemId="57" itemCount="100000" />
4655+ <item itemId="6673" itemCount="1"/>
4656+ </items>
4657+ </votesite>
4658+ <votesite name="MMOTOP.eu" ordinal="8">
4659+ <items>
4660+ <item itemId="57" itemCount="100000" />
4661+ <item itemId="6673" itemCount="1"/>
4662+ </items>
4663+ </votesite>
4664+ <votesite name="L2Topzone.com" ordinal="9">
4665+ <items>
4666+ <item itemId="57" itemCount="100000" />
4667+ </items>
4668+ </votesite>
4669+ <votesite name="L2Servers.com" ordinal="10">
4670+ <items>
4671+ <item itemId="57" itemCount="100000" />
4672+ <item itemId="6673" itemCount="1"/>
4673+ </items>
4674+ </votesite>
4675+ <votesite name="globalVotes" ordinal="11">
4676+ <items>
4677+ <item itemId="57" itemCount="100000" />
4678+ <item itemId="6673" itemCount="1"/>
4679+ </items>
4680+ </votesite>
4681+</list>
4682\ No newline at end of file
4683Index: data/xsd/votesystem.xsd
4684===================================================================
4685--- data/xsd/votesystem.xsd (nonexistent)
4686+++ data/xsd/votesystem.xsd (working copy)
4687@@ -0,0 +1,32 @@
4688+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
4689+ <xs:element name="list">
4690+ <xs:complexType>
4691+ <xs:sequence>
4692+ <xs:element name="votesite" maxOccurs="unbounded" minOccurs="0">
4693+ <xs:complexType>
4694+ <xs:sequence>
4695+ <xs:element name="items">
4696+ <xs:complexType>
4697+ <xs:sequence>
4698+ <xs:element name="item" maxOccurs="unbounded" minOccurs="0">
4699+ <xs:complexType>
4700+ <xs:simpleContent>
4701+ <xs:extension base="xs:string">
4702+ <xs:attribute type="xs:short" name="itemId" use="optional"/>
4703+ <xs:attribute type="xs:int" name="itemCount" use="optional"/>
4704+ </xs:extension>
4705+ </xs:simpleContent>
4706+ </xs:complexType>
4707+ </xs:element>
4708+ </xs:sequence>
4709+ </xs:complexType>
4710+ </xs:element>
4711+ </xs:sequence>
4712+ <xs:attribute type="xs:string" name="name" use="optional"/>
4713+ <xs:attribute type="xs:byte" name="ordinal" use="optional"/>
4714+ </xs:complexType>
4715+ </xs:element>
4716+ </xs:sequence>
4717+ </xs:complexType>
4718+ </xs:element>
4719+</xs:schema>
4720
4721==================================================== SQL ==============================================
4722
4723
4724\ No newline at end of file
4725-- ----------------------------
4726-- Table structure for globalvotes
4727-- ----------------------------
4728DROP TABLE IF EXISTS `globalvotes`;
4729CREATE TABLE `globalvotes` (
4730 `voteSite` tinyint(2) NOT NULL,
4731 `lastRewardVotes` int(11) NULL DEFAULT NULL,
4732 PRIMARY KEY (`voteSite`) USING BTREE
4733) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
4734
4735-- ----------------------------
4736-- Records of globalvotes
4737-- ----------------------------
4738INSERT INTO `globalvotes` VALUES (0, 13);
4739INSERT INTO `globalvotes` VALUES (1, 68);
4740INSERT INTO `globalvotes` VALUES (2, 0);
4741INSERT INTO `globalvotes` VALUES (3, 3);
4742INSERT INTO `globalvotes` VALUES (4, 2);
4743INSERT INTO `globalvotes` VALUES (5, 0);
4744INSERT INTO `globalvotes` VALUES (6, 0);
4745INSERT INTO `globalvotes` VALUES (7, 2);
4746INSERT INTO `globalvotes` VALUES (8, 3);
4747INSERT INTO `globalvotes` VALUES (9, 0);
4748INSERT INTO `globalvotes` VALUES (10, 75);
4749
4750-- ----------------------------
4751-- Table structure for individualvotes
4752-- ----------------------------
4753DROP TABLE IF EXISTS `individualvotes`;
4754CREATE TABLE `individualvotes` (
4755 `voterIp` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
4756 `voteSite` tinyint(3) NOT NULL,
4757 `diffTime` bigint(20) NULL DEFAULT NULL,
4758 `votingTimeSite` bigint(20) NULL DEFAULT NULL,
4759 `alreadyRewarded` tinyint(3) NULL DEFAULT NULL,
4760 PRIMARY KEY (`voterIp`, `voteSite`) USING BTREE
4761) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
4762
4763
4764INSERT INTO `frozen-vote`.`custom_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 (50009, 31228, 'Kayaa', 1, 'Vote System', 1, 'Monster.cat_the_cat', 9.00, 16.00, 70, 'male', 'L2NpcVoteReward', 40, 3862, 1493, 11.85, 2.78, 40, 43, 30, 21, 20, 10, 490, 10, 1335, 470, 780, 382, 278, 0, 333, 0, 0, 0, 88, 132, NULL, 0, 0, 0, 'LAST_HIT');
4765