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

    • Thanks for the collection and the free advertising! These files have been in the public domain for a long time — you just saved people the trouble of searching. A true fan. 😄 Just to clarify for everyone reading: these files have nothing to do with this topic. They are 10+ year old builds, and since various third-party modifications exist in the wild, we cannot guarantee what may have been added or changed in those versions. Use them at your own risk. We have absolutely no judgment toward those who are on a tight budget and can't afford our current builds — these old shared files might genuinely help you get started. Just use them carefully and at your own risk. And please don't judge developers for the mistakes they made early in their careers — every developer goes through stages of growth, and what you see in those old builds is simply a snapshot of where we were back then. We've come a long way since. If you're interested in our older builds, we have a dedicated thread for that with significantly reduced prices — very accessible for any budget. We have also recently resumed full technical support for legacy builds, handled by a separate team that doesn't interfere with our private development direction for larger projects. You can find our legacy builds here: Our OLd L2-scripts Packs Actual revisions Our current private sources are a completely different story — which is exactly what this thread is about. Too bad all your time goes into collecting other people's old code instead of developing your own project. Though judging by "L2MID is currently offline, we will come back soon in 2026" — you clearly have plenty of time on your hands. 😉
    • SHARED alreaxy! Are these files yours? https://fex.net/ru/s/kdop2z4
    • You asked for examples of coping projects, we provided them, you asked for feedback from our clients, some of them wrote their reviews on the same mmodev, what else can I prove to you? you just asked your friends from mmodev to write nasty things, they have never been our customers and never will be, because they are used to downloading only free products and hacking it. You just don't respect the work of others, this is the conclusion that can be drawn from your inflammatory topic on mmodev, where there are many people who once could not buy our assemblies or whom we kicked out of work or for some other reason. But you are completely wrong and you are behaving very lowly. But let it be on your conscience. Good luck, keep busy with your project, and don't interfere with others.
    • I will never use L2J as the basis for my project but what i saw in MMODEV was enough for me. GL    
  • Topics

×
×
  • 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..