Jump to content

Recommended Posts

Posted

Hallo This Java Code In By Vampirekiller L2Shax  Server

 

net.sf.l2j.gameserver.model

add New Class Name AutoVoteRewardHandler.java

 

package net.sf.l2j.gameserver.model;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import net.sf.l2j.Config;
import net.sf.l2j.L2DatabaseFactory;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.datatables.ItemTable;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.util.Broadcast;

public class AutoVoteRewardHandler
{
  private final int initialCheck = Config.VOTE_INIT_CHECK;

  private final int delayForCheck = Config.VOTE_DELAY;

  private String server_name = "";

  private final int votesRequiredForReward = Config.VOTE_DIFF;

  private static int lastVoteCount = 0;

  private AutoVoteRewardHandler(Object object)
  {
    System.out.println("Vote Reward System Initiated.");
    ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(null), initialCheck, delayForCheck);
  }

  private int getVotes()
  {
    URL url = null;
    InputStreamReader isr = null;
    BufferedReader in = null;
    try
    {
      url = new URL(Config.VOTE_URL);

      if (Config.VOTE_DEBUG_PARSE) System.out.println("HTML Parse-------------------------------------");

      isr = new InputStreamReader(url.openStream());
      in = new BufferedReader(isr);
      String inputLine;
      while ((inputLine = in.readLine()) != null)
      {
        if (Config.VOTE_DEBUG_PARSE) System.out.println(inputLine);
        if (inputLine.contains(">Votes<")) {
          inputLine = in.readLine();
          if (Config.VOTE_DEBUG_PARSE) System.out.println("-------------->" + inputLine.split(">")[5].replace("</font", ""));
          int i = Integer.valueOf(inputLine.split(">")[5].replace("</font", "")).intValue();
          return i;
        }
      }
    }
    catch (IOException e)
    {
      ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(null), initialCheck, delayForCheck);
      System.out.println("Server Votes: Site Down");
      if (Config.VOTE_DEBUG) e.printStackTrace();
    }
    finally
    {
      try
      {
        in.close();
      }
      catch (IOException e)
      {
      }
      try {
        isr.close();
      }
      catch (IOException e) {
      }
    }
    return 0;
  }

  private int getVotesForFirstPage(int topn)
  {
    URL url = null;
    InputStreamReader isr = null;
    BufferedReader in = null;
    try
    {
      url = new URL(Config.VOTE_LIST);
      isr = new InputStreamReader(url.openStream());
      in = new BufferedReader(isr);

      if (Config.VOTE_DEBUG_PARSE) System.out.println("HTML First Page Parse-------------------------------------");
      String inputLine;
      while ((inputLine = in.readLine()) != null)
      {
        if (Config.VOTE_DEBUG_PARSE) System.out.println(inputLine);
        if (inputLine.contains("<td><div align=\"center\">" + topn + "</div></td>")) {
          for (int i = 0; i < 3; i++) inputLine = in.readLine();
          server_name = inputLine.split("\"")[1];
          if (Config.VOTE_DEBUG_PARSE) System.out.println("First page parse ServerName-->" + server_name);
          for (int i = 0; i < 2; i++) inputLine = in.readLine();
          if (Config.VOTE_DEBUG_PARSE) System.out.println("First page parse FirstPage Last Server Votes-->" + inputLine.split(">")[2].replace("</div", ""));
          int i = Integer.valueOf(inputLine.split(">")[2].replace("</div", "")).intValue();
          return i;
        }
      }
    }
    catch (IOException e)
    {
      ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(null), initialCheck, delayForCheck);
      System.out.println("Server Votes: Site Down");
      if (Config.VOTE_DEBUG) e.printStackTrace();
    }
    finally
    {
      try
      {
        in.close();
      }
      catch (IOException e)
      {
      }
      try {
        isr.close();
      }
      catch (IOException e) {
      }
    }
    return 0;
  }

  public static void setLastVoteCount(int voteCount)
  {
    lastVoteCount = voteCount;
  }

  public static void onShutdown() throws SQLException {
    Connection con = null;
    try
    {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement("UPDATE Votes SET count = " + lastVoteCount);

      statement.execute();
      statement.close();
    }
    catch (SQLException e)
    {
      e.printStackTrace();
    }
    finally
    {
    	con.close();
    }
  }

  public static int getLastVoteCount()
  {
    return lastVoteCount;
  }

  public static void onStartup() throws SQLException {
    int count = 0;
    Connection con = null;
    try
    {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement("SELECT * FROM Votes");

      ResultSet rset = statement.executeQuery();
      while (rset.next())
      {
        count = rset.getInt("count");
      }

      rset.close();
      statement.close();
    }
    catch (SQLException e)
    {
      e.printStackTrace();
    }
    finally
    {
    	con.close();
    }

    setLastVoteCount(count);
  }

  public static AutoVoteRewardHandler getInstance()
  {
    return SingletonHolder._instance;
  }

  private static class SingletonHolder
  {
    protected static final AutoVoteRewardHandler _instance = new AutoVoteRewardHandler(null);
  }

  private class AutoReward
    implements Runnable
  {
    private AutoReward(Object object)
    {
    }

    public void run()
    {
      int votes = AutoVoteRewardHandler.this.getVotes();
      int votes_frs = AutoVoteRewardHandler.this.getVotesForFirstPage(Config.VOTE_TOP);
      if ((votes < AutoVoteRewardHandler.getLastVoteCount()) || (AutoVoteRewardHandler.getLastVoteCount() <= 0)) {
        AutoVoteRewardHandler.setLastVoteCount(votes);
      }
      System.out.println("Server Votes: " + votes + " - For First Page: " + (votes_frs - votes));
      if (Config.VOTE_DEBUG) {
        System.out.println("URL: " + Config.VOTE_URL);
        System.out.println("vote diff: " + AutoVoteRewardHandler.this.votesRequiredForReward);
        for (int[] reward : Config.VOTE_REWARDS)
          System.out.println("Reward Low : " + reward[0] + "-" + reward[1]);
        for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
          System.out.println("Reward High : " + reward[0] + "-" + reward[1]);
      }
      if (!Config.VOTE_DEBUG) {
        if ((votes != 0) && (AutoVoteRewardHandler.getLastVoteCount() != 0) && (votes >= AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward))
        {
          Connection con = null;
          try
          {
            con = L2DatabaseFactory.getInstance().getConnection();
            PreparedStatement statement = con.prepareStatement("SELECT\tc.obj_Id,\tc.char_name FROM \tcharacters AS c LEFT JOIN \taccounts AS a ON \tc.account_name = a.login WHERE \tc.online > 0 ORDER BY \tc.level DESC");

            ResultSet rset = statement.executeQuery();
            L2PcInstance player = null;

            if ((votes < votes_frs) || ((votes == votes_frs) && (!Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name)))) {
              Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", Config.VOTE_TEXT_SMALL_WIN));
              System.out.println("Server Votes: SMALL Rewarded at " + votes);
            }while (rset.next())
            {
              player = L2World.getInstance().getPlayer(rset.getInt("obj_Id"));
              if ((player == null) ||
             (player.isOffline())) continue;
              for (int[] reward : Config.VOTE_REWARDS)
              {
                player.addItem("Vote Reward", reward[0], reward[1], player, false);
                SystemMessage systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
                systemMessage.addItemName(reward[0]);
                systemMessage.addNumber(reward[1]);
                player.sendPacket(systemMessage);
              continue;
              
              }
              if ((votes <= votes_frs) && ((votes != votes_frs) || (!Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name)))) break;
              Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", Config.VOTE_TEXT_BIG_WIN));
              System.out.println("Server Votes: BIG Rewarded at " + votes);
              while (rset.next())
              {
                player = L2World.getInstance().getPlayer(rset.getInt("obj_Id"));
                if ((player == null) || 
                  (player.isOffline())) continue;
                for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
                {
                  player.addItem("Vote Reward", reward[0], reward[1], player, false);
                  SystemMessage systemMessage = new SystemMessage(SystemMessageId.EARNED_S2_S1_S);
                  systemMessage.addItemName(reward[0]);
                  systemMessage.addNumber(reward[1]);
                  player.sendPacket(systemMessage);
                }

              }

            }

            rset.close();
            statement.close();
          }
          catch (SQLException e)
          {
            e.printStackTrace();
          }
          finally
          {
			try {
				con.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

          }

          AutoVoteRewardHandler.setLastVoteCount(AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward);
        }

        if ((votes < votes_frs) || ((votes == votes_frs) && (!Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name))))
        {
          String msg = Config.VOTE_TEXT_CURRENT;
          msg = msg.replaceAll("%votes%", Integer.toString(votes));
          msg = msg.replaceAll("%votesRequiredForReward%", Integer.toString(AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward - votes));
          int count = 0;
          for (int[] reward : Config.VOTE_REWARDS)
          {
            msg = msg + reward[1] + " " + ItemTable.getInstance().getTemplate(reward[0]).getName();
            count++;
            if (count != Config.VOTE_REWARDS.size())
              msg = msg + ", ";
          }
          msg = msg + ")";

          Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", msg));

          msg = Config.VOTE_TEXT_FOR_FIRSTPAGE;
          msg = msg.replaceAll("%votes_frs%", Integer.toString(votes_frs - votes + 1));
          count = 0;
          for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
          {
            msg = msg + reward[1] + " " + ItemTable.getInstance().getTemplate(reward[0]).getName();
            count++;
            if (count != Config.VOTE_REWARDS_FIRST_PAGE.size())
              msg = msg + ", ";
          }
          msg = msg + ")";
          Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", msg));
        }
        else if ((votes > votes_frs) || ((votes == votes_frs) && (Config.VOTE_URL.equals(AutoVoteRewardHandler.this.server_name)))) {
          String msg = "Votes now: " + votes + ". " + (AutoVoteRewardHandler.getLastVoteCount() + AutoVoteRewardHandler.this.votesRequiredForReward - votes) + " Votes left at TopZone until next reward (";

          int count = 0;
          for (int[] reward : Config.VOTE_REWARDS_FIRST_PAGE)
          {
            msg = msg + reward[1] + " " + ItemTable.getInstance().getTemplate(reward[0]).getName();
            count++;
            if (count != Config.VOTE_REWARDS_FIRST_PAGE.size())
              msg = msg + ", ";
          }
          msg = msg + ")";

          Broadcast.toAllOnlinePlayers(new CreatureSay(1, 3, "Vote System", msg));
        }
      }
    }
  }
}

 

net.sf.l2j Config.java

  public static boolean VOTE_ENABLE;
  public static boolean VOTE_DEBUG;
  public static boolean VOTE_DEBUG_PARSE;
  public static String VOTE_URL;
  public static int VOTE_INIT_CHECK;
  public static int VOTE_DELAY;
  public static int VOTE_DIFF;
  public static List<int[]> VOTE_REWARDS;
  public static int VOTE_TOP;
  public static String VOTE_LIST;
  public static List<int[]> VOTE_REWARDS_FIRST_PAGE;
  public static String VOTE_TEXT_SMALL_WIN;
  public static String VOTE_TEXT_BIG_WIN;
  public static String VOTE_TEXT_CURRENT;
  public static String VOTE_TEXT_FOR_FIRSTPAGE;

 

    		      VOTE_ENABLE = Boolean.parseBoolean(votereward.getProperty("VoteEnable", "false"));
    		      VOTE_DEBUG = Boolean.parseBoolean(votereward.getProperty("VoteDebug", "false"));
    		      VOTE_DEBUG_PARSE = Boolean.parseBoolean(votereward.getProperty("VoteDebugParse", "false"));
    		      VOTE_URL = votereward.getProperty("VoteUrl", "");
    		      VOTE_INIT_CHECK = Integer.parseInt(votereward.getProperty("InitCheck", "0"));
    		      VOTE_DELAY = Integer.parseInt(votereward.getProperty("Delay", "0"));
    		      VOTE_DIFF = Integer.parseInt(votereward.getProperty("VoteDiff", "10"));
    		      VOTE_TOP = Integer.parseInt(votereward.getProperty("VoteTop", "10"));
    		      VOTE_REWARDS = new ArrayList<int[]>();

    		      VOTE_TEXT_SMALL_WIN = votereward.getProperty("VoteTextSmallWin", "");
    		      VOTE_TEXT_BIG_WIN = votereward.getProperty("VoteTextBigWin", "");
    		      VOTE_TEXT_CURRENT = votereward.getProperty("VoteCurrent", "");
    		      VOTE_TEXT_FOR_FIRSTPAGE = votereward.getProperty("VoteTextForFirstpage", "");

    		      VOTE_LIST = votereward.getProperty("VoteList", "");
    		      VOTE_REWARDS_FIRST_PAGE = new ArrayList<int[]>();

    		      String[] propertySplit = votereward.getProperty("VoteRewards", "100001,50").split(";");
    		      for (String reward : propertySplit)
    		      {
    		        String[] rewardSplit = reward.split(",");
    		        if (rewardSplit.length != 2) {
    		          _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		        }
    		        else {
    		          try
    		          {
    		            VOTE_REWARDS.add(new int[] { Integer.parseInt(rewardSplit[0]), Integer.parseInt(rewardSplit[1]) });
    		          }
    		          catch (NumberFormatException nfe)
    		          {
    		            if (!reward.isEmpty()) {
    		              _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		            }
    		          }
    		        }
    		      }
    		      propertySplit = votereward.getProperty("VoteRewardsFirstPage", "100001,50").split(";");
    		      for (String reward : propertySplit)
    		      {
    		        String[] rewardSplit = reward.split(",");
    		        if (rewardSplit.length != 2) {
    		          _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		        }
    		        else {
    		          try
    		          {
    		            VOTE_REWARDS_FIRST_PAGE.add(new int[] { Integer.parseInt(rewardSplit[0]), Integer.parseInt(rewardSplit[1]) });
    		          }
    		          catch (NumberFormatException nfe)
    		          {
    		            if (!reward.isEmpty()) {
    		              _log.warning(StringUtil.concat(new String[] { "VoteEngine[Config.load()]: invalid config property -> VoteReward \"", reward, "\"" }));
    		            }
    		          }
    		        }
    		      }

Custom Config

 

#Big Reward TopZone
#Vote Reward System By L2Shax

VoteEnable = False

VoteDebug = false

VoteDebugParse = false

#url to hopzone page
VoteUrl = http://l2topzone.com/lineage2/server-info/6764/L2Luxury.html

#60 * 1000(1000milliseconds = 1 second) = 60seconds
InitCheck = 300000

Working I Test
Delay = 600000

VoteDiff = 1

VoteRewards = 813,5;

VoteTop = 1

VoteList = http://l2topzone.com/lineage2/server-list/top.html

VoteRewardsFirstPage = 813,25;


VoteTextSmallWin = Votes achieved! We are not in first page of TopZone. You will get the SMALL reward in few seconds.

VoteTextBigWin = Votes achieved! We are in first page of TopZone!!! You will get the BIG reward in few seconds.

VoteCurrent = Votes now: %votes%. %votesRequiredForReward% Votes left at TopZone until next reward (

VoteTextForFirstpage = %votes_frs% Votes left at TopZone until the server be on first page and the rewards will be (

  • 5 weeks later...
  • 3 weeks later...
Posted

put the rightful credits that guy only adapted it.

That's the code i took the idea from Setekh. Then re-coded it in a more illegible and cleaner way.

  • 2 weeks later...
  • 1 month later...
  • 5 months later...

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


  • Posts

    • We've added 5% discounts for bulk purchases of Google accounts for orders of 300 or more, and 10% for orders of 500 or more. The discount is applied automatically when you place your order! The discount is indicated in the product title and description for each category.  
    • 🎄 CHRISTMAS EVENT 🎄   ‼️ Information and details: https://forum.l2harbor.com/threads/rozhdestvenskie-xlopoty-christmas-chores.9430/post-171464
    • METATG.ORG Direct Telegram Service Provider A bonus of +7% on every order! *We add 7% more followers than your ordered amount to proactively cover potential drops and guarantee you an honest result." Telegram Followers - Price per 1000 SUBSCRIBERS Subscribers 3 days - $0.10 ~ 8 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 7 days - $0.17 ~ 13.6 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 14 days - $0.20 ~ 16 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 30 days - $0.30 ~ 24 RUB Subscribers. Daily Completion: 200,000,000 Subscribers 60 days - $0.40 ~ 32 RUB Subscribers, 14-day guarantee. Daily Completion: 200,000,000 Subscribers 90 days (Super Fast) - $0.50 ~ 40 RUB Subscribers, 14-day guarantee. Daily Completion: 200,000,000 Subscribers 120 days (Super Fast) - $0.60 ~ 48 RUB Subscribers, 14-day guarantee. Daily Completion: 200,000,000 Subscribers Lifetime (Super Fast) - $0.70 ~ 56 RUB Lifetime Subscribers. 14-day guarantee. Daily Completion: 200,000,000 Telegram Services - Price per 1000 Post Views - $0.06 ~ 5 RUB Reactions - $0.08 ~ 6.5 RUB Bot Starts - $0.10 ~ 8 RUB Bot Starts with referrals - $0.15 ~ 12 RUB DISCOUNTS and CASHBACK for large volumes Direct Supplier. We work from our own accounts with our own software! High execution speed. Multiple payment methods. We work 24/7! Additional discounts are discussed for volumes starting from $1000 per day. SUPPORT 24/7 - TELEGRAM WEBSITE 24/7 - METATG.ORG
    • Added: a brand-new default dashboard template. You can now add multiple game/login server builds. Full support for running both PTS & L2J servers simultaneously, with switching between them. Payment systems: added OmegaPay and Pally (new PayPal-style API). Account history now stores everything: donations, items delivered to characters, referrals, transfers between game accounts, and coin transfers to another master account. Personal Promo Code System: you can create a promo code and assign it to a user or promoter. When donating, a player can enter this promo code to receive bonus coins, and the promo code owner also receives a bonus — all fully configurable in the admin panel.     Look demo site: demo
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock