Jump to content
  • 0

Change that code to work like a command


Question

Posted (edited)

[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;
 }
}

 

Edited by cyta5

1 answer to this question

Recommended Posts

Guest
This topic is now closed to further replies.


  • Posts

    • Hello everyone, I am selling the complete AdvExt64 FULL Extender for L2OFF PTS Interlude servers, including the complete source code.   Note: This is NOT the Vanganth extender. This is the complete, fully featured Interlude advext64 extender its full source code. Here is a breakdown of the key features included in this extender:   💻 Source Code Included   Full Extender Source: Modify, compile, and add your own custom features with zero limitations   ⚔️[NEW] Boss Spawns & Global Announcements   Boss Management (BossSpawn.txt): Full control over the exact spawn coordinates and respawn times for any Raid or Epic Boss. Auto-Announce: The server will automatically send a global announcement whenever a normal Raid Boss or Epic Boss spawns (supports custom chat colors). 🏪 Exclusive Systems (OtherSettings) [SearchStore] Costume system; Skins Clan Crest on NPCs:   🌟 Core Systems & Quality of Life AIO (All-In-One) System Premium & VIP System Offline Trade & Market Custom NPC Buffer Extended Teleports Buff Store System: Buff Item Fast Load L2Npc Multi-language System   ⚔️ [NEW] Event Engine (Fully Automated) Good vs Evil (GVE) & All vs All (AVA): Team vs Team (TvT) Capture the Flag (CTF): Last Hero (DeathMatch) Party Death "Server First" Promos: Custom Drop Events Vip System Newbie Rates: ⚙️ Custom Gameplay Mechanics Daily/Weekly/Monthly Missions: Advanced Enchant System: Attribute System Special Map Areas: Olympiad Extras: PvP/PK Systems: In-Game Mail Clan Search Seach Store Bot Report   🛡️ Security & Administration Anti-Bot Integrations:  Patch & HWID Protection: Builder System Jail & Chat Filter System   Price: 500 USD Contact Telegram: @TrakinasXP      
    • [SIZE=4][B]🇨🇦 NEWCANADA40 — 40% OFF VPS in Canada (Toronto)[/B][/SIZE] We are excited to announce the launch of our new location — Toronto, Canada. [B]Promo code:[/B] NEWCANADA40 [B]Discount:[/B] 40% on VPS orders [B]Valid until:[/B] June 7 ✔ New Canadian location ✔ Excellent North American connectivity ✔ Fast server deployment ✔ Suitable for any project [B]How to activate:[/B] — Visit our website — Select Canada (Toronto) as your location — Enter the promo code during checkout 👉 [url=https://bit.hosting]https://bit.hosting[/url] [I]The offer is valid for new Toronto VPS orders until June 7, 2026.</I>
    • Thanks for the collection and the free advertising! These files have been in the public domain for a long time — you just saved people the trouble of searching. A true fan. 😄 Just to clarify for everyone reading: these files have nothing to do with this topic. They are 10+ year old builds, and since various third-party modifications exist in the wild, we cannot guarantee what may have been added or changed in those versions. Use them at your own risk. We have absolutely no judgment toward those who are on a tight budget and can't afford our current builds — these old shared files might genuinely help you get started. Just use them carefully and at your own risk. And please don't judge developers for the mistakes they made early in their careers — every developer goes through stages of growth, and what you see in those old builds is simply a snapshot of where we were back then. We've come a long way since. If you're interested in our older builds, we have a dedicated thread for that with significantly reduced prices — very accessible for any budget. We have also recently resumed full technical support for legacy builds, handled by a separate team that doesn't interfere with our private development direction for larger projects. You can find our legacy builds here: Our OLd L2-scripts Packs Actual revisions Our current private sources are a completely different story — which is exactly what this thread is about. Too bad all your time goes into collecting other people's old code instead of developing your own project. Though judging by "L2MID is currently offline, we will come back soon in 2026" — you clearly have plenty of time on your hands. 😉
  • Topics

×
×
  • Create New...

Important Information

This community uses essential cookies to function properly. Non-essential cookies and third-party services are used only with your consent. Read our Privacy Policy and We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue..