Advertisement
Guest User

Hopzone / Topzone adapted for Acis by heopas

a guest
Oct 21st, 2013
2,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 29.63 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/GameServer.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 4)
  6. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  7. @@ -92,6 +92,8 @@
  8.  import net.sf.l2j.gameserver.model.PartyMatchWaitingList;
  9.  import net.sf.l2j.gameserver.model.entity.Castle;
  10.  import net.sf.l2j.gameserver.model.entity.Hero;
  11. +import net.sf.l2j.gameserver.model.entity.VoteRewardHopzone;
  12. +import net.sf.l2j.gameserver.model.entity.VoteRewardTopzone;
  13.  import net.sf.l2j.gameserver.model.olympiad.Olympiad;
  14.  import net.sf.l2j.gameserver.model.olympiad.OlympiadGameManager;
  15.  import net.sf.l2j.gameserver.network.L2GameClient;
  16. @@ -237,6 +239,12 @@
  17.         Olympiad.getInstance();
  18.         Hero.getInstance();
  19.        
  20. +       Util.printSection("Vote Manager");
  21. +       if (Config.ALLOW_HOPZONE_VOTE_REWARD)
  22. +           VoteRewardHopzone.getInstance();
  23. +       if (Config.ALLOW_TOPZONE_VOTE_REWARD)
  24. +           VoteRewardTopzone.getInstance();
  25. +      
  26.         Util.printSection("Four Sepulchers");
  27.         FourSepulchersManager.getInstance().init();
  28.        
  29. Index: java/net/sf/l2j/gameserver/model/entity/VoteRewardTopzone.java
  30. ===================================================================
  31. --- java/net/sf/l2j/gameserver/model/entity/VoteRewardTopzone.java  (revision 0)
  32. +++ java/net/sf/l2j/gameserver/model/entity/VoteRewardTopzone.java  (working copy)
  33. @@ -0,0 +1,314 @@
  34. +/*
  35. + * This program is free software: you can redistribute it and/or modify it under
  36. + * the terms of the GNU General Public License as published by the Free Software
  37. + * Foundation, either version 3 of the License, or (at your option) any later
  38. + * version.
  39. + *
  40. + * This program is distributed in the hope that it will be useful, but WITHOUT
  41. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  42. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  43. + * details.
  44. + *
  45. + * You should have received a copy of the GNU General Public License along with
  46. + * this program. If not, see <http://www.gnu.org/licenses/>.
  47. + */
  48. +package net.sf.l2j.gameserver.model.entity;
  49. +
  50. +import java.io.BufferedReader;
  51. +import java.io.InputStreamReader;
  52. +import java.net.URL;
  53. +import java.net.URLConnection;
  54. +import java.util.Collection;
  55. +import java.util.HashMap;
  56. +
  57. +import net.sf.l2j.Config;
  58. +import net.sf.l2j.gameserver.Announcements;
  59. +import net.sf.l2j.gameserver.ThreadPoolManager;
  60. +import net.sf.l2j.gameserver.model.L2World;
  61. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  62. +/**
  63. + * @author Anarchy
  64. + *
  65. + */
  66. +public class VoteRewardTopzone
  67. +{
  68. +   // Configurations.
  69. +   private static String topzoneUrl = Config.TOPZONE_SERVER_LINK;
  70. +   private static String page1Url = Config.TOPZONE_FIRST_PAGE_LINK;
  71. +   private static int voteRewardVotesDifference = Config.TOPZONE_VOTES_DIFFERENCE;
  72. +   private static int firstPageRankNeeded = Config.TOPZONE_FIRST_PAGE_RANK_NEEDED;
  73. +   private static int checkTime = 60*1000*Config.TOPZONE_REWARD_CHECK_TIME;
  74. +  
  75. +   // Don't-touch variables.
  76. +   private static int lastVotes = 0;
  77. +   private static HashMap<String, Integer> playerIps = new HashMap<>();
  78. +  
  79. +   public static void updateConfigurations()
  80. +   {
  81. +       topzoneUrl = Config.TOPZONE_SERVER_LINK;
  82. +       page1Url = Config.TOPZONE_FIRST_PAGE_LINK;
  83. +       voteRewardVotesDifference = Config.TOPZONE_VOTES_DIFFERENCE;
  84. +       firstPageRankNeeded = Config.TOPZONE_FIRST_PAGE_RANK_NEEDED;
  85. +       checkTime = 60*1000*Config.TOPZONE_REWARD_CHECK_TIME;
  86. +   }
  87. +  
  88. +   public static void getInstance()
  89. +   {
  90. +       System.out.println("Topzone - Vote reward system initialized.");
  91. +       ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()
  92. +       {
  93. +           @Override
  94. +           public void run()
  95. +           {
  96. +               if (Config.ALLOW_TOPZONE_VOTE_REWARD)
  97. +               {
  98. +                   reward();
  99. +               }
  100. +               else
  101. +               {
  102. +                   return;
  103. +               }
  104. +           }
  105. +       }, checkTime/2, checkTime);
  106. +   }
  107. +  
  108. +   static void reward()
  109. +   {
  110. +       int firstPageVotes = getFirstPageRankVotes();
  111. +       int currentVotes = getVotes();
  112. +      
  113. +       if (firstPageVotes == -1 || currentVotes == -1)
  114. +       {
  115. +           if (firstPageVotes == -1)
  116. +           {
  117. +               System.out.println("There was a problem on getting Topzone votes from server with rank "+firstPageRankNeeded+".");
  118. +           }
  119. +           if (currentVotes == -1)
  120. +           {
  121. +               System.out.println("There was a problem on getting Topzone server votes.");
  122. +           }
  123. +          
  124. +           return;
  125. +       }
  126. +      
  127. +       if (lastVotes == 0)
  128. +       {
  129. +           lastVotes = currentVotes;
  130. +           Announcements.announceToAll("Topzone: Current vote count is "+currentVotes+".");
  131. +           Announcements.announceToAll("Topzone: We need "+((lastVotes+voteRewardVotesDifference)-currentVotes)+" vote(s) for reward.");
  132. +           if (Config.ALLOW_TOPZONE_GAME_SERVER_REPORT)
  133. +           {
  134. +               System.out.println("Server votes on topzone: "+currentVotes);
  135. +               System.out.println("Votes needed for reward: "+((lastVotes+voteRewardVotesDifference)-currentVotes));
  136. +           }
  137. +           if (firstPageVotes-lastVotes <= 0)
  138. +           {
  139. +               Announcements.announceToAll("Topzone: We are in the top "+firstPageRankNeeded+" of topzone, so the reward will be big.");
  140. +               if (Config.ALLOW_TOPZONE_GAME_SERVER_REPORT)
  141. +               {
  142. +                   System.out.println("Server is on the top "+firstPageRankNeeded+" of topzone.");
  143. +               }
  144. +           }
  145. +           else
  146. +           {
  147. +               Announcements.announceToAll("Topzone: We need "+(firstPageVotes-lastVotes)+" vote(s) to get to the top "+firstPageRankNeeded+" of topzone for big reward.");
  148. +               if (Config.ALLOW_TOPZONE_GAME_SERVER_REPORT)
  149. +               {
  150. +                   System.out.println("Server votes needed for top "+firstPageRankNeeded+": "+(firstPageVotes-lastVotes));
  151. +               }
  152. +           }
  153. +           return;
  154. +       }
  155. +      
  156. +       if (currentVotes >= lastVotes+voteRewardVotesDifference)
  157. +       {
  158. +           Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  159. +           if (firstPageVotes-currentVotes <= 0)
  160. +           {
  161. +               if (Config.ALLOW_TOPZONE_GAME_SERVER_REPORT)
  162. +               {
  163. +                   System.out.println("Server votes on topzone: "+currentVotes);
  164. +                   System.out.println("Server is on the top "+firstPageRankNeeded+" of topzone.");
  165. +                   System.out.println("Votes needed for next reward: "+((currentVotes+voteRewardVotesDifference)-currentVotes));
  166. +               }
  167. +               Announcements.announceToAll("Topzone: Everyone has been rewarded with big reward.");
  168. +               Announcements.announceToAll("Topzone: Current vote count is "+currentVotes+".");
  169. +               for (L2PcInstance p : pls)
  170. +               {
  171. +                   boolean canReward = false;
  172. +                   String pIp = p.getClient().getConnection().getInetAddress().getHostAddress();
  173. +                   if (playerIps.containsKey(pIp))
  174. +                   {
  175. +                       int count = playerIps.get(pIp);
  176. +                       if (count < Config.TOPZONE_DUALBOXES_ALLOWED)
  177. +                       {
  178. +                           playerIps.remove(pIp);
  179. +                           playerIps.put(pIp, count+1);
  180. +                           canReward = true;
  181. +                       }
  182. +                   }
  183. +                   else
  184. +                   {
  185. +                       canReward = true;
  186. +                       playerIps.put(pIp, 1);
  187. +                   }
  188. +                   if (canReward)
  189. +                   {
  190. +                       for (int i = 0; i < Config.TOPZONE_BIG_REWARD.length; i++)
  191. +                       {
  192. +                           p.addItem("Vote reward.", Config.TOPZONE_BIG_REWARD[i][0], Config.TOPZONE_BIG_REWARD[i][1], p, true);
  193. +                       }
  194. +                   }
  195. +                   else
  196. +                   {
  197. +                       p.sendMessage("Already "+Config.TOPZONE_DUALBOXES_ALLOWED+" character(s) of your ip have been rewarded, so this character won't be rewarded.");
  198. +                   }
  199. +               }
  200. +               playerIps.clear();
  201. +           }
  202. +           else
  203. +           {
  204. +               if (Config.ALLOW_TOPZONE_GAME_SERVER_REPORT)
  205. +               {
  206. +                   System.out.println("Server votes on topzone: "+currentVotes);
  207. +                   System.out.println("Server votes needed for top "+firstPageRankNeeded+": "+(firstPageVotes-lastVotes));
  208. +                   System.out.println("Votes needed for next reward: "+((currentVotes+voteRewardVotesDifference)-currentVotes));
  209. +               }
  210. +               Announcements.announceToAll("Topzone: Everyone has been rewarded with small reward.");
  211. +               Announcements.announceToAll("Topzone: Current vote count is "+currentVotes+".");
  212. +               Announcements.announceToAll("Topzone: We need "+(firstPageVotes-currentVotes)+" vote(s) to get to the top "+firstPageRankNeeded+" of topzone for big reward.");
  213. +               for (L2PcInstance p : pls)
  214. +               {
  215. +                   boolean canReward = false;
  216. +                   String pIp = p.getClient().getConnection().getInetAddress().getHostAddress();
  217. +                   if (playerIps.containsKey(pIp))
  218. +                   {
  219. +                       int count = playerIps.get(pIp);
  220. +                       if (count < Config.TOPZONE_DUALBOXES_ALLOWED)
  221. +                       {
  222. +                           playerIps.remove(pIp);
  223. +                           playerIps.put(pIp, count+1);
  224. +                           canReward = true;
  225. +                       }
  226. +                   }
  227. +                   else
  228. +                   {
  229. +                       canReward = true;
  230. +                       playerIps.put(pIp, 1);
  231. +                   }
  232. +                   if (canReward)
  233. +                   {
  234. +                       for (int i = 0; i < Config.TOPZONE_SMALL_REWARD.length; i++)
  235. +                       {
  236. +                           p.addItem("Vote reward.", Config.TOPZONE_SMALL_REWARD[i][0], Config.TOPZONE_SMALL_REWARD[i][1], p, true);
  237. +                       }
  238. +                   }
  239. +                   else
  240. +                   {
  241. +                       p.sendMessage("Already "+Config.TOPZONE_DUALBOXES_ALLOWED+" character(s) of your ip have been rewarded, so this character won't be rewarded.");
  242. +                   }
  243. +               }
  244. +               playerIps.clear();
  245. +           }
  246. +          
  247. +           lastVotes = currentVotes;
  248. +       }
  249. +       else
  250. +       {
  251. +           if (firstPageVotes-currentVotes <= 0)
  252. +           {
  253. +               if (Config.ALLOW_TOPZONE_GAME_SERVER_REPORT)
  254. +               {
  255. +                   System.out.println("Server votes on topzone: "+currentVotes);
  256. +                   System.out.println("Server is on the top "+firstPageRankNeeded+" of topzone.");
  257. +                   System.out.println("Votes needed for next reward: "+((lastVotes+voteRewardVotesDifference)-currentVotes));
  258. +               }
  259. +               Announcements.announceToAll("Topzone: Current vote count is "+currentVotes+".");
  260. +               Announcements.announceToAll("Topzone: We need "+((lastVotes+voteRewardVotesDifference)-currentVotes)+" vote(s) for big reward.");
  261. +           }
  262. +           else
  263. +           {
  264. +               if (Config.ALLOW_TOPZONE_GAME_SERVER_REPORT)
  265. +               {
  266. +                   System.out.println("Server votes on topzone: "+currentVotes);
  267. +                   System.out.println("Server votes needed for top "+firstPageRankNeeded+": "+(firstPageVotes-lastVotes));
  268. +                   System.out.println("Votes needed for next reward: "+((lastVotes+voteRewardVotesDifference)-currentVotes));
  269. +               }
  270. +               Announcements.announceToAll("Topzone: Current vote count is "+currentVotes+".");
  271. +               Announcements.announceToAll("Topzone: We need "+((lastVotes+voteRewardVotesDifference)-currentVotes)+" vote(s) for small reward.");
  272. +               Announcements.announceToAll("Topzone: We need "+(firstPageVotes-currentVotes)+" vote(s) to get to the top "+firstPageRankNeeded+" of topzone for big reward.");
  273. +           }
  274. +       }
  275. +   }
  276. +  
  277. +   private static int getFirstPageRankVotes()
  278. +   {
  279. +       InputStreamReader isr = null;
  280. +       BufferedReader br = null;
  281. +      
  282. +       try
  283. +       {
  284. +           URLConnection con = new URL(page1Url).openConnection();
  285. +           con.addRequestProperty("User-Agent", "Mozilla/4.76");
  286. +           isr = new InputStreamReader(con.getInputStream());
  287. +           br = new BufferedReader(isr);
  288. +          
  289. +           String line;
  290. +           while ((line = br.readLine()) != null)
  291. +           {
  292. +               if (line.contains("<div class=\"slr\">"+firstPageRankNeeded+"<div class=\"votes\">Votes:<br><span>"))
  293. +               {
  294. +                   int votes = Integer.valueOf(line.split("<div class=\"slr\">"+firstPageRankNeeded+"<div class=\"votes\">Votes:<br><span>")[1].replace("</span></div></div>", ""));
  295. +                   return votes;
  296. +               }
  297. +           }
  298. +          
  299. +           br.close();
  300. +           isr.close();
  301. +       }
  302. +       catch (Exception e)
  303. +       {
  304. +           System.out.println(e);
  305. +           System.out.println("Error while getting Hopzone server vote count.");
  306. +       }
  307. +      
  308. +       return -1;
  309. +   }
  310. +      
  311. +   private static int getVotes()
  312. +   {
  313. +       InputStreamReader isr = null;
  314. +       BufferedReader br = null;
  315. +      
  316. +       try
  317. +       {
  318. +           URLConnection con = new URL(topzoneUrl).openConnection();
  319. +           con.addRequestProperty("User-Agent", "Mozilla/4.76");
  320. +           isr = new InputStreamReader(con.getInputStream());
  321. +           br = new BufferedReader(isr);
  322. +          
  323. +           boolean got = false;
  324. +          
  325. +           String line;
  326. +           while ((line = br.readLine()) != null)
  327. +           {
  328. +               if (line.contains("<div class=\"rank\"><div class=\"votes2\">Votes:<br>") && !got)
  329. +               {
  330. +                   got = true;
  331. +                   int votes = Integer.valueOf(line.split("<div class=\"rank\"><div class=\"votes2\">Votes:<br>")[1].replace("</div></div>", ""));
  332. +                   return votes;
  333. +               }
  334. +           }
  335. +          
  336. +           br.close();
  337. +           isr.close();
  338. +       }
  339. +       catch (Exception e)
  340. +       {
  341. +           System.out.println(e);
  342. +           System.out.println("Error while getting server vote count.");
  343. +       }
  344. +      
  345. +       return -1;
  346. +   }
  347. +}
  348. \ No newline at end of file
  349. Index: config/votemanager.properties
  350. ===================================================================
  351. --- config/votemanager.properties   (revision 0)
  352. +++ config/votemanager.properties   (working copy)
  353. @@ -0,0 +1,49 @@
  354. +# Vote reward for Hopzone.
  355. +AllowHopzoneVoteReward = True
  356. +# Vote reward server link.
  357. +HopzoneServerLink = http://l2.hopzone.net/lineage2/details/74078/L2World-Servers/
  358. +# First page of servers list link.
  359. +HopzoneFirstPageLink = http://l2.hopzone.net/lineage2/
  360. +# Votes for next reward needed.
  361. +HopzoneVotesDifference = 5
  362. +# Rank needed for server to be on first page.
  363. +HopzoneFirstPageRankNeeded = 15
  364. +# Minutes between rewards.
  365. +# Eg. You put 5 it checks every 5 minutes for reward.
  366. +HopzoneRewardCheckTime = 5
  367. +# Small reward(s).
  368. +HopzoneSmallReward = 57,100000000;
  369. +# Big reward(s).
  370. +HopzoneBigReward = 3470,1;
  371. +# Hopzone reward max dual boxes reward.
  372. +# For example if you put 2 and someone has 3 boxes open 2 will be rewarded.
  373. +HopzoneDuaboxesAllowed = 1
  374. +# Game server console report.
  375. +# If set to true, game server console will get a report of
  376. +# current vote count, votes needed for next reward and votes needed for first page.
  377. +AllowHopzoneGameServerReport = True
  378. +
  379. +# Vote reward for Topzone.
  380. +AllowTopzoneVoteReward = True
  381. +# Vote reward server link.
  382. +TopzoneServerLink = http://l2topzone.com/lineage2/server-info/6296/L2ToxiccomProMMORPG.html/
  383. +# First page of servers list link.
  384. +TopzoneFirstPageLink = http://l2topzone.com/lineage2/server-list/top.html/
  385. +# Votes for next reward needed.
  386. +TopzoneVotesDifference = 5
  387. +# Rank needed for server to be on first page.
  388. +TopzoneFirstPageRankNeeded = 15
  389. +# Minutes between rewards.
  390. +# Eg. You put 5 it checks every 5 minutes for reward.
  391. +TopzoneRewardCheckTime = 5
  392. +# Small reward(s).
  393. +TopzoneSmallReward = 57,100000000;
  394. +# Big reward(s).
  395. +TopzoneBigReward = 3470,1;
  396. +# Hopzone reward max dual boxes reward.
  397. +# For example if you put 2 and someone has 3 boxes open 2 will be rewarded.
  398. +TopzoneDuaboxesAllowed = 1
  399. +# Game server console report.
  400. +# If set to true, game server console will get a report of
  401. +# current vote count, votes needed for next reward and votes needed for first page.
  402. +AllowTopzoneGameServerReport = True
  403. \ No newline at end of file
  404. Index: java/net/sf/l2j/Config.java
  405. ===================================================================
  406. --- java/net/sf/l2j/Config.java (revision 4)
  407. +++ java/net/sf/l2j/Config.java (working copy)
  408. @@ -52,6 +52,7 @@
  409.     public static final String PLAYERS_FILE = "./config/players.properties";
  410.     public static final String SERVER_FILE = "./config/server.properties";
  411.     public static final String SIEGE_FILE = "./config/siege.properties";
  412. +   public static final String VOTE_MANAGER = "./config/votemanager.properties";
  413.    
  414.     // --------------------------------------------------
  415.     // Clans settings
  416. @@ -690,6 +691,28 @@
  417.     public static int CLIENT_PACKET_QUEUE_MAX_UNDERFLOWS_PER_MIN = 1; // default 1
  418.     public static int CLIENT_PACKET_QUEUE_MAX_UNKNOWN_PER_MIN = 5; // default 5
  419.    
  420. +  
  421. +   /** Vote Manager settings */
  422. +   public static boolean ALLOW_HOPZONE_VOTE_REWARD;
  423. +   public static String HOPZONE_SERVER_LINK;
  424. +   public static String HOPZONE_FIRST_PAGE_LINK;
  425. +   public static int HOPZONE_VOTES_DIFFERENCE;
  426. +   public static int HOPZONE_FIRST_PAGE_RANK_NEEDED;
  427. +   public static int HOPZONE_REWARD_CHECK_TIME;
  428. +   public static int[][] HOPZONE_SMALL_REWARD;
  429. +   public static int[][] HOPZONE_BIG_REWARD;
  430. +   public static int HOPZONE_DUALBOXES_ALLOWED;
  431. +   public static boolean ALLOW_HOPZONE_GAME_SERVER_REPORT;
  432. +   public static boolean ALLOW_TOPZONE_VOTE_REWARD;
  433. +   public static String TOPZONE_SERVER_LINK;
  434. +   public static String TOPZONE_FIRST_PAGE_LINK;
  435. +   public static int TOPZONE_VOTES_DIFFERENCE;
  436. +   public static int TOPZONE_FIRST_PAGE_RANK_NEEDED;
  437. +   public static int TOPZONE_REWARD_CHECK_TIME;
  438. +   public static int[][] TOPZONE_SMALL_REWARD;
  439. +   public static int[][] TOPZONE_BIG_REWARD;
  440. +   public static int TOPZONE_DUALBOXES_ALLOWED;
  441. +   public static boolean ALLOW_TOPZONE_GAME_SERVER_REPORT;
  442.     // --------------------------------------------------
  443.    
  444.     /**
  445. @@ -1241,6 +1264,28 @@
  446.             ZONE_TOWN = server.getProperty("ZoneTown", 0);
  447.             SERVER_NEWS = server.getProperty("ShowServerNews", false);
  448.             DISABLE_TUTORIAL = server.getProperty("DisableTutorial", false);
  449. +          
  450. +           ExProperties votemanager = load(VOTE_MANAGER);
  451. +           ALLOW_HOPZONE_VOTE_REWARD = votemanager.getProperty("AllowHopzoneVoteReward", false);
  452. +           HOPZONE_SERVER_LINK = votemanager.getProperty("HopzoneServerLink", "http://l2.topzone.net/lineage2/details/74078/L2World-Servers/");
  453. +           HOPZONE_FIRST_PAGE_LINK = votemanager.getProperty("HopzoneFirstPageLink", "http://l2.topzone.net/lineage2/");
  454. +           HOPZONE_VOTES_DIFFERENCE = votemanager.getProperty("HopzoneVotesDifference", 5);
  455. +               HOPZONE_FIRST_PAGE_RANK_NEEDED = votemanager.getProperty("HopzoneFirstPageRankNeeded", 15);
  456. +               HOPZONE_REWARD_CHECK_TIME = votemanager.getProperty("HopzoneRewardCheckTime", 5);
  457. +               HOPZONE_SMALL_REWARD = parseItemsList(votemanager.getProperty("HopzoneSmallReward", "57,100000000;"));
  458. +               HOPZONE_BIG_REWARD = parseItemsList(votemanager.getProperty("HopzoneBigReward", "3470,1;"));
  459. +            HOPZONE_DUALBOXES_ALLOWED = votemanager.getProperty("HopzoneDualboxesAllowed", 1);
  460. +            ALLOW_HOPZONE_GAME_SERVER_REPORT = votemanager.getProperty("AllowHopzoneGameServerReport", false);
  461. +            ALLOW_TOPZONE_VOTE_REWARD = votemanager.getProperty("AllowTopzoneVoteReward", false);
  462. +            TOPZONE_SERVER_LINK = votemanager.getProperty("TopzoneServerLink", "http://l2.topzone.net/lineage2/details/74078/L2World-Servers/");
  463. +            TOPZONE_FIRST_PAGE_LINK = votemanager.getProperty("TopzoneFirstPageLink", "http://l2.topzone.net/lineage2/");
  464. +            TOPZONE_VOTES_DIFFERENCE = votemanager.getProperty("TopzoneVotesDifference", 5);
  465. +               TOPZONE_FIRST_PAGE_RANK_NEEDED = votemanager.getProperty("TopzoneFirstPageRankNeeded", 15);
  466. +               TOPZONE_REWARD_CHECK_TIME = votemanager.getProperty("TopzoneRewardCheckTime", 5);
  467. +               TOPZONE_SMALL_REWARD = parseItemsList(votemanager.getProperty("TopzoneSmallReward", "57,100000000;"));
  468. +               TOPZONE_BIG_REWARD = parseItemsList(votemanager.getProperty("TopzoneBigReward", "3470,1;"));
  469. +            TOPZONE_DUALBOXES_ALLOWED = votemanager.getProperty("TopzoneDualboxesAllowed", 1);
  470. +            ALLOW_TOPZONE_GAME_SERVER_REPORT = votemanager.getProperty("AllowTopzoneGameServerReport", false);
  471.         }
  472.         else if (Server.serverMode == Server.MODE_LOGINSERVER)
  473.         {
  474. Index: java/net/sf/l2j/gameserver/model/entity/VoteRewardHopzone.java
  475. ===================================================================
  476. --- java/net/sf/l2j/gameserver/model/entity/VoteRewardHopzone.java  (revision 0)
  477. +++ java/net/sf/l2j/gameserver/model/entity/VoteRewardHopzone.java  (working copy)
  478. @@ -0,0 +1,317 @@
  479. +/*
  480. + * This program is free software: you can redistribute it and/or modify it under
  481. + * the terms of the GNU General Public License as published by the Free Software
  482. + * Foundation, either version 3 of the License, or (at your option) any later
  483. + * version.
  484. + *
  485. + * This program is distributed in the hope that it will be useful, but WITHOUT
  486. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  487. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  488. + * details.
  489. + *
  490. + * You should have received a copy of the GNU General Public License along with
  491. + * this program. If not, see <http://www.gnu.org/licenses/>.
  492. + */
  493. +package net.sf.l2j.gameserver.model.entity;
  494. +
  495. +import java.io.BufferedReader;
  496. +import java.io.InputStreamReader;
  497. +import java.net.URL;
  498. +import java.net.URLConnection;
  499. +import java.util.Collection;
  500. +import java.util.HashMap;
  501. +
  502. +import net.sf.l2j.Config;
  503. +import net.sf.l2j.gameserver.Announcements;
  504. +import net.sf.l2j.gameserver.ThreadPoolManager;
  505. +import net.sf.l2j.gameserver.model.L2World;
  506. +import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  507. +/**
  508. + * @author Anarchy
  509. + *
  510. + */
  511. +public class VoteRewardHopzone
  512. +{
  513. +   // Configurations.
  514. +   private static String hopzoneUrl = Config.HOPZONE_SERVER_LINK;
  515. +   private static String page1Url = Config.HOPZONE_FIRST_PAGE_LINK;
  516. +   private static int voteRewardVotesDifference = Config.HOPZONE_VOTES_DIFFERENCE;
  517. +   private static int firstPageRankNeeded = Config.HOPZONE_FIRST_PAGE_RANK_NEEDED;
  518. +   private static int checkTime = 60*1000*Config.HOPZONE_REWARD_CHECK_TIME;
  519. +  
  520. +   // Don't-touch variables.
  521. +   private static int lastVotes = 0;
  522. +   private static HashMap<String, Integer> playerIps = new HashMap<>();
  523. +  
  524. +   public static void updateConfigurations()
  525. +   {
  526. +       hopzoneUrl = Config.HOPZONE_SERVER_LINK;
  527. +       page1Url = Config.HOPZONE_FIRST_PAGE_LINK;
  528. +       voteRewardVotesDifference = Config.HOPZONE_VOTES_DIFFERENCE;
  529. +       firstPageRankNeeded = Config.HOPZONE_FIRST_PAGE_RANK_NEEDED;
  530. +       checkTime = 60*1000*Config.HOPZONE_REWARD_CHECK_TIME;
  531. +   }
  532. +  
  533. +   public static void getInstance()
  534. +   {
  535. +       System.out.println("Hopzone - Vote reward system initialized.");
  536. +       ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new Runnable()
  537. +       {
  538. +           @Override
  539. +           public void run()
  540. +           {
  541. +               if (Config.ALLOW_HOPZONE_VOTE_REWARD)
  542. +               {
  543. +                   reward();
  544. +               }
  545. +               else
  546. +               {
  547. +                   return;
  548. +               }
  549. +           }
  550. +       }, checkTime/2, checkTime);
  551. +   }
  552. +  
  553. +   static void reward()
  554. +   {
  555. +       int firstPageVotes = getFirstPageRankVotes();
  556. +       int currentVotes = getVotes();
  557. +      
  558. +       if (firstPageVotes == -1 || currentVotes == -1)
  559. +       {
  560. +           if (firstPageVotes == -1)
  561. +           {
  562. +               System.out.println("There was a problem on getting Hopzone votes from server with rank "+firstPageRankNeeded+".");
  563. +           }
  564. +           if (currentVotes == -1)
  565. +           {
  566. +               System.out.println("There was a problem on getting Hopzone server votes.");
  567. +           }
  568. +          
  569. +           return;
  570. +       }
  571. +      
  572. +       if (lastVotes == 0)
  573. +       {
  574. +           lastVotes = currentVotes;
  575. +           Announcements.announceToAll("Hopzone: Vote count is "+currentVotes+".");
  576. +           Announcements.announceToAll("Hopzone: We need "+((lastVotes+voteRewardVotesDifference)-currentVotes)+" vote(s) for reward.");
  577. +           if (Config.ALLOW_HOPZONE_GAME_SERVER_REPORT)
  578. +           {
  579. +               System.out.println("Server votes on hopzone: "+currentVotes);
  580. +               System.out.println("Votes needed for reward: "+((lastVotes+voteRewardVotesDifference)-currentVotes));
  581. +           }
  582. +           if (firstPageVotes-lastVotes <= 0)
  583. +           {
  584. +               Announcements.announceToAll("Hopzone: We are in the top "+firstPageRankNeeded+", so the reward will be big.");
  585. +               if (Config.ALLOW_HOPZONE_GAME_SERVER_REPORT)
  586. +               {
  587. +                   System.out.println("Server is on the top "+firstPageRankNeeded+" of hopzone.");
  588. +               }
  589. +           }
  590. +           else
  591. +           {
  592. +               Announcements.announceToAll("Hopzone: We need "+(firstPageVotes-lastVotes)+" vote(s) to get to the top "+firstPageRankNeeded+" of Hopzone for big reward.");
  593. +               if (Config.ALLOW_HOPZONE_GAME_SERVER_REPORT)
  594. +               {
  595. +                   System.out.println("Server votes needed for top "+firstPageRankNeeded+": "+(firstPageVotes-lastVotes));
  596. +               }
  597. +           }
  598. +           return;
  599. +       }
  600. +      
  601. +       if (currentVotes >= lastVotes+voteRewardVotesDifference)
  602. +       {
  603. +           Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().values();
  604. +           if (firstPageVotes-currentVotes <= 0)
  605. +           {
  606. +               if (Config.ALLOW_HOPZONE_GAME_SERVER_REPORT)
  607. +               {
  608. +                   System.out.println("Server votes on hopzone: "+currentVotes);
  609. +                   System.out.println("Server is on the first page of hopzone.");
  610. +                   System.out.println("Votes needed for next reward: "+((currentVotes+voteRewardVotesDifference)-currentVotes));
  611. +               }
  612. +               Announcements.announceToAll("Hopzone: Everyone has been rewarded with big reward.");
  613. +               Announcements.announceToAll("Hopzone: Current vote count is "+currentVotes+".");
  614. +               for (L2PcInstance p : pls)
  615. +               {
  616. +                   boolean canReward = false;
  617. +                   String pIp = p.getClient().getConnection().getInetAddress().getHostAddress();
  618. +                   if (playerIps.containsKey(pIp))
  619. +                   {
  620. +                       int count = playerIps.get(pIp);
  621. +                       if (count < Config.HOPZONE_DUALBOXES_ALLOWED)
  622. +                       {
  623. +                           playerIps.remove(pIp);
  624. +                           playerIps.put(pIp, count+1);
  625. +                           canReward = true;
  626. +                       }
  627. +                   }
  628. +                   else
  629. +                   {
  630. +                       canReward = true;
  631. +                       playerIps.put(pIp, 1);
  632. +                   }
  633. +                   if (canReward)
  634. +                   {
  635. +                       for (int i = 0; i < Config.HOPZONE_BIG_REWARD.length; i++)
  636. +                       {
  637. +                           p.addItem("Vote reward.", Config.HOPZONE_BIG_REWARD[i][0], Config.HOPZONE_BIG_REWARD[i][1], p, true);
  638. +                       }
  639. +                   }
  640. +                   else
  641. +                   {
  642. +                       p.sendMessage("Already "+Config.HOPZONE_DUALBOXES_ALLOWED+" character(s) of your ip have been rewarded, so this character won't be rewarded.");
  643. +                   }
  644. +               }
  645. +               playerIps.clear();
  646. +           }
  647. +           else
  648. +           {
  649. +               if (Config.ALLOW_HOPZONE_GAME_SERVER_REPORT)
  650. +               {
  651. +                   System.out.println("Server votes on hopzone: "+currentVotes);
  652. +                   System.out.println("Server votes needed for first page: "+(firstPageVotes-lastVotes));
  653. +                   System.out.println("Votes needed for next reward: "+((currentVotes+voteRewardVotesDifference)-currentVotes));
  654. +               }
  655. +               Announcements.announceToAll("Hopzone: Everyone has been rewarded with small reward.");
  656. +               Announcements.announceToAll("Hopzone: Current vote count is "+currentVotes+".");
  657. +               Announcements.announceToAll("Hopzone: We need "+(firstPageVotes-currentVotes)+" vote(s) to get to the top "+firstPageRankNeeded+" of Hopzone for big reward.");
  658. +               for (L2PcInstance p : pls)
  659. +               {
  660. +                   boolean canReward = false;
  661. +                   String pIp = p.getClient().getConnection().getInetAddress().getHostAddress();
  662. +                   if (playerIps.containsKey(pIp))
  663. +                   {
  664. +                       int count = playerIps.get(pIp);
  665. +                       if (count < Config.HOPZONE_DUALBOXES_ALLOWED)
  666. +                       {
  667. +                           playerIps.remove(pIp);
  668. +                           playerIps.put(pIp, count+1);
  669. +                           canReward = true;
  670. +                       }
  671. +                   }
  672. +                   else
  673. +                   {
  674. +                       canReward = true;
  675. +                       playerIps.put(pIp, 1);
  676. +                   }
  677. +                   if (canReward)
  678. +                   {
  679. +                       for (int i = 0; i < Config.HOPZONE_SMALL_REWARD.length; i++)
  680. +                       {
  681. +                           p.addItem("Vote reward.", Config.HOPZONE_SMALL_REWARD[i][0], Config.HOPZONE_SMALL_REWARD[i][1], p, true);
  682. +                       }
  683. +                   }
  684. +                   else
  685. +                   {
  686. +                       p.sendMessage("Already "+Config.HOPZONE_DUALBOXES_ALLOWED+" character(s) of your ip have been rewarded, so this character won't be rewarded.");
  687. +                   }
  688. +               }
  689. +               playerIps.clear();
  690. +           }
  691. +          
  692. +           lastVotes = currentVotes;
  693. +       }
  694. +       else
  695. +       {
  696. +           if (firstPageVotes-currentVotes <= 0)
  697. +           {
  698. +               if (Config.ALLOW_HOPZONE_GAME_SERVER_REPORT)
  699. +               {
  700. +                   System.out.println("Server votes on hopzone: "+currentVotes);
  701. +                   System.out.println("Server is on the first page of hopzone.");
  702. +                   System.out.println("Votes needed for next reward: "+((lastVotes+voteRewardVotesDifference)-currentVotes));
  703. +               }
  704. +               Announcements.announceToAll("Hopzone: Current vote count is "+currentVotes+".");
  705. +               Announcements.announceToAll("Hopzone: We need "+((lastVotes+voteRewardVotesDifference)-currentVotes)+" vote(s) for big reward.");
  706. +           }
  707. +           else
  708. +           {
  709. +               if (Config.ALLOW_HOPZONE_GAME_SERVER_REPORT)
  710. +               {
  711. +                   System.out.println("Server votes on hopzone: "+currentVotes);
  712. +                   System.out.println("Server votes needed for first page: "+(firstPageVotes-lastVotes));
  713. +                   System.out.println("Votes needed for next reward: "+((lastVotes+voteRewardVotesDifference)-currentVotes));
  714. +               }
  715. +               Announcements.announceToAll("Hopzone: Current vote count is "+currentVotes+".");
  716. +               Announcements.announceToAll("Hopzone: We need "+((lastVotes+voteRewardVotesDifference)-currentVotes)+" vote(s) for small reward.");
  717. +               Announcements.announceToAll("Hopzone: We need "+(firstPageVotes-currentVotes)+" vote(s) to get to the top "+firstPageRankNeeded+" of Hopzone for big reward.");
  718. +           }
  719. +       }
  720. +   }
  721. +  
  722. +   private static int getFirstPageRankVotes()
  723. +   {
  724. +       InputStreamReader isr = null;
  725. +       BufferedReader br = null;
  726. +      
  727. +       try
  728. +       {
  729. +           URLConnection con = new URL(page1Url).openConnection();
  730. +           con.addRequestProperty("User-Agent", "Mozilla/4.76");
  731. +           isr = new InputStreamReader(con.getInputStream());
  732. +           br = new BufferedReader(isr);
  733. +          
  734. +           String line;
  735. +           int i = 0;
  736. +           while ((line = br.readLine()) != null)
  737. +           {
  738. +               if (line.contains("<span class=\"no\">"+firstPageRankNeeded+"</span>"))
  739. +               {
  740. +                   i++;
  741. +               }
  742. +               if (line.contains("<span class=\"rank anonymous tooltip\"") && i == 1)
  743. +               {
  744. +                   i = 0;
  745. +                   int votes = Integer.valueOf(line.replaceAll("[^\\d]", ""));
  746. +                   return votes;
  747. +               }
  748. +           }
  749. +          
  750. +           br.close();
  751. +           isr.close();
  752. +       }
  753. +       catch (Exception e)
  754. +       {
  755. +           System.out.println(e);
  756. +           System.out.println("Error while getting Hopzone server vote count.");
  757. +       }
  758. +      
  759. +       return -1;
  760. +   }
  761. +  
  762. +   private static int getVotes()
  763. +   {
  764. +       InputStreamReader isr = null;
  765. +       BufferedReader br = null;
  766. +      
  767. +       try
  768. +       {
  769. +           URLConnection con = new URL(hopzoneUrl).openConnection();
  770. +           con.addRequestProperty("User-Agent", "Mozilla/4.76");
  771. +           isr = new InputStreamReader(con.getInputStream());
  772. +           br = new BufferedReader(isr);
  773. +          
  774. +           String line;
  775. +           while ((line = br.readLine()) != null)
  776. +           {
  777. +               if (line.contains("<li><span class=\"rank anonymous tooltip\""))
  778. +               {
  779. +                   int votes = Integer.valueOf(line.replaceAll("[^\\d]", ""));
  780. +                   return votes;
  781. +               }
  782. +           }
  783. +          
  784. +           br.close();
  785. +           isr.close();
  786. +       }
  787. +       catch (Exception e)
  788. +       {
  789. +           System.out.println(e);
  790. +           System.out.println("Error while getting server vote count.");
  791. +       }
  792. +      
  793. +       return -1;
  794. +   }
  795. +}
  796. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement