AutoVoteReward problem

Results 1 to 11 of 11
  1. #1
    Enthusiast Nokz is offline
    MemberRank
    Dec 2008 Join Date
    /homeLocation
    33Posts

    AutoVoteReward problem

    i found a file for l2jfrozen.. but i trying to do it for l2jserver:

    location: scripts\custom\votereward\AutoVoteRewardHandler.java
    Code:
    package custom.AutoVoteRewardHandler;
    
    import java.util.regex.*;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.logging.Logger;
    
    import com.l2jserver.gameserver.model.L2World;
    import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
    import com.l2jserver.gameserver.Announcements;
    import com.l2jserver.gameserver.ThreadPoolManager;
    
    public class AutoVoteRewardHandler
    {
            private static Logger _log = Logger.getLogger(AutoVoteRewardHandler.class.getName());
    
    		private final static String SERVER_WEB_SITE = "http://myWeb.tk";
    		private final static String SiteUrl = "http://myWeb/findVotes.php";
    		private final static int VOTES_FOR_REWARD = 10;
    		private final static int _INITIAL_DELAY = 1*60000;
    		private final static int _STEP_DELAY = 10*60000;
    		
    		//Item Id, Amount.
    		private final static int RW_ITEM = 14721;
    		private final static int RW_COUNT = 1;
    		
    		
            private int hopzoneVotesCount = 0;
            private List<String> already_rewarded;
            
            private static boolean hopzone = false;
    		private final boolean ALL_EXCEPTIONS = true;
            
            private AutoVoteRewardHandler()
            {
                _log.info("Vote Reward System Initiated.");
                    
    			if(hopzone){
    				int hopzone_votes = getHopZoneVotes();
    				
    				if(hopzone_votes == -1){
    						hopzone_votes = 0;
    				}
    				
    				setHopZoneVoteCount(hopzone_votes);
    			}
    			
    			ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), _INITIAL_DELAY , _STEP_DELAY );
            }
    		
    		private class AutoReward implements Runnable
            {
                    @Override
                    public void run()
                    {
    					int minutes = ( _STEP_DELAY / 1000 ) / 60;
    					
    					if(hopzone){
    						int hopzone_votes = getHopZoneVotes();
    							
    						if(hopzone_votes != -1){
    							_log.info("[AutoVoteReward] Server HOPZONE Votes: " + hopzone_votes);
    							Announcements.getInstance().announceToAll("[AutoVoteReward] Actual HOPZONE Votes are " + hopzone_votes + "...");
    							
    							if (hopzone_votes != 0 && hopzone_votes >= getHopZoneVoteCount() + VOTES_FOR_REWARD)
    							{
    								already_rewarded = new ArrayList<String>();
    								
    								Announcements.getInstance().announceToAll("[AutoVoteReward] Great Work! Check your inventory for Reward!!");
    								
    								L2PcInstance[] pls = L2World.getInstance().getAllPlayers().getValues(new L2PcInstance[0]);
    								
    								//L2ItemInstance item;
    								for (L2PcInstance player : pls)
    								{
    									if (player != null && !player.getClient().isDetached())
    									{
    										if(player.isOnline() && checkSingleBox(player)){
    												
    											if(player.getInventory().validateCapacityByItemId(RW_ITEM))
    											{
    												player.addItem("reward", RW_ITEM, RW_COUNT, player, true);
    											}
    										}
    									}
    								}
    								setHopZoneVoteCount(hopzone_votes);
    							}
    							Announcements.getInstance().announceToAll("[AutoVoteReward] Next HOPZONE Reward in "+minutes+" minutes at " + (getHopZoneVoteCount() + VOTES_FOR_REWARD) + " Votes!!");
    							//site web
    							Announcements.getInstance().announceToAll("[SiteWeb] "+SERVER_WEB_SITE);
    								
    						}
    							
    					}
                                    
    					if(hopzone && _STEP_DELAY > 0)
    						try
    						{
    							Thread.sleep(_INITIAL_DELAY/2);
    						}
    						catch(InterruptedException e)
    						{
    							if(ALL_EXCEPTIONS)
    									e.printStackTrace();
    						}
                            
                    }
            }
    		
            private boolean checkSingleBox(L2PcInstance player){
                    
    			if(player.getClient()!=null && player.getClient().getConnection()!=null && !player.getClient().getConnection().isClosed() && !player.getClient().isDetached()){
    					
    				String playerip = player.getClient().getConnection().getInetAddress().getHostAddress();
    				
    				if(already_rewarded.contains(playerip))
    						return false;
    				already_rewarded.add(playerip);
    				return true;
    			}
                    
    			//if no connection (maybe offline shop) dnt reward
    			return false;
            }
    		
    		private int getHopZoneVotes()
            {
    			int votes = -1;
    			URL url = null;
    			InputStreamReader isr = null;
    			BufferedReader in = null;
    			try
    			{
    				url = new URL(SiteUrl);
    				URLConnection con = url.openConnection();    
    				con.addRequestProperty("User-Agent", "Mozilla/4.76");               
    				isr = new InputStreamReader(con.getInputStream());                  
    				in = new BufferedReader(isr);
    				String inputLine;
    				
    				inputLine = in.readLine();
    				Pattern p = Pattern.compile("[0-9]");
    				Matcher m = p.matcher(inputLine);
    				
    				if ( m.find() ){
    					int o = Integer.parseInt(inputLine);
    					votes = Integer.valueOf(o);
    				}
    			}
    			catch (Exception e)
    			{
    				_log.info("[AutoVoteReward] Server HOPZONE is offline or something is wrong in link");
    				Announcements.getInstance().announceToAll("[AutoVoteReward] HOPZONE is offline. We will check reward as it will be online again");
    				//e.printStackTrace();
    			}
    			finally
    			{
    				try
    				{
    						if(in!=null)
    								in.close();
    				}
    				catch (Exception e)
    				{
    						if(ALL_EXCEPTIONS)
    								e.printStackTrace();
    				}
    				try
    				{
    						if(isr!=null)
    								isr.close();
    				}
    				catch (Exception e)
    				{
    						if(ALL_EXCEPTIONS)
    								e.printStackTrace();
    				}
    			}
                return votes;
            }
    		
            private void setHopZoneVoteCount(int voteCount)
            {
                    hopzoneVotesCount = voteCount;
            }
    
            private int getHopZoneVoteCount()
            {
                    return hopzoneVotesCount;
            }
    
            public static AutoVoteRewardHandler getInstance()
            {
                    if(SiteUrl != null && !SiteUrl.equals("")){
                            hopzone = true;
                    }
                    
                    if(hopzone)
                            return SingletonHolder._instance;
                    return null;
            }
    		
            @SuppressWarnings("synthetic-access")
            private static class SingletonHolder
            {
                    protected static final AutoVoteRewardHandler    _instance       = new AutoVoteRewardHandler();
            }
    }
    findVotes.php:
    PHP Code:
    <?php
    //here vote url:
    $url 'http://l2.hopzone.net/lineage2/details/YourIDHopzone/NameServer';


    function 
    Obtener_contenidos($url,$inicio='',$final){
        
    $source = @file_get_contents($url)or die('se ha producido un error');
        
    $posicion_inicio strpos($source$inicio) + strlen($inicio);
        
    $posicion_final strpos($source$final) - $posicion_inicio;
        
    $found_text substr($source$posicion_inicio$posicion_final);
    return 
    $inicio $found_text .$final;
    }

    function 
    Obtener_contenidos2($url,$inicio='',$final){

        
    $posicion_inicio strpos($url$inicio) + strlen($inicio);    
        
    $posicion_final strpos($url$final) - $posicion_inicio;
        
    $found_text substr($url$posicion_inicio$posicion_final);
        
    return 
    $inicio $found_text .$final;
    }

    $startFind="<span class=\"rank anonymous tooltip\" title=\"Anonymous User Votes\">";
    $EndFind="[0-9]+</span>";

    //take part of hopzone html code
    $obtenido Obtener_contenidos($url$startFind$EndFind);

    $startFind2="<span";
    $EndFind2="</span>";

    //clean all HTML/text/others to print only votes. (numbres)
    echo preg_replace("/[^0-9]/"""Obtener_contenidos2($obtenido$startFind2$EndFind2));
    ?>
    error log from AutoVoteRewardHandler.java:
    Code:
    Error on: D:\server\game\data\scripts\custom\votereward\AutoVoteRewardHandler.java.error.log
    Line: -1 - Column: -1
    
    java.lang.ClassNotFoundException: custom.VoteEngine.AutoVoteRewardHandler
    whats wrong?..
    i edited that code from: here


  2. #2
    ~ksemer~ DaRkAnGeL is offline
    MemberRank
    Oct 2006 Join Date
    Java_HomeLocation
    5,115Posts

    Re: AutoVoteReward problem

    this code is not a character handler but a gameserver handler. so it works every few mins for all the players. you must not add them in dp but in core

  3. #3
    Enthusiast Nokz is offline
    MemberRank
    Dec 2008 Join Date
    /homeLocation
    33Posts

    Re: AutoVoteReward problem

    Quote Originally Posted by DaRkAnGeL View Post
    this code is not a character handler but a gameserver handler. so it works every few mins for all the players. you must not add them in dp but in core
    the problem is im working with server files from 11.01.2012(dd-mm-yyyy) and i don't have a copy of them witouth coplie.
    i need to update it again.. but if i do that, i will lost a lot of scripts there.. coz they didnt work with the new l2jserver update

  4. #4
    Enthusiast cmec is offline
    MemberRank
    Oct 2008 Join Date
    31Posts

    Re: AutoVoteReward problem

    Quote Originally Posted by ZorroCS View Post
    the problem is im working with server files from 11.01.2012(dd-mm-yyyy) and i don't have a copy of them witouth coplie.
    i need to update it again.. but if i do that, i will lost a lot of scripts there.. coz they didnt work with the new l2jserver update
    decompile java;
    insert script;
    compile java with script;
    and u will not loose any scripts u have implemented before

  5. #5
    Enthusiast Nokz is offline
    MemberRank
    Dec 2008 Join Date
    /homeLocation
    33Posts

    Re: AutoVoteReward problem

    Quote Originally Posted by cmec View Post
    decompile java;
    insert script;
    compile java with script;
    and u will not loose any scripts u have implemented before
    decompile java;? how?

  6. #6
    Enthusiast cmec is offline
    MemberRank
    Oct 2008 Join Date
    31Posts

    Re: AutoVoteReward problem

    a bit of googling will help..
    u need to decompile only 1 file core.jar
    implement script and compile it again

    or use some editors which opens .class files without decompiling all thing
    Last edited by cmec; 01-02-12 at 09:14 PM.

  7. #7
    ~ksemer~ DaRkAnGeL is offline
    MemberRank
    Oct 2006 Join Date
    Java_HomeLocation
    5,115Posts

    Re: AutoVoteReward problem

    Quote Originally Posted by ZorroCS View Post
    the problem is im working with server files from 11.01.2012(dd-mm-yyyy) and i don't have a copy of them witouth coplie.
    i need to update it again.. but if i do that, i will lost a lot of scripts there.. coz they didnt work with the new l2jserver update
    why do not you update it manually?

  8. #8
    Enthusiast Nokz is offline
    MemberRank
    Dec 2008 Join Date
    /homeLocation
    33Posts

    Re: AutoVoteReward problem

    Quote Originally Posted by DaRkAnGeL View Post
    why do not you update it manually?
    don't know how to do that.. (i have edited like 200+ items, skills, default npcs)
    and i trying to learn how to all ^^"
    i get errors evry were when i try to update somthing like core, tables or datapak (or all same time).
    tables mysql, isnt my problem coz im php/mysql programer...
    but java is not easly for me

  9. #9
    ~ksemer~ DaRkAnGeL is offline
    MemberRank
    Oct 2006 Join Date
    Java_HomeLocation
    5,115Posts

    Re: AutoVoteReward problem

    Quote Originally Posted by ZorroCS View Post
    don't know how to do that.. (i have edited like 200+ items, skills, default npcs)
    and i trying to learn how to all ^^"
    i get errors evry were when i try to update somthing like core, tables or datapak (or all same time).
    tables mysql, isnt my problem coz im php/mysql programer...
    but java is not easly for me
    you can try with the easy way and edit whatever they edited in each change log

  10. #10
    Enthusiast Nokz is offline
    MemberRank
    Dec 2008 Join Date
    /homeLocation
    33Posts

    Re: AutoVoteReward problem

    Fixed, thanks DaRkAnGeL, cmec

  11. #11
    ~ksemer~ DaRkAnGeL is offline
    MemberRank
    Oct 2006 Join Date
    Java_HomeLocation
    5,115Posts

    Re: AutoVoteReward problem

    you are welcome , closed



Advertisement