Jump to content
  • 0

[bug] vote reward


Question

Posted

I have a vote reward, but is bugged i don't know why it shows 0 Votes and i have 25 votes

 

package com.l2jserver.gameserver.instancemanager;

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 com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.Announcements;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
import com.l2jserver.gameserver.util.Broadcast;

public class AutoVoteRewardHandler
{
private final String TOPZONE = "http://l2topzone.com/";
// 60 * 1000(1000milliseconds = 1 second) = 60seconds
private final int initialCheck = 60 * 1000;
// 1800 * 1000(1000milliseconds = 1 second) = 1800seconds = 30minutes
private final int delayForCheck = 1800 * 1000;
private final int[] itemId = { 9627, 9142 };
   private final int[] itemCount = { 2, 500 };
private final int[] maxStack = { 2, 500 };
private final int votesRequiredForReward = 10;
// do not change
private int lastVoteCount = 0;

private AutoVoteRewardHandler()
{
	System.out.println("Vote Reward System Initiated.");
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck, delayForCheck);
}

private class AutoReward implements Runnable
{
	public void run()
	{
		int votes = getVotes();
		System.out.println("Server Votes: " + votes);
		if (votes != 0 && getLastVoteCount() != 0 && votes >= getLastVoteCount() + votesRequiredForReward)
		{
			Connection con = null;
			try
			{
				con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement statement = con.prepareStatement("SELECT c.charId, c.char_name FROM characters AS c LEFT JOIN accounts AS a ON c.account_name = a.login WHERE c.online > 0 GROUP BY a.lastIP ORDER BY c.level DESC");
				ResultSet rset = statement.executeQuery();
				L2PcInstance player = null;
				L2ItemInstance item = null;
				while (rset.next())
				{
					player = L2World.getInstance().getPlayer(rset.getInt("charId"));
					if (player != null && !player.getClient().isDetached())
					{
						for (int i = 0; i < itemId.length; i++)
						{
							item = player.getInventory().getItemByItemId(itemId[i]);
							if (item == null || item.getCount() < maxStack[i])
								player.addItem("reward", itemId[i], itemCount[i], player, true);
						}
					}
				}
				statement.close();
		}
			catch (SQLException e)
		{
				e.printStackTrace();
			}
			finally
			{
				L2DatabaseFactory.close(con);
			}

			setLastVoteCount(getLastVoteCount() + votesRequiredForReward);
		}
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.ANNOUNCEMENT, "Announcements:", "Server Votes: " + votes + " | Next Reward on " + (getLastVoteCount() + votesRequiredForReward) + " Votes.)"));
		if (getLastVoteCount() == 0)
			setLastVoteCount(votes);
	}
}

private int getVotes()
{
	URL url = null;
	InputStreamReader isr = null;
	BufferedReader in = null;
	try
	{
		url = new URL(TOPZONE);
		isr = new InputStreamReader(url.openStream());
		in = new BufferedReader(isr);
		String inputLine;
		while ((inputLine = in.readLine()) != null)
		{
			if (inputLine.contains("rank anonymous tooltip"))
			{
				return Integer.valueOf(inputLine.split(">")[2].replace("</span", ""));
			}
		}
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
	finally
	{
		try
		{
			in.close();
		}
		catch (IOException e)
		{}
		try
		{
			isr.close();
		}
		catch (IOException e)
		{}
	}
	return 0;
}

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

private int getLastVoteCount()
{
	return lastVoteCount;
}

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

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

11 answers to this question

Recommended Posts

  • 0
Posted

put this sql in server

-- ----------------------------
-- Table structure for `votes`
-- ----------------------------
DROP TABLE IF EXISTS `votes`;
CREATE TABLE `votes` (
  `id` int(6) NOT NULL,
  `vote` int(6) NOT NULL,
  PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of votes
-- ----------------------------
INSERT INTO votes VALUES ('1', '0');

an tell as

  • 0
Posted

Dirty fix, will work for a while:

			while ((inputLine = in.readLine()) != null)
		{
			if (inputLine.contains("								<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">"))
			{
				return Integer.valueOf(inputLine.replace("								<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">", "").replace("</font></b></div></td></tr>", ""));
			}
		}

 

You need to copy the if statement and replace it in your script.

 

Please don't bump your topic 3 times in a row the same hour.

 

@l22expert do you have any idea of what you posted?

 

  • 0
Posted
package com.l2jserver.gameserver.instancemanager;

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 com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.ThreadPoolManager;
import com.l2jserver.gameserver.model.L2ItemInstance;
import com.l2jserver.gameserver.model.L2World;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.clientpackets.Say2;
import com.l2jserver.gameserver.network.serverpackets.CreatureSay;
import com.l2jserver.gameserver.util.Broadcast;

public class AutoVoteRewardHandler
{
private final String TOPZONE = "http://l2topzone.com";
// 60 * 1000(1000milliseconds = 1 second) = 60seconds
private final int initialCheck = 60 * 1000;
// 1800 * 1000(1000milliseconds = 1 second) = 1800seconds = 30minutes
private final int delayForCheck = 1800 * 1000;
private final int[] itemId = { 9627, 9142 };
    private final int[] itemCount = { 2, 500 };
private final int[] maxStack = { 2, 500 };
private final int votesRequiredForReward = 10;
// do not change
private int lastVoteCount = 0;

private AutoVoteRewardHandler()
{
	System.out.println("Vote Reward System Initiated.");
	ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new AutoReward(), initialCheck, delayForCheck);
}

private class AutoReward implements Runnable
{
	public void run()
	{
		int votes = getVotes();
		System.out.println("Server Votes: " + votes);
		if (votes != 0 && getLastVoteCount() != 0 && votes >= getLastVoteCount() + votesRequiredForReward)
		{
			Connection con = null;
			try
			{
				con = L2DatabaseFactory.getInstance().getConnection();
				PreparedStatement statement = con.prepareStatement("SELECT c.charId, c.char_name FROM characters AS c LEFT JOIN accounts AS a ON c.account_name = a.login WHERE c.online > 0 GROUP BY a.lastIP ORDER BY c.level DESC");
				ResultSet rset = statement.executeQuery();
				L2PcInstance player = null;
				L2ItemInstance item = null;
				while (rset.next())
				{
					player = L2World.getInstance().getPlayer(rset.getInt("charId"));
					if (player != null && !player.getClient().isDetached())
					{
						for (int i = 0; i < itemId.length; i++)
						{
							item = player.getInventory().getItemByItemId(itemId[i]);
							if (item == null || item.getCount() < maxStack[i])
								player.addItem("reward", itemId[i], itemCount[i], player, true);
						}
					}
				}
				statement.close();
		}
			catch (SQLException e)
		{
				e.printStackTrace();
			}
			finally
			{
				L2DatabaseFactory.close(con);
			}

			setLastVoteCount(getLastVoteCount() + votesRequiredForReward);
		}
		Broadcast.toAllOnlinePlayers(new CreatureSay(1, Say2.ANNOUNCEMENT, "Announcements:", "Server Votes: " + votes + " | Next Reward on " + (getLastVoteCount() + votesRequiredForReward) + " Votes.)"));
		if (getLastVoteCount() == 0)
			setLastVoteCount(votes);
	}
}

private int getVotes()
{
	URL url = null;
	InputStreamReader isr = null;
	BufferedReader in = null;
	try
	{
		url = new URL(TOPZONE);
		isr = new InputStreamReader(url.openStream());
		in = new BufferedReader(isr);
		String inputLine;
		while ((inputLine = in.readLine()) != null)
		{
			if (inputLine.contains("								<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">"))
			{
				return Integer.valueOf(inputLine.replace("								<tr><td><div align=\"center\"><b><font style=\"font-size:14px;color:#018BC1;\">", "").replace("</font></b></div></td></tr>", ""));
			}
		}
	}
	catch (IOException e)
	{
		e.printStackTrace();
	}
	finally
	{
		try
		{
			in.close();
		}
		catch (IOException e)
		{}
		try
		{
			isr.close();
		}
		catch (IOException e)
		{}
	}
	return 0;
}

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

private int getLastVoteCount()
{
	return lastVoteCount;
}

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

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

  • 0
Posted

The code is fine, the problem maybe in URL, test with this http://l2topzone.com/lineage2/server-info/3425/L2Worldx20&x1000.html

Should give you 2800+ votes.

 

Also for testing change private final int delayForCheck = 1800 * 1000; to private final int delayForCheck = 30 * 1000; thats initial delay.

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

    • Implemented ingame drop database, craft database, shop database, best farm for desired item
    • Since theres no reaction on MXC anymore, im giving you a downvote for what you’re selling or doing. Honestly, I think you people have lost your minds. What are these prices? Show someone popular who actually uses your services.
    • Adventure returns!! Are you ready to experience the ultimate Improved Classic Lineage II adventure? Our server combines the authentic Classic 2.5 atmosphere with modern gameplay improvements, balanced systems, and long-term progression designed for both hardcore and casual players!  Key Features: - Opening Date: 3rd July 2026 - Time: 20:00 GMT+3 - Mid Rate x3 - Adena x3 - 100% Drop Rate - Quest Reward Adena x3 - Vitality System - Classic Zaken 2.5 Based - Improved Classic Gameplay - Improved Buff System - No Dual Box - No Pay to Win - 7 Members Party System - Dynamic Stages Progression - Reworked Support Classes - Reworked Skills & New Skills - New Skill Visual Effects - Improved Quests & Better Rewards - Daily Missions & Daily Quests - Weekly Solo Instances - In-Game Wiki with .wiki Command - Olympiad Rework - Castle Siege Improvements - Grand Boss & Raid Boss Progression - Low Rate x1 planned around November *Working on Battle Royale Event!* ⚔ Designed to deliver a competitive, rewarding, and long-term Classic experience without destroying the original Lineage II feeling.   Don't forget to check the in-game wiki and discover all the unique features and gameplay improvements we prepared for you! Website: https://l2einhovant.net/en Discord: https://discord.gg/VfNngPrzaf Facebook: https://www.facebook.com/L2EinhovantClassic
    • L2 Editor is a desktop tool for editing Lineage 2 server and client data side by side. It opens L2J Mobius server XML (NPCs, skills, classes, zones, drops, experience), reads and writes the encrypted client data files for skills, NPC names, hunting zones, the minimap, and more, and renders the world map by stitching the client's radar textures and overlaying real zone polygons and NPC spawn points — both of which you can edit by dragging on the map. The NPC editor exposes every field as a structured form with enum dropdowns and includes a 3D point-cloud viewer of the NPC's model decoded straight from the client. The editor is chronicle-aware across 42 builds from Prelude to Orc Village: it decrypts every supported client format, derives which client files exist per chronicle at runtime, and shows a structured drift indicator that names exactly which fields disagree when server and client data drift apart. Built with Tauri, Rust, and React.   I am open to adding support for other server packs as well, if you are interested, send me a message on discord and send me the xml & xsd files   https://github.com/RumDum3/l2-editor    
  • 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..