Иконка ресурса

Пароль на персонажа (для люцероподобных) 1.0.0

Нет прав для скачивания
Url
1245.png

Теперь до ввода дополнительного пароля, персонажу вешается блокировка чата и запрещается торговля.
Так-же добавлены команды: ".cblock" ".cunblock" для блокировки и разблокировки персонажа.
=======================================================================
Папку: "Passkey" копируем в папку в корень "html"

#Создаем в: "ru\catssoftware\gameserver\handler\voicedcommandhandlers\" новый документ: "CharPassKey.java"

Java:
package ru.catssoftware.gameserver.handler.voicedcommandhandlers;

import ru.catssoftware.gameserver.handler.IVoicedCommandHandler;
import ru.catssoftware.gameserver.handler.VoicedCommandHandler;
import ru.catssoftware.gameserver.model.actor.instance.L2PcInstance;
import ru.catssoftware.gameserver.model.restriction.AvailableRestriction;
import ru.catssoftware.gameserver.model.restriction.ObjectRestrictions;
import ru.catssoftware.gameserver.model.restriction.RestrictionBindClassException;
import ru.catssoftware.gameserver.network.serverpackets.NpcHtmlMessage;


public class CharPassKey implements IVoicedCommandHandler
{
    public CharPassKey() {
        
    }
    
    private static final String[] VOICED_COMMANDS =
    {
        "cblock",
        "cunblock"
    };
    
    public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
    {
        // Check activeChar
        if (activeChar == null)
            return false;

        if (command.startsWith("cunblock"))
        {
            NpcHtmlMessage html = new NpcHtmlMessage(activeChar.getObjectId());
            
            html.setFile("data/html/passkey/charunblock.htm");
            activeChar.sendPacket(html);
        }
        
        if (command.startsWith("cblock"))
        {
            activeChar.setIsParalyzed(true);
            activeChar.setTradeRefusal(true);
            activeChar.sendMessage("[!] Вам заблокирован чат - до аутентификации персонажа.");
            activeChar.sendMessage("[!] Если вы случайно закрыли окно, введите: .cunblock.");
            
            NpcHtmlMessage html = new NpcHtmlMessage(activeChar.getObjectId());

            html.setFile("data/html/passkey/charblock.htm");
            activeChar.sendPacket(html);
            if (activeChar == null)
                return false;
        
            try
            {
                ObjectRestrictions.getInstance().addRestriction(activeChar, AvailableRestriction.PlayerChat);
            }
            catch (RestrictionBindClassException e)
            {
                return false;
            }
        }
        return false;
    }
    
    public String getDescription(String command)
    {
        if(command.equals(""))
            return "";
        return null;
    }

    public String[] getVoicedCommandList()
    {
        return VOICED_COMMANDS;
    }
}


#В: "ru\catssoftware\gameserver\network\clientpackets\EnterWorld.java" добавляем следующее:
Java:
import ru.catssoftware.gameserver.cache.HtmCache;
import ru.catssoftware.gameserver.model.actor.instance.L2PcInstance;
import ru.catssoftware.gameserver.model.restriction.AvailableRestriction;
import ru.catssoftware.gameserver.model.restriction.ObjectRestrictions;
import ru.catssoftware.gameserver.model.restriction.RestrictionBindClassException;
import ru.catssoftware.gameserver.network.serverpackets.NpcHtmlMessage;

public static void enablePasskey(L2PcInstance activeChar)
{
    activeChar.setIsParalyzed(true);
    activeChar.setTradeRefusal(true);

    String str;
    NpcHtmlMessage localNpcHtmlMessage;
    if (RequestBypassToServer.getPassKeyEnable(activeChar))
    {
        activeChar.sendMessage("[!] Если вы случайно закрыли окно, введите: .cunblock.");
        str = HtmCache.getInstance().getHtm("data/html/passkey/login.htm", activeChar);
        localNpcHtmlMessage = new NpcHtmlMessage(1);
        localNpcHtmlMessage.setHtml(str);
        activeChar.sendPacket(localNpcHtmlMessage);
        localNpcHtmlMessage = null;
        if (activeChar == null)
            return;
        
        try
        {
            ObjectRestrictions.getInstance().addRestriction(activeChar, AvailableRestriction.PlayerChat);
        }
        catch (RestrictionBindClassException e)
        {
            return;
        }
    }
    else
    {
        str = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm", activeChar);
        localNpcHtmlMessage = new NpcHtmlMessage(1);
        localNpcHtmlMessage.setHtml(str);
        activeChar.sendPacket(localNpcHtmlMessage);
        localNpcHtmlMessage = null;
        if (activeChar == null)
            return;
        
        try
        {
            ObjectRestrictions.getInstance().addRestriction(activeChar, AvailableRestriction.PlayerChat);
        }
        catch (RestrictionBindClassException e)
        {
            return;
        }
    }
#В: "ru\catssoftware\gameserver\network\clientpackets\EnterWorld.java" добавляем:
Java:
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.StringTokenizer;

import ru.catssoftware.Config;
import ru.catssoftware.gameserver.cache.HtmCache;
import ru.catssoftware.gameserver.model.actor.instance.L2PcInstance;
import ru.catssoftware.gameserver.model.restriction.AvailableRestriction;
import ru.catssoftware.gameserver.model.restriction.ObjectRestrictions;
import ru.catssoftware.gameserver.model.restriction.RestrictionBindClassException;
import ru.catssoftware.gameserver.network.serverpackets.NpcHtmlMessage;
import ru.catssoftware.tools.codec.Base64;
import ru.catssoftware.L2DatabaseFactory;


        else if (_command.equalsIgnoreCase("pkrecovery"))
        {
            String msg = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm",activeChar);
            NpcHtmlMessage html = new NpcHtmlMessage(1);
            html.setHtml(msg);
            html.replace("%question%", getPassKeyQuestion(activeChar));
            activeChar.sendPacket(html);
            html = null;
        }
        else if (_command.startsWith("pkset"))
        {
            StringTokenizer st = new StringTokenizer(_command, "]");
            
            if (st.countTokens() != 5)
            {
                activeChar.sendMessage("[!] Вы ввели не все данные.");
                String msg = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm",activeChar);
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setHtml(msg);
                activeChar.sendPacket(html);
                html = null;
                return;
            }
            
            String newCommand = st.nextToken();
            String pass1 = st.nextToken();
            pass1 = pass1.substring(1, pass1.length() - 1);
            String pass2 = st.nextToken();
            pass2 = pass2.substring(1, pass2.length() - 1);
            String question = st.nextToken();
            question = question.substring(1, question.length() - 1);
            String answer = st.nextToken();
            answer = answer.substring(1, answer.length());
            
            if (pass1 == null || pass2 == null || question == null || answer == null)
            {
                activeChar.sendMessage("[!] Вы ввели недопустимые символы.");
                String msg = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm",activeChar);
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setHtml(msg);
                activeChar.sendPacket(html);
                html = null;
                return;
            }
            
            if (!pass1.equals(pass2))
            {
                activeChar.sendMessage("[!] Пароли не совпадают. Пожалуйста, проверьте.");
                activeChar.sendMessage("[!] pass1 = " + pass1 + ".");
                activeChar.sendMessage("[!] pass2 = " + pass2 + ".");
                activeChar.sendMessage("[!] Question = " + question + ".");
                activeChar.sendMessage("[!] answer = " + answer + ".");
                
                String msg = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm",activeChar);
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setHtml(msg);
                activeChar.sendPacket(html);
                html = null;
                return;
            }
            insertPassKeyInformation(activeChar, pass1, question, answer);
            
            activeChar.sendMessage("[!] Установлена двухфакторная аутентификация!");
            String msg = HtmCache.getInstance().getHtm("data/html/passkey/login.htm",activeChar);
            NpcHtmlMessage html = new NpcHtmlMessage(1);
            html.setHtml(msg);
            activeChar.sendPacket(html);
            html = null;
        }
        else if (_command.startsWith("pklogin"))
        {
            StringTokenizer st = new StringTokenizer(_command, " ");
            if (st.countTokens() != 2)
            {
                activeChar.sendMessage("[!] Допущена ошибка при вводе пароля.");
                String msg = HtmCache.getInstance().getHtm("data/html/passkey/login.htm",activeChar);
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setHtml(msg);
                activeChar.sendPacket(html);
                html = null;
                return;
            }
            String newCommand = st.nextToken();
            String pass = st.nextToken();
            
            Connection con = null;
            String query = "SELECT passkey FROM passkey WHERE obj_Id = ?";
            String pwdindb = "error";
            try
            {
                con = L2DatabaseFactory.getInstance().getConnection();
                PreparedStatement ps = con.prepareStatement(query);
                ps.setInt(1, activeChar.getObjectId());
                ResultSet rs = ps.executeQuery();
                
                while (rs.next())
                    pwdindb = rs.getString(1);
                
                rs.close();
                ps.close();
                ps = null;
                rs = null;
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    con.close();
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
                con = null;
            }
            
            if (pwdindb.equals(encodePass(pass)))
            {
                activeChar.setIsParalyzed(false);
                activeChar.setTradeRefusal(false);
                try
                {
                    ObjectRestrictions.getInstance().removeRestriction(activeChar, AvailableRestriction.PlayerChat);
                }
                catch (Exception e)
                {
                    e.printStackTrace();
                    return;
                }
            }
            else
            {
                activeChar.sendMessage("[!] Неправильный пароль от персонажа.");
                String msg = HtmCache.getInstance().getHtm("data/html/passkey/login.htm",activeChar);
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setHtml(msg);
                activeChar.sendPacket(html);
                html = null;
                return;
            }
        }
        else if (_command.startsWith("pkrec"))
        {
            StringTokenizer st = new StringTokenizer(_command, " ");
            if (st.countTokens() != 4)
            {
                activeChar.sendMessage("[!] Допущена ошибка при вводе данных!");
                String msg = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm",activeChar);
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setHtml(msg);
                html.replace("%question%", getPassKeyQuestion(activeChar));
                activeChar.sendPacket(html);
                html = null;
                return;
            }
            
            String newCommand = st.nextToken();
            String answer = st.nextToken();
            String pass1 = st.nextToken();
            String pass2 = st.nextToken();
            
            if (!pass1.equals(pass2))
            {
                activeChar.sendMessage("[!] Пароли не совпадают. Пожалуйста, проверьте.");
                String msg = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm",activeChar);
                NpcHtmlMessage html = new NpcHtmlMessage(1);
                html.setHtml(msg);
                html.replace("%question%", getPassKeyQuestion(activeChar));
                activeChar.sendPacket(html);
                html = null;
                return;
            }
            
            Connection con = null;
            String query = "SELECT answer FROM passkey WHERE obj_Id = ?";
            String anwindb = "error";
            try
            {
                con = L2DatabaseFactory.getInstance().getConnection();
                PreparedStatement ps = con.prepareStatement(query);
                ps.setInt(1, activeChar.getObjectId());
                ResultSet rs = ps.executeQuery();
                
                while (rs.next())
                    anwindb = rs.getString(1);
                
                rs.close();
                ps.close();
                ps = null;
                rs = null;
            }
            catch (Exception e)
            {
                e.printStackTrace();
            }
            finally
            {
                try
                {
                    con.close();
                }
                catch (SQLException e)
                {
                    e.printStackTrace();
                }
                con = null;
            }
            
            if (anwindb.equals(answer))
            {
                updPassKey(activeChar, pass1);
                activeChar.sendMessage(
  • 42145.png
    42145.png
    33,6 KB · Просмотры: 1
  • 414124.png
    414124.png
    33,4 KB · Просмотры: 1
Автор
CrazyCort
Скачивания
0
Просмотры
37
Первый выпуск
Обновление
Оценка
0,00 звёзд 0 оценок

Другие ресурсы пользователя CrazyCort