Elfocrash

Individual vote reward 2016 by Elfocrash

Jul 15th, 2016
2,264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 31.29 KB | None | 0 0
  1. diff --git config/server.properties config/server.properties
  2. index 8cb45ab..784144c 100644
  3. --- config/server.properties
  4. +++ config/server.properties
  5. @@ -25,6 +25,15 @@
  6.  AcceptAlternateID = True
  7.  
  8.  # ================================================================
  9. +#                        Vote reward system
  10. +# ================================================================
  11. +
  12. +VoteNetworkName = adler1313
  13. +VoteTopzoneApiKey = 2e83b3bf89f0d34f9eb0b7151608349d
  14. +VoteTopzoneServerId = 10994
  15. +VoteHopzoneApiKey = LHu2UpXFNYWXYklS
  16. +
  17. +# ================================================================
  18.  #                        Database informations
  19.  # ================================================================
  20.  
  21. diff --git java/net/sf/l2j/Config.java java/net/sf/l2j/Config.java
  22. index 23216b2..56e2266 100644
  23. --- java/net/sf/l2j/Config.java
  24. +++ java/net/sf/l2j/Config.java
  25. @@ -52,6 +52,13 @@
  26.     public static final String SERVER_FILE = "./config/server.properties";
  27.     public static final String SIEGE_FILE = "./config/siege.properties";
  28.    
  29. +   /** Vote configs */
  30. +  
  31. +   public static String VOTE_NETWORK_NAME;
  32. +   public static String VOTE_TOPZONE_APIKEY;
  33. +   public static int VOTE_TOPZONE_SERVERID;
  34. +   public static String VOTE_HOPZONE_APIKEY;
  35. +  
  36.     // --------------------------------------------------
  37.     // Clans settings
  38.     // --------------------------------------------------
  39. @@ -1261,6 +1268,11 @@
  40.         PLAYER_DROPPED_ITEM_MULTIPLIER = server.getProperty("PlayerDroppedItemMultiplier", 1);
  41.         SAVE_DROPPED_ITEM = server.getProperty("SaveDroppedItem", false);
  42.        
  43. +       VOTE_NETWORK_NAME = server.getProperty("VoteNetworkName", "");
  44. +       VOTE_TOPZONE_APIKEY = server.getProperty("VoteTopzoneApiKey", "");
  45. +       VOTE_TOPZONE_SERVERID = server.getProperty("VoteTopzoneServerId", 0);
  46. +       VOTE_HOPZONE_APIKEY = server.getProperty("VoteHopzoneApiKey", "");
  47. +      
  48.         RATE_XP = server.getProperty("RateXp", 1.);
  49.         RATE_SP = server.getProperty("RateSp", 1.);
  50.         RATE_PARTY_XP = server.getProperty("RatePartyXp", 1.);
  51. diff --git java/net/sf/l2j/commons/lang/StringUtil.java java/net/sf/l2j/commons/lang/StringUtil.java
  52. index 61c9f76..b61d8b5 100644
  53. --- java/net/sf/l2j/commons/lang/StringUtil.java
  54. +++ java/net/sf/l2j/commons/lang/StringUtil.java
  55. @@ -163,6 +163,22 @@
  56.         LOG.info(sb.toString());
  57.     }
  58.    
  59. +   public static String substringBetween(String str, String open, String close) {
  60. +       final int INDEX_NOT_FOUND = -1;
  61. +        if (str == null || open == null || close == null) {
  62. +            return null;
  63. +        }
  64. +        int start = str.indexOf(open);
  65. +        if (start != INDEX_NOT_FOUND) {
  66. +            int end = str.indexOf(close, start + open.length());
  67. +            if (end != INDEX_NOT_FOUND) {
  68. +                return str.substring(start + open.length(), end);
  69. +            }
  70. +        }
  71. +        return null;
  72. +    }
  73. +          
  74. +  
  75.     /**
  76.      * Format a time given in seconds into "h m s" String format.
  77.      * @param time : a time given in seconds.
  78. diff --git java/net/sf/l2j/gameserver/GameServer.java java/net/sf/l2j/gameserver/GameServer.java
  79. index c9f02ea..0b9715f 100644
  80. --- java/net/sf/l2j/gameserver/GameServer.java
  81. +++ java/net/sf/l2j/gameserver/GameServer.java
  82. @@ -72,6 +72,7 @@
  83.  import net.sf.l2j.gameserver.handler.ItemHandler;
  84.  import net.sf.l2j.gameserver.handler.SkillHandler;
  85.  import net.sf.l2j.gameserver.handler.UserCommandHandler;
  86. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  87.  import net.sf.l2j.gameserver.idfactory.IdFactory;
  88.  import net.sf.l2j.gameserver.instancemanager.AuctionManager;
  89.  import net.sf.l2j.gameserver.instancemanager.AutoSpawnManager;
  90. @@ -292,6 +293,7 @@
  91.         _log.config("ItemHandler: Loaded " + ItemHandler.getInstance().size() + " handlers.");
  92.         _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
  93.         _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
  94. +       _log.config("VoicedCommandHandler: Loaded " + VoicedCommandHandler.getInstance().size() + " handlers.");
  95.        
  96.         StringUtil.printSection("System");
  97.         Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
  98. diff --git java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java
  99. new file mode 100644
  100. index 0000000..c1f737d
  101. --- /dev/null
  102. +++ java/net/sf/l2j/gameserver/handler/IVoicedCommandHandler.java
  103. @@ -0,0 +1,27 @@
  104. +/*
  105. + * This program is free software: you can redistribute it and/or modify it under
  106. + * the terms of the GNU General Public License as published by the Free Software
  107. + * Foundation, either version 3 of the License, or (at your option) any later
  108. + * version.
  109. + *
  110. + * This program is distributed in the hope that it will be useful, but WITHOUT
  111. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  112. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  113. + * details.
  114. + *
  115. + * You should have received a copy of the GNU General Public License along with
  116. + * this program. If not, see <http://www.gnu.org/licenses/>.
  117. + */
  118. +package net.sf.l2j.gameserver.handler;
  119. +
  120. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  121. +
  122. +/**
  123. + * @author Elfocrash
  124. + *
  125. + */
  126. +public interface IVoicedCommandHandler
  127. +{
  128. +    public void useVoicedCommand(L2PcInstance activeChar);
  129. +    public String[] getVoicedCommands();
  130. +}
  131. \ No newline at end of file
  132. diff --git java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
  133. new file mode 100644
  134. index 0000000..a14e449
  135. --- /dev/null
  136. +++ java/net/sf/l2j/gameserver/handler/VoicedCommandHandler.java
  137. @@ -0,0 +1,60 @@
  138. +/*
  139. + * This program is free software: you can redistribute it and/or modify it under
  140. + * the terms of the GNU General Public License as published by the Free Software
  141. + * Foundation, either version 3 of the License, or (at your option) any later
  142. + * version.
  143. + *
  144. + * This program is distributed in the hope that it will be useful, but WITHOUT
  145. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  146. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  147. + * details.
  148. + *
  149. + * You should have received a copy of the GNU General Public License along with
  150. + * this program. If not, see <http://www.gnu.org/licenses/>.
  151. + */
  152. +package net.sf.l2j.gameserver.handler;
  153. +
  154. +import java.util.Arrays;
  155. +import java.util.HashMap;
  156. +import java.util.Map;
  157. +
  158. +import net.sf.l2j.gameserver.handler.voicedcommandhandlers.VoteCommand;
  159. +
  160. +/**
  161. + * @author Elfocrash
  162. + *
  163. + */
  164. +public class VoicedCommandHandler
  165. +{
  166. +   private static final Map<Integer, IVoicedCommandHandler> VOICED_COMMANDS = new HashMap<>();
  167. +  
  168. +   VoicedCommandHandler()
  169. +   {
  170. +       registerVoicedCommand(new VoteCommand());
  171. +   }
  172. +  
  173. +   private static void registerVoicedCommand(IVoicedCommandHandler voicedCommand)
  174. +   {
  175. +       Arrays.stream(voicedCommand.getVoicedCommands()).forEach(v -> VOICED_COMMANDS.put(v.intern().hashCode(), voicedCommand));
  176. +   }
  177. +  
  178. +   public IVoicedCommandHandler getVoicedCommand(String voicedCommand)
  179. +   {
  180. +       return VOICED_COMMANDS.get(voicedCommand.hashCode());
  181. +   }
  182. +  
  183. +   public int size()
  184. +   {
  185. +       return VOICED_COMMANDS.size();
  186. +   }
  187. +  
  188. +   public static final VoicedCommandHandler getInstance()
  189. +   {
  190. +       return SingletonHolder.INSTANCE;
  191. +   }
  192. +  
  193. +   private static final class SingletonHolder
  194. +   {
  195. +        static final VoicedCommandHandler INSTANCE = new VoicedCommandHandler();
  196. +   }
  197. +}
  198. diff --git java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
  199. index 4c1c9e6..679a471 100644
  200. --- java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
  201. +++ java/net/sf/l2j/gameserver/handler/chathandlers/ChatAll.java
  202. @@ -15,6 +15,8 @@
  203.  package net.sf.l2j.gameserver.handler.chathandlers;
  204.  
  205.  import net.sf.l2j.gameserver.handler.IChatHandler;
  206. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  207. +import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
  208.  import net.sf.l2j.gameserver.model.BlockList;
  209.  import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  210.  import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  211. @@ -34,12 +36,17 @@
  212.         if (!FloodProtectors.performAction(activeChar.getClient(), Action.GLOBAL_CHAT))
  213.             return;
  214.        
  215. +       if (text.startsWith("."))
  216. +       {
  217. +           final IVoicedCommandHandler voicedCommand = VoicedCommandHandler.getInstance().getVoicedCommand(text.substring(1).toLowerCase());
  218. +           if (voicedCommand != null)
  219. +           {
  220. +               voicedCommand.useVoicedCommand(activeChar);
  221. +               return;
  222. +           }
  223. +       }
  224.         final CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
  225. -       for (L2PcInstance player : activeChar.getKnownTypeInRadius(L2PcInstance.class, 1250))
  226. -       {
  227. -           if (!BlockList.isBlocked(player, activeChar))
  228. -               player.sendPacket(cs);
  229. -       }
  230. +       activeChar.getKnownTypeInRadius(L2PcInstance.class, 1250).stream().filter(p -> !BlockList.isBlocked(p, activeChar)).forEach(p -> p.sendPacket(cs));
  231.         activeChar.sendPacket(cs);
  232.     }
  233.    
  234. diff --git java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteCommand.java java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteCommand.java
  235. new file mode 100644
  236. index 0000000..a8042bc
  237. --- /dev/null
  238. +++ java/net/sf/l2j/gameserver/handler/voicedcommandhandlers/VoteCommand.java
  239. @@ -0,0 +1,68 @@
  240. +/*
  241. + * This program is free software: you can redistribute it and/or modify it under
  242. + * the terms of the GNU General Public License as published by the Free Software
  243. + * Foundation, either version 3 of the License, or (at your option) any later
  244. + * version.
  245. + *
  246. + * This program is distributed in the hope that it will be useful, but WITHOUT
  247. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  248. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  249. + * details.
  250. + *
  251. + * You should have received a copy of the GNU General Public License along with
  252. + * this program. If not, see <http://www.gnu.org/licenses/>.
  253. + */
  254. +package net.sf.l2j.gameserver.handler.voicedcommandhandlers;
  255. +
  256. +import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
  257. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  258. +import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
  259. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  260. +
  261. +/**
  262. + * @author Elfocrash
  263. + *
  264. + */
  265. +public class VoteCommand implements IVoicedCommandHandler
  266. +{
  267. +   private static final String[] VOICED_COMMANDS = {"vote"};
  268. +  
  269. +   @Override
  270. +   public void useVoicedCommand(L2PcInstance player)
  271. +   {
  272. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  273. +       html.setHtml(getVoteHtml(player));
  274. +       player.sendPacket(html);
  275. +      
  276. +       player.sendPacket(ActionFailed.STATIC_PACKET);
  277. +   }
  278. +  
  279. +   private static String getVoteHtml(L2PcInstance player)
  280. +   {
  281. +       StringBuilder sb = new StringBuilder();
  282. +       sb.append("<html><body><center><br>");
  283. +       if(player.eligibleToVoteHop())
  284. +           sb.append("<a action=\"bypass -h vote hopzone\">I have voted on hopzone</a><br1>");
  285. +       else
  286. +           sb.append(String.format("You can vote again in: %s <br1>",player.getVoteCountdownHop()));
  287. +      
  288. +       if(player.eligibleToVoteTop())
  289. +           sb.append("<a action=\"bypass -h vote topzone\">I have voted on topzone</a><br1>");
  290. +       else
  291. +           sb.append(String.format("You can vote again in: %s <br1>",player.getVoteCountdownTop()));
  292. +      
  293. +       if(player.eligibleToVoteNet())
  294. +           sb.append("<a action=\"bypass -h vote network\">I have voted on network</a><br1>");
  295. +       else
  296. +           sb.append(String.format("You can vote again in: %s <br1>",player.getVoteCountdownNet()));
  297. +      
  298. +       sb.append("</body></html>");
  299. +       return sb.toString();
  300. +   }
  301. +
  302. +   @Override
  303. +   public String[] getVoicedCommands()
  304. +   {
  305. +       return VOICED_COMMANDS;
  306. +   }
  307. +}
  308. diff --git java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  309. index de6d35e..d1adf59 100644
  310. --- java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  311. +++ java/net/sf/l2j/gameserver/model/actor/instance/L2PcInstance.java
  312. @@ -315,9 +315,9 @@
  313.     private static final String RESTORE_SKILL_SAVE = "SELECT skill_id,skill_level,effect_count,effect_cur_time, reuse_delay, systime, restore_type FROM character_skills_save WHERE char_obj_id=? AND class_index=? ORDER BY buff_index ASC";
  314.     private static final String DELETE_SKILL_SAVE = "DELETE FROM character_skills_save WHERE char_obj_id=? AND class_index=?";
  315.    
  316. -   private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  317. +   private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date,last_hop_vote,last_top_vote,last_net_vote) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  318.     private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=? WHERE obj_id=?";
  319. -   private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level FROM characters WHERE obj_id=?";
  320. +   private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,last_hop_vote,last_top_vote,last_net_vote FROM characters WHERE obj_id=?";
  321.    
  322.     private static final String RESTORE_CHAR_SUBCLASSES = "SELECT class_id,exp,sp,level,class_index FROM character_subclasses WHERE char_obj_id=? ORDER BY class_index ASC";
  323.     private static final String ADD_CHAR_SUBCLASS = "INSERT INTO character_subclasses (char_obj_id,class_id,exp,sp,level,class_index) VALUES (?,?,?,?,?,?)";
  324. @@ -371,6 +371,9 @@
  325.     private long _onlineBeginTime;
  326.     private long _lastAccess;
  327.     private long _uptime;
  328. +   private long _lastHopVote;
  329. +   private long _lastTopVote;
  330. +   private long _lastNetVote;
  331.    
  332.     protected int _baseClass;
  333.     protected int _activeClass;
  334. @@ -723,6 +726,9 @@
  335.             statement.setInt(32, player.isNoble() ? 1 : 0);
  336.             statement.setLong(33, 0);
  337.             statement.setLong(34, System.currentTimeMillis());
  338. +           statement.setLong(35, System.currentTimeMillis()-43200000);
  339. +           statement.setLong(36, System.currentTimeMillis()-43200000);
  340. +           statement.setLong(37, System.currentTimeMillis()-43200000);
  341.             statement.executeUpdate();
  342.             statement.close();
  343.         }
  344. @@ -5384,6 +5390,9 @@
  345.                 player.setAllianceWithVarkaKetra(rset.getInt("varka_ketra_ally"));
  346.                
  347.                 player.setDeathPenaltyBuffLevel(rset.getInt("death_penalty_level"));
  348. +               player.setLastHopVote(rset.getLong("last_hop_vote"));
  349. +               player.setLastTopVote(rset.getLong("last_top_vote"));
  350. +               player.setLastNetVote(rset.getLong("last_net_vote"));
  351.                
  352.                 // Set the x,y,z position of the L2PcInstance and make it invisible
  353.                 player.getPosition().set(rset.getInt("x"), rset.getInt("y"), rset.getInt("z"));
  354. @@ -8425,6 +8434,36 @@
  355.         return _lastAccess;
  356.     }
  357.    
  358. +   public long getLastHopVote()
  359. +   {
  360. +       return _lastHopVote;
  361. +   }
  362. +  
  363. +   public long getLastTopVote()
  364. +   {
  365. +       return _lastTopVote;
  366. +   }
  367. +  
  368. +   public long getLastNetVote()
  369. +   {
  370. +       return _lastNetVote;
  371. +   }
  372. +  
  373. +   public void setLastHopVote(long val)
  374. +   {
  375. +       _lastHopVote = val;
  376. +   }
  377. +  
  378. +   public void setLastTopVote(long val)
  379. +   {
  380. +       _lastTopVote = val;
  381. +   }
  382. +  
  383. +   public void setLastNetVote(long val)
  384. +   {
  385. +       _lastNetVote = val;
  386. +   }
  387. +  
  388.     private void checkRecom(int recsHave, int recsLeft)
  389.     {
  390.         Calendar check = Calendar.getInstance();
  391. @@ -8621,6 +8660,51 @@
  392.         }
  393.     }
  394.    
  395. +   public boolean eligibleToVoteHop()
  396. +   {
  397. +       return (getLastHopVote() + 43200000) < System.currentTimeMillis();
  398. +   }
  399. +  
  400. +   public boolean eligibleToVoteTop()
  401. +   {
  402. +       return (getLastTopVote() + 43200000) < System.currentTimeMillis();
  403. +   }
  404. +  
  405. +   public boolean eligibleToVoteNet()
  406. +   {
  407. +       return (getLastNetVote() + 43200000) < System.currentTimeMillis();
  408. +   }
  409. +  
  410. +   public String getVoteCountdownHop()
  411. +   {
  412. +       long youCanVote = getLastHopVote() - (System.currentTimeMillis() - 43200000);
  413. +       return convertLongToCountdown(youCanVote);
  414. +   }
  415. +  
  416. +   public String getVoteCountdownTop()
  417. +   {
  418. +       long youCanVote = getLastTopVote() - (System.currentTimeMillis() - 43200000);
  419. +       return convertLongToCountdown(youCanVote);
  420. +   }
  421. +  
  422. +   public String getVoteCountdownNet()
  423. +   {
  424. +       long youCanVote = getLastNetVote() - (System.currentTimeMillis() - 43200000);
  425. +       return convertLongToCountdown(youCanVote);
  426. +   }
  427. +
  428. +   public static String convertLongToCountdown(long youCanVote)
  429. +   {
  430. +       String formattedCountdown = String.format("%d hours, %d mins, %d secs",
  431. +            TimeUnit.MILLISECONDS.toHours(youCanVote),
  432. +               TimeUnit.MILLISECONDS.toMinutes(youCanVote) -
  433. +               TimeUnit.HOURS.toMinutes(TimeUnit.MILLISECONDS.toHours(youCanVote)),
  434. +               TimeUnit.MILLISECONDS.toSeconds(youCanVote) -
  435. +               TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(youCanVote))
  436. +       );
  437. +       return formattedCountdown;
  438. +   }
  439. +  
  440.     /**
  441.      * @param expertiseIndex The expertiseIndex to set.
  442.      */
  443. diff --git java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  444. index 113a32c..cb71311 100644
  445. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  446. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  447. @@ -35,6 +35,9 @@
  448.  import net.sf.l2j.gameserver.util.FloodProtectors;
  449.  import net.sf.l2j.gameserver.util.FloodProtectors.Action;
  450.  import net.sf.l2j.gameserver.util.GMAudit;
  451. +import net.sf.l2j.gameserver.voteengine.VoteHopzone;
  452. +import net.sf.l2j.gameserver.voteengine.VoteNetwork;
  453. +import net.sf.l2j.gameserver.voteengine.VoteTopzone;
  454.  
  455.  public final class RequestBypassToServer extends L2GameClientPacket
  456.  {
  457. @@ -95,6 +98,67 @@
  458.             {
  459.                 playerHelp(activeChar, _command.substring(12));
  460.             }
  461. +           else if (_command.startsWith("vote "))
  462. +           {
  463. +               String voteSiteName = _command.substring(5);
  464. +               switch(voteSiteName)
  465. +               {
  466. +                   case "hopzone":
  467. +                       new Thread(() -> {
  468. +                           if(activeChar.eligibleToVoteHop())
  469. +                           {
  470. +                               VoteHopzone voteHop = new VoteHopzone();
  471. +                               if(voteHop.hasVoted(activeChar))
  472. +                               {
  473. +                                   voteHop.updateDB(activeChar, "last_hop_vote");
  474. +                                   voteHop.setVoted(activeChar);
  475. +                                   voteHop.reward(activeChar);
  476. +                               }
  477. +                               else
  478. +                                   activeChar.sendMessage("You haven't voted yet.");
  479. +                           }
  480. +                           else
  481. +                               _log.warning(activeChar.getName() + " tried to send a bypass with adrenalin/phx");
  482. +                       }).start();
  483. +                       break;
  484. +                   case "topzone":
  485. +                       new Thread(() -> {
  486. +                           if(activeChar.eligibleToVoteTop())
  487. +                           {
  488. +                               VoteTopzone voteTop = new VoteTopzone();
  489. +                               if(voteTop.hasVoted(activeChar))
  490. +                               {
  491. +                                   voteTop.updateDB(activeChar, "last_top_vote");
  492. +                                   voteTop.setVoted(activeChar);
  493. +                                   voteTop.reward(activeChar);
  494. +                               }
  495. +                               else
  496. +                                   activeChar.sendMessage("You haven't voted yet.");
  497. +                           }
  498. +                           else
  499. +                               _log.warning(activeChar.getName() + " tried to send a bypass with adrenalin/phx");
  500. +                       }).start();
  501. +                       break;
  502. +                   case "network":
  503. +                       new Thread(() -> {
  504. +                           if(activeChar.eligibleToVoteNet())
  505. +                           {
  506. +                               VoteNetwork voteNet = new VoteNetwork();
  507. +                               if(voteNet.hasVoted(activeChar))
  508. +                               {
  509. +                                   voteNet.updateDB(activeChar, "last_net_vote");
  510. +                                   voteNet.setVoted(activeChar);
  511. +                                   voteNet.reward(activeChar);
  512. +                               }
  513. +                               else
  514. +                                   activeChar.sendMessage("You haven't voted yet.");
  515. +                           }
  516. +                           else
  517. +                               _log.warning(activeChar.getName() + " tried to send a bypass with adrenalin/phx");
  518. +                       }).start();
  519. +                       break;
  520. +               }
  521. +           }
  522.             else if (_command.startsWith("npc_"))
  523.             {
  524.                 if (!activeChar.validateBypass(_command))
  525. diff --git java/net/sf/l2j/gameserver/voteengine/VoteBase.java java/net/sf/l2j/gameserver/voteengine/VoteBase.java
  526. new file mode 100644
  527. index 0000000..8217360
  528. --- /dev/null
  529. +++ java/net/sf/l2j/gameserver/voteengine/VoteBase.java
  530. @@ -0,0 +1,124 @@
  531. +/*
  532. + * This program is free software: you can redistribute it and/or modify it under
  533. + * the terms of the GNU General Public License as published by the Free Software
  534. + * Foundation, either version 3 of the License, or (at your option) any later
  535. + * version.
  536. + *
  537. + * This program is distributed in the hope that it will be useful, but WITHOUT
  538. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  539. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  540. + * details.
  541. + *
  542. + * You should have received a copy of the GNU General Public License along with
  543. + * this program. If not, see <http://www.gnu.org/licenses/>.
  544. + */
  545. +package net.sf.l2j.gameserver.voteengine;
  546. +
  547. +import java.io.BufferedReader;
  548. +import java.io.InputStreamReader;
  549. +import java.net.HttpURLConnection;
  550. +import java.net.URL;
  551. +import java.sql.Connection;
  552. +import java.sql.PreparedStatement;
  553. +
  554. +import net.sf.l2j.commons.lang.StringUtil;
  555. +
  556. +import net.sf.l2j.L2DatabaseFactory;
  557. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  558. +
  559. +/**
  560. + * @author Elfocrash
  561. + *
  562. + */
  563. +public abstract class VoteBase
  564. +{
  565. +
  566. +   public String getPlayerIp(L2PcInstance player)
  567. +   {
  568. +       System.out.println(player.getClient().getConnection().getInetAddress().getHostAddress());
  569. +       return player.getClient().getConnection().getInetAddress().getHostAddress();
  570. +   }
  571. +  
  572. +   public abstract void reward(L2PcInstance player);
  573. +  
  574. +   public abstract void setVoted(L2PcInstance player);
  575. +  
  576. +   public void updateDB(L2PcInstance player, String columnName)
  577. +   {
  578. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  579. +       {
  580. +           PreparedStatement statement = con.prepareStatement(String.format("Update characters set %s=? where obj_Id=?",columnName));
  581. +           statement.setLong(1, System.currentTimeMillis());
  582. +           statement.setInt(2, player.getObjectId());
  583. +           statement.execute();
  584. +           statement.close();
  585. +       }
  586. +       catch (Exception e)
  587. +       {
  588. +           e.printStackTrace();
  589. +           System.out.println("Error in VoteBase::updateDB");
  590. +       }
  591. +   }
  592. +  
  593. +   public boolean hasVoted(L2PcInstance player)
  594. +   {
  595. +       try
  596. +       {
  597. +           String endpoint = getApiEndpoint(player);
  598. +           if(endpoint.startsWith("err"))
  599. +               return false;
  600. +           String voted = endpoint.startsWith("http://api.hopzone.net") ? StringUtil.substringBetween(getApiResponse(endpoint),"\"voted\":",",\"hopzoneServerTime\"") : getApiResponse(endpoint);
  601. +           return tryParseBool(voted);
  602. +       }
  603. +       catch (Exception e)
  604. +       {
  605. +           player.sendMessage("Something went wrong. Please try again later.");
  606. +           e.printStackTrace();
  607. +       }
  608. +       return false;
  609. +   }
  610. +  
  611. +   public boolean tryParseBool(String bool)
  612. +   {
  613. +       if(bool.startsWith("1"))
  614. +           return true;
  615. +
  616. +       return Boolean.parseBoolean(bool.trim());
  617. +   }
  618. +  
  619. +   public abstract String getApiEndpoint(L2PcInstance player);
  620. +  
  621. +   public String getApiResponse(String endpoint)
  622. +   {
  623. +       StringBuilder stringBuilder = new StringBuilder();
  624. +
  625. +       try
  626. +       {
  627. +         URL url = new URL(endpoint);
  628. +         HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  629. +         connection.addRequestProperty("User-Agent", "Mozilla/4.76");
  630. +         connection.setRequestMethod("GET");
  631. +        
  632. +         connection.setReadTimeout(5*1000);
  633. +         connection.connect();
  634. +
  635. +         try(BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())))
  636. +         {
  637. +             String line = null;
  638. +             while ((line = reader.readLine()) != null)
  639. +             {
  640. +               stringBuilder.append(line + "\n");
  641. +             }
  642. +         }
  643. +         connection.disconnect();
  644. +         System.out.println(stringBuilder.toString());//
  645. +         return stringBuilder.toString();
  646. +       }
  647. +       catch (Exception e)
  648. +       {
  649. +           System.out.println("Something went wrong in VoteBase::getApiResponse");
  650. +           e.printStackTrace();
  651. +           return "err";
  652. +       }
  653. +   }
  654. +}
  655. diff --git java/net/sf/l2j/gameserver/voteengine/VoteHopzone.java java/net/sf/l2j/gameserver/voteengine/VoteHopzone.java
  656. new file mode 100644
  657. index 0000000..d6ac852
  658. --- /dev/null
  659. +++ java/net/sf/l2j/gameserver/voteengine/VoteHopzone.java
  660. @@ -0,0 +1,44 @@
  661. +/*
  662. + * This program is free software: you can redistribute it and/or modify it under
  663. + * the terms of the GNU General Public License as published by the Free Software
  664. + * Foundation, either version 3 of the License, or (at your option) any later
  665. + * version.
  666. + *
  667. + * This program is distributed in the hope that it will be useful, but WITHOUT
  668. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  669. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  670. + * details.
  671. + *
  672. + * You should have received a copy of the GNU General Public License along with
  673. + * this program. If not, see <http://www.gnu.org/licenses/>.
  674. + */
  675. +package net.sf.l2j.gameserver.voteengine;
  676. +
  677. +import net.sf.l2j.Config;
  678. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  679. +
  680. +/**
  681. + * @author Elfocrash
  682. + *
  683. + */
  684. +public class VoteHopzone extends VoteBase
  685. +{
  686. +   @Override
  687. +   public void reward(L2PcInstance player)
  688. +   {
  689. +       player.sendMessage("The admin should add the reward method here.");
  690. +   }
  691. +
  692. +   @Override
  693. +   public String getApiEndpoint(L2PcInstance player)
  694. +   {
  695. +       return String.format("http://api.hopzone.net/lineage2/vote?token=%s&ip_address=%s",Config.VOTE_HOPZONE_APIKEY, getPlayerIp(player));
  696. +   }
  697. +
  698. +   @Override
  699. +   public void setVoted(L2PcInstance player)
  700. +   {
  701. +       player.setLastHopVote(System.currentTimeMillis());
  702. +   }
  703. +  
  704. +}
  705. diff --git java/net/sf/l2j/gameserver/voteengine/VoteNetwork.java java/net/sf/l2j/gameserver/voteengine/VoteNetwork.java
  706. new file mode 100644
  707. index 0000000..317809f
  708. --- /dev/null
  709. +++ java/net/sf/l2j/gameserver/voteengine/VoteNetwork.java
  710. @@ -0,0 +1,45 @@
  711. +/*
  712. + * This program is free software: you can redistribute it and/or modify it under
  713. + * the terms of the GNU General Public License as published by the Free Software
  714. + * Foundation, either version 3 of the License, or (at your option) any later
  715. + * version.
  716. + *
  717. + * This program is distributed in the hope that it will be useful, but WITHOUT
  718. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  719. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  720. + * details.
  721. + *
  722. + * You should have received a copy of the GNU General Public License along with
  723. + * this program. If not, see <http://www.gnu.org/licenses/>.
  724. + */
  725. +package net.sf.l2j.gameserver.voteengine;
  726. +
  727. +import net.sf.l2j.Config;
  728. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  729. +
  730. +/**
  731. + * @author Elfocrash
  732. + *
  733. + */
  734. +public class VoteNetwork extends VoteBase
  735. +{
  736. +
  737. +   @Override
  738. +   public void reward(L2PcInstance player)
  739. +   {
  740. +       player.sendMessage("The admin should add the reward method here.");
  741. +   }
  742. +
  743. +   @Override
  744. +   public String getApiEndpoint(L2PcInstance player)
  745. +   {
  746. +       return String.format("http://l2network.eu/index.php?a=in&u=%s&ipc=%s", Config.VOTE_NETWORK_NAME, getPlayerIp(player));
  747. +   }
  748. +
  749. +   @Override
  750. +   public void setVoted(L2PcInstance player)
  751. +   {
  752. +       player.setLastNetVote(System.currentTimeMillis());
  753. +   }
  754. +  
  755. +}
  756. diff --git java/net/sf/l2j/gameserver/voteengine/VoteTopzone.java java/net/sf/l2j/gameserver/voteengine/VoteTopzone.java
  757. new file mode 100644
  758. index 0000000..c56cd09
  759. --- /dev/null
  760. +++ java/net/sf/l2j/gameserver/voteengine/VoteTopzone.java
  761. @@ -0,0 +1,44 @@
  762. +/*
  763. + * This program is free software: you can redistribute it and/or modify it under
  764. + * the terms of the GNU General Public License as published by the Free Software
  765. + * Foundation, either version 3 of the License, or (at your option) any later
  766. + * version.
  767. + *
  768. + * This program is distributed in the hope that it will be useful, but WITHOUT
  769. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  770. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  771. + * details.
  772. + *
  773. + * You should have received a copy of the GNU General Public License along with
  774. + * this program. If not, see <http://www.gnu.org/licenses/>.
  775. + */
  776. +package net.sf.l2j.gameserver.voteengine;
  777. +
  778. +import net.sf.l2j.Config;
  779. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  780. +
  781. +/**
  782. + * @author Elfocrash
  783. + *
  784. + */
  785. +public class VoteTopzone extends VoteBase
  786. +{
  787. +   @Override
  788. +   public void reward(L2PcInstance player)
  789. +   {
  790. +       player.sendMessage("The admin should add the reward method here.");
  791. +   }
  792. +
  793. +   @Override
  794. +   public String getApiEndpoint(L2PcInstance player)
  795. +   {
  796. +       return String.format("http://l2topzone.com/api.php?API_KEY=%s&SERVER_ID=%d&IP=%s",Config.VOTE_TOPZONE_APIKEY,Config.VOTE_TOPZONE_SERVERID, getPlayerIp(player));
  797. +   }
  798. +
  799. +   @Override
  800. +   public void setVoted(L2PcInstance player)
  801. +   {
  802. +       player.setLastTopVote(System.currentTimeMillis());
  803. +   }
  804. +  
  805. +}
  806. ### Eclipse Workspace Patch 1.0
  807. #P aCis_datapack
  808. diff --git sql/characters.sql sql/characters.sql
  809. index 1a04a4a..11fd549 100644
  810. --- sql/characters.sql
  811. +++ sql/characters.sql
  812. @@ -54,6 +54,9 @@
  813.    `clan_join_expiry_time` BIGINT UNSIGNED NOT NULL DEFAULT 0,
  814.    `clan_create_expiry_time` BIGINT UNSIGNED NOT NULL DEFAULT 0,
  815.    `death_penalty_level` SMALLINT UNSIGNED NOT NULL DEFAULT 0,
  816. +  `last_hop_vote` BIGINT UNSIGNED NOT NULL DEFAULT 0,
  817. +  `last_top_vote` BIGINT UNSIGNED NOT NULL DEFAULT 0,
  818. +  `last_net_vote` BIGINT UNSIGNED NOT NULL DEFAULT 0,
  819.    PRIMARY KEY (obj_Id),
  820.    KEY `clanid` (`clanid`)
  821.  );
  822. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment