Noticias:

Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate

Menú Principal

Automatic cleaner for inactive characters

Iniciado por Swarlog, Sep 01, 2022, 12:32 AM

Tema anterior - Siguiente tema

Swarlog

Simple script de limpieza automatica de jugadores inactivos, tiempo configurable desde la misma clase.

/*
 * Copyright (C) 2004-2016 L2J DataPack
 *
 * This file is part of L2J DataPack.
 *
 * L2J DataPack is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * L2J DataPack is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package cron;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;
import java.util.logging.Logger;

import com.l2jserver.commons.database.pool.impl.ConnectionFactory;

/**
 * @author Sacrifice
 */
public final class ScheduledAutoCleanCharacters
{
private static final short MAX_STORED_DAYS = 45; // By default is 45 days
private static final Logger _log = Logger.getLogger(ScheduledAutoCleanCharacters.class.getName());

public static void main(String[] args)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM characters WHERE lastAccess <= ? AND accessLevel = 0 AND online = 0"))
{
ps.setLong(1, System.currentTimeMillis() - (MAX_STORED_DAYS * 24L * 60L * 60L * 1000L));
ps.executeUpdate();
ps.close();
}
catch (Exception e)
{
e.printStackTrace();
}
String sdf = new SimpleDateFormat("EEE MMM dd, yyyy' at 'HH:mm:ss").format(System.currentTimeMillis() - (MAX_STORED_DAYS * 24L * 60L * 60L * 1000L));
_log.info("Inactive players Deleted from: " + sdf);
}
}

INSERT INTO `global_tasks` VALUES ('101', 'script', 'TYPE_GLOBAL_TASK', '0', '1', '04:00:00', 'ScheduledAutoCleanCharacters.java');


Actualización de Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate:

Actualizado con SLF4J Logger.
/*
 * Copyright (C) 2004-2016 L2J DataPack
 *
 * This file is part of L2J DataPack.
 *
 * L2J DataPack is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * L2J DataPack is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package cron;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.text.SimpleDateFormat;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.l2jserver.commons.database.pool.impl.ConnectionFactory;

/**
 * @author Sacrifice
 */
public final class ScheduledAutoCleanCharacters
{
private static final short MAX_STORED_DAYS = 45; // By default is 45 days
private static final Logger _log = LoggerFactory.getLogger(ScheduledAutoCleanCharacters.class.getName());

public static void main(String[] args)
{
try (Connection con = ConnectionFactory.getInstance().getConnection();
PreparedStatement ps = con.prepareStatement("DELETE FROM characters WHERE lastAccess <= ? AND accessLevel = 0 AND online = 0"))
{
ps.setLong(1, System.currentTimeMillis() - (MAX_STORED_DAYS * 24L * 60L * 60L * 1000L));
ps.executeUpdate();
ps.close();
}
catch (Exception e)
{
e.printStackTrace();
}
String sdf = new SimpleDateFormat("EEE MMM dd, yyyy' at 'HH:mm:ss").format(System.currentTimeMillis() - (MAX_STORED_DAYS * 24L * 60L * 60L * 1000L));
_log.info("Inactive players Deleted from: {}", sdf);
}
}
INSERT INTO `global_tasks` VALUES ('101', 'script', 'TYPE_GLOBAL_TASK', '0', '1', '04:00:00', 'ScheduledAutoCleanCharacters.java');