Сообщений: 290
Тем: 23
Зарегистрирован: Aug 2009
Репутация:
116
возможно етот менедреж под старые сылки л2топа...
Сообщений: 531
Тем: 71
Зарегистрирован: Jul 2009
Репутация:
193
Скрипт проверил сылка указана нормально.
Сообщений: 3,968
Тем: 90
Зарегистрирован: Nov 2010
Репутация:
15,337
02-22-2011, 10:52 PM
(Сообщение последний раз редактировалось: 02-22-2011, 11:44 PM Ro_0TT.)
Скиньте в ПМ ссылку на свою статистику.
Добавлено через 51 минуту
Сверь..
[src=sql]
package services;
import l2p.Config;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.logging.Logger;
import java.util.concurrent.ScheduledFuture;
import java.net.URL;
import l2p.common.ThreadPoolManager;
import l2p.database.FiltredPreparedStatement;
import l2p.database.L2DatabaseFactory;
import l2p.database.ThreadConnection;
import l2p.extensions.scripts.Functions;
import l2p.extensions.scripts.ScriptFile;
import l2p.gameserver.model.L2ObjectsStorage;
import l2p.gameserver.model.L2Player;
import l2p.util.Rnd;
public class VoteManager extends Functions implements ScriptFile
{
/*
* © Ro0TT
*/
private static Logger log = Logger.getLogger(VoteManager.class.getName());
private static ScheduledFuture<?> _startTask;
Timestamp _lastVote;
private String urlS = "";
public class StartTask implements Runnable
{
public void run()
{
while (Config.L2VOTEMANAGER_ENABLE)
{
try
{
URL url = new URL(urlS);
parse(url.openStream());
}
catch(Exception e)
{
log.warning("VoteManager: Error url parse.");
}
try
{
Thread.sleep(Config.L2VOTEMANAGER_TIME);
}
catch(InterruptedException e)
{
e.printStackTrace();
}
}
}
}
public void onShutdown()
{
}
public void onLoad()
{
try
{
ThreadConnection con = L2DatabaseFactory.getInstance().getConnection();
FiltredPreparedStatement stm = con.prepareStatement("select max(votedate) from character_votes");
ResultSet r = stm.executeQuery();
if(r.next())
_lastVote = new Timestamp(r.getLong(1) * 1000);
if (_lastVote==null)
{
_lastVote = new Timestamp(0);
}
r.close();
stm.close();
con.close();
}
catch(SQLException e)
{
log.warning("VoteManager: Error connection to database: "+e);
}
urlS = "http://l2top.ru/editServ/?adminAct=lastVotes&uid=" + Config.L2TOP_ID + "&key=" + Config.L2TOP_KEY;
_startTask = ThreadPoolManager.getInstance().scheduleGeneralAtFixedRate(new StartTask(), 1, 1);
}
public void onReload()
{
_startTask.cancel(true);
onLoad();
}
public void parse(InputStream is) throws Exception
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"windows-1251"));
String line;
int votes = 0;
Timestamp last = _lastVote;
while((line=reader.readLine()) != null)
{
if (line.indexOf("\t") != -1)
{
Timestamp voteDate = Timestamp.valueOf(line.substring(0,line.indexOf("\t")).trim());
if (voteDate.after(_lastVote))
{
if(voteDate.after(last))
last = voteDate;
String charName = line.substring(line.indexOf("\t")+1).toLowerCase();
Store(charName, voteDate);
votes++;
}
}
}
_lastVote = last;
log.info("VoteManager: "+votes+" processed");
}
public void reward(L2Player player)
{
if(player != null)
{
player.getInventory().addItem(Config.L2VOTEMANAGER_REWARD_ID, Config.L2VOTEMANAGER_REWARD_KEY);
if (player.isOnline())
player.sendMessage("Спасибо, что проголосовали за наш сервер!");
player.store(true);
}
}
public void Store(String _charName, Timestamp _votedate)
{
try
{
ThreadConnection con = L2DatabaseFactory.getInstance().getConnection();
FiltredPreparedStatement stm = con.prepareStatement("insert into character_votes select ?,? from characters where not exists(select * from character_votes where votedate=? and charName =?) limit 1");
stm.setLong(1, _votedate.getTime()/1000);
stm.setString(2, _charName);
stm.setLong(3, _votedate.getTime()/1000);
stm.setString(4, _charName);
boolean sendPrize = stm.executeUpdate() > 0;
stm.close();
if (sendPrize)
{
L2Player player = L2ObjectsStorage.getPlayer(_charName);
if(player != null)
reward(player);
}
}
catch (SQLException e)
{
log.warning("VoteManager: Error storing data "+e);
}
}
}
[/src]