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

    • GRAND OPENING FROM - 25/09/2026 FRIDAY 20:00    
    • does anyone has the tools in the third link ?
    • ⚡ Weekend special! Upgrade your personal Google account with 5TB storage and Gemini Pro in under 60 seconds.
    • Chronicle: Chronicle 1 - Harbingers Of War General Information: EXP/SP: x1 Adena: x1 Drop chance: x1 Spoil chance: x1 Raid drop chance: x1 Quest adena: x1 Quest EXP/SP: x1 Quest drop chance: x1 Box limit: 1+1    Buff time: 40min normal buffs. 5min song/dance. Sub Acumulative 1+1 You can create a "sub" starting at level 20.   With a simple quest. Level 40 need a simple quest. You can crea a sub with your same race (simple quest) or other race (more hard quest). You need learn all your class and sub skills. You can start with the "Master of Talents" NPC, located in every city next to the Grand Master.    The Client: We use the official original Chronica 1 game client, but we have made some modifications we deemed necessary for a better gameplay experience.   1. In-game buff duration timer. 2. ALT+M or M (with enter-chat) show map without needing to buy it 3. AutoSoulshot—but use it wisely. Soulshots aren't cheap! 4. Private Workshop (craft) 5. Game window in windowed mode, allowing it to be moved freely around Windows. 6. Combat Log. DISCORD: https://discord.gg/uzWj8M4gcm SITE: https://l2giran.com/
    • ⚔️ DRAGON-NETWORK LEGACY x15 ⚔️ INTERLUDE+ • SUBSTACK • STAGE PROGRESSION 🔥 GRAND OPENING: OCTOBER 2, 2026 🕖 19:00 UTC+2 🌐 https://dragon-network.eu ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ THE LEGACY RETURNS. YOUR STORY BEGINS. The battlefield is calling once again! Dragon-Network returns with LEGACY x15, delivering a unique Interlude+ Substack experience featuring competitive PvP, expanded content, and progressive gameplay. Forge your build. Gather your clan. Conquer your enemies. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ⚙️ SERVER INFORMATION • Chronicle: Interlude+ • Gameplay: Substack • EXP / SP: x15 • Adena: x10 • Drop / Spoil: x10 • Seal Stones: x10 • Raid Boss Drops: x5 • Epic Drops: x1 • Maximum Level: 85 • Box Limit: 1 Main + 2 Boxes ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ⚔️ SUBSTACK SYSTEM Create your own playstyle and explore unique class combinations. ✓ Free starting Golkonda Horn ✓ First Stack Sub from level 40 ✓ Additional horns obtainable through gameplay ✓ Custom class and skill adjustments Your build. Your strategy. Your legacy. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🌍 INTERLUDE+ CONTENT Experience the classic world of Lineage II with additional content and expanded progression. ✓ Kamaloka & Labyrinth ✓ Pailaka Quests ✓ Hellbound Island ✓ Isle of Prayer ✓ Improved Pets ✓ S80 Equipment ✓ Attribute System ✓ Siegeable Fortresses Content is introduced progressively through server stages. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🏆 PVP & EVENTS Prepare for competitive battles and valuable rewards! ✓ Daily Team vs Team events ✓ Event Coins and exclusive rewards ✓ Epic jewelry reward opportunities ✓ Weekly Olympiad cycles ✓ Castle Sieges ✓ Clan competition Fight for glory. Earn your rewards. ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🛡️ FAIR PLAY & QUALITY OF LIFE ✓ DragonGuard Anti-Cheat ✓ Custom Anti-Bot CAPTCHA ✓ No Pay-to-Win philosophy ✓ Improved class balance ✓ Progressive NPC Buffer ✓ 1-hour buffs ✓ Offline Shops ✓ Community Board skill learning ✓ Shift+Click monster drop information ✓ Combo Songs & Dances ✓ Tattoo System ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 📅 SERVER ROADMAP OCT 02 — GRAND OPENING OCT 05 — Seven Signs Quest Period OCT 07 — Team vs Team Begins OCT 12 — Olympiad & Seal Validation OCT 17–18 — First Castle Sieges OCT 19 — First Heroes OCT 28 — Stage 2: Dynasty & Attribute Stones ━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 🔥 THE COUNTDOWN HAS BEGUN! Old rivalries will return. New alliances will rise. Legends will be written. Will you be part of the next chapter? ⚔️ DRAGON-NETWORK LEGACY x15 📅 OCTOBER 2, 2026 — 19:00 UTC+2 🌐 OFFICIAL WEBSITE https://dragon-network.eu 📜 SERVER FEATURES https://dragon-network.eu/features 🔧 SEASON IMPROVEMENTS https://dragon-network.eu/whats-new DRAGON-NETWORK — FORGE YOUR LEGACY.
  • 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..