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

    • Expanding the dominion, the magical Scroll of Escape   The months passed and Orcis dominance over Aden was absolute. Everyone respected his leadership and authority. Now many of his highly ranked soldiers have learned the boat dance of invulnerability but the army had trouble mastering it.    The orc ordered his most loyal engineer, that stranger who his name we still query, to find a way to teach the dance to the solders to turn them into super-soldiers. The stranger searched and search ed and searched, but he could not make the dance easier. For a soldier, with his heavy armor and slow movement was confined to the limits that this shell provided.   But sometimes, the truth hides in simpler things. One day, after testing the dance on the boat many times, the stranger decided to call it a day. But he was too tired to walk back to the city from the Giran Harbor. So he opened his back and used a scroll of escape while still on the boat.  He visited the weapons store, then the church and later decided to go to the west gate of Giran, to do some light sparring with the random villagers.    To his surprise, he could not fight the villagers. Whenever they tried to swing on him, their sword bounced away. And so it came to the strnager, that its not the dance that makes Einhasad bless him with immortality. It's not gods themselves, but an inherent flaw of the mortal world.    And so ... he went to the king, with a bright idea, and a bunch of Scrolls of Escape in hand.   Master I know of a way. And I know of a thousand other ways to trick the gods and gain immortality without dancing infront of them. For it is not the blessing of Einhasad that gives us the gift.    The gods have erred, the world is flawed and only a redesign of the nature's principles can now stop us ...
    • I just found it funny that you reversed the reverse engineer champions. They won't like this for sure.    Anyway, the project vision is very good it is aligned with what the players need and want something that both e-global and l2reborn has failed to provide. These are stable projects, they are not good "games". And players play "games" they don't play "projects".  When no good "games" exist, they flock towards good "projects". Lineage 2 private scene has produced decent projects the last years, but no decent "game". I hope you are the first ones to do so.   Generally there are two axis that Lineage 2 needs to evolve on. Modern gaming concepts and the need to respect the aging player's time. So far, most projects treat these aspects as taboo, they seem so afraid to deviate from what they call "true" Lineage 2. But the reality is that times change, you can't stay static forever, you have to evolve. NCSoft failed,they are not paving the way no more. It is us now, the collective community that have to pave our own pathways. WoW has went the same way, private projects took initiative because the company (while not failed) could not steer the game towards what players want and need in 2026.    For that reason I believe your project is going towards the right direction. The four keystones listed in the vision is what I believe is the community really needs but clearly doesn't understand it wants, because noone so far has give them a glimspe of what is beyond their retail-like garden.    I personally don't respect projects like reborn and e-global. As "games", they are simply trash, regardless of their high professionalism as endeavors. They lack innovation, they lack creativity, they are simply good software products,     
    • Giving up has never been part of my mindset. I respect projects like Reborn and E-Global they've earned their reputation. But every successful project started with people saying it would fail. If everyone gave up because there was competition, nothing new would ever exist. Skepticism is completely fair, and I'm not asking anyone to blindly believe in promises. Judge us by what we release, not by assumptions. That's exactly why we're taking our time instead of rushing something unfinished. At the end of the day, time will tell. I'd rather try to build something different and fail than never try at all.
    • Good luck beating projects like reborn eglobal and other crap l can bet you will give up after 1 year or first grand opening after online drops😁  l am very sceptical if honestly, at least run test server first or make something to show 🙂
    • Dunno, I have a friend who's really good at reverse engineering, so I don't really see a reason for anyone to be mad about it. At the end of the day, if someone has the skills and knowledge to do something, that's just part of the scene. 
  • 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..