Jump to content
  • 0

[Help] Vote reward freya


Question

Posted

Hi i have a problem whit vote reward on my servar...

 

AutoVoteRewardManager: Current Votes: 0

AutoVoteRewardManager: Votes needed: 5

AutoVoteRewardManager: Next Check in: 120 sec.

AutoVoteRewardManager: Current Votes: 0

AutoVoteRewardManager: Votes needed: 5

AutoVoteRewardManager: Next Check in: 120 sec.

 

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().values();
               {
                   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();
   }
}

 

please someone help!

THX

7 answers to this question

Recommended Posts

  • 0
Posted

AutoVoteRewardManager: Current Votes: 0

AutoVoteRewardManager: Votes needed: 5

AutoVoteRewardManager: Next Check in: 120 sec.

AutoVoteRewardManager: Current Votes: 0

AutoVoteRewardManager: Votes needed: 5

AutoVoteRewardManager: Next Check in: 120 sec.

 

this says in server... current votes says is 0 but i have more vote on hopzone

and don't give vote reward

  • 0
Posted

#==============================================================#
#                 Vote System HopZone/TopZone                  #
#==============================================================#
# Enable vote system?
EnableVoteSystem = true
#Hopzone = true / Topzone = true
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/94653/L2End-of-Ages.html
# Reward players every xxx votes.
VoteSystemVotes = 5
# 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

#==============================================================#
#                   TopZone/Vote System                        #
#==============================================================#
# Enable vote system?
TopZoneEnableVoteSystem = true
#Hopzone = true / Topzone = true
TopZoneVoteSystemHopzone = true
# Save Votes in Database?
# Recomendable true if you Shutdown/Restart the server.
TopZoneSaveVotesIntoDataBase = true
# Vote Page URL.
# Working/Tested in HopZone.
TopZoneVoteSystemPage = http://l2.hopzone.net/lineage2/details/94653/L2End-of-Ages.html
# Reward players every xxx votes.
TopZoneVoteSystemVotes = 5
# Frist Check delay.
# In Seconds.
TopZoneVoteSystemStartCheckTime = 60
# Continue Check delay.
# In Seconds.
TopZoneVoteSystemRunCheckTime = 120
# Items Rewards ID.
# Separated whit a ",".
TopZoneVoteSystemItemID = 57,20034
# Items Rewards Count.
# Separated whit a ",".
TopZoneVoteSystemItemCount = 1000,2

 

				// Load VoteReward L2Properties file (if exists)
			try
			{
				L2Properties voterewardSettings = new L2Properties();
				is = new FileInputStream(new File(VOTEREWARD_CONFIG_FILE));
				voterewardSettings.load(is);
				VOTE_SYSTEM_ENABLE = Boolean.parseBoolean(voterewardSettings.getProperty("EnableVoteSystem", "True"));
				VOTE_SYSTEM_HOPZONE = Boolean.parseBoolean(voterewardSettings.getProperty("VoteSystemHopzone", "true"));
				VOTE_SYSTEM_DATABASE_SAVE = Boolean.parseBoolean(voterewardSettings.getProperty("SaveVotesIntoDataBase", "true"));
				VOTE_SYSTEM_PAGE = voterewardSettings.getProperty("VoteSystemPage", "http://l2.hopzone.net/lineage2/details/95594/l2sonsofanarchy");
				VOTE_SYSTEM_COUNT = Integer.parseInt(voterewardSettings.getProperty("VoteSystemVotes", "5"));
				VOTE_SYSTEM_START_TIME = Integer.parseInt(voterewardSettings.getProperty("VoteSystemStartCheckTime", "60"));
				VOTE_SYSTEM_CHECK_TIME = Integer.parseInt(voterewardSettings.getProperty("VoteSystemRunCheckTime", "120"));
				VOTE_SYSTEM_ITEM_ID = voterewardSettings.getProperty("VoteSystemItemID", "57, 1000");
				VOTE_SYSTEM_ITEM_COUNT = voterewardSettings.getProperty("VoteSystemItemCount", "1000, 1");

				TOPZONE_VOTE_SYSTEM_ENABLE = Boolean.parseBoolean(voterewardSettings.getProperty("TopZoneEnableVoteSystem", "true"));
				TOPZONE_VOTE_SYSTEM_HOPZONE = Boolean.parseBoolean(voterewardSettings.getProperty("TopZoneVoteSystemHopzone", "true"));
				TOPZONE_VOTE_SYSTEM_DATABASE_SAVE = Boolean.parseBoolean(voterewardSettings.getProperty("TopZoneSaveVotesIntoDataBase", "true"));
				TOPZONE_VOTE_SYSTEM_PAGE = voterewardSettings.getProperty("TopZoneVoteSystemPage", "");
				TOPZONE_VOTE_SYSTEM_COUNT = Integer.parseInt(voterewardSettings.getProperty("TopZoneVoteSystemVotes", "5"));
				TOPZONE_VOTE_SYSTEM_START_TIME = Integer.parseInt(voterewardSettings.getProperty("TopZoneVoteSystemStartCheckTime", "60"));
				TOPZONE_VOTE_SYSTEM_CHECK_TIME = Integer.parseInt(voterewardSettings.getProperty("TopZoneVoteSystemRunCheckTime", "120"));
				TOPZONE_VOTE_SYSTEM_ITEM_ID = voterewardSettings.getProperty("TopZoneVoteSystemItemID", "57, 1000");
				TOPZONE_VOTE_SYSTEM_ITEM_COUNT = voterewardSettings.getProperty("TopZoneVoteSystemItemCount", "1000, 1");
			}
			catch (Exception e)
			{
				e.printStackTrace();
				throw new Error("Failed to Load "+VOTEREWARD_CONFIG_FILE+" File.");
			}

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..