Jump to content

[Share] Topzone vote reward


Recommended Posts

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.

Link to comment
Share on other sites

  • 2 months later...
  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...