Jump to content

cyta5

Members
  • Posts

    61
  • Credits

  • Joined

  • Last visited

  • Feedback

    0%

Posts posted by cyta5

  1. 18 minutes ago, SweeTs said:

    Find the method and add a check if (target instanceof L2Monster || ...) 

     

    where i use that ?

    
    /**
         * Manage and Display the GM console to modify the L2NpcInstance (GM only).<BR>
         * <BR>
         * <B><U> Actions (If the L2PcInstance is a GM only)</U> :</B><BR>
         * <BR>
         * <li>Set the L2NpcInstance as target of the L2PcInstance player (if necessary)</li> <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li> <li>If L2NpcInstance is autoAttackable, send a Server->Client packet StatusUpdate to the
         * L2PcInstance in order to update L2NpcInstance HP bar</li> <li>Send a Server->Client NpcHtmlMessage() containing the GM console about this L2NpcInstance</li><BR>
         * <BR>
         * <FONT COLOR=#FF0000><B> <U>Caution</U> : Each group of Server->Client packet must be terminated by a ActionFailed packet in order to avoid that client wait an other packet</B></FONT><BR>
         * <BR>
         * <B><U> Example of use </U> :</B><BR>
         * <BR>
         * <li>Client packet : Action</li><BR>
         * <BR>
         * @param client The thread that manage the player that pessed Shift and click on the L2NpcInstance
         */
        @Override
        public void onActionShift(final L2GameClient client)
        {        
            // Get the L2PcInstance corresponding to the thread
            L2PcInstance player = client.getActiveChar();
            if (player == null)
                return;
            
            final L2Weapon currentWeapon = player.getActiveWeaponItem();
            
            // Check if the L2PcInstance is a GM
            if (player.getAccessLevel().isGm())
            {
                // Set the target of the L2PcInstance player
                player.setTarget(this);
                
                // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
                // The player.getLevel() - getLevel() permit to display the correct color in the select window
                MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel() - getLevel());
                player.sendPacket(my);
                my = null;
                
                // Check if the player is attackable (without a forced attack)
                if (isAutoAttackable(player))
                {
                    // Send a Server->Client packet StatusUpdate of the L2NpcInstance to the L2PcInstance to update its HP bar
                    StatusUpdate su = new StatusUpdate(getObjectId());
                    su.addAttribute(StatusUpdate.CUR_HP, (int) getCurrentHp());
                    su.addAttribute(StatusUpdate.MAX_HP, getMaxHp());
                    player.sendPacket(su);
                    su = null;
                }
                
                // Send a Server->Client NpcHtmlMessage() containing the GM console about this L2NpcInstance
                NpcHtmlMessage html = new NpcHtmlMessage(0);
    
    

  2. /* 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 2, 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, write to the Free Software
    * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
    * 02111-1307, USA.
    *
    * http://www.gnu.org/copyleft/gpl.html
    */
    package com.l2jfrozen.gameserver.model.actor.instance;
    
    import com.l2jfrozen.crypt.Base64;
    import com.l2jfrozen.gameserver.ai.CtrlIntention;
    import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
    import com.l2jfrozen.gameserver.network.serverpackets.LeaveWorld;
    import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
    import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
    import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
    import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
    import com.l2jfrozen.util.database.L2DatabaseFactory;
    
    import java.security.MessageDigest;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.util.StringTokenizer;
    import javolution.text.TextBuilder;
    
    public class L2PasswordChangerInstance extends L2FolkInstance
    {
    public L2PasswordChangerInstance(int objectId, L2NpcTemplate template)
    {
    super(objectId, template);
    }
    
    public void onBypassFeedback(L2PcInstance player, String command)
    {
    if (command.startsWith("change_password"))
    {
    StringTokenizer st = new StringTokenizer(command);
    st.nextToken();
    String currPass = null;
    String newPass = null;
    String repeatNewPass = null;
    try
    {
    if (st.hasMoreTokens())
    {
    currPass = st.nextToken();
    newPass = st.nextToken();
    repeatNewPass = st.nextToken();
    }
    else
    {
    player.sendMessage("Please fill in all the blanks before requesting for a password change.");
    return;
    }
    changePassword(currPass, newPass, repeatNewPass, player);
    }
    catch (StringIndexOutOfBoundsException e)
    {
    }
    }
    }
    
    public void onAction(L2PcInstance player)
    {
    if (!canTarget(player)) {
    return;
    }
    
    if (this != player.getTarget())
    {
    player.setTarget(this);
    
    player.sendPacket(new MyTargetSelected(getObjectId(), 0));
    
    player.sendPacket(new ValidateLocation(this));
    }
    else if (!canInteract(player))
    {
    player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
    }
    else
    {
    showHtmlWindow(player);
    }
    
    player.sendPacket(new ActionFailed());
    }
    
    private void showHtmlWindow(L2PcInstance activeChar)
    {
    NpcHtmlMessage nhm = new NpcHtmlMessage(5);
    TextBuilder replyMSG = new TextBuilder("");
    
    replyMSG.append("<html><title>L2 InStadia Account Manager</title>");
    replyMSG.append("<body><center>");
    replyMSG.append("To change your password:<br1> First fill in your current password and then your new!</font><br>");
    replyMSG.append("Current Password: <edit var=\"cur\" width=100 height=15><br>");
    replyMSG.append("New Password: <edit var=\"new\" width=100 height=15><br>");
    replyMSG.append("Repeat New Password: <edit var=\"repeatnew\" width=100 height=15><br><br>");
    replyMSG.append("<button value=\"Change Password\" action=\"bypass -h npc_" + getObjectId() + "_change_password $cur $new $repeatnew\" width=204 height=20 back=\"sek.cbui75\" fore=\"sek.cbui75\">");
    replyMSG.append("</center></body></html>");
    
    nhm.setHtml(replyMSG.toString());
    activeChar.sendPacket(nhm);
    
    activeChar.sendPacket(new ActionFailed());
    }
    
    public static boolean changePassword(String currPass, String newPass, String repeatNewPass, L2PcInstance activeChar)
    {
    if (newPass.length() < 5)
    {
    activeChar.sendMessage("The new password is too short!");
    return false;
    }
    if (newPass.length() > 20)
    {
    activeChar.sendMessage("The new password is too long!");
    return false;
    }
    if (!newPass.equals(repeatNewPass))
    {
    activeChar.sendMessage("Repeated password doesn't match the new password.");
    return false;
    }
    
    Connection con = null;
    String password = null;
    try
    {
    MessageDigest md = MessageDigest.getInstance("SHA");
    byte[] raw = currPass.getBytes("UTF-8");
    raw = md.digest(raw);
    String currPassEncoded = Base64.encodeBytes(raw);
    
    con = L2DatabaseFactory.getInstance().getConnection();
    PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
    statement.setString(1, activeChar.getAccountName());
    ResultSet rset = statement.executeQuery();
    while (rset.next())
    {
    password = rset.getString("password");
    }
    rset.close();
    statement.close();
    byte[] password2 =
    null;
    if (currPassEncoded.equals(password))
    {
    password2 = newPass.getBytes("UTF-8");
    password2 = md.digest(password2);
    
    PreparedStatement statement2 = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?");
    statement2.setString(1, Base64.encodeBytes(password2));
    statement2.setString(2, activeChar.getAccountName());
    statement2.executeUpdate();
    statement2.close();
    
    activeChar.sendMessage("Congratulations! Your password has been changed succesfully. You will now be disconnected for security reasons. Please login again!");
    try
    {
    Thread.sleep(3000L);
    }
    catch (Exception e)
    {
    }
    
    activeChar.deleteMe();
    
    activeChar.sendPacket(new LeaveWorld());
    }
    else
    {
    activeChar.sendMessage("The current password you've inserted is incorrect! Please try again!");
    
    return password2 != null;
    }
    }
    catch (Exception e)
    {
    _log.warning("could not update the password of account: " + activeChar.getAccountName());
    }
    finally
    {
    try
    {
    if (con != null)
    con.close();
    }
    catch (SQLException e)
    {
    _log.warning("Failed to close database connection!");
    }
    
    }
    
    return true;
    }
    }

     

  3. [GR]Μπορεί κάποιος να με βοηθήσει να αλλάξω αυτόν τον κώδικα  να λειτουργεί σαν  command ?

    [EN]Maybe someone can help me to change that code to work like a command ?

     

    /* 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 2, 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, write to the Free Software
     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
     * 02111-1307, USA.
     *
     * http://www.gnu.org/copyleft/gpl.html
     */
    package com.l2jfrozen.gameserver.model.actor.instance;
    
    import java.security.MessageDigest;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.util.StringTokenizer;
    
    import com.l2jfrozen.Config;
    import com.l2jfrozen.crypt.Base64;
    import com.l2jfrozen.gameserver.ai.CtrlIntention;
    import com.l2jfrozen.gameserver.network.serverpackets.ActionFailed;
    import com.l2jfrozen.gameserver.network.serverpackets.MyTargetSelected;
    import com.l2jfrozen.gameserver.network.serverpackets.NpcHtmlMessage;
    import com.l2jfrozen.gameserver.network.serverpackets.ValidateLocation;
    import com.l2jfrozen.gameserver.templates.L2NpcTemplate;
    import com.l2jfrozen.util.CloseUtil;
    import com.l2jfrozen.util.database.L2DatabaseFactory;
    
    public class L2ChangePasswordInstance extends L2FolkInstance
    {
     public L2ChangePasswordInstance(int objectId, L2NpcTemplate template)
     {
     super(objectId, template);
     }
    
     @Override
     public void onAction(L2PcInstance player)
     {
     if (!canTarget(player))
     {
     return;
     }
    
     player.setLastFolkNPC(this);
    
     // Check if the L2PcInstance already target the L2NpcInstance
     if (this != player.getTarget())
     {
     // Set the target of the L2PcInstance player
     player.setTarget(this);
    
     // Send a Server->Client packet MyTargetSelected to the L2PcInstance player
     MyTargetSelected my = new MyTargetSelected(getObjectId(), 0);
     player.sendPacket(my);
     my = null;
    
     // Send a Server->Client packet ValidateLocation to correct the L2NpcInstance position and heading on the client
     player.sendPacket(new ValidateLocation(this));
     }
     else
     {
     // Calculate the distance between the L2PcInstance and the L2NpcInstance
     if (!canInteract(player))
     {
     // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
     player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this);
     }
     else
     {
     showHtmlWindow(player);
     }
     }
    
     player.sendPacket(new ActionFailed());
     }
    
     private void showHtmlWindow(L2PcInstance player)
     {
     String filename = "data/html/mods/ChangePassword.htm";
     NpcHtmlMessage html = new NpcHtmlMessage(1);
     html.setFile(filename);
     html.replace("%objectId%", String.valueOf(getObjectId()));
     player.sendPacket(html);
     filename = null;
     html = null;
     }
    
     @Override
     public void onBypassFeedback(L2PcInstance player, String command)
     {
     if (command.startsWith("change_password"))
     {
     StringTokenizer st = new StringTokenizer(command);
     st.nextToken();
     String curPass = null;
     String newPass = null;
     String repPass = null;
     try
     {
     if (st.hasMoreTokens())
     {
     curPass = st.nextToken();
     newPass = st.nextToken();
     repPass = st.nextToken();
     }
     else
     {
     player.sendMessage("Please fill in all the blanks before requesting for a password change.");
     return;
     }
     changePassword(curPass, newPass, repPass, player);
     }
     catch (StringIndexOutOfBoundsException e)
     {
     if (Config.ENABLE_ALL_EXCEPTIONS)
     {
     e.printStackTrace();
     }
     }
     }
     }
    
     @SuppressWarnings("null")
    public static boolean changePassword(String currPass, String newPass, String repeatNewPass, L2PcInstance activeChar)
     {
     if (newPass.length() < 5)
     {
     activeChar.sendMessage("The new password is too short!");
     return false;
     }
     if (newPass.length() > 15)
     {
     activeChar.sendMessage("The new password is too long!");
     return false;
     }
     if (!newPass.equals(repeatNewPass))
     {
     activeChar.sendMessage("Repeated password doesn't match the new password.");
     return false;
     }
    
     Connection con = null;
     String password = null;
     try
     {
     MessageDigest md = MessageDigest.getInstance("SHA");
     byte[] raw = currPass.getBytes("UTF-8");
     raw = md.digest(raw);
     String currPassEncoded = Base64.encodeBytes(raw);
    
     con = L2DatabaseFactory.getInstance().getConnection(false);
     PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
     statement.setString(1, activeChar.getAccountName());
     ResultSet rset = statement.executeQuery();
     while (rset.next())
     {
     password = rset.getString("password");
     }
     rset.close();
     statement.close();
     byte[] password2 = null;
     if (currPassEncoded.equals(password))
     {
     password2 = newPass.getBytes("UTF-8");
     password2 = md.digest(password2);
    
     PreparedStatement statement2 = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?");
     statement2.setString(1, Base64.encodeBytes(password2));
     statement2.setString(2, activeChar.getAccountName());
     statement2.executeUpdate();
     statement2.close();
    
     activeChar.sendMessage("Your password has been changed successfully!");
     }
     else
     {
     activeChar.sendMessage("The current password you've inserted is incorrect, please try again!");
    
     return password2 != null;
     }
     }
     catch (Exception e)
     {
     if (Config.ENABLE_ALL_EXCEPTIONS)
     {
     e.printStackTrace();
     }
    
     LOGGER.info("could not update the password of account: " + activeChar.getAccountName());
     }
     finally
     {
     CloseUtil.close(con);
     }
    
     return true;
     }
    }

     

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock