Noticias:

No tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

Menú Principal

Anty Dual Box

Iniciado por Swarlog, Jul 26, 2025, 12:00 AM

Tema anterior - Siguiente tema

Swarlog

/*
 * This program 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.
 * 
 * This program 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 custom.AntiDualBox;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.l2jserver.L2DatabaseFactory;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.quest.Quest;

public class AntiDualBox extends Quest
{
	public AntiDualBox(int questId, String name, String descr)
	{
		super(questId, name, descr);
		setOnEnterWorld(true);
	}
	
	@Override
	public final String onEnterWorld(L2PcInstance player)
	{
		// Cantidad maxima de usuarios desde la misma computadora:
		long MaximumBoxAllowed = 1;
		
		Connection con = null;
		PreparedStatement statement = null;
		String PlayerAccountName = player.getAccountName();
		String PlayerLastIP = "";
		String PlayerPcIP = "";
		long CharsFromSamePC = 0;
	
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			statement = con.prepareStatement("SELECT accounts.lastIP FROM accounts WHERE accounts.login = ?");
			statement.setString(1, PlayerAccountName);
			
			ResultSet resultSet = statement.executeQuery();
			
			while (resultSet.next())
			{
				PlayerLastIP = resultSet.getString(1);
			}
			
			resultSet.close();
			statement.close();
		}
		
		catch (Exception e)
		{
			//Errors
		}
		
		finally
		{
			L2DatabaseFactory.close(con);
		}
		
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			statement = con.prepareStatement("SELECT accounts.pcIp FROM accounts WHERE accounts.login = ?");
			statement.setString(1, PlayerAccountName);
			
			ResultSet resultSet = statement.executeQuery();
			
			while (resultSet.next())
			{
				PlayerPcIP = resultSet.getString(1);
			}
			
			resultSet.close();
			statement.close();
		}
		
		catch (Exception e)
		{
			//Errors
		}
		
		finally
		{
			L2DatabaseFactory.close(con);
		}
		
		try
		{
			con = L2DatabaseFactory.getInstance().getConnection();
			statement = con.prepareStatement("SELECT COUNT(characters.char_name) FROM accounts INNER JOIN characters ON accounts.login = characters.account_name WHERE characters.online = 1 AND accounts.lastIP = ? AND accounts.pcIp = ?");
			statement.setString(1, PlayerLastIP);
			statement.setString(2, PlayerPcIP);
			
			ResultSet resultSet = statement.executeQuery();
			
			while (resultSet.next())
			{
				CharsFromSamePC = resultSet.getLong(1);
			}
			
			resultSet.close();
			statement.close();
		}
		
		catch (Exception e)
		{
			//Errors
		}
		
		finally
		{
			L2DatabaseFactory.close(con);
		}
		
		if (CharsFromSamePC > MaximumBoxAllowed)
		{
			//player.sendMessage("You are allowed to use " + MaximumBoxAllowed + " client!);
			player.logout();
		}
    
		return null;
	}
	
	public static void main(String[] args)
	{
		new AntiDualBox(-1, "AntiDualBox", "custom");
	}
}