Jump to content
  • 0

Question

Posted

i am having trouble about  .vote command. if one player type .vote, the entire players in the game have to wait 12 hours.

 

how can i remove all Hwid record from this code without any error : 
i just want to use theese two checking code

ACCOUNT_NAME,
IP_ADRESS,

 

HWID (this code have to gone)

 

image.png.ecfcd84c0f7c617c4f4896203ee39a9f.png

 

package handler.voicecommands;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import l2f.commons.util.Rnd;
import l2f.gameserver.Config;
import l2f.gameserver.ThreadPoolManager;
import l2f.gameserver.database.DatabaseFactory;
import l2f.gameserver.handler.voicecommands.IVoicedCommandHandler;
import l2f.gameserver.handler.voicecommands.VoicedCommandHandler;
import l2f.gameserver.model.GameObjectsStorage;
import l2f.gameserver.model.Player;
import l2f.gameserver.network.serverpackets.Say2;
import l2f.gameserver.network.serverpackets.components.ChatType;
import l2f.gameserver.scripts.Functions;
import l2f.gameserver.scripts.ScriptFile;
import l2f.gameserver.utils.BatchStatement;
import l2f.gameserver.vote.VoteRead;

public class RewardVote implements IVoicedCommandHandler, ScriptFile
{
	private static enum ValueType
	{
		ACCOUNT_NAME,
		IP_ADRESS,
		HWID
	}

	private static final String[] COMMANDS_LIST = new String[] { "vote", "getreward", "getvote", "votereward", "voteme", "fuckvote", "rewardget", "reward", "votereward"};

	// Rewards
	private static final int[][] BLESSED_ENCHANTS_CATEGORY = { { 6673, 1 } };

	private static final int[] PERMANENT_CATEGORY = { 37004, // Vote Rune
			1 };

	private static final int[][] MISC_CATEGORY = { { 37007, 1 }, { 37007, 2 },  { 37007, 3 } };
	private static final double[][] RANDOM_CATEGORY = { { 6577,// 1 Blessed Enchant Weapon S
			1,
			0.05 }, { 6578,// 1 Blessed Enchant Armor S
			1,
			0.05 }, { 13071,// 1 Red Soul Crystal - Stage 16
			1,
			0.05 }, { 13072,// 1 Blue Soul Crystal - Stage 16
			1,
			0.05 }, { 13073,// 1 Green Soul Crystal - Stage 16
			1,
			0.155 }, { 10480,// 1 Red Soul Crystal - Stage 15
			1,
			0.155 }, { 10481,// 1 Blue Soul Crystal - Stage 15
			1,
			0.155 }, { 10482,// 1 Green Soul Crystal - Stage 15
			1,
			0.566 }, { 14169,// 1 Top Life Stone Level 84
			1,
			1.25 }, { 14168,// 1 High Life Stone Level 84
			1,
			2.0 }, { 13073,// 1 Giant's Codex - Mastery
			1,
			3.333 }, { 959,// 1 Enchant Weapon S
			1,
			3.0 }, { 6622,// 1 Giant's Codex
			3,
			8.0 }, { 960,// 1 Enchant Armor S
			1,
			8.0 }, { 9552,// 1 Fire Crystal
			1,
			8.0 }, { 9553,// 1 Water Crystal
			1,
			8.0 }, { 9556,// 1 Dark Crystal
			1,
			8.0 }, { 9557,// 1 Holy Crystal
			1,
			8.0 }, { 9554,// 1 Earth Crystal
			1,
			8.0 }, { 9555,// 1 Wind Crystal
			1,
			8.0 }, { 9546,// 1 Fire Stone
			2,
			20.0 }, { 9547,// 1 Water Stone
			2,
			20.0 }, { 9548,// 1 Earth Stone
			2,
			20.0 }, { 9549,// 1 Wind Stone
			2,
			20.0 }, { 9550,// 1 Dark Stone
			2,
			20.0 }, { 9551,// 1 Holy Stone
			2,
			100.0 }, };

	private static final long VOTE_COMMAND_REUSE = 1 * 3 * 1000L; // 5 Minutes
	private static final long VOTE_PENALTY = 12 * 60 * 60 * 1000L; // 12 Hours

	public static final Map<Integer, Long> _votePlayerReuses = new ConcurrentHashMap<Integer, Long>();
	public static final Map<String, Long> _accountPenalties = new ConcurrentHashMap<String, Long>();
	public static final Map<String, Long> _ipPenalties = new ConcurrentHashMap<String, Long>();
	public static final Map<String, Long> _hwidPenalties = new ConcurrentHashMap<String, Long>();

	public RewardVote()
	{
		// If there is a set vote reward message, schedule it
		if(!Config.VOTE_REWARD_MSG.isEmpty())
			ThreadPoolManager.getInstance().scheduleAtFixedRate(new VoteAnnounceTask(), 1 * 60 * 1000, Config.ANNOUNCE_VOTE_DELAY * 1000);

		// Restore from the db all the penalties of the votes, it doesn't matter if its 0. So we can do it only once at start
		Connection con = null;
		PreparedStatement statement = null;
		ResultSet rset = null;
		try
		{
			con = DatabaseFactory.getInstance().getConnection();
			statement = con.prepareStatement("SELECT * FROM vote_system");

			rset = statement.executeQuery();
			while(rset.next())
			{
				final String value = rset.getString("value");
				final long time = rset.getLong("penalty_time");

				switch(rset.getInt("value_type"))
				{
					// Account Name
					case 0:
					{
						_accountPenalties.put(value, time);
						break;
					}
					// Ip Address
					case 1:
					{
						_ipPenalties.put(value, time);
						break;
					}
					// Hwid
					case 2:
					{
						_hwidPenalties.put(value, time);
						break;
					}
				}
			}
		}
		catch(Exception e)
		{}
	}

	@Override
	public boolean useVoicedCommand(String command, Player activeChar, String params)
	{
		if(command.equalsIgnoreCase("vote"))
		{
			try
			{
				// No connection, no vote
				if(activeChar.getNetConnection() == null)
					return false;

				if(!Config.ENABLE_VOTE)
				{
					activeChar.sendMessage("Voting is currently disabled!");
					return false;
				}

				// Min lvl 40
				if(activeChar.getLevel() < 1)
				{
					activeChar.sendMessage("You need to be at least level 1 to use this command.");
					return false;
				}

				final long currentTime = System.currentTimeMillis();

				// Synerge - Check if voting is not blocked. If a web connection ocurrs, then the vote will be block for everyone for 15 minutes
				if(VoteRead._siteBlockTime >= currentTime)
				{
					activeChar.sendMessage("There are problems with the connection to the vote site, so it has been disabled for some minutes. Try again later");
					return false;
				}

				// Check player vote reuse
				if(activeChar.getAccessLevel() < 1 && _votePlayerReuses.containsKey(activeChar.getObjectId()))
				{
					if(_votePlayerReuses.get(activeChar.getObjectId()) > currentTime)
					{
						activeChar.sendMessage("You can use this command only once every 5 minutes.");
						return false;
					}
				}

				_votePlayerReuses.put(activeChar.getObjectId(), currentTime + VOTE_COMMAND_REUSE);

				// Getting IP of client, here we will have to check for HWID when we have LAMEGUARD
				final String IPClient = activeChar.getIP();
				final String HWID = (activeChar.getHWID() != null ? activeChar.getHWID() : "");

				// Check the penalties of the player to see if he can vote again
				if(!checkPlayerPenalties(activeChar, IPClient, HWID, true))
					return false;

				// Return 0 if he didnt voted. Date when he voted on website
				/*final long dateHeVotedOnWebsite = VoteRead.checkVotedIP(IPClient);
				if(dateHeVotedOnWebsite < 1)
				{
					activeChar.sendMessage("To claim reward, you need to vote on all banners!");
					return false;
				}*/

				if (!hasVoted(activeChar)) {
					activeChar.sendMessage("To claim reward, you need to vote!");
					return false;
				}


				// Add the vote penalty to the player
				addNewPlayerPenalty(activeChar, IPClient, HWID);

				// Give the rewards
				giveRewards(activeChar);
				activeChar.sendMessage("Successfully rewarded.");

				return true;
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		return false;
	}

	// Thread to send to all players that didn't voted yet to vote for the server
	protected static class VoteAnnounceTask implements Runnable
	{
		@Override
		public void run()
		{
			if(Config.VOTE_REWARD_MSG.isEmpty())
				return;

			final Say2 announce = new Say2(0, ChatType.ANNOUNCEMENT, "", Config.VOTE_REWARD_MSG);

			final Iterable<Player> world = GameObjectsStorage.getAllPlayersForIterate();
			for(Player player : world)
			{
				if(player == null || player.getNetConnection() == null)
					continue;

				// No offline or store mode
				if(player.isInStoreMode())
					continue;

				// If the player has an active penalty means that he already voted
				if(!checkPlayerPenalties(player, player.getIP(), player.getHWID(), false))
					continue;

				player.sendPacket(announce);
			}
		}
	}

	/**
	 * Gives to the player all the vote rewards
	 *
	 * @param player
	 */
	protected static void giveRewards(Player player)
	{
		// First give the permanent item
		Functions.addItem(player, PERMANENT_CATEGORY[0], PERMANENT_CATEGORY[1], "VoteReward Permanent");

		// First give the vote main random reward
		final int[] reward = getReward();
		Functions.addItem(player, reward[0], reward[1], "VoteReward Main");

		// Then give some random rewards
		for(double[] item : RANDOM_CATEGORY)
		{
			if(Rnd.chance(item[2]))
			{
				Functions.addItem(player, (int) item[0], (long) item[1], "Vote Random Reward");
				return;
			}
		}
	}

	/**
	 * Puts new penalties for the account name, ip and hwid of the player after he succesfully voted
	 *
	 * @param activeChar
	 * @param IPClient
	 * @param HWID
	 */
	protected static void addNewPlayerPenalty(Player activeChar, String IPClient, String HWID)
	{
		final long newPenalty = System.currentTimeMillis() + VOTE_PENALTY;
		_accountPenalties.put(activeChar.getAccountName(), newPenalty);
		_ipPenalties.put(IPClient, newPenalty);
		_hwidPenalties.put(HWID, newPenalty);

		// Also store the penalties in the db
		Connection con = null;
		PreparedStatement statement = null;
		try
		{
			con = DatabaseFactory.getInstance().getConnection();
			statement = BatchStatement.createPreparedStatement(con, "REPLACE INTO vote_system(value_type, value, penalty_time) VALUES (?, ?, ?)");
			final String[] values = new String[] { activeChar.getAccountName(), IPClient, HWID };
			for(ValueType type : ValueType.values())
			{
				statement.setInt(1, type.ordinal());
				statement.setString(2, values[type.ordinal()]);
				statement.setLong(3, newPenalty);
				statement.addBatch();
			}

			statement.executeBatch();
		}
		catch(Exception e)
		{}
	}

	/**
	 * @param activeChar
	 * @param IPClient
	 * @param HwID
	 * @param sendMessage
	 * @return Returns true if the player doesn't have an active penalty after voting
	 */
	protected static boolean checkPlayerPenalties(Player activeChar, String IPClient, String HwID, boolean sendMessage)
	{
		final long accountPenalty = checkPenalty(ValueType.ACCOUNT_NAME, activeChar.getAccountName());
		final long ipPenalty = checkPenalty(ValueType.IP_ADRESS, IPClient);
		final long hwidPenalty = checkPenalty(ValueType.HWID, HwID);

		final int penalty = (int) ((Math.max(accountPenalty, Math.max(ipPenalty, hwidPenalty)) - System.currentTimeMillis()) / (60 * 1000L));

		if(penalty > 0)
		{
			if(sendMessage)
			{
				if(penalty > 60)
				{
					activeChar.sendMessage("You can vote only once every 12 hours. You still have to wait " + (penalty / 60) + " hours " + (penalty % 60) + " minutes.");
				}
				else
				{
					activeChar.sendMessage("You can vote only once every 12 hours. You still have to wait " + penalty + " minutes.");
				}
			}
			return false;
		}
		return true;
	}

	/**
	 * @param type
	 * @param value
	 * @return Returns the penalty of a particular type and value if it exists
	 */
	private static long checkPenalty(ValueType type, String value)
	{
		switch(type)
		{
			case ACCOUNT_NAME:
			{
				if(_accountPenalties.containsKey(value))
					return _accountPenalties.get(value);
				break;
			}
			case IP_ADRESS:
			{
				if(_ipPenalties.containsKey(value))
					return _ipPenalties.get(value);
				break;
			}
			case HWID:
			{
				if(_hwidPenalties.containsKey(value))
					return _hwidPenalties.get(value);
				break;
			}
		}

		return 0;
	}

	public static int[] getReward()
	{
		return MISC_CATEGORY[Rnd.get(MISC_CATEGORY.length)];
	}

	@Override
	public void onLoad()
	{
		VoicedCommandHandler.getInstance().registerVoicedCommandHandler(this);
	}

	@Override
	public void onReload()
	{
		//
	}

	@Override
	public void onShutdown()
	{
		//
	}

	@Override
	public String[] getVoicedCommandList()
	{
		return COMMANDS_LIST;
	}

	// New Topzone Vote Reward System (API)

	public String getApiEndpoint(Player player) {
		return String.format("https://api.l2topzone.com/v1/vote?token=%s&ip=%s", Config.VOTE_TOPZONE_APIKEY, player.getIP());
	}

	public boolean hasVoted(Player player) {
		try {
			String endpoint = getApiEndpoint(player);
			if (endpoint.startsWith("err"))
				return false;
			String voted = grabValue(getApiResponse(endpoint), "\"isVoted\":", ",\"serverTime\"");
			return tryParseBool(voted);
		} catch (Exception e) {
			player.sendMessage("Something went wrong. Please try again later.");
			e.printStackTrace();
		}
		return false;
	}

	public boolean tryParseBool(String bool) {
		if (bool.startsWith("1"))
			return true;

		CharSequence cs = "voteTime";
		if (bool.contains(cs)) {
			//System.out.println("Contains \"voteTime\"");
			String newbool = bool.substring(0, 4);
			//System.out.println("Bool to pass: " + newbool);
			return Boolean.parseBoolean(newbool);
		}

		return Boolean.parseBoolean(bool.trim());
	}

	public String getApiResponse(String endpoint) {
		StringBuilder stringBuilder = new StringBuilder();

		try {
			URL url = new URL(endpoint);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.addRequestProperty("User-Agent", "Mozilla/4.76");
			connection.setRequestMethod("GET");

			connection.setReadTimeout(5 * 1000);
			connection.connect();

			try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
				String line = null;
				while ((line = reader.readLine()) != null) {
					stringBuilder.append(line + "\n");
				}
			}
			connection.disconnect();
			System.out.println(stringBuilder.toString());//
			return stringBuilder.toString();
		} catch (Exception e) {
			System.out.println("Something went wrong in VoteBase::getApiResponse");
			e.printStackTrace();
			return "err";
		}
	}

	private static String grabValue(String str, String open, String close) {
		final int INDEX_NOT_FOUND = -1;
		if (str == null || open == null || close == null) {
			return null;
		}
		int start = str.indexOf(open);
		if (start != INDEX_NOT_FOUND) {
			int end = str.indexOf(close, start + open.length());
			if (end != INDEX_NOT_FOUND) {
				return str.substring(start + open.length(), end);
			}
		}
		return null;
	}
}

 

3 answers to this question

Recommended Posts

  • 0
Posted
DELETE FROM vote_system WHERE value_type=2;

Execute this query from Navicat or phpMyAdmin.

package handler.voicecommands;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

import l2f.commons.util.Rnd;
import l2f.gameserver.Config;
import l2f.gameserver.ThreadPoolManager;
import l2f.gameserver.database.DatabaseFactory;
import l2f.gameserver.handler.voicecommands.IVoicedCommandHandler;
import l2f.gameserver.handler.voicecommands.VoicedCommandHandler;
import l2f.gameserver.model.GameObjectsStorage;
import l2f.gameserver.model.Player;
import l2f.gameserver.network.serverpackets.Say2;
import l2f.gameserver.network.serverpackets.components.ChatType;
import l2f.gameserver.scripts.Functions;
import l2f.gameserver.scripts.ScriptFile;
import l2f.gameserver.utils.BatchStatement;
import l2f.gameserver.vote.VoteRead;

public class RewardVote implements IVoicedCommandHandler, ScriptFile
{
	private static enum ValueType
	{
		ACCOUNT_NAME,
		IP_ADRESS
	}

	private static final String[] COMMANDS_LIST = new String[] { "vote", "getreward", "getvote", "votereward", "voteme", "fuckvote", "rewardget", "reward", "votereward"};

	// Rewards
	private static final int[][] BLESSED_ENCHANTS_CATEGORY = { { 6673, 1 } };

	private static final int[] PERMANENT_CATEGORY = { 37004, // Vote Rune
			1 };

	private static final int[][] MISC_CATEGORY = { { 37007, 1 }, { 37007, 2 },  { 37007, 3 } };
	private static final double[][] RANDOM_CATEGORY = { { 6577,// 1 Blessed Enchant Weapon S
			1,
			0.05 }, { 6578,// 1 Blessed Enchant Armor S
			1,
			0.05 }, { 13071,// 1 Red Soul Crystal - Stage 16
			1,
			0.05 }, { 13072,// 1 Blue Soul Crystal - Stage 16
			1,
			0.05 }, { 13073,// 1 Green Soul Crystal - Stage 16
			1,
			0.155 }, { 10480,// 1 Red Soul Crystal - Stage 15
			1,
			0.155 }, { 10481,// 1 Blue Soul Crystal - Stage 15
			1,
			0.155 }, { 10482,// 1 Green Soul Crystal - Stage 15
			1,
			0.566 }, { 14169,// 1 Top Life Stone Level 84
			1,
			1.25 }, { 14168,// 1 High Life Stone Level 84
			1,
			2.0 }, { 13073,// 1 Giant's Codex - Mastery
			1,
			3.333 }, { 959,// 1 Enchant Weapon S
			1,
			3.0 }, { 6622,// 1 Giant's Codex
			3,
			8.0 }, { 960,// 1 Enchant Armor S
			1,
			8.0 }, { 9552,// 1 Fire Crystal
			1,
			8.0 }, { 9553,// 1 Water Crystal
			1,
			8.0 }, { 9556,// 1 Dark Crystal
			1,
			8.0 }, { 9557,// 1 Holy Crystal
			1,
			8.0 }, { 9554,// 1 Earth Crystal
			1,
			8.0 }, { 9555,// 1 Wind Crystal
			1,
			8.0 }, { 9546,// 1 Fire Stone
			2,
			20.0 }, { 9547,// 1 Water Stone
			2,
			20.0 }, { 9548,// 1 Earth Stone
			2,
			20.0 }, { 9549,// 1 Wind Stone
			2,
			20.0 }, { 9550,// 1 Dark Stone
			2,
			20.0 }, { 9551,// 1 Holy Stone
			2,
			100.0 }, };

	private static final long VOTE_COMMAND_REUSE = 1 * 3 * 1000L; // 5 Minutes
	private static final long VOTE_PENALTY = 12 * 60 * 60 * 1000L; // 12 Hours

	public static final Map<Integer, Long> _votePlayerReuses = new ConcurrentHashMap<Integer, Long>();
	public static final Map<String, Long> _accountPenalties = new ConcurrentHashMap<String, Long>();
	public static final Map<String, Long> _ipPenalties = new ConcurrentHashMap<String, Long>();

	public RewardVote()
	{
		// If there is a set vote reward message, schedule it
		if(!Config.VOTE_REWARD_MSG.isEmpty())
			ThreadPoolManager.getInstance().scheduleAtFixedRate(new VoteAnnounceTask(), 1 * 60 * 1000, Config.ANNOUNCE_VOTE_DELAY * 1000);

		// Restore from the db all the penalties of the votes, it doesn't matter if its 0. So we can do it only once at start
		Connection con = null;
		PreparedStatement statement = null;
		ResultSet rset = null;
		try
		{
			con = DatabaseFactory.getInstance().getConnection();
			statement = con.prepareStatement("SELECT * FROM vote_system");

			rset = statement.executeQuery();
			while(rset.next())
			{
				final String value = rset.getString("value");
				final long time = rset.getLong("penalty_time");

				switch(rset.getInt("value_type"))
				{
					// Account Name
					case 0:
					{
						_accountPenalties.put(value, time);
						break;
					}
					// Ip Address
					case 1:
					{
						_ipPenalties.put(value, time);
						break;
					}
				}
			}
		}
		catch(Exception e)
		{}
	}

	@Override
	public boolean useVoicedCommand(String command, Player activeChar, String params)
	{
		if(command.equalsIgnoreCase("vote"))
		{
			try
			{
				// No connection, no vote
				if(activeChar.getNetConnection() == null)
					return false;

				if(!Config.ENABLE_VOTE)
				{
					activeChar.sendMessage("Voting is currently disabled!");
					return false;
				}

				// Min lvl 40
				if(activeChar.getLevel() < 1)
				{
					activeChar.sendMessage("You need to be at least level 1 to use this command.");
					return false;
				}

				final long currentTime = System.currentTimeMillis();

				// Synerge - Check if voting is not blocked. If a web connection ocurrs, then the vote will be block for everyone for 15 minutes
				if(VoteRead._siteBlockTime >= currentTime)
				{
					activeChar.sendMessage("There are problems with the connection to the vote site, so it has been disabled for some minutes. Try again later");
					return false;
				}

				// Check player vote reuse
				if(activeChar.getAccessLevel() < 1 && _votePlayerReuses.containsKey(activeChar.getObjectId()))
				{
					if(_votePlayerReuses.get(activeChar.getObjectId()) > currentTime)
					{
						activeChar.sendMessage("You can use this command only once every 5 minutes.");
						return false;
					}
				}

				_votePlayerReuses.put(activeChar.getObjectId(), currentTime + VOTE_COMMAND_REUSE);

				// Getting IP of client.
				final String IPClient = activeChar.getIP();

				// Check the penalties of the player to see if he can vote again
				if(!checkPlayerPenalties(activeChar, IPClient, true))
					return false;

				// Return 0 if he didnt voted. Date when he voted on website
				/*final long dateHeVotedOnWebsite = VoteRead.checkVotedIP(IPClient);
				if(dateHeVotedOnWebsite < 1)
				{
					activeChar.sendMessage("To claim reward, you need to vote on all banners!");
					return false;
				}*/

				if (!hasVoted(activeChar)) {
					activeChar.sendMessage("To claim reward, you need to vote!");
					return false;
				}


				// Add the vote penalty to the player
				addNewPlayerPenalty(activeChar, IPClient);

				// Give the rewards
				giveRewards(activeChar);
				activeChar.sendMessage("Successfully rewarded.");

				return true;
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		return false;
	}

	// Thread to send to all players that didn't voted yet to vote for the server
	protected static class VoteAnnounceTask implements Runnable
	{
		@Override
		public void run()
		{
			if(Config.VOTE_REWARD_MSG.isEmpty())
				return;

			final Say2 announce = new Say2(0, ChatType.ANNOUNCEMENT, "", Config.VOTE_REWARD_MSG);

			final Iterable<Player> world = GameObjectsStorage.getAllPlayersForIterate();
			for(Player player : world)
			{
				if(player == null || player.getNetConnection() == null)
					continue;

				// No offline or store mode
				if(player.isInStoreMode())
					continue;

				// If the player has an active penalty means that he already voted
				if(!checkPlayerPenalties(player, player.getIP(), false))
					continue;

				player.sendPacket(announce);
			}
		}
	}

	/**
	 * Gives to the player all the vote rewards
	 *
	 * @param player
	 */
	protected static void giveRewards(Player player)
	{
		// First give the permanent item
		Functions.addItem(player, PERMANENT_CATEGORY[0], PERMANENT_CATEGORY[1], "VoteReward Permanent");

		// First give the vote main random reward
		final int[] reward = getReward();
		Functions.addItem(player, reward[0], reward[1], "VoteReward Main");

		// Then give some random rewards
		for(double[] item : RANDOM_CATEGORY)
		{
			if(Rnd.chance(item[2]))
			{
				Functions.addItem(player, (int) item[0], (long) item[1], "Vote Random Reward");
				return;
			}
		}
	}

	/**
	 * Puts new penalties for the account name, ip and hwid of the player after he succesfully voted
	 *
	 * @param activeChar
	 * @param IPClient
	 */
	protected static void addNewPlayerPenalty(Player activeChar, String IPClient)
	{
		final long newPenalty = System.currentTimeMillis() + VOTE_PENALTY;
		_accountPenalties.put(activeChar.getAccountName(), newPenalty);
		_ipPenalties.put(IPClient, newPenalty);

		// Also store the penalties in the db
		Connection con = null;
		PreparedStatement statement = null;
		try
		{
			con = DatabaseFactory.getInstance().getConnection();
			statement = BatchStatement.createPreparedStatement(con, "REPLACE INTO vote_system(value_type, value, penalty_time) VALUES (?, ?, ?)");
			final String[] values = new String[] { activeChar.getAccountName(), IPClient};
			for(ValueType type : ValueType.values())
			{
				statement.setInt(1, type.ordinal());
				statement.setString(2, values[type.ordinal()]);
				statement.setLong(3, newPenalty);
				statement.addBatch();
			}

			statement.executeBatch();
		}
		catch(Exception e)
		{}
	}

	/**
	 * @param activeChar
	 * @param IPClient
	 * @param sendMessage
	 * @return Returns true if the player doesn't have an active penalty after voting
	 */
	protected static boolean checkPlayerPenalties(Player activeChar, String IPClient, boolean sendMessage)
	{
		final long accountPenalty = checkPenalty(ValueType.ACCOUNT_NAME, activeChar.getAccountName());
		final long ipPenalty = checkPenalty(ValueType.IP_ADRESS, IPClient);

		final int penalty = (int) ((Math.max(accountPenalty, ipPenalty) - System.currentTimeMillis()) / (60 * 1000L));

		if(penalty > 0)
		{
			if(sendMessage)
			{
				if(penalty > 60)
				{
					activeChar.sendMessage("You can vote only once every 12 hours. You still have to wait " + (penalty / 60) + " hours " + (penalty % 60) + " minutes.");
				}
				else
				{
					activeChar.sendMessage("You can vote only once every 12 hours. You still have to wait " + penalty + " minutes.");
				}
			}
			return false;
		}
		return true;
	}

	/**
	 * @param type
	 * @param value
	 * @return Returns the penalty of a particular type and value if it exists
	 */
	private static long checkPenalty(ValueType type, String value)
	{
		switch(type)
		{
			case ACCOUNT_NAME:
			{
				if(_accountPenalties.containsKey(value))
					return _accountPenalties.get(value);
				break;
			}
			case IP_ADRESS:
			{
				if(_ipPenalties.containsKey(value))
					return _ipPenalties.get(value);
				break;
			}
		}

		return 0;
	}

	public static int[] getReward()
	{
		return MISC_CATEGORY[Rnd.get(MISC_CATEGORY.length)];
	}

	@Override
	public void onLoad()
	{
		VoicedCommandHandler.getInstance().registerVoicedCommandHandler(this);
	}

	@Override
	public void onReload()
	{
		//
	}

	@Override
	public void onShutdown()
	{
		//
	}

	@Override
	public String[] getVoicedCommandList()
	{
		return COMMANDS_LIST;
	}

	// New Topzone Vote Reward System (API)

	public String getApiEndpoint(Player player) {
		return String.format("https://api.l2topzone.com/v1/vote?token=%s&ip=%s", Config.VOTE_TOPZONE_APIKEY, player.getIP());
	}

	public boolean hasVoted(Player player) {
		try {
			String endpoint = getApiEndpoint(player);
			if (endpoint.startsWith("err"))
				return false;
			String voted = grabValue(getApiResponse(endpoint), "\"isVoted\":", ",\"serverTime\"");
			return tryParseBool(voted);
		} catch (Exception e) {
			player.sendMessage("Something went wrong. Please try again later.");
			e.printStackTrace();
		}
		return false;
	}

	public boolean tryParseBool(String bool) {
		if (bool.startsWith("1"))
			return true;

		CharSequence cs = "voteTime";
		if (bool.contains(cs)) {
			//System.out.println("Contains \"voteTime\"");
			String newbool = bool.substring(0, 4);
			//System.out.println("Bool to pass: " + newbool);
			return Boolean.parseBoolean(newbool);
		}

		return Boolean.parseBoolean(bool.trim());
	}

	public String getApiResponse(String endpoint) {
		StringBuilder stringBuilder = new StringBuilder();

		try {
			URL url = new URL(endpoint);
			HttpURLConnection connection = (HttpURLConnection) url.openConnection();
			connection.addRequestProperty("User-Agent", "Mozilla/4.76");
			connection.setRequestMethod("GET");

			connection.setReadTimeout(5 * 1000);
			connection.connect();

			try (BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
				String line = null;
				while ((line = reader.readLine()) != null) {
					stringBuilder.append(line + "\n");
				}
			}
			connection.disconnect();
			System.out.println(stringBuilder.toString());//
			return stringBuilder.toString();
		} catch (Exception e) {
			System.out.println("Something went wrong in VoteBase::getApiResponse");
			e.printStackTrace();
			return "err";
		}
	}

	private static String grabValue(String str, String open, String close) {
		final int INDEX_NOT_FOUND = -1;
		if (str == null || open == null || close == null) {
			return null;
		}
		int start = str.indexOf(open);
		if (start != INDEX_NOT_FOUND) {
			int end = str.indexOf(close, start + open.length());
			if (end != INDEX_NOT_FOUND) {
				return str.substring(start + open.length(), end);
			}
		}
		return null;
	}
}

 

  • Thanks 1
Guest
This topic is now closed to further replies.


  • Posts

    • General Trackers :   IPTorrents invite IPTorrents account 1 tb TorrentLeech invite Torrentleech account 1 tb buffer  InTheShaDow ( ITS ) account Acid-lounge invite Torrentday invite Crnaberza account Abn.Lol account Limit-of-eden account Norbits account Xspeeds account Xspeeds invite Bemaniso invite Wigornot account Bithumen invite Filelist account Funfile invite AvistaZ invite Potuk.net invite ResurrectThe.Net invite GrabThe.Info invite Greek-Team invite LinkoManija invite Fano.in account tracker.czech-server.com Speed.cd invite Arab-torrents.net account Arabscene.me account Scenetime account 4thd.xyz invite Btarg.com.ar account Dedbit invite Estone.cc account Speedapp invite Finvip invite Fluxzone account GigaTorrents account Gimmepeers account Haidan.video invite Mojblink account Mycarpathians invite Newinsane.info account Oscarworld.xyz account Peers.FM invite Pt.msg.vg account Ransackedcrew account Redemption invite Scene-rush account Seedfile.io invite Teracod invite Torrent.ai account Torrentmasters invite Ttsweb invite X-files invite X-ite invite Ncore account TorrentHR account Rptorrents account BwTorrents account Superbits invite Krazyzone account Immortalseed account Tntracker invite Pt.eastgame.org account Bitturk account Rstorrent account Tracker.btnext invite Torrent-turk.de account BeiTai.PT account Pt.keepfrds account 52pt.site account Pthome account Torrentseeds account Aystorrent account Blues-brothers.biz invite Divteam account Thesceneplace invite CinemaMovies.pl account Brasiltracker account Patiodebutacas account Newheaven.nl account  Swarmazon.club invite Bc-reloaded account Crazyspirits account Silentground invite Omg.wtftrackr invite Milkie.cc invite Breathetheword invite Madsrevolution account Chilebt account Yubraca account Uniongang.tv account Frboard account Exvagos account Diablotorrent account Microbit account Carp-hunter.hu account Majomparade.eu account Theshinning.me account Youiv.info account Dragonworld-reloaded account Sharewood.tv account Partis.si account Digitalcore.club invite Fuzer.me account R3vuk.wtf invite Ztracker account 1 tb buffer 3changtrai account Best-core.info account Bitsite.us account Eliteunitedcrew invite Exitorrent.org account Tophos invite Torrent.lt account Sktorrent.eu account Oshen account Blackhattorrent account Pirata.digital account Esharenet account Ohmenarikgi.la Pirate-share account Immortuos account Kiesbits account Cliente.amigos-share.club account Broadcity invite Ilovetorzz account Torrentbytes account Polishsource account Portugas invite Shareisland account ArabaFenice account Hudbt.hust.edu.cn account Audiences account Nanyangpt account Pt.sjtu.edu.cn account Pt.zhixing.bjtu.edu.cn account Byr.pt invite Ptfiles invite Red-bits account Pt.hdpost.top account Irrenhaus.dyndns.dk (NewPropaganda) account Mnvv2.info (MaxNewVision V2) account 1ptba.com account Spidertk.top account Film-paleis account Generation-free account Aftershock-tracker account Twilightsdreams account Back-ups.me invite Sor-next.tk ( Spirit Of Revolution ) account Tfa.tf ( The Falling Angels ) account Hdmayi account S-f-p.dyndns.dk ( Share Friends Projekt ) account Unlimitz.biz account Pttime account St-tracker.eu account New-retro.eu account Zbbit account Tigers-dl.net account Jptvts.us account Lat-team account Club.hares.top account Falkonvision-team account Concen account Drugari account T.ceskeforum account Peeratiko.org account Zamunda.se account Central-torrent.eu account h-o-d.org account Torrentleech.pl account Demonoid invite Lst.gg account Fakedoor.store account LaidBackManor account Vrbsharezone.co.uk invite Torrenteros account Arenaelite account Datascene account Tracker.0day.community Tapochek.net invite Ptchina invite Lesaloon account Exyusubs account Therebels.tv account Ubits.club invite Zmpt.cc account Turktorrent.us account Dasunerwarte account Hawke.uno account Monikadesign account Fearnopeer account Alpharatio account Wukongwendao.top account Chinapyg account Azusa.wiki account Yggtorrent.top account Torrentdd account Cyanbug.net invite Hhanclub.top account Wintersakura.net account Xthor account Tctg.pm account Finelite invite Agsvpt.com account Pt.0ff.cc invite Qingwapt.com account Xingtan.one account Ptcafe.club invite W-o-t.pro account Coastal-crew.bounceme.net account Darkpeers.org account Pianyuan.org account Seedpool.org  account Tempelbox account Pt.itzmx.com account Capybarabr.com account Itatorrents.xyz  account Letseed.org account The-new-fun.com  account Malayabits.cc account Trellas.me account Yu-scene.net account Futuretorrent.org account Bitpt.cn account Tocashare.biz  account Videoteka.org  account White-angel.hu account Xbytesv2.li account   Movies Trackers :   Anthelion account Pixelhd account Cinemageddon account DVDSeed account Cinemageddon account Cinemaz account Retroflix account Classix-unlimited - invite Movie-Torrentz (m2g.link) invite Punck-tracker.net account Tmghub account Tb-asian account Cathode-ray.tube account Greatposterwall account Telly account Arabicsource.net account Upload.cx account Crabpt.vip invite Onlyencodes.cc account Exyusubs account Hellashut.net invite Nordichd.sytes.net invite Locadora.cc account   HD Trackers :   Blutopia buffered account Hd-olimpo buffered account Hdf.world account Torrentland.li account HdSky account Hdchina account Chdbits account Totheglory account Hdroute account Hdhome account TorrentCCF aka et8.org account 3DTorrents invite HD-Torrents account Bit-HDTV account HDME.eu invite Hdarea.co account Asiancinema.me account JoyHD invite HDSpace invite CrazyHD invite Bluebird-hd invite Htpt.cc account Hdtime invite Ourbits.club account Hd4fans account Siambit account Privatehd account Springsunday account Tjupt account Hdcity.leniter invite Ccfbits account Discfan account Pt.btschool.club account Ptsbao.club invite Hdzone.me invite Danishbytes account Zonaq.pw account Tracker.tekno3d account Arabp2p account Hd-united account Reelflix.xyz account Hdatmos.club account Anasch.cc invite Tigris-t account Nethd.org account Hd.ai invite Hitpt.com account Hdmonkey account Dragonhd.xyz account Hdclub.eu account Forum.bluraycd.com account Carpt account Hdfun.me invite Pt.hdupt invite Puntotorrent account Ultrahd account Rousi.zip account Bearbit account Hdturk.club account Asiandvdclub account Star-space.net account Nordicq.org account Hdkyl.in account Utp.to account Hdzero account   Music Trackers :   Dicmusic account Music-Vid account Open.cd account LzTr account ProAudioTorrents invite Jpopsuki invite TranceTraffic invite Audionews invite Kraytracker invite Libble.me invite Losslessclub invite Indietorrents.com invite Dimeadozen account Funkytorrents invite Karaokedl account zombtracker.the-zomb account Concertos account Sugoimusic account Satclubbing.club invite Metal.iplay invite Psyreactor invite Panda.cd account Adamsfile account Freehardmusic account Tracker.hqmusic.vn accouunt Twilightzoom account 3 tb buffer Hiresmusic account Metalguru account Musictorrents.org account Musebootlegs.com invite Zappateers.com account Jungleland.dnsalias.com account Naftamusic account   E-Learning Trackers :   Thevault account BitSpyder invite Brsociety account Learnbits invite Myanonamouse account Libranet account 420Project account Learnflakes account Pt.soulvoice.club account P2pelite account Aaaaarg.fail invite Ebooks-shares.org account Abtorrents account Pt.tu88.men invite Docspedia.world invite   TV-Trackers :   Skipthecommericals Cryptichaven account TV-Vault invite Shazbat.TV account Myspleen account Tasmanit.es invite Tvstore.me account Tvchaosuk account Jptv.club account Tvroad.info   XXX - Porn Trackers :   FemdomCult account Pornbay account Pussytorrents account Adult-cinema-network account Bootytape account 1 Tb buffer Exoticaz account Bitporn account Kufirc account Gaytorrent.ru invite Nicept account Gay-torrents.org invite Ourgtn account Pt.hdbd.us account BitSexy account Happyfappy.org account Kamept.com account Lesbians4u.org account   Gaming Trackers :   Mteam.fr account BitGamer invite Retrowithin invite Gamegamept account   Cartoon/Anime/Comic Trackers :   Animeworld account Oldtoons.world account U2.dmhy account CartoonChaos invite Animetorrents account Mononoke account Totallykids.tv account Bakabt.me invite Revanime account Ansktracker account Tracker.shakaw.com.br invite Bt.mdan.org account Skyey2.com account Animetracker.cc Adbt.it.cx invite Tracker.uniotaku.com account Mousebits.com account   Sports Trackers :   MMA-Tracker invite T3nnis.tv invite AcrossTheTasman account RacingForMe invite Sportscult invite Ultimatewrestlingtorrents account Worldboxingvideoarchive invite CyclingTorrents account Xtremewrestlingtorrents account Tc-boxing invite Mma-torrents account Aussierul invite Xwt-classics account Racing4everyone account Talk.tenyardtracker account Stalker.societyglitch invite Extremebits invite Rgfootball.net account F1carreras.xyz account   Software/Apps Trackers :   Brokenstones account Appzuniverse invite Teamos.xyz account Macbb.org account   Graphics Trackers:   Forum.Cgpersia account Gfxpeers account Forum.gfxdomain account   Documentary Trackers:   Forums.mvgroup account   Others   Fora.snahp.eu account Board4all.biz account Filewarez.tv account Makingoff.org/forum account Xrel.to account Undergunz.su account Corebay account Endoftheinter.net ( EOTI ) account Thismight.be invite Skull.facefromouter.space account Avxhm.se (AvaxHome) account Ssdforum account Notfake.vip account Intotheinter.net account Tildes.net invite Thetoonz account Usinavirtual account Hdclasico invite HispaShare account Valentine.wtf account Adit-hd account Forum-andr.net account Warezforums account Justanothermusic.site account Forbiddenlibrary.moe account Senturion.to account Movieparadise account Militaryzone account Dcdnet.ru account Sftdevils.net account Heavy-r.com account New-team.org account Ddl.tv account Filewarez.club account Hispamula.org account Hubwarez.tv account   NZB :   Ninjacentral.co.za account Tabula-rasa.pw account Drunkenslug account Drunkenslug invite Usenet-4all account Brothers-of-Usenet account Dognzb.cr invite Kleverig account Nzb.cat account Nzbplanet.net invite Ng4you.com account Nzbsa.co.za account Bd25.eu account NZB.to account Samuraiplace account Abhdtv.net account Abook.link account Comix.pw account House-of-usenet Secretbinaries.net account Vnext.to account Stockboxx.top account Sky-of-use.net account Prices start from 3 $ to 100 $   Payment methods: Crypto, Neteller, Webmoney, Revolut   If you want to buy something send me a pm or contact me on:   Email: morrison2102@gmail.com   Discord: LFC4LIFE#4173   Telegram: https://t.me/LFC4LIFE4173   Skype: morrison2102@hotmail.com
    • It removes the AA (Anti-Cheat) protection from the files, converting them from binary/encrypted formats into readable and editable ones. This is the first step for any client modification.
    • you need to move the contents of the staticmeshes/maps/textures folders of the respective screens and replace your existing files. If you are using interlude, you need to rename the .unr file to lobby.unr first. Or conversely if the file is already named lobby.unr and you wanna use it on h5, you rename it to lobby01.unr. Some might work, some might not, it's trial and error. Make backups of your client.
  • 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..