Jump to content
  • 0

[HELP] Autovote system error in Eclipse...


Question

Posted

I have this auto vote system:

Index: dist/game/config/l2jmods.properties
===================================================================
--- dist/game/config/l2jmods.properties	(revision 5038)
+++ dist/game/config/l2jmods.properties	(working copy)

@@ -456,7 +459,67 @@
# Default: 127.0.0.1,0 (no limits from localhost)
DualboxCheckWhitelist = 127.0.0.1,0

+
# ---------------------------------------------------------------------------
+# Vote System
+# ---------------------------------------------------------------------------
+
+# Enable vote system?
+EnableVoteSystem = true
+
+#Hopzone = true / Topzone = false
+VoteSystemHopzone = true
+
+# Save Votes in Database?
+# Recomendable true if you Shutdown/Restart the server.
+SaveVotesIntoDataBase = true
+
+# Vote Page URL.
+# Working/Tested in HopZone.
+VoteSystemPage = http://l2.hopzone.net/lineage2/details/74078/L2World-Servers
+
+# Reward players every xxx votes.
+VoteSystemVotes = 10
+
+# Frist Check delay.
+# In Seconds.
+VoteSystemStartCheckTime = 60
+
+# Continue Check delay.
+# In Seconds.
+VoteSystemRunCheckTime = 120
+
+# Items Rewards ID.
+# Separated whit a ",".
+VoteSystemItemID = 57,20034
+
+# Items Rewards Count.
+# Separated whit a ",".
+VoteSystemItemCount = 1000,2
\ No newline at end of file
Index: java/com/l2jserver/gameserver/GameServer.java
===================================================================
--- java/com/l2jserver/gameserver/GameServer.java	(revision 5038)
+++ java/com/l2jserver/gameserver/GameServer.java	(working copy)
@@ -79,6 +79,7 @@
import com.l2jserver.gameserver.instancemanager.AirShipManager;
import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
import com.l2jserver.gameserver.instancemanager.AuctionManager;
+import com.l2jserver.gameserver.instancemanager.AutoVoteRewardManager;
import com.l2jserver.gameserver.instancemanager.BoatManager;
import com.l2jserver.gameserver.instancemanager.CHSiegeManager;
import com.l2jserver.gameserver.instancemanager.CastleManager;

@@ -311,6 +314,11 @@
		BoatManager.getInstance();
		AirShipManager.getInstance();
		GraciaSeedsManager.getInstance();
+                if(Config.VOTE_SYSTEM_ENABLE == true){
+		AutoVoteRewardManager.getInstance();
+		}

		try
		{
Index: java/com/l2jserver/gameserver/instancemanager/AutoVoteRewardManager.java
===================================================================
--- java/com/l2jserver/gameserver/instancemanager/AutoVoteRewardManager.java	(revision 0)
+++ java/com/l2jserver/gameserver/instancemanager/AutoVoteRewardManager.java	(revision 0)
@@ -0,0 +1,222 @@
+package com.l2jserver.gameserver.instancemanager;
+    
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+    
+import com.l2jserver.Config;
+import com.l2jserver.L2DatabaseFactory;
+import com.l2jserver.gameserver.Announcements;
+import com.l2jserver.gameserver.ThreadPoolManager;
+import com.l2jserver.gameserver.model.L2World;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+    
+public class AutoVoteRewardManager
+{
+   private static Logger _log = Logger.getLogger(AutoVoteRewardManager.class.getName());
+       
+   private static final int initialCheck  = Config.VOTE_SYSTEM_START_TIME * 1000;
+   private static final int delayForCheck = Config.VOTE_SYSTEM_CHECK_TIME * 1000;
+   private int votesneed;
+   
+   private static List<String> _ips = new ArrayList<String>();
+   private static int lastVoteCount = 0;
+      
+   private AutoVoteRewardManager()
+   {
+       _log.info("AutoVoteRewardManager: Vote reward system initiated.");
+       if (Config.VOTE_SYSTEM_DATABASE_SAVE)
+           load();
+       ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck, delayForCheck);
+   }
+      
+   private class AutoReward implements Runnable
+   {
+       @Override
+	public void run()
+       {
+           int votes = getVotes();
+           _log.info("AutoVoteRewardManager: Current Votes: " + getVotes());
+           _log.info("AutoVoteRewardManager: Votes needed: "+(getLastVoteCount()+Config.VOTE_SYSTEM_COUNT));
+           _log.info("AutoVoteRewardManager: Next Check in: "+(delayForCheck/1000)+" sec.");
+           Announcements.getInstance().announceToAll("Vote for us in HopZone!");
+           
+           if (votes >= getLastVoteCount() + Config.VOTE_SYSTEM_COUNT)
+           {
+        	   Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers().valueCollection();
+               {
+                   for (L2PcInstance onlinePlayer : pls)
+                   {
+                       if (onlinePlayer.isOnline() && !onlinePlayer.getClient().isDetached() && !_ips.contains(onlinePlayer.getClient().getConnection().getInetAddress().getHostAddress()))
+                       {
+                    	   String[] parase = Config.VOTE_SYSTEM_ITEM_ID.split(",");
+                    	   String[] parase3 = Config.VOTE_SYSTEM_ITEM_COUNT.split(",");
+                    	   for(int o = 0; o <parase.length; o++){
+                    		   int parase2 = Integer.parseInt(parase[o]);
+                    		   int parase4 = Integer.parseInt(parase3[o]);
+                           for (int i = 0; i < parase.length; i++)
+                           {
+                               onlinePlayer.addItem("vote_reward", parase2, parase4, onlinePlayer, true);
+                           }
+                    	   }
+                           _ips.add(onlinePlayer.getClient().getConnection().getInetAddress().getHostAddress());
+                       }
+                   }
+               }
+               _log.info("AutoVoteRewardManager: All players has been rewared!");
+               Announcements.getInstance().announceToAll("Thanks for vote, you has been rewarded!");
+               setLastVoteCount(getLastVoteCount() + Config.VOTE_SYSTEM_COUNT);
+           }
+                
+           if (getLastVoteCount() == 0)
+           {
+               setLastVoteCount(votes);
+           }
+           else if ((getLastVoteCount() + Config.VOTE_SYSTEM_COUNT) - votes > Config.VOTE_SYSTEM_COUNT || votes > (getLastVoteCount() + Config.VOTE_SYSTEM_COUNT))
+           {
+               setLastVoteCount(votes);
+           }
+           votesneed = (getLastVoteCount()+Config.VOTE_SYSTEM_COUNT) - votes;
+           if(votesneed == 0){
+        	   votesneed = Config.VOTE_SYSTEM_COUNT;
+           }
+           Announcements.getInstance().announceToAll("Need " + votesneed + " votes more to reward all players.");
+           _ips.clear();
+       }
+   }
+      
+   private int getVotes()
+   {
+       URL url = null;
+       InputStreamReader isr = null;
+       BufferedReader in = null;
+       try
+       {
+           url = new URL(Config.VOTE_SYSTEM_PAGE);
+           URLConnection con = url.openConnection();
+           con.addRequestProperty("User-Agent", "Mozilla/4.76"); 
+           isr = new InputStreamReader(con.getInputStream());
+           in = new BufferedReader(isr);
+           String inputLine;
+           while ((inputLine = in.readLine()) != null)
+           {
+        	   if(Config.VOTE_SYSTEM_HOPZONE == false){
+        	   //TopZone
+        	   if(inputLine.contains("<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">")){
+        	   String i = inputLine.replace("<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">", "");
+        	   i = i.replace("</font></b></div></td></tr>", "");
+        	   i = i.trim();
+        	   int o = Integer.parseInt(i);
+        	   return Integer.valueOf(o);
+        	   }
+        	   } else {
+        	                 //for hopzone
+               if (inputLine.contains("Anonymous User Votes"))
+                   return Integer.valueOf(inputLine.split(">")[2].replace("</span", ""));
+
+               }
+           }
+       }
+       catch (IOException e)
+       {
+           _log.warning("AutoVoteRewardHandler: "+e);
+       }
+       finally
+       {
+           try
+           {
+               in.close();
+           }
+           catch (IOException e)
+           {}
+           try
+           {
+               isr.close();
+           }
+           catch (IOException e)
+           {}
+       }
+       return 0;
+   }
+      
+   private void setLastVoteCount(int voteCount)
+   {
+       lastVoteCount = voteCount;
+   }
+      
+   private int getLastVoteCount()
+   {
+       return lastVoteCount;
+   }
+   
+   private void load()
+   {
+       int votes = 0;
+       Connection con = null;
+       try
+       {
+           con = L2DatabaseFactory.getInstance().getConnection();
+           PreparedStatement statement = con.prepareStatement("SELECT vote FROM votes LIMIT 1");
+           ResultSet rset = statement.executeQuery();
+
+           while (rset.next())
+           {
+               votes = rset.getInt("vote");
+           }
+           rset.close();
+           statement.close();
+       }
+       catch (Exception e)
+       {
+           _log.log(Level.WARNING, "data error on vote: ", e);
+       }
+       finally
+       {
+           L2DatabaseFactory.close(con);
+       }
+      
+       setLastVoteCount(votes);
+   }
+   
+   public void save()
+   {
+       Connection con = null;
+       try
+       {
+           con = L2DatabaseFactory.getInstance().getConnection();
+           PreparedStatement statement = con.prepareStatement("UPDATE votes SET vote = ? WHERE id=1");
+           statement.setInt(1, getLastVoteCount());
+           statement.execute();
+           statement.close();
+       }
+       catch (Exception e)
+       {
+           _log.log(Level.WARNING, "data error on vote: ", e);
+       }
+       finally
+       {
+           L2DatabaseFactory.close(con);
+       }
+   }
+  
+   public static AutoVoteRewardManager getInstance()
+   {
+       return SingletonHolder._instance;
+   }
+      
+   @SuppressWarnings("synthetic-access")
+   private static class SingletonHolder
+   {
+       protected static final AutoVoteRewardManager _instance = new AutoVoteRewardManager();
+   }
+}
\ No newline at end of file
Index: java/com/l2jserver/Config.java
===================================================================
--- java/com/l2jserver/Config.java	(revision 5038)
+++ java/com/l2jserver/Config.java	(working copy)

@@ -763,6 +764,26 @@
	public static int L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP;
	public static int L2JMOD_DUALBOX_CHECK_MAX_L2EVENT_PARTICIPANTS_PER_IP;
	public static TIntIntHashMap L2JMOD_DUALBOX_CHECK_WHITELIST;
+        public static boolean VOTE_SYSTEM_ENABLE;
+	public static boolean VOTE_SYSTEM_HOPZONE;
+	public static boolean VOTE_SYSTEM_DATABASE_SAVE;
+	public static String VOTE_SYSTEM_PAGE;
+	public static int VOTE_SYSTEM_COUNT;
+	public static int VOTE_SYSTEM_START_TIME;
+	public static int VOTE_SYSTEM_CHECK_TIME;
+	public static String VOTE_SYSTEM_ITEM_ID;
+	public static String VOTE_SYSTEM_ITEM_COUNT;



	//--------------------------------------------------

@@ -2628,7 +2649,17 @@

					L2WALKER_PROTECTION = Boolean.parseBoolean(L2JModSettings.getProperty("L2WalkerProtection", "False"));
					L2JMOD_DEBUG_VOICE_COMMAND = Boolean.parseBoolean(L2JModSettings.getProperty("DebugVoiceCommand", "False"));
-
+					
+					VOTE_SYSTEM_ENABLE = Boolean.parseBoolean(L2JModSettings.getProperty("EnableVoteSystem", "False"));
+					VOTE_SYSTEM_HOPZONE = Boolean.parseBoolean(L2JModSettings.getProperty("VoteSystemHopzone", "true"));
+					VOTE_SYSTEM_DATABASE_SAVE = Boolean.parseBoolean(L2JModSettings.getProperty("SaveVotesIntoDataBase", "true"));
+					VOTE_SYSTEM_PAGE = L2JModSettings.getProperty("VoteSystemPage", "");
+					VOTE_SYSTEM_COUNT = Integer.parseInt(L2JModSettings.getProperty("VoteSystemVotes", "10"));
+					VOTE_SYSTEM_START_TIME = Integer.parseInt(L2JModSettings.getProperty("VoteSystemStartCheckTime", "60"));
+					VOTE_SYSTEM_CHECK_TIME = Integer.parseInt(L2JModSettings.getProperty("VoteSystemRunCheckTime", "120"));
+					VOTE_SYSTEM_ITEM_ID = L2JModSettings.getProperty("VoteSystemItemID", "57, 1000");
+					VOTE_SYSTEM_ITEM_COUNT = L2JModSettings.getProperty("VoteSystemItemCount", "1000, 1");
+	
					L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP = Integer.parseInt(L2JModSettings.getProperty("DualboxCheckMaxPlayersPerIP", "0"));
					L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP = Integer.parseInt(L2JModSettings.getProperty("DualboxCheckMaxOlympiadParticipantsPerIP", "0"));
					L2JMOD_DUALBOX_CHECK_MAX_L2EVENT_PARTICIPANTS_PER_IP = Integer.parseInt(L2JModSettings.getProperty("DualboxCheckMaxL2EventParticipantsPerIP", "0"));

Index: java/com/l2jserver/gameserver/Shutdown.java
===================================================================
--- java/com/l2jserver/gameserver/Shutdown.java	(revision 5038)
+++ java/com/l2jserver/gameserver/Shutdown.java	(working copy)
@@ -44,6 +44,7 @@
import com.l2jserver.gameserver.network.serverpackets.ServerClose;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
import com.l2jserver.gameserver.util.Broadcast;
+import com.l2jserver.gameserver.instancemanager.AutoVoteRewardManager;


/**
@@ -543,6 +544,12 @@
		SevenSigns.getInstance().saveSevenSignsStatus();
		_log.info("SevenSigns: Seven Signs status saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");

+		//Save Votes if save votes enable
+		if(Config.VOTE_SYSTEM_DATABASE_SAVE){
+			AutoVoteRewardManager.getInstance().save();
+			_log.info("Vote System: Votes has been saved!!");
+		}
+		
		// Save all raidboss and GrandBoss status ^_^
		RaidBossSpawnManager.getInstance().cleanUp();
		_log.info("RaidBossSpawnManager: All raidboss info saved("+tc.getEstimatedTimeAndRestartCounter()+"ms).");

 

But it gives me some errors in Eclipse: http://imageshack.us/photo/my-images/14/autovoterewardmanager.jpg/

                                                            http://imageshack.us/photo/my-images/197/gameserver.JPG/

 

Anyone can help???

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...