Jump to content
  • 0

Auto Vote Reward ->Network


Question

Posted (edited)

l2jfrozen ,Rev:1004, interlude .

 

So hopzone and topzone work ok, network doesnt . I tried to fix it but I cant . What I used for core are these lines

No Console errors.

Just logger that says network is offline.

First try:


	protected int getL2NetworkVotes()
	{
	       int votes = -1;
		
		try
		{
					{
							final URL obj = new URL(PowerPakConfig.VOTES_SITE_L2NETWORK_URL);
							final HttpURLConnection con = (HttpURLConnection) obj.openConnection();
							
							con.addRequestProperty("User-Agent", "L2Network");
							con.setConnectTimeout(5000);
							
							final int responseCode = con.getResponseCode();
							if (responseCode == 200)
							{
								try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())))
								{
									String inputLine;
									while ((inputLine = in.readLine()) != null)
									{
										if (inputLine.contains("color:#e7ebf2"))
										{
											votes = Integer.valueOf(inputLine.split(">")[2].replace("</b", ""));
											break;
										}
									}
								}
							}
						}
		}
		catch (final Exception e)
		{
		_log.info("[NETWORK] offline!!!!!!!");
		Broadcast.toAllOnlinePlayers(new CreatureSay(2, Say2.HERO_VOICE,"[Network]", "Offline!"));
			// e.printStackTrace();
		}
		return votes;
	}

Second try:

 


	
	protected int getL2NetworkVotes()
	{
		int votes = -1;
		URL url = null;
		URLConnection con = null;
		InputStream is = null;
		InputStreamReader isr = null;
		BufferedReader in = null;
		
		try
		{
			url = new URL(PowerPakConfig.VOTES_SITE_L2NETWORK_URL);
			con = url.openConnection();
			con.addRequestProperty("User-Agent", "L2Network");
			is = con.getInputStream();
			isr = new InputStreamReader(is);
			in = new BufferedReader(isr);
			String inputLine;
			while ((inputLine = in.readLine()) != null)
			{
				if (inputLine.contains("color:#e7ebf2"))
				{
					votes = Integer.valueOf(inputLine.split(">")[2].replace("</b", ""));
					break;
				}
			}
		}
		catch (final Exception e)
		{
		_log.info("[NETWORK] offline!!!!!!!");
		Broadcast.toAllOnlinePlayers(new CreatureSay(2, Say2.HERO_VOICE,"[Network]", "Offline!"));
		Broadcast.toAllOnlinePlayers(new CreatureSay(0, Say2.HERO_VOICE,"[Server Site]", PowerPakConfig.SERVER_WEB_SITE));
			// e.printStackTrace();
		}
		finally
		{
			if (in != null)
				try
				{
					in.close();
				}
				catch (final IOException e1)
				{
					e1.printStackTrace();
				}
			if (isr != null)
				try
				{
					isr.close();
				}
				catch (final IOException e1)
				{
					e1.printStackTrace();
				}
			if (is != null)
				try
				{
					is.close();
				}
				catch (final IOException e1)
				{
					e1.printStackTrace();
				}
		}
		return votes;
	}

HTML ,powerpack

 

# Do you want enable powerpack?
PowerPakEnabled  = True


# Automatic Vote Reward System
VoteRewardSystem= True
VotesRequiredForReward = 1
VotesSystemInitialDelay= 60000
VotesSystemStepDelay= 5000
VotesRewards= 1851,20;

 

What is wrong?

Searched everywhere for many hours .. cant figure it out.

 

Edited by sotid

Recommended Posts

  • 0
Posted
7 hours ago, Kara` said:

We have discovered clone, quantum teleportation for individual atoms how to cure 70% of illnesses but sure let's use the topzone website to get the votes when they provide us API. :keepo:

 

Sure API is better and I will use it on the vote manager, plus I dont have links for api to test if its working.

 

5 hours ago, melron said:

as kara said, you should use API instead of all those crap connections...

 

@Kara` How old do you think are the above codes? :D

 

Ontopic:

try this one:


protected int getL2NetworkVotes()
{
	try
	{
		final URL obj = new URL(PowerPakConfig.VOTES_SITE_L2NETWORK_URL);
		final HttpURLConnection con = (HttpURLConnection) obj.openConnection();

		con.addRequestProperty("User-Agent", "L2Network");
		con.setConnectTimeout(5000);
		String inputLine;
		try (BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())))
		{
			while ((inputLine = in.readLine()) != null)
			{
				if (inputLine.contains("color:#e7ebf2"))
					return Integer.valueOf(inputLine.split(">")[2].split("<")[0].replace(",", ""));
			}
		}
	} 
	catch (Exception e)
	{
		Broadcast.toAllOnlinePlayers(new CreatureSay(2, Say2.HERO_VOICE,"[Network]", "Offline!"));
		Broadcast.toAllOnlinePlayers(new CreatureSay(0, Say2.HERO_VOICE,"[Server Site]", PowerPakConfig.SERVER_WEB_SITE));
	}
	return -1;
}

 


https://ibb.co/VgqGMNZ

 

Got an error

  • 0
Posted (edited)
7 minutes ago, sotid said:

 

Sure API is better and I will use it on the vote manager, plus I dont have links for api to test if its working.

 


https://ibb.co/VgqGMNZ

 

Got an error

paste it first in to a notepad and then copy it again from there

Edited by melron
  • 0
Posted (edited)
9 hours ago, wongerlt said:

this line:


votes = Integer.valueOf(inputLine.split(">")[2].replace("</b", ""));

change to:


votes = Integer.valueOf(inputLine.split(">")[2].replace("</b", "").replaceAll(",",""));

 

Either this or
 

votes = Integer.valueOf(inputLine.split(">")[2].split("<")[0].replace(",", ""));


this seems to work , thank you both.

You can lock it.

Edited by sotid
Guest
This topic is now closed to further replies.
×
×
  • Create New...