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