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

    • When you say bots allowed, it means we are allowed to use adrenaline ?
    • https://l2mayhem.ru/   The Mayhem Server is designed for players who want to enjoy the game without unnecessary stress or steep barriers. We focus on a comfortable gaming experience: the mechanics are adapted so that even newcomers can get up to speed quickly, while veterans will be happy to return to the beloved universe. On the server, character progression and content difficulty are well balanced: your character develops steadily, without the need to spend huge amounts of time on repetitive tasks. For players’ convenience, we’ve implemented autofarm - it lets you complete daily tasks efficiently. Moreover, bots are officially allowed on the server: they help automate routine actions, so you can focus on the most exciting parts of the game - sieges, PvP, clan wars, and crafting. The server’s atmosphere is friendly: the active community is always ready to offer advice, and the administration ensures order and fairness. Whether you’re looking for a relaxed leveling and world‑exploration experience or want to take part in intense events, everyone can find their own pace and playstyle here. Right now, the server features new activities: we’ve added new instances and locations with unique mechanics and rewards, as well as rare items that can only be obtained in these zones. This is a great chance to get powerful gear and stand out among other players.   Rates: - Grind: EXP/SP x3 (Raid Bosses: x3). - Loot: Drop/Spoil/Adena x3; Raid/Epic Raid drops x3. - Quests: All rewards x1.   Gameplay: - Accounts are created automatically. - Mammons is located in the Town of Giran. - Each character has access to the unlimited Auto Farm function. - Mass party functions activated by the party leader. - A pre-installed shortcut panel is provided for each new character. - The full list of chat commands is available on the Community Board. - Players have a x25 weight limit and an increased inventory capacity. - All buffs, dances, and songs last for 2 hours. - Spawn protection lasts 10 seconds after teleporting. - Treasure Chests have been removed from spawns. - Cursed Weapons have been removed from drops. - Common items can no longer be purchased or obtained as drops. - Mobs and Raid Bosses no longer use Cancel skill. - Equipment up to the Dynasty can be purchased with adena. - Shots up to S grade and consumables are available in the Community Board. - Offline shops are supported: simply set up a shop and type the .offline command in chat. - No drop penalty on Raid Bosses unless the player is over 5 levels higher than the boss; otherwise, the drop chance is reduced. - Mana Potions restore 1500 MP and have a 10‑second reuse time. Newbie Mana Potions restore 500 MP. - The Vitality, Nevit, and Recommendations systems have been disabled. - The store now offers a lower buy price for player‑sold items. - NPC Victor visits Town of Giran on Wednesdays and Saturdays for gear/doll upgrades and elemental exchange. - Once you hit level 40, every mob can drop one of three medals: Bronze, Silver, or Gold.   Premium: - +35% to EXP/SP, Adena, Seal Stones, Element Stones, and Epaulette drops. - Buffs, dances, and songs last 3 hours. - With Premium, players can get 3‑hour buffs by purchasing them from other players.   Enchanting: - The chance to successfully enchant gear is 65%. Safe enchantment is up to +3; the maximum enchant level is +20. - Elemental Stones: 50% chance. Elemental Crystals: 30% chance.   Skills: - Auto‑learn all skills and Forgotten Skills. - 30 buff slots, 12 Dance/Song slots. - Subclass max level raised to 85.   Quests: - 25 000 Adena is required to obtain the 1st class; 250 000 Adena for the 2nd class; 10 000 000 Adena for the 3rd class. - The subclass quest is not required. - The Freya quest is not required. - The Hard Freya quest is not required. - Access to Frintezza is granted only after completing the quest or upon having the purchased quest item. - Access to Baium is granted only after completing the quest or upon having the purchased quest item. - Access to Antharas is granted only after completing the quest or upon having the purchased quest item. - Access to Valakas is granted only after completing the quest or upon having the purchased quest item. - Hellbound progression is at level 1.   Olympiad: - Olympiads are held monthly. - Enchantment limit is +6. - Starting Olympiad requires 6 characters. - You need 15 battles to receive a reward. - Only non‑class battles are available.   Sieges/Territory Wars: - Flags are returned to their owners at the start of each Territory War, which occurs every 2 weeks. - A clan’s maximum number of captured flags in TW is 3.   Raid Bosses/Epic Bosses/Instance Features: - RB status is available on the Community Board. - Freya - 6-27 chars to enter. - Hard Freya - 6-27 chars to enter. - Frintezza - 6-45 chars to enter. - Ultra Daytime Zaken - 6-9 chars to enter. - Daytime Zaken - 6-9 chars to enter. - Nightly Zaken - 6-450 chars to enter. - Tiat - 9-45 chars to enter. - Beleth - 9 chars to enter. - Day/night restrictions for all Zaken instances have been removed. - Level‑limited zones: Ant Nest (levels 1–45), Sea of Spores (levels 1–56), Core (levels 1–56). - Almost all Raid Bosses listed in the Community Board drop an Enchanting Box with a 100% chance. - New Raid Bosses and their jewelry have been added. Teleport to these bosses via NPC Mirelle in Town of Giran. - New Instances: dolls, timed epic jewelry, and upgrade item for cloaks, bracelets, and accessories. Enter via NPC Ancient Portal in Town of Giran; 6-9 chars to enter.
    • Estou procurando cloacks do classic adaptadas para cliente interlude.
    • Good luck with your sales, but: Demo video. Show the siege, the olympiad, the tvt when you are selling something so complex and expensive.
    • 1.8 BILION NEW STOCK.70 E PER BILION DISCOUNT IF BUY ALL
  • 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..