Advertisement
l2TopgameserverNet

L2JFrozen Interlud vote reward system - l2.topgameserver.net

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