Advertisement
l2TopgameserverNet

L2Mythras (2017.07.12) Vote reward System - l2.topgameserver.net - Lineage 2 Top List

Jan 3rd, 2021 (edited)
483
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ### Eclipse Workspace Patch 1.0
  2. #P Trunk
  3. Index: java/l2f/gameserver/model/instances/VoteRewardInstance.java
  4. ===================================================================
  5. --- java/l2f/gameserver/model/instances/VoteRewardInstance.java (nonexistent)
  6. +++ java/l2f/gameserver/model/instances/VoteRewardInstance.java (working copy)
  7. @@ -0,0 +1,102 @@
  8. +package l2f.gameserver.model.instances;
  9. +
  10. +
  11. +import l2f.gameserver.Config;
  12. +import l2f.gameserver.data.xml.holder.ItemHolder;
  13. +import l2f.gameserver.model.Player;
  14. +import l2f.gameserver.network.serverpackets.NpcHtmlMessage;
  15. +import l2f.gameserver.templates.npc.NpcTemplate;
  16. +import l2f.gameserver.votesystem.Enum.voteSite;
  17. +import l2f.gameserver.votesystem.Handler.voteManager;
  18. +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml;
  19. +import l2f.gameserver.votesystem.Model.Reward;
  20. +
  21. +@SuppressWarnings("serial")
  22. +public class VoteRewardInstance extends NpcInstance{
  23. +
  24. +   public VoteRewardInstance(int objectId, NpcTemplate template) {
  25. +       super(objectId,template);
  26. +   }
  27. +  
  28. +   @Override
  29. +   public void onBypassFeedback(Player player, String command)
  30. +   {
  31. +       if (command == null)
  32. +       {
  33. +           return;
  34. +       }
  35. +       int Ordinalsite = Integer.parseInt(command);
  36. +       voteManager.getInatance().getReward(player, Ordinalsite);
  37. +       showChatWindow(player, 0);
  38. +       super.onBypassFeedback(player, command);
  39. +   }
  40. +  
  41. +   @Override
  42. +   public boolean isNpc()
  43. +   {
  44. +       return true;
  45. +   }
  46. +  
  47. +   @Override
  48. +   public void showChatWindow(Player player, int val, Object... arg)
  49. +   {
  50. +      
  51. +       final NpcHtmlMessage html = new NpcHtmlMessage(player, this,getHtmlPath(this.getTemplate().getNpcId(), 0, player) , 0);
  52. +       StringBuilder sb = new StringBuilder();
  53. +       if (Config.ENABLE_VOTE_SYSTEM && Config.ENABLE_INDIVIDUAL_VOTE)
  54. +       {
  55. +           for (voteSite vs : voteSite.values())
  56. +           {
  57. +               sb.append("<table bgcolor=000000 width=280><tr>");
  58. +               sb.append("<td width=42><img src=\"icon.etc_treasure_box_i08\" width=32 height=32></td>");
  59. +               sb.append("<td width=220><table width=220>");
  60. +               sb.append("<tr><td><table width=220><tr><td width=145>On " + String.format("%s", VoteSiteXml.getInstance().getSiteName(vs.ordinal())) + "</td>");
  61. +               if (voteManager.getInatance().checkIndividualAvailableVote(player, vs.ordinal()))
  62. +               {
  63. +                   sb.append("<td width=75>" + String.format("<button value=\"Get reward\" action=\"bypass -h vote_%s_site %s\" height=17 width=64 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\">", getObjectId(), vs.ordinal()) + "</td>");
  64. +               }
  65. +               else
  66. +               {
  67. +                   sb.append(String.format("<td width=75 align=center><font color=C68E00>%s</font></td>", voteManager.getInatance().getTimeRemainingWithSampleFormat(player, vs.ordinal())));
  68. +               }
  69. +               sb.append("</tr></table></td></tr>");
  70. +               sb.append("<tr><td><table width=220><tr>");
  71. +               int i = 0;
  72. +               for (Reward r : VoteSiteXml.getInstance().getRewards(vs.ordinal()))
  73. +               {
  74. +                   sb.append(String.format("<td width=110 height=32 align=center><font color=BFAF00>%s x%s</font></td>", ItemHolder.getInstance().getTemplate(r.getItemId()).getName(), r.getItemCount()));
  75. +                   i++;
  76. +                   if ((i % 2) == 0)
  77. +                   {
  78. +                       sb.append("</tr><tr>");
  79. +                   }
  80. +               }
  81. +               sb.append("</tr></table></td></tr></table></td></tr></table><br>");
  82. +           }
  83. +       }
  84. +       else
  85. +       {
  86. +           sb.append("<table bgcolor=000000 width=280><tr><td><p><font color=#bfb300 >Individual vote system has been disabled for your server owner.</font></p></td></tr></table>");
  87. +       }
  88. +       html.replace("%everyXtime%", Config.INTERVAL_TO_NEXT_VOTE / (3600 * 1000));
  89. +       html.replace("%enablevote%", sb.toString());
  90. +       html.replace("%accountName%", player.getName());
  91. +       player.sendPacket(html);
  92. +   }
  93. +  
  94. +   @Override
  95. +   public String getHtmlPath(int npcId, int val,Player player)
  96. +   {
  97. +       String filename = "";
  98. +       if (val == 0)
  99. +       {
  100. +           filename = "" + npcId;
  101. +       }
  102. +       else
  103. +       {
  104. +           filename = npcId + "-" + val;
  105. +       }
  106. +      
  107. +       return "custom/votesystem/" + filename + ".html";
  108. +   }
  109. +}
  110. Index: java/l2f/gameserver/handler/voicecommands/impl/VoteReward.java
  111. ===================================================================
  112. --- java/l2f/gameserver/handler/voicecommands/impl/VoteReward.java  (nonexistent)
  113. +++ java/l2f/gameserver/handler/voicecommands/impl/VoteReward.java  (working copy)
  114. @@ -0,0 +1,64 @@
  115. +package l2f.gameserver.handler.voicecommands.impl;
  116. +
  117. +import l2f.gameserver.Config;
  118. +import l2f.gameserver.handler.voicecommands.IVoicedCommandHandler;
  119. +import l2f.gameserver.model.Player;
  120. +import l2f.gameserver.votesystem.Enum.voteSite;
  121. +import l2f.gameserver.votesystem.Handler.voteManager;
  122. +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml;
  123. +
  124. +public class VoteReward implements IVoicedCommandHandler{
  125. +  
  126. +   @Override
  127. +   public boolean useVoicedCommand(String command, Player player, String params)
  128. +   {
  129. +       if (command.equalsIgnoreCase("rewardme"))
  130. +       {
  131. +           if (player.isJailed())
  132. +           {
  133. +               player.sendMessage("You cannot use this function while you are jailed");
  134. +               return false;
  135. +           }
  136. +           if (!Config.ENABLE_VOTE_SYSTEM)
  137. +           {
  138. +               player.sendMessage("The rewards system has been disabled by your administrator");
  139. +               return false;
  140. +           }
  141. +           if (!Config.ENABLE_INDIVIDUAL_VOTE)
  142. +           {
  143. +               player.sendMessage("The individual reward system is disabled");
  144. +               return false;
  145. +           }
  146. +          
  147. +          
  148. +           for (voteSite vs : voteSite.values())
  149. +           {
  150. +               new Thread(() ->
  151. +               {
  152. +                   voteManager.getInatance().getReward(player, vs.ordinal());
  153. +               }).start();
  154. +           }
  155. +          
  156. +           return true;
  157. +          
  158. +       }
  159. +       if (command.equalsIgnoreCase("reloadrewards") && player.isGM())
  160. +       {
  161. +           VoteSiteXml.getInstance().load();
  162. +           player.sendMessage("=====All reward has been reloaded======");
  163. +           return true;
  164. +       }
  165. +       return false;
  166. +   }
  167. +  
  168. +   @Override
  169. +   public String[] getVoicedCommandList()
  170. +   {
  171. +       return new String[]
  172. +       {
  173. +           "rewardme",
  174. +           "reloadrewards",
  175. +       };
  176. +   }
  177. +
  178. +}
  179. Index: java/l2f/gameserver/votesystem/DB/globalVoteDB.java
  180. ===================================================================
  181. --- java/l2f/gameserver/votesystem/DB/globalVoteDB.java (nonexistent)
  182. +++ java/l2f/gameserver/votesystem/DB/globalVoteDB.java (working copy)
  183. @@ -0,0 +1,121 @@
  184. +package l2f.gameserver.votesystem.DB;
  185. +
  186. +import java.sql.Connection;
  187. +import java.sql.PreparedStatement;
  188. +import java.sql.ResultSet;
  189. +import java.sql.SQLException;
  190. +import java.util.logging.Logger;
  191. +
  192. +import l2f.gameserver.database.DatabaseFactory;
  193. +import l2f.gameserver.votesystem.Enum.voteSite;
  194. +import l2f.gameserver.votesystem.Model.globalVote;
  195. +
  196. +
  197. +/**
  198. + * @author l2.topgameserver.net
  199. + */
  200. +public class globalVoteDB
  201. +{
  202. +   public static final Logger LOGGER = Logger.getLogger(globalVoteDB.class.getName());
  203. +   private final globalVote[] _globalVotes;
  204. +  
  205. +   private globalVoteDB()
  206. +   {
  207. +       _globalVotes = new globalVote[voteSite.values().length];
  208. +       loadGlobalVotes();
  209. +   }
  210. +  
  211. +   public void loadGlobalVotes()
  212. +   {
  213. +      
  214. +       try (Connection con = DatabaseFactory.getInstance().getConnection();PreparedStatement ps = con.prepareStatement("Select voteSite,lastRewardVotes from globalvotes");
  215. +           ResultSet rs = ps.executeQuery();)
  216. +       {
  217. +           if (rs.getRow() == 0)
  218. +           {
  219. +               for (voteSite vs : voteSite.values())
  220. +               {
  221. +                   globalVote gv = new globalVote();
  222. +                   gv.setVoteSite(vs.ordinal());
  223. +                   gv.setVotesLastReward(0);
  224. +                   _globalVotes[gv.getVoyeSite()] = gv;
  225. +               }
  226. +               return;
  227. +           }
  228. +           while (rs.next())
  229. +           {
  230. +               globalVote gv = new globalVote();
  231. +               gv.setVoteSite(rs.getInt("voteSite"));
  232. +               gv.setVotesLastReward(rs.getInt("lastRewardVotes"));
  233. +               _globalVotes[gv.getVoyeSite()] = gv;
  234. +           }
  235. +           ps.close();
  236. +           con.close();
  237. +          
  238. +       }
  239. +       catch (SQLException e)
  240. +       {
  241. +           e.printStackTrace();
  242. +       }
  243. +   }
  244. +  
  245. +   public void saveGlobalVote(globalVote gb)
  246. +   {
  247. +       try (Connection con = DatabaseFactory.getInstance().getConnection();
  248. +           PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
  249. +      
  250. +       {
  251. +           ps.setInt(1, gb.getVoyeSite());
  252. +           ps.setInt(2, gb.getVotesLastReward());
  253. +           ps.executeUpdate();
  254. +          
  255. +           ps.close();
  256. +           con.close();
  257. +          
  258. +       }
  259. +       catch (SQLException e)
  260. +       {
  261. +           e.printStackTrace();
  262. +       }
  263. +   }
  264. +  
  265. +   public void saveGlobalVotes(globalVote[] globalVotes)
  266. +   {
  267. +       try (Connection con = DatabaseFactory.getInstance().getConnection();
  268. +           PreparedStatement ps = con.prepareStatement("INSERT INTO globalvotes(voteSite,lastRewardVotes) VALUES(?,?)" + "ON DUPLICATE KEY UPDATE voteSite = VALUES(voteSite), lastRewardVotes = VALUES(lastRewardVotes)"))
  269. +      
  270. +       {
  271. +           for (voteSite vs : voteSite.values())
  272. +           {
  273. +               globalVote gb = globalVotes[vs.ordinal()];
  274. +               ps.setInt(1, gb.getVoyeSite());
  275. +               ps.setInt(2, gb.getVotesLastReward());
  276. +               ps.addBatch();
  277. +           }
  278. +           ps.executeBatch();
  279. +          
  280. +           ps.close();
  281. +           con.close();
  282. +          
  283. +       }
  284. +       catch (SQLException e)
  285. +       {
  286. +           e.printStackTrace();
  287. +       }
  288. +   }
  289. +  
  290. +   public globalVote[] getGlobalVotes()
  291. +   {
  292. +       return _globalVotes;
  293. +   }
  294. +  
  295. +   public static final globalVoteDB getInstance()
  296. +   {
  297. +       return SingleHolder.INSTANCE;
  298. +   }
  299. +  
  300. +   private static final class SingleHolder
  301. +   {
  302. +       protected static final globalVoteDB INSTANCE = new globalVoteDB();
  303. +   }
  304. +}
  305. Index: java/l2f/gameserver/handler/voicecommands/VoicedCommandHandler.java
  306. ===================================================================
  307. --- java/l2f/gameserver/handler/voicecommands/VoicedCommandHandler.java (revision 1)
  308. +++ java/l2f/gameserver/handler/voicecommands/VoicedCommandHandler.java (working copy)
  309. @@ -36,6 +36,7 @@
  310.  import l2f.gameserver.handler.voicecommands.impl.ServerInfo;
  311.  import l2f.gameserver.handler.voicecommands.impl.Teleport;
  312.  import l2f.gameserver.handler.voicecommands.impl.VoiceGmEvent;
  313. +import l2f.gameserver.handler.voicecommands.impl.VoteReward;
  314.  import l2f.gameserver.handler.voicecommands.impl.Wedding;
  315.  import l2f.gameserver.handler.voicecommands.impl.WhoAmI;
  316.  import l2f.gameserver.handler.voicecommands.impl.res;
  317. @@ -83,6 +84,7 @@
  318.         registerVoicedCommandHandler(new LockPc());
  319.         registerVoicedCommandHandler(new NpcSpawn());
  320.         registerVoicedCommandHandler(new Donate());
  321. +       registerVoicedCommandHandler(new VoteReward());
  322.  
  323.         if (Config.ENABLE_ACHIEVEMENTS)
  324.             registerVoicedCommandHandler(new AchievementsVoice());
  325. Index: dist/gameserver/data/xsd/votesystem.xsd
  326. ===================================================================
  327. --- dist/gameserver/data/xsd/votesystem.xsd (nonexistent)
  328. +++ dist/gameserver/data/xsd/votesystem.xsd (working copy)
  329. @@ -0,0 +1,32 @@
  330. +<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  331. +  <xs:element name="list">
  332. +    <xs:complexType>
  333. +      <xs:sequence>
  334. +        <xs:element name="votesite" maxOccurs="unbounded" minOccurs="0">
  335. +          <xs:complexType>
  336. +            <xs:sequence>
  337. +              <xs:element name="items">
  338. +                <xs:complexType>
  339. +                  <xs:sequence>
  340. +                    <xs:element name="item" maxOccurs="unbounded" minOccurs="0">
  341. +                      <xs:complexType>
  342. +                        <xs:simpleContent>
  343. +                          <xs:extension base="xs:string">
  344. +                            <xs:attribute type="xs:short" name="itemId" use="optional"/>
  345. +                            <xs:attribute type="xs:int" name="itemCount" use="optional"/>
  346. +                          </xs:extension>
  347. +                        </xs:simpleContent>
  348. +                      </xs:complexType>
  349. +                    </xs:element>
  350. +                  </xs:sequence>
  351. +                </xs:complexType>
  352. +              </xs:element>
  353. +            </xs:sequence>
  354. +            <xs:attribute type="xs:string" name="name" use="optional"/>
  355. +            <xs:attribute type="xs:byte" name="ordinal" use="optional"/>
  356. +          </xs:complexType>
  357. +        </xs:element>
  358. +      </xs:sequence>
  359. +    </xs:complexType>
  360. +  </xs:element>
  361. +</xs:schema>
  362.  
  363. Index: java/l2f/gameserver/votesystem/VoteUtil/VoteSiteXml.java
  364. ===================================================================
  365. --- java/l2f/gameserver/votesystem/VoteUtil/VoteSiteXml.java    (nonexistent)
  366. +++ java/l2f/gameserver/votesystem/VoteUtil/VoteSiteXml.java    (working copy)
  367. @@ -0,0 +1,122 @@
  368. +package l2f.gameserver.votesystem.VoteUtil;
  369. +
  370. +import java.io.File;
  371. +import java.util.Collection;
  372. +import java.util.HashMap;
  373. +import java.util.Map;
  374. +
  375. +import javax.xml.parsers.DocumentBuilderFactory;
  376. +
  377. +import org.apache.log4j.Logger;
  378. +import org.w3c.dom.Document;
  379. +import org.w3c.dom.NamedNodeMap;
  380. +import org.w3c.dom.Node;
  381. +
  382. +
  383. +import l2f.gameserver.Config;
  384. +import l2f.gameserver.votesystem.Model.Reward;
  385. +import l2f.gameserver.votesystem.Model.VoteSite;
  386. +
  387. +/**
  388. + * @author l2.topgameserver.net
  389. + */
  390. +public class VoteSiteXml
  391. +{
  392. +   private final Map<Integer, VoteSite> _voteSites = new HashMap<>();
  393. +   private static Logger LOGGER = Logger.getLogger(VoteSiteXml.class);
  394. +  
  395. +   private VoteSiteXml(){
  396. +       load();
  397. +   }
  398. +  
  399. +  
  400. +   public void load()
  401. +   {
  402. +       try
  403. +       {
  404. +           final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
  405. +           factory.setValidating(false);
  406. +           factory.setIgnoringComments(true);
  407. +          
  408. +           File file = new File(Config.DATAPACK_ROOT + "/data/votesystem.xml");
  409. +           if (!file.exists())
  410. +           {
  411. +               if (Config.DEBUG)
  412. +               {
  413. +                   LOGGER.info("The votesystem file is missing.");
  414. +               }
  415. +               return;
  416. +           }
  417. +          
  418. +           Document doc = factory.newDocumentBuilder().parse(file);
  419. +          
  420. +           for (Node n = doc.getFirstChild(); n != null; n = n.getNextSibling())
  421. +           {
  422. +               if ("list".equalsIgnoreCase(n.getNodeName()))
  423. +               {
  424. +                   for (Node d = n.getFirstChild(); d != null; d = d.getNextSibling())
  425. +                   {
  426. +                       final VoteSite votesite = new VoteSite();
  427. +                       if ("votesite".equalsIgnoreCase(d.getNodeName()))
  428. +                       {
  429. +                           NamedNodeMap attrs = d.getAttributes();
  430. +                           String name = attrs.getNamedItem("name").getNodeValue();
  431. +                           int ordinal = Integer.parseInt(attrs.getNamedItem("ordinal").getNodeValue());
  432. +                           votesite.setSiteName(name);
  433. +                           votesite.setSiteOrdinal(ordinal);
  434. +                           for (Node cd = d.getFirstChild(); cd != null; cd = cd.getNextSibling())
  435. +                           {
  436. +                               if ("item".equalsIgnoreCase(cd.getNodeName()))
  437. +                               {
  438. +                                   attrs = cd.getAttributes();
  439. +                                   int itemId = Integer.parseInt(attrs.getNamedItem("itemId").getNodeValue());
  440. +                                   int itemCount = Integer.parseInt(attrs.getNamedItem("itemCount").getNodeValue());
  441. +                                   votesite.getRewardList().add(new Reward(itemId,itemCount));
  442. +                               }
  443. +                              
  444. +                           }
  445. +                           _voteSites.put(votesite.getSiteOrdinal(), votesite);
  446. +                           attrs = null;
  447. +                       }
  448. +                   }
  449. +               }
  450. +           }
  451. +          
  452. +          
  453. +           doc = null;
  454. +           file = null;
  455. +       }
  456. +       catch (final Exception e)
  457. +       {
  458. +           e.printStackTrace();
  459. +          
  460. +           LOGGER.error("Error parsing votesystem.xml", e);
  461. +          
  462. +           return;
  463. +       }
  464. +   }
  465. +
  466. +  
  467. +   public String getSiteName(int ordinal)
  468. +   {
  469. +       return _voteSites.get(ordinal).getSiteName();
  470. +   }
  471. +  
  472. +   public Collection<Reward> getRewards(int ordinal)
  473. +   {
  474. +       return _voteSites.get(ordinal).getRewardList();
  475. +   }
  476. +  
  477. +   public static final VoteSiteXml getInstance()
  478. +   {
  479. +       return SingletonHolder.INSTANCE;
  480. +   }
  481. +  
  482. +   private static final class SingletonHolder
  483. +   {
  484. +       protected static final VoteSiteXml INSTANCE = new VoteSiteXml();
  485. +   }
  486. +
  487. +  
  488. +  
  489. +}
  490. Index: java/l2f/gameserver/GameServer.java
  491. ===================================================================
  492. --- java/l2f/gameserver/GameServer.java (revision 1)
  493. +++ java/l2f/gameserver/GameServer.java (working copy)
  494. @@ -90,6 +90,8 @@
  495.  import l2f.gameserver.taskmanager.tasks.RestoreOfflineTraders;
  496.  import l2f.gameserver.utils.Strings;
  497.  import l2f.gameserver.vote.VoteMain;
  498. +import l2f.gameserver.votesystem.Handler.voteManager;
  499. +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml;
  500.  import net.sf.ehcache.CacheManager;
  501.  
  502.  import org.slf4j.Logger;
  503. @@ -296,6 +298,19 @@
  504.         VoicedCommandHandler.getInstance().log();
  505.         TaskManager.getInstance();
  506.         _log.info("======================[Loading Castels & Clan Halls]==========================");
  507. +      
  508. +       // load vote reward system
  509. +               printSection("Vote Reward System");
  510. +               if (Config.ENABLE_VOTE_SYSTEM)
  511. +               {
  512. +                   voteManager.getInatance();
  513. +                   _log.info("======================Vote System Enabled=========================");
  514. +                   VoteSiteXml.getInstance();
  515. +               }
  516. +               else
  517. +               {
  518. +                   _log.info("======================Vote System Disabled=========================");
  519. +               }
  520.         ResidenceHolder.getInstance().callInit();
  521.         EventHolder.getInstance().callInit();
  522.         CastleManorManager.getInstance();
  523. Index: java/l2f/gameserver/network/clientpackets/RequestBypassToServer.java
  524. ===================================================================
  525. --- java/l2f/gameserver/network/clientpackets/RequestBypassToServer.java    (revision 1)
  526. +++ java/l2f/gameserver/network/clientpackets/RequestBypassToServer.java    (working copy)
  527. @@ -122,6 +122,29 @@
  528.                     ((NpcInstance) object).onBypassFeedback(activeChar, bp.bypass.substring(endOfId + 1));
  529.                 }
  530.             }
  531. +           else if (bp.bypass.startsWith("vote_"))
  532. +           {
  533. +              
  534. +               int endOfId = bp.bypass.indexOf('_', 6);
  535. +               String id;
  536. +               if (endOfId > 0)
  537. +               {
  538. +                   id = bp.bypass.substring(5, endOfId);
  539. +               }
  540. +               else
  541. +               {
  542. +                   id = bp.bypass.substring(5);
  543. +               }
  544. +              
  545. +               if (bp.bypass.split(" ")[1].toString() != null)
  546. +               {
  547. +                   GameObject object = activeChar.getVisibleObject(Integer.parseInt(id));
  548. +                   if ((object != null) && object.isNpc() && (endOfId > 0) && activeChar.isInRange(object, Creature.INTERACTION_DISTANCE))
  549. +                   {
  550. +                       ((NpcInstance) object).onBypassFeedback(activeChar, bp.bypass.split(" ")[1].toString());
  551. +                   }
  552. +               }
  553. +           }
  554.             else if (bp.bypass.startsWith("_olympiad?"))
  555.             {
  556.                 String[] ar = bp.bypass.replace("_olympiad?", "").split("&");
  557. Index: java/l2f/gameserver/votesystem/Model/individualVote.java
  558. ===================================================================
  559. --- java/l2f/gameserver/votesystem/Model/individualVote.java    (nonexistent)
  560. +++ java/l2f/gameserver/votesystem/Model/individualVote.java    (working copy)
  561. @@ -0,0 +1,78 @@
  562. +package l2f.gameserver.votesystem.Model;
  563. +
  564. +/**
  565. + * @author l2.topgameserver.net
  566. + */
  567. +public class individualVote
  568. +{
  569. +   private String _voterIp;
  570. +   private long _diffTime;
  571. +   private long _votingTimeSite;
  572. +   private int _voteSite;
  573. +   private boolean _alreadyRewarded;
  574. +  
  575. +   public individualVote(String voterIp, long diffTime, long votingTimeSite, int voteSite, boolean alreadyRewarded)
  576. +   {
  577. +       _voterIp = voterIp;
  578. +       _diffTime = diffTime;
  579. +       _votingTimeSite = votingTimeSite;
  580. +       _voteSite = voteSite;
  581. +       _alreadyRewarded = alreadyRewarded;
  582. +   }
  583. +  
  584. +   public individualVote()
  585. +   {
  586. +      
  587. +   }
  588. +  
  589. +   public void setVoterIp(String voterIp)
  590. +   {
  591. +       _voterIp = voterIp;
  592. +   }
  593. +  
  594. +   public void setDiffTime(long diffTime)
  595. +   {
  596. +       _diffTime = diffTime;
  597. +   }
  598. +  
  599. +   public void setVotingTimeSite(long votingTimeSite)
  600. +   {
  601. +       _votingTimeSite = votingTimeSite;
  602. +   }
  603. +  
  604. +   public void setVoteSite(int voteSite)
  605. +   {
  606. +       _voteSite = voteSite;
  607. +   }
  608. +  
  609. +   public void setAlreadyRewarded(boolean alreadyRewarded)
  610. +   {
  611. +       _alreadyRewarded = alreadyRewarded;
  612. +   }
  613. +  
  614. +   public String getVoterIp()
  615. +   {
  616. +       return _voterIp;
  617. +   }
  618. +  
  619. +   public long getDiffTime()
  620. +   {
  621. +       return _diffTime;
  622. +   }
  623. +  
  624. +   public long getVotingTimeSite()
  625. +   {
  626. +       return _votingTimeSite;
  627. +   }
  628. +  
  629. +   public int getVoteSite()
  630. +   {
  631. +       return _voteSite;
  632. +   }
  633. +  
  634. +   public boolean getAlreadyRewarded()
  635. +   {
  636. +       return _alreadyRewarded;
  637. +   }
  638. +  
  639. +}
  640. Index: java/l2f/gameserver/votesystem/Model/Reward.java
  641. ===================================================================
  642. --- java/l2f/gameserver/votesystem/Model/Reward.java    (nonexistent)
  643. +++ java/l2f/gameserver/votesystem/Model/Reward.java    (working copy)
  644. @@ -0,0 +1,44 @@
  645. +package l2f.gameserver.votesystem.Model;
  646. +
  647. +import l2f.gameserver.templates.StatsSet;
  648. +
  649. +/**
  650. + * @author l2.topgameserver.net
  651. + */
  652. +public class Reward
  653. +{
  654. +   private int _itemId;
  655. +   private int _itemCount;
  656. +  
  657. +   public Reward(int itemId, int itemCount)
  658. +   {
  659. +       this._itemId = itemId;
  660. +       this._itemCount = itemCount;
  661. +   }
  662. +  
  663. +   public Reward(StatsSet set)
  664. +   {
  665. +       _itemId = set.getInteger("itemId");
  666. +       _itemCount = set.getInteger("itemCount");
  667. +   }
  668. +  
  669. +   public void setItemId(int itemId)
  670. +   {
  671. +       _itemId = itemId;
  672. +   }
  673. +  
  674. +   public void setItemCount(int itemCount)
  675. +   {
  676. +       _itemCount = itemCount;
  677. +   }
  678. +  
  679. +   public int getItemId()
  680. +   {
  681. +       return _itemId;
  682. +   }
  683. +  
  684. +   public int getItemCount()
  685. +   {
  686. +       return _itemCount;
  687. +   }
  688. +}
  689. Index: java/l2f/gameserver/votesystem/VoteUtil/VoteUtil.java
  690. ===================================================================
  691. --- java/l2f/gameserver/votesystem/VoteUtil/VoteUtil.java   (nonexistent)
  692. +++ java/l2f/gameserver/votesystem/VoteUtil/VoteUtil.java   (working copy)
  693. @@ -0,0 +1,122 @@
  694. +package l2f.gameserver.votesystem.VoteUtil;
  695. +
  696. +import java.io.BufferedReader;
  697. +import java.io.InputStreamReader;
  698. +import java.net.HttpURLConnection;
  699. +import java.net.URL;
  700. +import java.time.LocalDateTime;
  701. +import java.time.ZoneId;
  702. +import java.time.ZonedDateTime;
  703. +import java.util.logging.Logger;
  704. +
  705. +
  706. +/**
  707. + * @author l2.topgameserver.net
  708. + */
  709. +public final class VoteUtil
  710. +{
  711. +   public static final Logger LOGGER = Logger.getLogger(VoteUtil.class.getName());
  712. +  
  713. +   private static String voteTimeZones[] =
  714. +   {
  715. +       "topgameserver.net=Europe/Berlin",
  716. +       "itopz.com=America/New_York",
  717. +       "l2top.co=Europe/London",
  718. +       "l2votes.com=GMT",
  719. +       "hopzone.net=Europe/Athens",
  720. +       "l2network.eu=America/Chicago",
  721. +       "l2topservers.com=Europe/Athens",
  722. +       "top.l2jbrasil.com=America/Sao_Paulo",
  723. +       "mmotop.eu=America/Chicago",
  724. +       "l2topzone.com=America/Chicago",
  725. +       "l2servers.com=America/Chicago",
  726. +   };
  727. +  
  728. +   public long getTimeRemaining(individualVote iv)
  729. +   {
  730. +       long timeRemaining = 0L;
  731. +       timeRemaining = ((iv.getVotingTimeSite() + Config.INTERVAL_TO_NEXT_VOTE) - ((iv.getDiffTime() > 0) ? (System.currentTimeMillis() + iv.getDiffTime()) : (System.currentTimeMillis() - iv.getDiffTime())));
  732. +       return timeRemaining;
  733. +   }
  734. +  
  735. +   public static final String Sites[] =
  736. +   {
  737. +       "L2.TopGameServer.net",
  738. +       "ITopZ.com",
  739. +       "L2Top.co",
  740. +       "L2Votes.com",
  741. +       "L2.Hopzone.net",
  742. +       "L2Network.eu",
  743. +       "L2TopServers.com",
  744. +       "top.l2jbrasil.com",
  745. +       "MMOTOP.eu",
  746. +       "L2Topzone.com",
  747. +       "L2Servers.com"
  748. +   };
  749. +  
  750. +   public static final String getResponse(String Url, int ordinal)
  751. +   {
  752. +      
  753. +       try
  754. +       {
  755. +           int responseCode = 0;
  756. +           URL objUrl = new URL(Url);
  757. +           HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
  758. +           con.setRequestMethod("GET");
  759. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  760. +           con.setConnectTimeout(5000);
  761. +           responseCode = con.getResponseCode();
  762. +           if (responseCode == HttpURLConnection.HTTP_OK)
  763. +           {
  764. +              
  765. +               String inputLine;
  766. +               StringBuffer response = new StringBuffer();
  767. +               BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  768. +               while ((inputLine = in.readLine()) != null)
  769. +               {
  770. +                   if (ordinal == 3)
  771. +                   {
  772. +                       if (inputLine.contains("Votes:"))
  773. +                       {
  774. +                           response.append(inputLine);
  775. +                           break;
  776. +                       }
  777. +                   }
  778. +                   if (ordinal == 7)
  779. +                   {
  780. +                       if (inputLine.contains("<b>Entradas "))
  781. +                       {
  782. +                           response.append(inputLine);
  783. +                           break;
  784. +                       }
  785. +                   }
  786. +               }
  787. +               in.close();
  788. +               return response.toString();
  789. +           }
  790. +          
  791. +       }
  792. +       catch (Exception e)
  793. +       {
  794. +           LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getStackTrace());
  795. +           return "";
  796. +       }
  797. +      
  798. +       return "";
  799. +   }
  800. +  
  801. +   public static final String between(String p1, String str, String p2)
  802. +   {
  803. +       String returnValue = "";
  804. +       int i1 = str.indexOf(p1);
  805. +       int i2 = str.indexOf(p2);
  806. +       if ((i1 != -1) && (i2 != -1))
  807. +       {
  808. +           i1 = i1 + p1.length();
  809. +           returnValue = str.substring(i1, i2);
  810. +       }
  811. +       return returnValue;
  812. +   }
  813. +  
  814. +}
  815. Index: java/l2f/gameserver/votesystem/Model/globalVote.java
  816. ===================================================================
  817. --- java/l2f/gameserver/votesystem/Model/globalVote.java    (nonexistent)
  818. +++ java/l2f/gameserver/votesystem/Model/globalVote.java    (working copy)
  819. @@ -0,0 +1,53 @@
  820. +package l2f.gameserver.votesystem.Model;
  821. +
  822. +/**
  823. + * @author l2.topgameserver.net
  824. + */
  825. +public class globalVote
  826. +{
  827. +   private int _voteSite;
  828. +   private int _votesLastReward;
  829. +   private int _currentVotes;
  830. +  
  831. +   public globalVote()
  832. +   {
  833. +      
  834. +   }
  835. +  
  836. +   public globalVote(int voteSite, int votesLastReward)
  837. +   {
  838. +       _voteSite = voteSite;
  839. +       _votesLastReward = votesLastReward;
  840. +   }
  841. +  
  842. +   public void setVoteSite(int voteSite)
  843. +   {
  844. +       _voteSite = voteSite;
  845. +   }
  846. +  
  847. +   public void setVotesLastReward(int votesLastReward)
  848. +   {
  849. +       _votesLastReward = votesLastReward;
  850. +   }
  851. +  
  852. +   public void setCurrentVotes(int currentVotes)
  853. +   {
  854. +       _currentVotes = currentVotes;
  855. +   }
  856. +  
  857. +   public int getVoyeSite()
  858. +   {
  859. +       return _voteSite;
  860. +   }
  861. +  
  862. +   public int getVotesLastReward()
  863. +   {
  864. +       return _votesLastReward;
  865. +   }
  866. +  
  867. +   public int getCurrentVotes()
  868. +   {
  869. +       return _currentVotes;
  870. +   }
  871. +  
  872. +}
  873. Index: java/l2f/gameserver/votesystem/Enum/voteSite.java
  874. ===================================================================
  875. --- java/l2f/gameserver/votesystem/Enum/voteSite.java   (nonexistent)
  876. +++ java/l2f/gameserver/votesystem/Enum/voteSite.java   (working copy)
  877. @@ -0,0 +1,19 @@
  878. +package l2f.gameserver.votesystem.Enum;
  879. +
  880. +/**
  881. + * @author l2.topgameserver.net
  882. + */
  883. +public enum voteSite
  884. +{
  885. +   L2TOPGAMESERVER, // 0
  886. +   ITOPZ, // 1
  887. +   L2TOPCO, // 2
  888. +   L2VOTES, // 3
  889. +   HOPZONE, // 4
  890. +   L2NETWORK, // 5
  891. +   L2TOPSERVERS, // 6
  892. +   TOPL2JBRASIL, // 7
  893. +   MMOTOP, // 8
  894. +   TOPZONE, // 9
  895. +   L2SERVERS,// 10
  896. +}
  897. Index: java/l2f/gameserver/votesystem/Model/individualVoteResponse.java
  898. ===================================================================
  899. --- java/l2f/gameserver/votesystem/Model/individualVoteResponse.java    (nonexistent)
  900. +++ java/l2f/gameserver/votesystem/Model/individualVoteResponse.java    (working copy)
  901. @@ -0,0 +1,46 @@
  902. +package l2f.gameserver.votesystem.Model;
  903. +
  904. +/**
  905. + * @author l2.topgameserver.net
  906. + */
  907. +public class individualVoteResponse
  908. +{
  909. +   private boolean _isVoted;
  910. +   private long _diffTime;
  911. +   private long _voteSiteTime;
  912. +  
  913. +   public individualVoteResponse()
  914. +   {
  915. +      
  916. +   }
  917. +  
  918. +   public void setIsVoted(boolean isVoted)
  919. +   {
  920. +       _isVoted = isVoted;
  921. +   }
  922. +  
  923. +   public void setDiffTime(long diffTime)
  924. +   {
  925. +       _diffTime = diffTime;
  926. +   }
  927. +  
  928. +   public void setVoteSiteTime(long voteSiteTime)
  929. +   {
  930. +       _voteSiteTime = voteSiteTime;
  931. +   }
  932. +  
  933. +   public boolean getIsVoted()
  934. +   {
  935. +       return _isVoted;
  936. +   }
  937. +  
  938. +   public long getDiffTime()
  939. +   {
  940. +       return _diffTime;
  941. +   }
  942. +  
  943. +   public long getVoteSiteTime()
  944. +   {
  945. +       return _voteSiteTime;
  946. +   }
  947. +}
  948.  
  949. Index: dist/gameserver/data/votesystem.xml
  950. ===================================================================
  951. --- dist/gameserver/data/votesystem.xml (nonexistent)
  952. +++ dist/gameserver/data/votesystem.xml (working copy)
  953. @@ -0,0 +1,46 @@
  954. +<?xml version="1.0" encoding="UTF-8"?>
  955. +<list xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../xsd/votesystem.xsd">
  956. +   <votesite name="l2.topgameserver.net" ordinal="0">
  957. +       <item itemId="57" itemCount="100000" />
  958. +   </votesite>
  959. +   <votesite name="ItopZ.com" ordinal="1">
  960. +       <item itemId="57" itemCount="100000" />
  961. +   </votesite>
  962. +   <votesite name="L2Top.co" ordinal="2">
  963. +       <item itemId="57" itemCount="100000" />
  964. +       <item itemId="6673" itemCount="1"/>
  965. +   </votesite>
  966. +   <votesite name="L2Votes.com" ordinal="3">
  967. +       <item itemId="57" itemCount="100000" />
  968. +   </votesite>
  969. +   <votesite name="Hopzone.net" ordinal="4">
  970. +       <item itemId="57" itemCount="100000" />
  971. +   </votesite>
  972. +   <votesite name="L2Network.eu" ordinal="5">
  973. +       <item itemId="57" itemCount="100000" />
  974. +       <item itemId="6673" itemCount="1"/>
  975. +   </votesite>
  976. +   <votesite name="L2Topservers.com" ordinal="6">
  977. +       <item itemId="57" itemCount="100000" />
  978. +       <item itemId="6673" itemCount="1"/>
  979. +   </votesite>
  980. +   <votesite name="top.l2jbrasil.com" ordinal="7">
  981. +       <item itemId="57" itemCount="100000" />
  982. +       <item itemId="6673" itemCount="1"/>
  983. +   </votesite>
  984. +   <votesite name="MMOTOP.eu" ordinal="8">
  985. +       <item itemId="57" itemCount="100000" />
  986. +       <item itemId="6673" itemCount="1"/>
  987. +   </votesite>
  988. +   <votesite name="L2Topzone.com" ordinal="9">
  989. +       <item itemId="57" itemCount="100000" />
  990. +   </votesite>
  991. +   <votesite name="L2Servers.com" ordinal="10">
  992. +       <item itemId="57" itemCount="100000" />
  993. +       <item itemId="6673" itemCount="1"/>
  994. +   </votesite>
  995. +   <votesite name="globalVotes" ordinal="11">
  996. +       <item itemId="57" itemCount="100000" />
  997. +       <item itemId="6673" itemCount="1"/>
  998. +   </votesite>
  999. +</list>
  1000. \ No newline at end of file
  1001. Index: dist/gameserver/config/votesystem.ini
  1002. ===================================================================
  1003. --- dist/gameserver/config/votesystem.ini   (nonexistent)
  1004. +++ dist/gameserver/config/votesystem.ini   (working copy)
  1005. @@ -0,0 +1,95 @@
  1006. +EnableVoteSystem = True
  1007. +
  1008. +EnableGlobalVote = True
  1009. +
  1010. +EnableIndividualVote = True
  1011. +
  1012. +## Time to Update table totalVotes from DB
  1013. +NextTimeToAutoUpdateTotalVote = 2
  1014. +
  1015. +## Time to update table individualVotes
  1016. +NextTimeToAutoUpdateIndividualVotes = 2
  1017. +
  1018. +NextTimeToAutoCleanInnecesaryVotes = 30
  1019. +
  1020. +NextTimeToCheckAutoGlobalVotesReward = 1
  1021. +
  1022. +IntervalToNextVote = 12
  1023. +
  1024. +GlobalVotesAmountToNextReward = 1
  1025. +
  1026. +EnableVotingCommand = True
  1027. +
  1028. +VotingCommand = rewardme
  1029. +
  1030. +## l2.topgameserver.net
  1031. +VoteLinkTgs = http://l2.topgameserver.net/lineage/VoteApi/
  1032. +
  1033. +TgsApiKey =
  1034. +
  1035. +## l2top.co
  1036. +VoteLinkTopCo = https://l2top.co/reward/
  1037. +
  1038. +TopCoSrvId =
  1039. +
  1040. +## ITopz.com
  1041. +VoteLinkItopz = https://itopz.com/check/
  1042. +
  1043. +ItopzZpiKey =
  1044. +
  1045. +ItopzSrvId =
  1046. +
  1047. +## l2votes.com
  1048. +VoteLinkVts = https://l2votes.com/
  1049. +
  1050. +VtsApiKey =
  1051. +
  1052. +VtsSid =
  1053. +
  1054. +## Hopzone.net
  1055. +VoteLinkHz = https://api.hopzone.net/lineage2/
  1056. +
  1057. +HzApiKey =
  1058. +
  1059. +## l2network.eu
  1060. +VoteNetworkLink = https://l2network.eu/api.php
  1061. +
  1062. +VoteNetworkUserName =
  1063. +
  1064. +VoteNetworkApiKey =
  1065. +
  1066. +## L2TopServer.com
  1067. +VoteLinkTss = https://l2topservers.com/votes?
  1068. +
  1069. +TssApiToken =
  1070. +
  1071. +TsSrvId = 453
  1072. +
  1073. +TsDomainName= l2catgang
  1074. +
  1075. +## top.l2jbrasil.com
  1076. +BrasilVoteLink = https://top.l2jbrasil.com/votesystem/index.php?
  1077. +
  1078. +BrasilUserName = julioguzman
  1079. +
  1080. +## Mmotop.eu
  1081. +VoteLinkMmotop = https://l2jtop.com/api/
  1082. +
  1083. +MmotopApiKey =
  1084. +
  1085. +## L2TopZone.com
  1086. +VoteLinkTz = https://api.l2topzone.com/v1/
  1087. +
  1088. +TzApiKey =
  1089. +
  1090. +## L2Servers.com
  1091. +VoteLinkServers = https://www.l2servers.com/api/
  1092. +
  1093. +ServersHashCode =
  1094. +
  1095. +ServersSrvId =
  1096. +
  1097. +
  1098. +## for localhost test if your project is live, put the word off or leave it blank
  1099. +TestIp =
  1100. +
  1101.  
  1102. Index: java/l2f/gameserver/votesystem/DB/individualVoteDB.java
  1103. ===================================================================
  1104. --- java/l2f/gameserver/votesystem/DB/individualVoteDB.java (nonexistent)
  1105. +++ java/l2f/gameserver/votesystem/DB/individualVoteDB.java (working copy)
  1106. @@ -0,0 +1,180 @@
  1107. +package l2f.gameserver.votesystem.DB;
  1108. +
  1109. +import java.sql.Connection;
  1110. +import java.sql.PreparedStatement;
  1111. +import java.sql.ResultSet;
  1112. +import java.sql.SQLException;
  1113. +import java.sql.Statement;
  1114. +import java.util.HashMap;
  1115. +import java.util.HashSet;
  1116. +import java.util.Map;
  1117. +import java.util.logging.Logger;
  1118. +
  1119. +import l2f.gameserver.database.DatabaseFactory;
  1120. +import l2f.gameserver.votesystem.Enum.voteSite;
  1121. +import l2f.gameserver.votesystem.Model.individualVote;
  1122. +
  1123. +
  1124. +/**
  1125. + * @author l2.topgameserver.net
  1126. + */
  1127. +public class individualVoteDB
  1128. +{
  1129. +   private static final Logger LOGGER = Logger.getLogger(individualVoteDB.class.getName());
  1130. +   private final Map<String, individualVote[]> _votes;
  1131. +  
  1132. +   private individualVoteDB()
  1133. +   {
  1134. +       _votes = new HashMap<>();
  1135. +       loadVotes();
  1136. +   }
  1137. +  
  1138. +   public void loadVotes()
  1139. +   {
  1140. +       _votes.clear();
  1141. +       try (Connection con = DatabaseFactory.getInstance().getConnection();
  1142. +           PreparedStatement ps = con.prepareStatement("SELECT voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded FROM individualvotes");
  1143. +           ResultSet rs = ps.executeQuery();)
  1144. +       {
  1145. +           individualVote[] ivs = new individualVote[voteSite.values().length];
  1146. +           while (rs.next())
  1147. +           {
  1148. +               individualVote iv = new individualVote();
  1149. +               iv.setVoterIp(rs.getString("voterIp"));
  1150. +               iv.setVoteSite(rs.getInt("voteSite"));
  1151. +               iv.setDiffTime(rs.getLong("diffTime"));
  1152. +               iv.setVotingTimeSite(rs.getLong("votingTimeSite"));
  1153. +               iv.setAlreadyRewarded(rs.getBoolean("alreadyRewarded"));
  1154. +              
  1155. +               if (_votes.containsKey(iv.getVoterIp()))
  1156. +               {
  1157. +                   if (_votes.get(iv.getVoterIp())[iv.getVoteSite()] == null)
  1158. +                   {
  1159. +                       ivs[iv.getVoteSite()] = iv;
  1160. +                       _votes.replace(iv.getVoterIp(), ivs);
  1161. +                   }
  1162. +               }
  1163. +               else
  1164. +               {
  1165. +                   ivs[iv.getVoteSite()] = iv;
  1166. +                   _votes.put(iv.getVoterIp(), ivs);
  1167. +                  
  1168. +               }
  1169. +           }
  1170. +          
  1171. +       }
  1172. +       catch (SQLException e)
  1173. +       {
  1174. +           e.printStackTrace();
  1175. +       }
  1176. +      
  1177. +   }
  1178. +  
  1179. +   public void SaveVotes(Map<String, individualVote[]> votes)
  1180. +   {
  1181. +      
  1182. +       if (votes == null)
  1183. +       {
  1184. +           return;
  1185. +       }
  1186. +       if (votes.size() == 0)
  1187. +       {
  1188. +           return;
  1189. +       }
  1190. +       try (Connection con = DatabaseFactory.getInstance().getConnection();
  1191. +           PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE " + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite),alreadyRewarded = VALUES(alreadyRewarded)");)
  1192. +       {
  1193. +          
  1194. +           for (Map.Entry<String, individualVote[]> ivm : votes.entrySet())
  1195. +           {
  1196. +               for (individualVote iv : ivm.getValue())
  1197. +               {
  1198. +                   if (iv == null)
  1199. +                   {
  1200. +                       continue;
  1201. +                   }
  1202. +                   ps.setString(1, iv.getVoterIp());
  1203. +                   ps.setInt(2, iv.getVoteSite());
  1204. +                   ps.setLong(3, iv.getDiffTime());
  1205. +                   ps.setLong(4, iv.getVotingTimeSite());
  1206. +                   ps.setBoolean(5, iv.getAlreadyRewarded());
  1207. +                   ps.addBatch();
  1208. +               }
  1209. +           }
  1210. +           ps.executeBatch();
  1211. +       }
  1212. +       catch (SQLException e)
  1213. +       {
  1214. +           e.printStackTrace();
  1215. +       }
  1216. +   }
  1217. +  
  1218. +   public void SaveVote(individualVote vote)
  1219. +   {
  1220. +      
  1221. +       if (vote == null)
  1222. +       {
  1223. +           return;
  1224. +       }
  1225. +      
  1226. +       try (Connection con = DatabaseFactory.getInstance().getConnection();
  1227. +           PreparedStatement ps = con.prepareStatement("INSERT INTO individualvotes(voterIp,voteSite,diffTime,votingTimeSite,alreadyRewarded) VALUES(?,?,?,?,?) ON DUPLICATE KEY UPDATE" + "voterIp = VALUES(voterIp), voteSite = VALUES(voteSite), diffTime = VALUES(diffTime), votingTimeSite = VALUES(votingTimeSite), alreadyRewarded = VALUES(alreadyRewarded)");)
  1228. +       {
  1229. +           ps.setString(1, vote.getVoterIp());
  1230. +           ps.setInt(2, vote.getVoteSite());
  1231. +           ps.setLong(3, vote.getDiffTime());
  1232. +           ps.setLong(4, vote.getVotingTimeSite());
  1233. +           ps.setBoolean(5, vote.getAlreadyRewarded());
  1234. +           ps.executeUpdate();
  1235. +       }
  1236. +       catch (SQLException e)
  1237. +       {
  1238. +           e.printStackTrace();
  1239. +       }
  1240. +   }
  1241. +  
  1242. +   public void DeleteVotes(HashSet<individualVote> deleteVotes)
  1243. +   {
  1244. +       if (deleteVotes == null)
  1245. +       {
  1246. +           return;
  1247. +       }
  1248. +       if (deleteVotes.size() == 0)
  1249. +       {
  1250. +           return;
  1251. +       }
  1252. +       try(Connection con = DatabaseFactory.getInstance().getConnection();Statement st = con.createStatement();)
  1253. +       {
  1254. +          
  1255. +           for (individualVote iv : deleteVotes)
  1256. +           {
  1257. +               String sql = String.format("Delete from individualvotes where voterIp = '%s' AND voteSite = %s", iv.getVoterIp(), iv.getVoteSite());
  1258. +               st.addBatch(sql);
  1259. +           }
  1260. +           int[] result = st.executeBatch();
  1261. +           st.close();
  1262. +           con.close();
  1263. +           LOGGER.info(result.length + " Innecesary votes has been deleted");
  1264. +          
  1265. +       }
  1266. +       catch (SQLException e)
  1267. +       {
  1268. +           e.printStackTrace();
  1269. +       }
  1270. +   }
  1271. +  
  1272. +   public Map<String, individualVote[]> getVotesDB()
  1273. +   {
  1274. +       return _votes;
  1275. +   }
  1276. +  
  1277. +   public static final individualVoteDB getInstance()
  1278. +   {
  1279. +       return SingleHolder.INSTANCE;
  1280. +   }
  1281. +  
  1282. +   private static final class SingleHolder
  1283. +   {
  1284. +       protected static final individualVoteDB INSTANCE = new individualVoteDB();
  1285. +   }
  1286. +}
  1287.  
  1288. Index: java/l2f/gameserver/votesystem/Handler/voteHandler.java
  1289. ===================================================================
  1290. --- java/l2f/gameserver/votesystem/Handler/voteHandler.java (nonexistent)
  1291. +++ java/l2f/gameserver/votesystem/Handler/voteHandler.java (working copy)
  1292. @@ -0,0 +1,510 @@
  1293. +package l2f.gameserver.votesystem.Handler;
  1294. +
  1295. +import java.io.BufferedReader;
  1296. +import java.io.DataOutputStream;
  1297. +import java.io.InputStreamReader;
  1298. +import java.net.HttpURLConnection;
  1299. +import java.net.URL;
  1300. +import java.nio.charset.Charset;
  1301. +import java.text.ParseException;
  1302. +import java.text.SimpleDateFormat;
  1303. +import java.util.logging.Logger;
  1304. +
  1305. +import l2f.gameserver.Config;
  1306. +import l2f.gameserver.votesystem.Enum.voteSite;
  1307. +import l2f.gameserver.votesystem.Model.individualVoteResponse;
  1308. +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml;
  1309. +import l2f.gameserver.votesystem.VoteUtil.VoteUtil;
  1310. +
  1311. +
  1312. +/**
  1313. + * @author l2.topgameserver.net
  1314. + */
  1315. +public class voteHandler
  1316. +{
  1317. +   public static final Logger LOGGER = Logger.getLogger(voteHandler.class.getName());
  1318. +  
  1319. +   protected static String getNetWorkResponse(String URL, int ordinal)
  1320. +   {
  1321. +       if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
  1322. +       {
  1323. +           return "";
  1324. +       }
  1325. +      
  1326. +       StringBuffer response = new StringBuffer();
  1327. +       try
  1328. +       {
  1329. +           String API_URL = Config.VOTE_NETWORK_LINK;
  1330. +           String detail = URL;
  1331. +           String postParameters = "";
  1332. +           postParameters += "apiKey=" + VoteUtil.between("apiKey=", detail, "&type=");
  1333. +           postParameters += "&type=" + VoteUtil.between("&type=", detail, "&player");
  1334. +           String beginIndexPlayer = "&player=";
  1335. +           String player = detail.substring(detail.indexOf(beginIndexPlayer) + beginIndexPlayer.length());
  1336. +          
  1337. +           if ((player != null) && !player.equals(""))
  1338. +           {
  1339. +               postParameters += "&player=" + player;
  1340. +           }
  1341. +          
  1342. +           byte[] postData = postParameters.getBytes(Charset.forName("UTF-8"));
  1343. +           URL url = new URL(API_URL);
  1344. +           HttpURLConnection con = (HttpURLConnection) url.openConnection();
  1345. +           con.setConnectTimeout(5000);
  1346. +           con.setRequestMethod("POST");
  1347. +           con.setRequestProperty("Content-Length", Integer.toString(postData.length));
  1348. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  1349. +           con.setDoOutput(true);
  1350. +          
  1351. +           DataOutputStream os = new DataOutputStream(con.getOutputStream());
  1352. +           os.write(postData);
  1353. +           os.flush();
  1354. +           os.close();
  1355. +          
  1356. +           BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  1357. +           String inputLine;
  1358. +          
  1359. +           while ((inputLine = in.readLine()) != null)
  1360. +           {
  1361. +               response.append(inputLine);
  1362. +           }
  1363. +           in.close();
  1364. +          
  1365. +           return response.toString();
  1366. +          
  1367. +       }
  1368. +       catch (Exception e)
  1369. +       {
  1370. +           LOGGER.warning(VoteUtil.Sites[ordinal] + " Say: An error ocurred " + e.getCause());
  1371. +           return "";
  1372. +       }
  1373. +   }
  1374. +  
  1375. +   protected static String getResponse(String Url, int ordinal)
  1376. +   {
  1377. +       if ((ordinal == voteSite.L2NETWORK.ordinal()) && ("".equals(Config.VOTE_NETWORK_API_KEY) || "".equals(Config.VOTE_NETWORK_LINK) || "".equals(Config.VOTE_NETWORK_USER_NAME)))
  1378. +       {
  1379. +           return "";
  1380. +       }
  1381. +      
  1382. +       try
  1383. +       {
  1384. +           int responseCode = 0;
  1385. +           URL objUrl = new URL(Url);
  1386. +           HttpURLConnection con = (HttpURLConnection) objUrl.openConnection();
  1387. +           con.setRequestMethod("GET");
  1388. +           con.setRequestProperty("User-Agent", "Mozilla/5.0");
  1389. +           con.setConnectTimeout(5000);
  1390. +           responseCode = con.getResponseCode();
  1391. +           if (responseCode == HttpURLConnection.HTTP_OK)
  1392. +           {
  1393. +               String inputLine;
  1394. +               StringBuffer response = new StringBuffer();
  1395. +               BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
  1396. +               while ((inputLine = in.readLine()) != null)
  1397. +               {
  1398. +                   response.append(inputLine);
  1399. +               }
  1400. +               in.close();
  1401. +               return response.toString();
  1402. +           }
  1403. +          
  1404. +       }
  1405. +       catch (Exception e)
  1406. +       {
  1407. +           LOGGER.warning(VoteSiteXml.getInstance().getSiteName(ordinal) + " Say: An error ocurred " + e.getCause());
  1408. +           return "";
  1409. +       }
  1410. +      
  1411. +       return "";
  1412. +   }
  1413. +  
  1414. +   public static individualVoteResponse getIndividualVoteResponse(int ordinal, String ip, String AccountName)
  1415. +   {
  1416. +       String response = "";
  1417. +       boolean isVoted = false;
  1418. +       long voteSiteTime = 0L, diffTime = 0L;
  1419. +       SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
  1420. +       individualVoteResponse ivr = new individualVoteResponse();
  1421. +      
  1422. +       switch (ordinal)
  1423. +       {
  1424. +           case 0:
  1425. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1426. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"already_voted\":", response, ",\"vote_time\""));
  1427. +               if (isVoted)
  1428. +               {
  1429. +                   try
  1430. +                   {
  1431. +                       voteSiteTime = format.parse(VoteUtil.between("\"vote_time\":\"", response, "\",\"server_time\"")).getTime();
  1432. +                       diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"server_time\":\"", response, "\"}")).getTime();
  1433. +                   }
  1434. +                   catch (ParseException e)
  1435. +                   {
  1436. +                       e.printStackTrace();
  1437. +                   }
  1438. +               }
  1439. +               break;
  1440. +          
  1441. +           case 1:
  1442. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1443. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isvoted\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"votetime").replaceAll("\"", ""));
  1444. +               if (isVoted)
  1445. +               {
  1446. +                   try
  1447. +                   {
  1448. +                       voteSiteTime = (Long.parseLong(VoteUtil.between("\"votetime\":", response.toString().toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), ",\"servertime"))) * 1000;
  1449. +                       diffTime = System.currentTimeMillis() - ((Long.parseLong(VoteUtil.between("\"servertime\":", response.toLowerCase().replaceAll("\n", "").replaceAll(" ", ""), "}"))) * 1000);
  1450. +                   }
  1451. +                   catch (Exception e)
  1452. +                   {
  1453. +                       e.printStackTrace();
  1454. +                   }
  1455. +               }
  1456. +               break;
  1457. +          
  1458. +           case 2:
  1459. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1460. +               isVoted = (response == "") ? false : Boolean.parseBoolean(response);
  1461. +               if (isVoted)
  1462. +               {
  1463. +                   voteSiteTime = System.currentTimeMillis();
  1464. +                   diffTime = 0;
  1465. +               }
  1466. +               break;
  1467. +          
  1468. +           case 3:
  1469. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1470. +               isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"date\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"date\"")) == 1)) ? true : false;
  1471. +               if (isVoted)
  1472. +               {
  1473. +                   String dateString = VoteUtil.between("\"date\":\"", response, "\"}]");
  1474. +                   try
  1475. +                   {
  1476. +                       voteSiteTime = System.currentTimeMillis();
  1477. +                       diffTime = 0;
  1478. +                   }
  1479. +                   catch (Exception e)
  1480. +                   {
  1481. +                       e.printStackTrace();
  1482. +                   }
  1483. +                  
  1484. +               }
  1485. +               break;
  1486. +          
  1487. +           case 4:
  1488. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1489. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
  1490. +               if (isVoted)
  1491. +               {
  1492. +                   try
  1493. +                   {
  1494. +                       voteSiteTime = format.parse(VoteUtil.between("\"voteTime\":\"", response, "\",\"hopzoneServerTime\"")).getTime();
  1495. +                       diffTime = System.currentTimeMillis() - format.parse(VoteUtil.between("\"hopzoneServerTime\":\"", response, "\",\"status_code\":")).getTime();
  1496. +                   }
  1497. +                   catch (ParseException e)
  1498. +                   {
  1499. +                       e.printStackTrace();
  1500. +                   }
  1501. +               }
  1502. +               break;
  1503. +          
  1504. +           case 5:
  1505. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1506. +               isVoted = (!"".equals(response) && (Integer.parseInt(response) == 1)) ? true : false;
  1507. +               if (isVoted)
  1508. +               {
  1509. +                   voteSiteTime = System.currentTimeMillis();
  1510. +                   diffTime = 0;
  1511. +               }
  1512. +               break;
  1513. +          
  1514. +           case 6:
  1515. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1516. +               isVoted = ("".equals(response)) ? false : Boolean.parseBoolean(VoteUtil.between("\"voted\":", response, ",\"voteTime\""));
  1517. +               if (isVoted)
  1518. +               {
  1519. +                   try
  1520. +                   {
  1521. +                       voteSiteTime = System.currentTimeMillis();
  1522. +                       diffTime = 0;
  1523. +                   }
  1524. +                   catch (Exception e)
  1525. +                   {
  1526. +                       e.printStackTrace();
  1527. +                   }
  1528. +                  
  1529. +               }
  1530. +               break;
  1531. +          
  1532. +           case 7:
  1533. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1534. +               isVoted = ((VoteUtil.between("\"status\":\"", response, "\",\"server_time\"") != "") && (Integer.parseInt(VoteUtil.between("\"status\":\"", response, "\",\"server_time\"")) == 1)) ? true : false;
  1535. +               if (isVoted)
  1536. +               {
  1537. +                   try
  1538. +                   {
  1539. +                       voteSiteTime = System.currentTimeMillis();
  1540. +                       diffTime = 0;
  1541. +                   }
  1542. +                   catch (Exception e)
  1543. +                   {
  1544. +                       e.printStackTrace();
  1545. +                   }
  1546. +               }
  1547. +               break;
  1548. +          
  1549. +           case 8:
  1550. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1551. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"is_voted\":", response, ",\"vote_time\""));
  1552. +               if (isVoted)
  1553. +               {
  1554. +                   try
  1555. +                   {
  1556. +                       voteSiteTime = (Long.parseLong(VoteUtil.between("\"vote_time\":", response, ",\"server_time\""))) * 1000;
  1557. +                       diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"server_time\":", response, "}}")) * 1000);
  1558. +                   }
  1559. +                   catch (Exception e)
  1560. +                   {
  1561. +                       e.printStackTrace();
  1562. +                   }
  1563. +               }
  1564. +               break;
  1565. +          
  1566. +           case 9:
  1567. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1568. +               isVoted = (response == "") ? false : Boolean.parseBoolean(VoteUtil.between("\"isVoted\": ", response, ",\"voteTime\""));
  1569. +               if (isVoted)
  1570. +               {
  1571. +                   voteSiteTime = Long.parseLong(VoteUtil.between("\"voteTime\": \"", response, "\",\"serverTime\"")) * 1000;
  1572. +                   diffTime = System.currentTimeMillis() - (Long.parseLong(VoteUtil.between("\"serverTime\": ", response, "}}")) * 1000);
  1573. +               }
  1574. +               break;
  1575. +          
  1576. +           case 10:
  1577. +               response = getResponse(getIndividualUrl(ordinal, ip, null), ordinal);
  1578. +               isVoted = (response == "") ? false : Boolean.parseBoolean(response);
  1579. +               if (isVoted)
  1580. +               {
  1581. +                   voteSiteTime = System.currentTimeMillis();
  1582. +                   diffTime = 0;
  1583. +               }
  1584. +               break;
  1585. +          
  1586. +       }
  1587. +       if (!response.equals(""))
  1588. +       {
  1589. +           ivr.setIsVoted(isVoted);
  1590. +           ivr.setDiffTime(diffTime);
  1591. +           ivr.setVoteSiteTime(voteSiteTime);
  1592. +           return ivr;
  1593. +       }
  1594. +       return null;
  1595. +   }
  1596. +  
  1597. +   public int getGlobalVotesResponse(int ordinal)
  1598. +   {
  1599. +      
  1600. +       String response = "";
  1601. +       int totalVotes = 0;
  1602. +      
  1603. +       switch (ordinal)
  1604. +       {
  1605. +           case 0:
  1606. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1607. +               response = VoteUtil.between("\"getVotes\":", response, "}");
  1608. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1609. +               break;
  1610. +          
  1611. +           case 1:
  1612. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1613. +               response = VoteUtil.between("server_votes\":", response.replace(" ", ""), ",\"server_rank");
  1614. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1615. +               break;
  1616. +          
  1617. +           case 2:
  1618. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1619. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1620. +               break;
  1621. +          
  1622. +           case 3:
  1623. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1624. +               response = VoteUtil.between("Votes:</th><th><a class='votes'>", response, "</a></th></tr><tr><th>Clicks:");
  1625. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1626. +               break;
  1627. +          
  1628. +           case 4:
  1629. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1630. +               response = VoteUtil.between("\"totalvotes\":", response, ",\"status_code\"");
  1631. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1632. +               break;
  1633. +          
  1634. +           case 5:
  1635. +               String responseNetwork = getNetWorkResponse(getGlobalUrl(ordinal), ordinal);
  1636. +               totalVotes = (!"".equals(responseNetwork)) ? Integer.parseInt(responseNetwork) : -1;
  1637. +               break;
  1638. +          
  1639. +           case 6:
  1640. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1641. +               response = VoteUtil.between("VOTE <span>", response.toString().replaceAll("\n", ""), "</span>");
  1642. +              
  1643. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1644. +               break;
  1645. +          
  1646. +           case 7:
  1647. +               response = VoteUtil.getResponse(getGlobalUrl(ordinal), ordinal);
  1648. +               response = VoteUtil.between("nicas:</b> ", response, "<br /><br />");
  1649. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1650. +               break;
  1651. +          
  1652. +           case 8:
  1653. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1654. +               response = VoteUtil.between("\"monthly_votes\":", response, "}}");
  1655. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1656. +               break;
  1657. +          
  1658. +           case 9:
  1659. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1660. +               response = VoteUtil.between("\"totalVotes\":\"", response, "\",\"serverRank\"");
  1661. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1662. +               break;
  1663. +          
  1664. +           case 10:
  1665. +               response = getResponse(getGlobalUrl(ordinal), ordinal);
  1666. +               totalVotes = (!"".equals(response)) ? Integer.parseInt(response) : -1;
  1667. +               break;
  1668. +       }
  1669. +      
  1670. +       return totalVotes;
  1671. +   }
  1672. +  
  1673. +   public static String getIndividualUrl(int ordinal, String ip, String AccountName)
  1674. +   {
  1675. +       String url = "";
  1676. +       ip = (Config.TEST_IP.equalsIgnoreCase("off") || Config.TEST_IP.equalsIgnoreCase("")) ? ip : Config.TEST_IP;
  1677. +       switch (ordinal)
  1678. +       {
  1679. +           case 0:
  1680. +               // l2.topgameserver.net
  1681. +               url = String.format("%sAPI_KEY=%s/getData/%s", Config.VOTE_LINK_TGS, Config.TGS_API_KEY, ip);
  1682. +               break;
  1683. +          
  1684. +           case 1:
  1685. +               // itopz.com
  1686. +               url = String.format("%s%s/%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID, ip);
  1687. +               break;
  1688. +          
  1689. +           case 2:
  1690. +               // l2top.co
  1691. +               url = String.format("%sVoteCheck.php?id=%s&ip=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID, ip);
  1692. +               break;
  1693. +          
  1694. +           case 3:
  1695. +               // l2votes.com
  1696. +               url = String.format("%sapi.php?apiKey=%s&ip=%s", Config.VOTE_LINK_VTS, Config.VTS_API_KEY, ip);
  1697. +               break;
  1698. +          
  1699. +           case 4:
  1700. +               // hopzone.net
  1701. +               url = String.format("%svote?token=%s&ip_address=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY, ip);
  1702. +               break;
  1703. +          
  1704. +           case 5:
  1705. +               // l2network.eu
  1706. +               url = String.format("https://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_USER_NAME, ip);
  1707. +               break;
  1708. +          
  1709. +           case 6:
  1710. +               // l2topservers.com
  1711. +               url = String.format("%stoken=%s&ip=%s", Config.VOTE_LINK_TSS, Config.TSS_API_TOKEN, ip);
  1712. +               break;
  1713. +          
  1714. +           case 7:
  1715. +               // top.l2jbrasil.com
  1716. +               url = String.format("%susername=%s&ip=%s&type=json", Config.BRASIL_VOTE_LINK, Config.BRASIL_USER_NAME, ip);
  1717. +               break;
  1718. +          
  1719. +           case 8:
  1720. +               // mmotop
  1721. +               url = String.format("%s%s/ip/%s", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY, ip);
  1722. +               break;
  1723. +          
  1724. +           case 9:
  1725. +               // topzone.com
  1726. +               url = String.format("%svote?token=%s&ip=%s", Config.VOTE_LINK_TZ, Config.TZ_API_KEY, ip);
  1727. +               break;
  1728. +          
  1729. +           case 10:
  1730. +               // l2servers.com
  1731. +               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);
  1732. +               break;
  1733. +       }
  1734. +      
  1735. +       return url;
  1736. +   }
  1737. +  
  1738. +   public String getGlobalUrl(int ordinal)
  1739. +   {
  1740. +       String url = "";
  1741. +      
  1742. +       switch (ordinal)
  1743. +       {
  1744. +           case 0:
  1745. +               // l2.topgameserver.net
  1746. +               url = String.format("%sAPI_KEY=%s/getData", Config.VOTE_LINK_TGS, Config.TGS_API_KEY);
  1747. +               break;
  1748. +          
  1749. +           case 1:
  1750. +               // itopz.com
  1751. +               url = String.format("%s%s/%s", Config.VOTE_LINK_ITOPZ, Config.ITOPZ_API_KEY, Config.ITOPZ_SRV_ID);
  1752. +               break;
  1753. +          
  1754. +           case 2:
  1755. +               // l2top.co
  1756. +               url = String.format("%sVoteCheck_Total.php?id=%s", Config.VOTE_LINK_TOP_CO, Config.TOP_CO_SRV_ID);
  1757. +               break;
  1758. +          
  1759. +           case 3:
  1760. +               // l2votes.com
  1761. +               url = String.format("%sserverPage.php?sid=%s", Config.VOTE_LINK_VTS, Config.VTS_SID);
  1762. +               break;
  1763. +          
  1764. +           case 4:
  1765. +               // hopzone.net
  1766. +               url = String.format("%svotes?token=%s", Config.VOTE_LINK_HZ, Config.HZ_API_KEY);
  1767. +               break;
  1768. +          
  1769. +           case 5:
  1770. +               // l2network.eu
  1771. +               url = String.format("apiKey=%s&type=%s&player=", Config.VOTE_NETWORK_API_KEY, 1);
  1772. +               break;
  1773. +          
  1774. +           case 6:
  1775. +               // l2topservers
  1776. +               url = String.format("https://l2topservers.com/l2top/%s/%s", Config.TS_SRV_ID, Config.TS_DOMAIN_NAME);
  1777. +               break;
  1778. +          
  1779. +           case 7:
  1780. +               // top.l2jbrasil.com
  1781. +               url = String.format("https://top.l2jbrasil.com/index.php?a=stats&u=%s", Config.BRASIL_USER_NAME);
  1782. +               break;
  1783. +          
  1784. +           case 8:
  1785. +               // mmotop.eu/l2/
  1786. +               url = String.format("%s%s/info/", Config.VOTE_LINK_MMOTOP, Config.MMOTOP_API_KEY);
  1787. +               break;
  1788. +          
  1789. +           case 9:
  1790. +               // l2topzone.com
  1791. +               url = String.format("%sserver_%s/getServerData", Config.VOTE_LINK_TZ, Config.TZ_API_KEY);
  1792. +               break;
  1793. +          
  1794. +           case 10:
  1795. +               // l2servers.com
  1796. +               url = String.format("%syearlyvotes.php?server_id=%s", Config.VOTE_LINK_SERVERS, Config.SERVERS_SRV_ID);
  1797. +               break;
  1798. +       }
  1799. +      
  1800. +       return url;
  1801. +   }
  1802. +}
  1803. \ No newline at end of file
  1804. Index: java/l2f/gameserver/votesystem/Handler/voteManager.java
  1805. ===================================================================
  1806. --- java/l2f/gameserver/votesystem/Handler/voteManager.java (nonexistent)
  1807. +++ java/l2f/gameserver/votesystem/Handler/voteManager.java (working copy)
  1808. @@ -0,0 +1,394 @@
  1809. +package l2f.gameserver.votesystem.Handler;
  1810. +
  1811. +import java.util.HashSet;
  1812. +import java.util.Map;
  1813. +import java.util.concurrent.ConcurrentHashMap;
  1814. +import java.util.concurrent.ScheduledFuture;
  1815. +
  1816. +import l2f.gameserver.Announcements;
  1817. +import l2f.gameserver.Config;
  1818. +import l2f.gameserver.ThreadPoolManager;
  1819. +import l2f.gameserver.model.GameObjectsStorage;
  1820. +import l2f.gameserver.model.Player;
  1821. +import l2f.gameserver.network.GameClient;
  1822. +import l2f.gameserver.network.serverpackets.components.ChatType;
  1823. +import l2f.gameserver.votesystem.DB.globalVoteDB;
  1824. +import l2f.gameserver.votesystem.DB.individualVoteDB;
  1825. +import l2f.gameserver.votesystem.Enum.voteSite;
  1826. +import l2f.gameserver.votesystem.Model.Reward;
  1827. +import l2f.gameserver.votesystem.Model.globalVote;
  1828. +import l2f.gameserver.votesystem.Model.individualVote;
  1829. +import l2f.gameserver.votesystem.Model.individualVoteResponse;
  1830. +import l2f.gameserver.votesystem.VoteUtil.VoteSiteXml;
  1831. +import l2f.gameserver.votesystem.VoteUtil.VoteUtil;
  1832. +import l2f.gameserver.network.serverpackets.SystemMessage2;
  1833. +import l2f.gameserver.network.serverpackets.components.SystemMsg;
  1834. +
  1835. +/**
  1836. + * @author l2.topgameserver.net
  1837. + */
  1838. +public final class voteManager extends voteHandler
  1839. +{
  1840. +   private ScheduledFuture<?> _saveGlobalVotes;
  1841. +   private ScheduledFuture<?> _updateIndividualVotes;
  1842. +   private ScheduledFuture<?> _autoGlobalVotesReward;
  1843. +  
  1844. +   private Map<String, individualVote[]> _foundVoters;
  1845. +   private globalVote[] _globalVotes = new globalVote[voteSite.values().length];
  1846. +  
  1847. +   public voteManager()
  1848. +   {
  1849. +       _foundVoters = new ConcurrentHashMap<>();
  1850. +       loadVotes();
  1851. +       loadGlobalVotes();
  1852. +       checkAllResponseGlobalVotes();
  1853. +       stopAutoTasks();
  1854. +      
  1855. +       if (Config.ENABLE_INDIVIDUAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
  1856. +       {
  1857. +           _updateIndividualVotes = ThreadPoolManager.getInstance().scheduleAtFixedRate(new AutoUpdateIndividualVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES);
  1858. +       }
  1859. +       if (Config.ENABLE_GLOBAL_VOTE && Config.ENABLE_VOTE_SYSTEM)
  1860. +       {
  1861. +           _autoGlobalVotesReward = ThreadPoolManager.getInstance().scheduleAtFixedRate(new AutoGlobalVoteRewardTask(), 10000, Config.NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD);
  1862. +           _saveGlobalVotes = ThreadPoolManager.getInstance().scheduleAtFixedRate(new AutoSaveGlobalVotesTask(), 30000, Config.NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE);
  1863. +       }
  1864. +   }
  1865. +  
  1866. +   private void stopAutoTasks()
  1867. +   {
  1868. +       if (_saveGlobalVotes != null)
  1869. +       {
  1870. +           _saveGlobalVotes.cancel(true);
  1871. +           _saveGlobalVotes = null;
  1872. +       }
  1873. +       if (_updateIndividualVotes != null)
  1874. +       {
  1875. +           _updateIndividualVotes.cancel(true);
  1876. +           _updateIndividualVotes = null;
  1877. +       }
  1878. +       if (_autoGlobalVotesReward != null)
  1879. +       {
  1880. +           _autoGlobalVotesReward.cancel(true);
  1881. +           _autoGlobalVotesReward = null;
  1882. +       }
  1883. +   }
  1884. +  
  1885. +   public void getReward(Player player, int ordinalSite)
  1886. +   {
  1887. +       String ip = existIp(player);
  1888. +       if (ip == null)
  1889. +       {
  1890. +           return;
  1891. +       }
  1892. +       individualVoteResponse ivr = getIndividualVoteResponse(ordinalSite, ip, player.getAccountName());
  1893. +       if (ivr == null)
  1894. +       {
  1895. +           player.sendMessage("We were unable to verify your vote with: " + VoteSiteXml.getInstance().getSiteName(ordinalSite) + ", please try again");
  1896. +           return;
  1897. +       }
  1898. +
  1899. +       if (getTimeRemaining(new individualVote(ip, ivr.getVoteSiteTime(), ordinalSite, false)) < 0)
  1900. +       {
  1901. +           player.sendMessage("We were unable to verify your vote with: " + VoteSiteXml.getInstance().getSiteName(ordinalSite) + ", please try again");
  1902. +           return;
  1903. +       }
  1904. +       if (!ivr.getIsVoted())
  1905. +       {
  1906. +           player.sendMessage(String.format("You haven't vote on %s yet!", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
  1907. +           return;
  1908. +       }
  1909. +       if (!checkIndividualAvailableVote(player, ordinalSite))
  1910. +       {
  1911. +           player.sendMessage(String.format("You can get the reward again on %s at %s", VoteSiteXml.getInstance().getSiteName(ordinalSite), getTimeRemainingWithSampleFormat(player, ordinalSite)));
  1912. +           return;
  1913. +       }
  1914. +       individualVote iv = new individualVote(ip, ivr.getDiffTime(), ivr.getVoteSiteTime(), ordinalSite, false);
  1915. +      
  1916. +       individualVote[] aiv;
  1917. +       if (!_foundVoters.containsKey(ip))
  1918. +       {
  1919. +           aiv = new individualVote[voteSite.values().length];
  1920. +           iv.setAlreadyRewarded(true);
  1921. +           aiv[ordinalSite] = iv;
  1922. +           _foundVoters.put(ip, aiv);
  1923. +       }
  1924. +       else
  1925. +       {
  1926. +           aiv = _foundVoters.get(ip);
  1927. +           iv.setAlreadyRewarded(true);
  1928. +           aiv[ordinalSite] = iv;
  1929. +           _foundVoters.replace(ip, aiv);
  1930. +          
  1931. +       }
  1932. +       for (Reward reward : VoteSiteXml.getInstance().getRewards(ordinalSite))
  1933. +       {
  1934. +          
  1935. +           player.getInventory().addItem(reward.getItemId(), reward.getItemCount(),"VoteSystem");
  1936. +           player.sendPacket(new SystemMessage2(SystemMsg.YOU_HAVE_EARNED_S2_S1S).addItemName(reward.getItemId()).addInteger(reward.getItemCount()));
  1937. +       }
  1938. +       player.sendMessage(String.format("%s: Thank you for voting for our server, your reward has been delivered.", VoteSiteXml.getInstance().getSiteName(ordinalSite)));
  1939. +       player.sendItemList(true);;
  1940. +   }
  1941. +  
  1942. +   public boolean checkIndividualAvailableVote(Player player, int ordinalSite)
  1943. +   {
  1944. +       String ip = existIp(player);
  1945. +       if (_foundVoters.containsKey(ip))
  1946. +       {
  1947. +           individualVote[] ivs = _foundVoters.get(ip);
  1948. +           if (ivs[ordinalSite] == null)
  1949. +           {
  1950. +               return true;
  1951. +           }
  1952. +           if (ivs[ordinalSite] != null)
  1953. +           {
  1954. +               individualVote iv = ivs[ordinalSite];
  1955. +               if (getTimeRemaining(iv) < 0)
  1956. +               {
  1957. +                   return true;
  1958. +               }
  1959. +           }
  1960. +       }
  1961. +       else
  1962. +       {
  1963. +           return true;
  1964. +       }
  1965. +      
  1966. +       return false;
  1967. +   }
  1968. +  
  1969. +   public long getTimeRemaining(individualVote iv)
  1970. +   {
  1971. +       long timeRemaining = 0L;
  1972. +       timeRemaining = ((iv.getVotingTimeSite() + Config.INTERVAL_TO_NEXT_VOTE) - (iv.getDiffTime() > 0 ? iv.getDiffTime() : -1 * iv.getDiffTime())) - System.currentTimeMillis();
  1973. +       return timeRemaining;
  1974. +   }
  1975. +  
  1976. +   public String getTimeRemainingWithSampleFormat(Player player, int ordinalSite)
  1977. +   {
  1978. +       String ip = existIp(player);
  1979. +       String timeRemainingWithSampleFormat = "";
  1980. +       if (_foundVoters.containsKey(ip))
  1981. +       {
  1982. +           individualVote[] ivs = _foundVoters.get(ip);
  1983. +           if (ivs[ordinalSite] != null)
  1984. +           {
  1985. +               individualVote iv = ivs[ordinalSite];
  1986. +               long timeRemaining = getTimeRemaining(iv);
  1987. +               if (timeRemaining > 0)
  1988. +               {
  1989. +                   timeRemainingWithSampleFormat = CalculateTimeRemainingWithSampleDateFormat(timeRemaining);
  1990. +                   return timeRemainingWithSampleFormat;
  1991. +               }
  1992. +           }
  1993. +       }
  1994. +       return timeRemainingWithSampleFormat;
  1995. +   }
  1996. +  
  1997. +   public String CalculateTimeRemainingWithSampleDateFormat(long timeRemaining)
  1998. +   {
  1999. +       long t = timeRemaining / 1000;
  2000. +       int hours = Math.round(((t / 3600) % 24));
  2001. +       int minutes = Math.round((t / 60) % 60);
  2002. +       int seconds = Math.round(t % 60);
  2003. +       return String.format("%sH:%sm:%ss", hours, minutes, seconds);
  2004. +   }
  2005. +  
  2006. +   public String existIp(Player p)
  2007. +   {
  2008. +      
  2009. +       GameClient client = p.getNetConnection();
  2010. +       if ((client.getConnection() != null) && (client.getActiveChar() != null) && client.isAuthed())
  2011. +       {
  2012. +           try
  2013. +           {
  2014. +               return client.getIpAddr();
  2015. +           }
  2016. +           catch (Exception e)
  2017. +           {
  2018. +               e.printStackTrace();
  2019. +           }
  2020. +       }
  2021. +       return null;
  2022. +      
  2023. +   }
  2024. +  
  2025. +   public final void loadVotes()
  2026. +   {
  2027. +       _foundVoters = individualVoteDB.getInstance().getVotesDB();
  2028. +   }
  2029. +  
  2030. +   protected void loadGlobalVotes()
  2031. +   {
  2032. +       _globalVotes = globalVoteDB.getInstance().getGlobalVotes();
  2033. +   }
  2034. +  
  2035. +   public void saveVotes()
  2036. +   {
  2037. +       individualVoteDB.getInstance().SaveVotes(_foundVoters);
  2038. +   }
  2039. +  
  2040. +   protected void AutoGlobalVoteReward()
  2041. +   {
  2042. +       HashSet<String> ipList = new HashSet<>();
  2043. +      
  2044. +       for (voteSite vs : voteSite.values())
  2045. +       {
  2046. +          
  2047. +           new Thread(() ->
  2048. +           {
  2049. +               checkNewUpdate(vs.ordinal());
  2050. +               if (_globalVotes[vs.ordinal()].getCurrentVotes() >= (_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)))
  2051. +               {
  2052. +                   _globalVotes[vs.ordinal()].setVotesLastReward(_globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD));
  2053. +                   for (Player player : GameObjectsStorage.getAllPlayersForIterate())
  2054. +                   {
  2055. +                       String ip = existIp(player);
  2056. +                       if (ip == null)
  2057. +                       {
  2058. +                           continue;
  2059. +                       }
  2060. +                       if (ipList.contains(ip))
  2061. +                       {
  2062. +                           continue;
  2063. +                       }
  2064. +                       for (Reward reward : VoteSiteXml.getInstance().getRewards(11))
  2065. +                       {
  2066. +                           player.getInventory().addItem(reward.getItemId(), reward.getItemCount(),"VoteSystem");
  2067. +                           player.sendPacket(new SystemMessage2(SystemMsg.YOU_HAVE_EARNED_S2_S1S).addItemName(reward.getItemId()).addInteger(reward.getItemCount()));
  2068. +                       }
  2069. +                       ipList.add(ip);
  2070. +                       player.sendItemList(true);;
  2071. +                   }
  2072. +                   Announcements.getInstance().announceToAll(VoteUtil.Sites[vs.ordinal()] + ": All players has been rewarded, please check your inventory", ChatType.CRITICAL_ANNOUNCE);
  2073. +               }
  2074. +               else
  2075. +               {
  2076. +                   String encourage = "";
  2077. +                   int nextReward = _globalVotes[vs.ordinal()].getVotesLastReward() + (vs.ordinal() == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
  2078. +                   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());
  2079. +                   Announcements.getInstance().announceToAll(encourage, ChatType.CRITICAL_ANNOUNCE);
  2080. +               }
  2081. +           }).start();
  2082. +          
  2083. +       }
  2084. +   }
  2085. +  
  2086. +   protected void AutoSaveGlobalVotes()
  2087. +   {
  2088. +       globalVoteDB.getInstance().saveGlobalVotes(_globalVotes);
  2089. +   }
  2090. +  
  2091. +   protected synchronized void AutoUpdateIndividualVotes()
  2092. +   {
  2093. +       AutoCleanInnecesaryIndividualVotes();
  2094. +       individualVoteDB.getInstance().SaveVotes(_foundVoters);
  2095. +   }
  2096. +  
  2097. +   protected synchronized void AutoCleanInnecesaryIndividualVotes()
  2098. +   {
  2099. +       HashSet<individualVote> removeVotes = new HashSet<>();
  2100. +       for (Map.Entry<String, individualVote[]> ivs : _foundVoters.entrySet())
  2101. +       {
  2102. +           for (individualVote individualvote : ivs.getValue())
  2103. +           {
  2104. +               if (individualvote == null)
  2105. +               {
  2106. +                   continue;
  2107. +               }
  2108. +               if (getTimeRemaining(individualvote) < 0)
  2109. +               {
  2110. +                   removeVotes.add(individualvote);
  2111. +                   if (_foundVoters.containsKey(individualvote.getVoterIp()))
  2112. +                   {
  2113. +                       if (_foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] != null)
  2114. +                       {
  2115. +                           _foundVoters.get(individualvote.getVoterIp())[individualvote.getVoteSite()] = null;
  2116. +                       }
  2117. +                   }
  2118. +               }
  2119. +           }
  2120. +       }
  2121. +       individualVoteDB.getInstance().DeleteVotes(removeVotes);
  2122. +   }
  2123. +  
  2124. +   public void checkAllResponseGlobalVotes()
  2125. +   {
  2126. +       for (voteSite vs : voteSite.values())
  2127. +       {
  2128. +           new Thread(() ->
  2129. +           {
  2130. +               checkNewUpdate(vs.ordinal());
  2131. +           });
  2132. +       }
  2133. +   }
  2134. +  
  2135. +   public void checkNewUpdate(int ordinalSite)
  2136. +   {
  2137. +       int globalVotesResponse = getGlobalVotesResponse(ordinalSite);
  2138. +       if (globalVotesResponse == -1)
  2139. +       {
  2140. +           return;
  2141. +       }
  2142. +       _globalVotes[ordinalSite].setCurrentVotes(globalVotesResponse);
  2143. +       int last = globalVotesResponse - (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD);
  2144. +       if (last < 0)
  2145. +       {
  2146. +           _globalVotes[ordinalSite].setVotesLastReward(0);
  2147. +           return;
  2148. +       }
  2149. +       if ((_globalVotes[ordinalSite].getVotesLastReward() + (ordinalSite == voteSite.L2SERVERS.ordinal() ? 25 * Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD : Config.GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD)) < globalVotesResponse)
  2150. +       {
  2151. +           _globalVotes[ordinalSite].setVotesLastReward(globalVotesResponse);
  2152. +           return;
  2153. +       }
  2154. +   }
  2155. +  
  2156. +   public void Shutdown()
  2157. +   {
  2158. +       AutoSaveGlobalVotes();
  2159. +       AutoCleanInnecesaryIndividualVotes();
  2160. +       AutoUpdateIndividualVotes();
  2161. +   }
  2162. +  
  2163. +   protected class AutoGlobalVoteRewardTask implements Runnable
  2164. +   {
  2165. +      
  2166. +       @Override
  2167. +       public void run()
  2168. +       {
  2169. +           AutoGlobalVoteReward();
  2170. +          
  2171. +       }
  2172. +      
  2173. +   }
  2174. +  
  2175. +   protected class AutoSaveGlobalVotesTask implements Runnable
  2176. +   {
  2177. +      
  2178. +       @Override
  2179. +       public void run()
  2180. +       {
  2181. +           AutoSaveGlobalVotes();
  2182. +          
  2183. +       }
  2184. +      
  2185. +   }
  2186. +  
  2187. +   protected class AutoUpdateIndividualVotesTask implements Runnable
  2188. +   {
  2189. +      
  2190. +       @Override
  2191. +       public void run()
  2192. +       {
  2193. +           AutoUpdateIndividualVotes();
  2194. +          
  2195. +       }
  2196. +      
  2197. +   }
  2198. +  
  2199. +   public static voteManager getInatance()
  2200. +   {
  2201. +       return SingleHolder.INSTANCE;
  2202. +   }
  2203. +  
  2204. +   private static class SingleHolder
  2205. +   {
  2206. +       protected static final voteManager INSTANCE = new voteManager();
  2207. +   }
  2208. +}
  2209.  
  2210. Index: java/l2f/gameserver/votesystem/Model/VoteSite.java
  2211. ===================================================================
  2212. --- java/l2f/gameserver/votesystem/Model/VoteSite.java  (nonexistent)
  2213. +++ java/l2f/gameserver/votesystem/Model/VoteSite.java  (working copy)
  2214. @@ -0,0 +1,53 @@
  2215. +package l2f.gameserver.votesystem.Model;
  2216. +
  2217. +import java.util.ArrayList;
  2218. +import java.util.List;
  2219. +
  2220. +/**
  2221. + * @author l2.topgameserver.net
  2222. + */
  2223. +public class VoteSite
  2224. +{
  2225. +   private int _siteOrdinal;
  2226. +   private String _siteName;
  2227. +   private final List<Reward> _rewards = new ArrayList<>();
  2228. +  
  2229. +   public VoteSite()
  2230. +   {
  2231. +      
  2232. +   }
  2233. +  
  2234. +   public void setSiteOrdinal(int siteOrdinal)
  2235. +   {
  2236. +       _siteOrdinal = siteOrdinal;
  2237. +   }
  2238. +  
  2239. +   public void setSiteName(String siteName)
  2240. +   {
  2241. +       _siteName = siteName;
  2242. +   }
  2243. +  
  2244. +   public void setRewardList(List<Reward> rewards)
  2245. +   {
  2246. +       for (Reward r : rewards)
  2247. +       {
  2248. +           _rewards.add(r);
  2249. +       }
  2250. +   }
  2251. +  
  2252. +   public int getSiteOrdinal()
  2253. +   {
  2254. +       return _siteOrdinal;
  2255. +   }
  2256. +  
  2257. +   public String getSiteName()
  2258. +   {
  2259. +       return _siteName;
  2260. +   }
  2261. +  
  2262. +   public List<Reward> getRewardList()
  2263. +   {
  2264. +       return _rewards;
  2265. +   }
  2266. +  
  2267. +}
  2268. \ No newline at end of file
  2269. Index: java/l2f/gameserver/Shutdown.java
  2270. ===================================================================
  2271. --- java/l2f/gameserver/Shutdown.java   (revision 1)
  2272. +++ java/l2f/gameserver/Shutdown.java   (working copy)
  2273. @@ -27,6 +27,7 @@
  2274.  import l2f.gameserver.scripts.Scripts;
  2275.  import l2f.gameserver.utils.Log;
  2276.  import l2f.gameserver.utils.Util;
  2277. +import l2f.gameserver.votesystem.Handler.voteManager;
  2278.  
  2279.  import org.slf4j.Logger;
  2280.  import org.slf4j.LoggerFactory;
  2281.  
  2282.      */
  2283.     public synchronized void cancel()
  2284.     {
  2285. @@ -247,6 +248,12 @@
  2286.  
  2287.     private void saveData()
  2288.     {
  2289. +       // Save individual votes data
  2290. +               if (Config.ENABLE_VOTE_SYSTEM)
  2291. +               {
  2292. +                   voteManager.getInatance().Shutdown();
  2293. +                   _log.info("VoteSystem: Data saved.");
  2294. +               }
  2295.         try
  2296.         {
  2297.             // Seven Signs data is now saved along with Festival data.
  2298. Index: java/l2f/gameserver/Config.java
  2299. ===================================================================
  2300. --- java/l2f/gameserver/Config.java (revision 1)
  2301. +++ java/l2f/gameserver/Config.java (working copy)
  2302.  
  2303. import java.util.Properties;
  2304. +import java.util.concurrent.TimeUnit;
  2305. import java.util.logging.Level;
  2306.  
  2307. @@ -114,6 +114,7 @@
  2308.     public static final String DEFENSE_TOWNS_CONFIG_FILE = "config/events/DefenseTowns.ini";
  2309.     public static final String VIKTORINA_CONFIG_FILE = "config/events/Victorina.ini";
  2310.     public static final String PVP_MOD_CONFIG_FILE = "config/mod/PvPmod.ini";
  2311. +    public static final String VOTE_SYSTEM_FILE = "config/votesystem.ini";
  2312.  
  2313.     public static final String ZONE_DRAGONVALLEY_FILE = "config/zones/DragonValley.ini";
  2314.     public static final String ZONE_LAIROFANTHARAS_FILE = "config/zones/LairOfAntharas.ini";
  2315. @@ -313,7 +314,52 @@
  2316.     public static int SERVICES_EXCHANGE_EQUIP_ITEM_PRICE;
  2317.     public static int SERVICES_EXCHANGE_UPGRADE_EQUIP_ITEM;
  2318.     public static int SERVICES_EXCHANGE_UPGRADE_EQUIP_ITEM_PRICE;
  2319. +  
  2320.  
  2321. +   // ---------------------------------------------------
  2322. +       // VOTE SYSTEM
  2323. +       // ---------------------------------------------------
  2324. +       public static boolean ENABLE_VOTE_SYSTEM;
  2325. +       public static boolean ENABLE_INDIVIDUAL_VOTE;
  2326. +       public static boolean ENABLE_GLOBAL_VOTE;
  2327. +       public static long NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE;
  2328. +       public static long NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES;
  2329. +       public static long NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES;
  2330. +       public static long NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD;
  2331. +       public static long INTERVAL_TO_NEXT_VOTE;
  2332. +       public static int GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD;
  2333. +       public static boolean ENABLE_VOTING_COMMAND;
  2334. +       public static String VOTING_COMMAND;
  2335. +       public static String VOTE_LINK_TGS;
  2336. +       public static String TGS_API_KEY;
  2337. +       public static String VOTE_LINK_TOP_CO;
  2338. +       public static String TOP_CO_SRV_ID;
  2339. +       public static String VOTE_LINK_ITOPZ;
  2340. +       public static String ITOPZ_API_KEY;
  2341. +       public static String ITOPZ_SRV_ID;
  2342. +       public static String VOTE_LINK_VTS;
  2343. +       public static String VTS_API_KEY;
  2344. +       public static String VTS_SID;
  2345. +       public static String VOTE_LINK_HZ;
  2346. +       public static String HZ_API_KEY;
  2347. +       public static String VOTE_NETWORK_LINK;
  2348. +       public static String VOTE_NETWORK_USER_NAME;
  2349. +       public static String VOTE_NETWORK_API_KEY;
  2350. +       public static String VOTE_LINK_TSS;
  2351. +       public static String TSS_API_TOKEN;
  2352. +       public static String TS_SRV_ID;
  2353. +       public static String TS_DOMAIN_NAME;
  2354. +       public static String BRASIL_VOTE_LINK;
  2355. +       public static String BRASIL_USER_NAME;
  2356. +       public static String VOTE_LINK_MMOTOP;
  2357. +       public static String MMOTOP_API_KEY;
  2358. +       public static String VOTE_LINK_TZ;
  2359. +       public static String TZ_API_KEY;
  2360. +       public static String VOTE_LINK_SERVERS;
  2361. +       public static String SERVERS_HASH_CODE;
  2362. +       public static String SERVERS_SRV_ID;
  2363. +       public static String TEST_IP;
  2364. +      
  2365.     // L2Mythras Configs
  2366.     public static int DONATOR_NPC_ITEM;
  2367.     public static String DONATOR_NPC_ITEM_NAME;
  2368.  
  2369. @@ -2643,6 +2689,49 @@
  2370.         SERVICES_EXCHANGE_UPGRADE_EQUIP_ITEM_PRICE = DonationStore.getProperty("ExchangeUpgradeEquipPrice", 50);
  2371.     }
  2372.  
  2373. +   public static void loadVoteSystemConfig() {
  2374. +       ExProperties votesystem = load(VOTE_SYSTEM_FILE);
  2375. +       ENABLE_VOTE_SYSTEM = votesystem.getProperty("EnableVoteSystem", true);
  2376. +       ENABLE_INDIVIDUAL_VOTE = votesystem.getProperty("EnableIndividualVote", true);
  2377. +       ENABLE_GLOBAL_VOTE = votesystem.getProperty("EnableGlobalVote", true);
  2378. +       NEXT_TIME_TO_AUTO_UPDATE_TOTAL_VOTE = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoUpdateTotalVote", 60));// -> minutes
  2379. +       NEXT_TIME_TO_AUTO_UPDATE_INDIVIDUAL_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoUpdateIndividualVotes", 60));// -> minutes
  2380. +       NEXT_TIME_TO_AUTO_CLEAN_INECESARY_VOTES = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToAutoCleanInnecesaryVotes", 30));// -> minutes
  2381. +       NEXT_TIME_TO_CHECK_AUTO_GLOBAL_VOTES_REWARD = TimeUnit.MINUTES.toMillis(votesystem.getProperty("NextTimeToCheckAutoGlobalVotesReward", 5));// -> minutes
  2382. +       INTERVAL_TO_NEXT_VOTE = TimeUnit.HOURS.toMillis(votesystem.getProperty("IntervalTimeToNextVote", 12)); // -> hours
  2383. +       GLOBAL_VOTES_AMOUNT_TO_NEXT_REWARD = votesystem.getProperty("GlobalVotesAmountToNextReward", 50);
  2384. +       ENABLE_VOTING_COMMAND = votesystem.getProperty("EnableVotingCommand", true);
  2385. +       VOTING_COMMAND = votesystem.getProperty("VotingCommand", "rewardme");
  2386. +       VOTE_LINK_TGS = votesystem.getProperty("VoteLinkTgs", "");
  2387. +       TGS_API_KEY = votesystem.getProperty("TgsApiKey", "");
  2388. +       VOTE_LINK_TOP_CO = votesystem.getProperty("VoteLinkTopCo", "");
  2389. +       TOP_CO_SRV_ID = votesystem.getProperty("TopCoSrvId", "");
  2390. +       VOTE_LINK_ITOPZ = votesystem.getProperty("VoteLinkItopz", "");
  2391. +       ITOPZ_API_KEY = votesystem.getProperty("ItopzZpiKey", "");
  2392. +       ITOPZ_SRV_ID = votesystem.getProperty("ItopzSrvId", "");
  2393. +       VOTE_LINK_VTS = votesystem.getProperty("VoteLinkVts", "");
  2394. +       VTS_API_KEY = votesystem.getProperty("VtsApiKey", "");
  2395. +       VTS_SID = votesystem.getProperty("VtsSid", "");
  2396. +       VOTE_LINK_HZ = votesystem.getProperty("VoteLinkHz", "");
  2397. +       HZ_API_KEY = votesystem.getProperty("HzApiKey", "");
  2398. +       VOTE_NETWORK_LINK = votesystem.getProperty("VoteNetworkLink", "");
  2399. +       VOTE_NETWORK_USER_NAME = votesystem.getProperty("VoteNetworkUserName", "");
  2400. +       VOTE_NETWORK_API_KEY = votesystem.getProperty("VoteNetworkApiKey", "");
  2401. +       VOTE_LINK_TSS = votesystem.getProperty("VoteLinkTss", "");
  2402. +       TSS_API_TOKEN = votesystem.getProperty("TssApiToken", "");
  2403. +       TS_SRV_ID = votesystem.getProperty("TsSrvId", "");
  2404. +       TS_DOMAIN_NAME = votesystem.getProperty("TsDomainName", "");
  2405. +       BRASIL_VOTE_LINK = votesystem.getProperty("BrasilVoteLink", "");
  2406. +       BRASIL_USER_NAME = votesystem.getProperty("BrasilUserName", "");
  2407. +       VOTE_LINK_MMOTOP = votesystem.getProperty("VoteLinkMmotop", "");
  2408. +       MMOTOP_API_KEY = votesystem.getProperty("MmotopApiKey", "");
  2409. +       VOTE_LINK_TZ = votesystem.getProperty("VoteLinkTz", "");
  2410. +       TZ_API_KEY = votesystem.getProperty("TzApiKey", "");
  2411. +       VOTE_LINK_SERVERS = votesystem.getProperty("VoteLinkServers", "");
  2412. +       SERVERS_HASH_CODE = votesystem.getProperty("ServersHashCode", "");
  2413. +       SERVERS_SRV_ID = votesystem.getProperty("ServersSrvId", "");
  2414. +       TEST_IP = votesystem.getProperty("TestIp", "");
  2415. +   }
  2416.     public static void loadNpcConfig()
  2417.     {
  2418.         ExProperties npcSettings = load(NPC_FILE);
  2419. @@ -4423,6 +4512,7 @@
  2420.         loadItemsUseConfig();
  2421.         loadSchemeBuffer();
  2422.         loadChatConfig();
  2423. +       loadVoteSystemConfig();
  2424.         loadDonationStore();
  2425.         loadNpcConfig();
  2426.         loadBossConfig();
  2427.  
  2428. Index: dist/gameserver/data/html-en/custom/votesystem/53008.html
  2429. ===================================================================
  2430. --- dist/gameserver/data/html-en/custom/votesystem/53008.html   (nonexistent)
  2431. +++ dist/gameserver/data/html-en/custom/votesystem/53008.html   (working copy)
  2432. @@ -0,0 +1,19 @@
  2433. +<html>
  2434. +<title>Voting panel</title>
  2435. +<body><center>
  2436. +   <br><img src="L2UI_CH3.herotower_deco" width=256 height=32><br>
  2437. +   <table cellpadding=2 width=280>
  2438. +       <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>
  2439. +   </table>
  2440. +   <table width="290"><tr><td width="290" align="center">You can vote: </td></tr></table>
  2441. +   <br><img src="l2ui.SquareWhite" width=290 height=1><br>
  2442. +
  2443. +   %enablevote%
  2444. +
  2445. +   <br>
  2446. +   <img src="l2ui.SquareWhite" width=290 height=1><br>
  2447. +
  2448. +
  2449. +
  2450. +</center></body>
  2451. +</html>
  2452. \ No newline at end of file
  2453.  
  2454. Index: dist/gameserver/data/npc/53000-53099.xml
  2455. ===================================================================
  2456. --- dist/gameserver/data/npc/53000-53099.xml    (revision 1)
  2457. +++ dist/gameserver/data/npc/53000-53099.xml    (working copy)
  2458. @@ -621,4 +621,51 @@
  2459.             <defence attribute="unholy" value="200" />
  2460.         </attributes>
  2461.     </npc>
  2462. +   <npc id="53008" name="Kaaya" title="Vote Reward System">
  2463. +       <set name="aggroRange" value="0" />
  2464. +       <set name="ai_type" value="CharacterAI" />
  2465. +       <set name="baseAtkRange" value="40" />
  2466. +       <set name="baseCON" value="43" />
  2467. +       <set name="baseCritRate" value="40" />
  2468. +       <set name="baseDEX" value="30" />
  2469. +       <set name="baseHpMax" value="2444.468" />
  2470. +       <set name="baseHpRate" value="1" />
  2471. +       <set name="baseHpReg" value="7.5" />
  2472. +       <set name="baseINT" value="21" />
  2473. +       <set name="baseMAtk" value="780" />
  2474. +       <set name="baseMAtkSpd" value="500" />
  2475. +       <set name="baseMDef" value="382" />
  2476. +       <set name="baseMEN" value="20" />
  2477. +       <set name="baseMpMax" value="1345.8" />
  2478. +       <set name="baseMpReg" value="2.7" />
  2479. +       <set name="basePAtk" value="1303" />
  2480. +       <set name="basePAtkSpd" value="253" />
  2481. +       <set name="basePDef" value="471" />
  2482. +       <set name="baseRunSpd" value="120" />
  2483. +       <set name="baseSTR" value="40" />
  2484. +       <set name="baseShldDef" value="0" />
  2485. +       <set name="baseShldRate" value="0" />
  2486. +       <set name="baseWIT" value="20" />
  2487. +       <set name="baseWalkSpd" value="26" />
  2488. +       <set name="collision_height" value="15.0" />
  2489. +       <set name="collision_radius" value="8.0" />
  2490. +       <set name="level" value="70" />
  2491. +       <set name="rewardExp" value="0" />
  2492. +       <set name="rewardRp" value="0" />
  2493. +       <set name="rewardSp" value="0" />
  2494. +       <set name="shots" value="NONE" />
  2495. +       <set name="texture" value="" />
  2496. +       <set name="type" value="VoteReward" />
  2497. +       <skills>
  2498. +           <skill id="4416" level="7" />   <!--Spirits-->
  2499. +       </skills>
  2500. +       <attributes>
  2501. +           <defence attribute="fire" value="150" />
  2502. +           <defence attribute="water" value="150" />
  2503. +           <defence attribute="wind" value="150" />
  2504. +           <defence attribute="earth" value="150" />
  2505. +           <defence attribute="holy" value="150" />
  2506. +           <defence attribute="unholy" value="150" />
  2507. +       </attributes>
  2508. +   </npc>
  2509.  </list>
  2510.  
  2511.  
  2512. ==========================================SQL================================
  2513. -- ----------------------------
  2514. -- Table structure for globalvotes
  2515. -- ----------------------------
  2516. DROP TABLE IF EXISTS `globalvotes`;
  2517. CREATE TABLE `globalvotes`  (
  2518.   `voteSite` tinyint(2) NOT NULL,
  2519.   `lastRewardVotes` int(11) NULL DEFAULT NULL,
  2520.   PRIMARY KEY (`voteSite`) USING BTREE
  2521. ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
  2522.  
  2523. -- ----------------------------
  2524. -- Records of globalvotes
  2525. -- ----------------------------
  2526. INSERT INTO `globalvotes` VALUES (0, 13);
  2527. INSERT INTO `globalvotes` VALUES (1, 68);
  2528. INSERT INTO `globalvotes` VALUES (2, 0);
  2529. INSERT INTO `globalvotes` VALUES (3, 3);
  2530. INSERT INTO `globalvotes` VALUES (4, 2);
  2531. INSERT INTO `globalvotes` VALUES (5, 0);
  2532. INSERT INTO `globalvotes` VALUES (6, 0);
  2533. INSERT INTO `globalvotes` VALUES (7, 2);
  2534. INSERT INTO `globalvotes` VALUES (8, 3);
  2535. INSERT INTO `globalvotes` VALUES (9, 0);
  2536. INSERT INTO `globalvotes` VALUES (10, 75);
  2537.  
  2538. -- ----------------------------
  2539. -- Table structure for individualvotes
  2540. -- ----------------------------
  2541. DROP TABLE IF EXISTS `individualvotes`;
  2542. CREATE TABLE `individualvotes`  (
  2543.   `voterIp` varchar(40) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  2544.   `voteSite` tinyint(3) NOT NULL,
  2545.   `diffTime` bigint(20) NULL DEFAULT NULL,
  2546.   `votingTimeSite` bigint(20) NULL DEFAULT NULL,
  2547.   `alreadyRewarded` tinyint(3) NULL DEFAULT NULL,
  2548.   PRIMARY KEY (`voterIp`, `voteSite`) USING BTREE
  2549. ) ENGINE = InnoDB CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;
Advertisement
RAW Paste Data Copied
Advertisement