Jump to content

Recommended Posts

Posted

As l2topzone.com updated it's source and hopzone's vote reward does not work for topzone too here is a vote reward,

 

 package net.sf.l2j.gameserver.model;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.Collection;

import javolution.util.FastList;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.Announcements;
import net.sf.l2j.gameserver.GmListTable;
import net.sf.l2j.gameserver.ThreadPoolManager;
import net.sf.l2j.gameserver.model.L2ItemInstance;
import net.sf.l2j.gameserver.model.L2World;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.serverpackets.ExShowScreenMessage;
import net.sf.l2j.gameserver.serverpackets.ExShowScreenMessage.SMPOS;


public class TopzoneVoteRewardHandler
{
private int	lastVoteCount = 0;
private int	initialCheck = 60 * 1000;														
private int	delayForCheck = 300 * 1000;														
private int	votesForReward = 5;
private int	maxRewardStack = 500;

@SuppressWarnings("synthetic-access")
private TopzoneVoteRewardHandler()
{
	System.out.println("Topzone Vote Reward System activated.");
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck, delayForCheck);
}

private class AutoReward implements Runnable
{
	public void run()
	{
		System.out.println("Topzone Vote Count Check.");
		if (Config.TOPZONE_VOTE_REWARD1_ID == 0 || Config.TOPZONE_VOTE_REWARD1_COUNT == 0)
		{
			GmListTable.broadcastMessageToGMs("The rewards aren't Identified. Please take a look.");
			return;
		}
		int newVoteCount = getVotes(Config.TOPZONE_VOTE_HTML_PATCH);
		System.out.println("newVoteCount:"+newVoteCount);
		System.out.println("getLastVoteCount:"+getLastVoteCount());
		if (newVoteCount != 0 && getLastVoteCount() != 0 && newVoteCount >= getLastVoteCount() + votesForReward)
		{
			FastList<InetAddress> ip = new FastList<InetAddress>();
			Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();
			for (L2PcInstance player : pls)
			{
				if (player != null)
				{
					L2ItemInstance item1 = player.getInventory().getItemByItemId(Config.TOPZONE_VOTE_REWARD1_ID);
					if (item1 == null || item1.getCount() < maxRewardStack)
					{
						InetAddress ipc = player.getClient().getConnection().getSocketChannel().socket().getInetAddress();

						if(ip.contains(ipc))
							continue;

						ip.add(ipc);
						player.addItem("reward", Config.TOPZONE_VOTE_REWARD1_ID, Config.TOPZONE_VOTE_REWARD1_COUNT, player, true);
						player.sendMessage("Keep Voting For Us.Rewards given.");
					}
				}
			}	
			setLastVoteCount(getLastVoteCount()+ votesForReward);
		}

		Announcements.getInstance().announceToAll("L2Godrich TopZone : " + newVoteCount + " Votes.");
		Announcements.getInstance().announceToAll("Next reward will be on : " + (getLastVoteCount()+ votesForReward) + " Votes.");
		Collection<L2PcInstance> pls = L2World.getInstance().getAllPlayers();

		if (getLastVoteCount() == 0)
		{
			setLastVoteCount(newVoteCount);
		}
	}
}

static int getVotes(String urlString)
{
	String htmlText = "";
	boolean startAdd = false;
	int voteCount = 0;
	boolean ok = false;
	try
	{
		URL pageToDisplay;
		pageToDisplay = new URL(urlString);
		URLConnection conn = pageToDisplay.openConnection();
		conn.connect();				
		InputStream in = conn.getInputStream();
		BufferedReader br = new BufferedReader(new InputStreamReader(in));
		htmlText = "";
		while(!ok)
		{
			String newLine = br.readLine();
			if (newLine == null)
			{
				ok = true;
			}
			else 
			{
				if (htmlText.length() < 110000)
				{
					if (!startAdd && newLine.indexOf(">Votes<") > 0) 
						startAdd = true;
					if (startAdd && newLine.indexOf(">Uptime<") > 0) 
						startAdd = false;
					if (startAdd) 
						htmlText = htmlText+newLine;
					if (htmlText.length() > 10 && !startAdd) 
						ok = true;					     
				}
			}
		}
		br.close();
	}
	catch (MalformedURLException mfe)
	{
	} 
	catch (IOException e)
	{ 
	}
	htmlText = htmlText.substring(htmlText.indexOf("font-size")+ 31);
	htmlText = htmlText.substring(0,htmlText.indexOf("</font>"));
	try
	{
		voteCount = Integer.parseInt(htmlText);
	}
	catch (NumberFormatException a)
	{
		voteCount = 0;
	}
        return voteCount;
}

private void setLastVoteCount(int voteCount)
{
	lastVoteCount = voteCount;
}

private int getLastVoteCount()
{
	return lastVoteCount;
}

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

@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
	protected static final TopzoneVoteRewardHandler _instance = new TopzoneVoteRewardHandler();
}
}

 

Config.java

public static boolean TOPZONE_VOTE_ENABLE;
public static String TOPZONE_VOTE_HTML_PATCH;
public static int TOPZONE_VOTE_REWARD1_ID;
public static int TOPZONE_VOTE_REWARD2_ID;
public static int TOPZONE_VOTE_REWARD1_COUNT;
public static int TOPZONE_VOTE_REWARD2_COUNT;




TOPZONE_VOTE_ENABLE = Boolean.parseBoolean(Customs.getProperty("TopzoneVoteEnable", "False"));
    			PROTECTED_GAMESERVER = Boolean.parseBoolean(Customs.getProperty("ProtectGameServerWithPassword", "False"));
                TOPZONE_VOTE_HTML_PATCH = Customs.getProperty("TopzoneVoteHtmlPatch", "Null");
			TOPZONE_VOTE_REWARD1_COUNT = Integer.parseInt(Customs.getProperty("TopzoneVoteReward1Count", "1000"));
			TOPZONE_VOTE_REWARD2_COUNT = Integer.parseInt(Customs.getProperty("TopzoneVoteReward2Count", "1000"));
			TOPZONE_VOTE_REWARD1_ID = Integer.parseInt(Customs.getProperty("TopzoneVoteReward1Id", "57"));
			TOPZONE_VOTE_REWARD2_ID = Integer.parseInt(Customs.getProperty("TopzoneVoteReward2Id", "57"));
    			

Do not forget to register this on gameserver.

 

Credits: me

 

PS: it's tested.

  • 2 months later...
  • 2 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

    • Only 3 days left and we'll start with some events, you can check our Discord for more info!
    • Tired of frantically switching between windows trying to find that specific Warlock who should be casting saves? Forgot which server you left your Warsmith on? This mod solves these problems! What it does: Turns the boring window title into an information panel: Server Name - Character Name [Class] Real-life examples: - ServerName - HardcoreFarm [Spoilerr] (who's been spoiling for 3 months already) - ServerName - ClericHelper [Buffer] (eternal buffer on standby) - ServerName - MainChar [Gladiator] (main character who's always AFK) Why you need this: For multiboxers - to avoid confusing where the DD is and where the healer is For the forgetful - if your memory is like a goldfish For streamers - viewers immediately see who's on screen For adults - when playing at work and need to quickly hide the window DLL only - no Interface files needed Installation (more complicated than making tea): 1. Download the DLL 2. Drop it into the System folder 3. Launch the client 4. Be amazed how you lived without this before! Purchase Conditions: Price: 100$ Payment Method: USDT. How to Buy: Contact me on Telegram: @kiselevwv for a quick response. I will answer all your questions and provide additional information if needed. I guarantee functionality at the moment of sale and prompt assistance with setup after purchase.
    • I agree, l2damage crap to compare to l2java which was the father of pvp servers and till this days people playing there for good time.
    • 📝 Registration — Account Registration Creating a new player account. Usually includes: login password password confirmation email Result: a new record is created in the accounts table (loginserver). 🔑 Change Password — Password Change The player changes the password knowing the current one. Required: current password new password new password confirmation Result: the password field is updated in the accounts table. ♻️ Password Recovery — Password Reset If the player forgot the password. Implementation only via email: the player enters their login, email the system sends an email with a link or code the player opens the link / enters the code sets a new password Result: the password is updated in the accounts table.   All fields are validated (required, format, length, uniqueness, security checks).   Price: 80$   and i can rewrite script for PTS server.   Contacts:   Telegram Discord
  • 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..