Autor Tema: [IMP] Cambiar contraseña del jugador con comandos  (Leído 1650 veces)

Febrero 24, 2014, 02:23:08 pm

Desconectado swarlog

  • Desarrollador
  • Usuario
  • *
  • Mensajes: 1.605
  • Karma: 4
  • Sexo: Masculino
    • U3Games
Se trata de un comando a añadir en vuestros servidores con el que un jugador desde dentro del servidor, podrá cambiar su contraseña de cuenta mediante el uso de un comando. By Jing~Jang, espero que os guste!

Código: You are not allowed to view links. Register or Login
/*
 * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */
package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;

import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.StringTokenizer;

import com.l2jfrozen.crypt.Base64;
import com.l2jfrozen.util.database.L2DatabaseFactory;
import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.network.serverpackets.ExShowScreenMessage;

/*
 * @Author: Unknow
 * @Adaptation: |-Jing~Jang-|
 */

public class ChangePassword implements IVoicedCommandHandler
{
private static final String[] _voicedCommands =
{
"changepass"
};

@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
if(command.equalsIgnoreCase("changepass") && target != null)
{
StringTokenizer st = new StringTokenizer(target);
try
{
String curpass = null, newpass = null, repeatnewpass = null;

if(st.hasMoreTokens())
curpass = st.nextToken();
if(st.hasMoreTokens())
newpass = st.nextToken();
if(st.hasMoreTokens())
repeatnewpass = st.nextToken();

if(!(curpass == null || newpass == null || repeatnewpass == null))
{
if(!newpass.equals(repeatnewpass))
{
activeChar.sendMessage("The new password doesn't match with the repeated one!");
return false;
}
if(newpass.length() < 4)
{
activeChar.sendMessage("The new password is shorter than 4 characters! Please try with a longer one.");
return false;
}
if(newpass.length() > 25)
{
activeChar.sendMessage("The new password is longer than 25 characters! Please try with a shorter one.");
return false;
}

MessageDigest md = MessageDigest.getInstance("SHA");

byte[] raw = curpass.getBytes("UTF-8");
raw = md.digest(raw);
String curpassEnc = Base64.encodeBytes(raw);
String pass = null;
int passUpdated = 0;

Connection con = null;
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
statement.setString(1, activeChar.getAccountName());
ResultSet rset = statement.executeQuery();

if(rset.next())
{
pass = rset.getString("password");
}

rset.close();
statement.close();

if(curpassEnc.equals(pass))
{
byte[] password = newpass.getBytes("UTF-8");
password = md.digest(password);

PreparedStatement ps = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?");
ps.setString(1, Base64.encodeBytes(password));
ps.setString(2, activeChar.getAccountName());
passUpdated = ps.executeUpdate();
ps.close();
con.close();

if(passUpdated > 0)
{
activeChar.sendMessage("You have successfully changed your password!");
activeChar.sendPacket(new ExShowScreenMessage("You have successfully changed your password!#Enjoy :)", 6000));
}
else
{
activeChar.sendMessage("The password change was unsuccessful!");
activeChar.sendPacket(new ExShowScreenMessage("The password change was unsuccessful!!#U_u)", 6000));
}
}
else
{
activeChar.sendMessage("CurrentPass doesn't match with your current one.");
return false;
}
}
else
{
activeChar.sendMessage("Invalid pass data! Format: .changepass CurrentPass NewPass NewPass");
return false;
}
}
catch(Exception e)
{
activeChar.sendMessage("A problem occured while changing password!");
}
}
else
{
activeChar.sendMessage("To change your current password, you have to type the command in the following format(without the brackets []): [.changepass CurrentPass NewPass NewPass]. You should also know that the password is case sensitive.");
activeChar.sendPacket(new ExShowScreenMessage("To change your current password, you have to type the command in the following format(without the brackets []):#[.changepass CurrentPass NewPass NewPass]. You should also know that the password is case sensitive.)", 7000));
return false;
}

return true;
}

@Override
public String[] getVoicedCommandList()
{
return _voicedCommands;
}

}

Mayo 27, 2017, 05:59:10 pm
Respuesta #1

Desconectado heladito

  • Usuario
  • *
  • Mensajes: 12
  • Karma: 0
  • Sexo: Masculino
hoal, como estas? muy bueno. Como tengo que llamar al .java? no entiendo eso.

Mayo 28, 2017, 09:04:03 am
Respuesta #2

Desconectado swarlog

  • Desarrollador
  • Usuario
  • *
  • Mensajes: 1.605
  • Karma: 4
  • Sexo: Masculino
    • U3Games
You are not allowed to view links. Register or Login
hoal, como estas? muy bueno. Como tengo que llamar al .java? no entiendo eso.

Código: You are not allowed to view links. Register or Login
public class ChangePassword implements IVoicedCommandHandler
ChangePassword.java

Septiembre 29, 2019, 06:21:58 pm
Respuesta #3

Desconectado wazarro

  • Usuario
  • *
  • Mensajes: 1
  • Karma: 0
Se podra modificar para que cambie el PIN code

Este es mi SQL
Código: You are not allowed to view links. Register or Login
DROP TABLE IF EXISTS `characters`;
CREATE TABLE `characters`  (
  `account_name` varchar(45) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,
  `obj_Id` decimal(11, 0) NOT NULL DEFAULT 0,
  `char_name` varchar(35) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,
  `level` decimal(11, 0) NULL DEFAULT NULL,
  `maxHp` decimal(11, 0) NULL DEFAULT 1,
  `curHp` decimal(18, 0) NULL DEFAULT 1,
  `maxCp` decimal(11, 0) NULL DEFAULT 1,
  `curCp` decimal(18, 0) NULL DEFAULT 1,
  `maxMp` decimal(11, 0) NULL DEFAULT 1,
  `curMp` decimal(18, 0) NULL DEFAULT 1,
  `acc` decimal(11, 0) NULL DEFAULT NULL,
  `crit` decimal(10, 0) NULL DEFAULT NULL,
  `evasion` decimal(11, 0) NULL DEFAULT NULL,
  `mAtk` decimal(11, 0) NULL DEFAULT NULL,
  `mDef` decimal(11, 0) NULL DEFAULT NULL,
  `mSpd` decimal(11, 0) NULL DEFAULT NULL,
  `pAtk` decimal(11, 0) NULL DEFAULT NULL,
  `pDef` decimal(11, 0) NULL DEFAULT NULL,
  `pSpd` decimal(11, 0) NULL DEFAULT NULL,
  `runSpd` decimal(11, 0) NULL DEFAULT NULL,
  `walkSpd` decimal(11, 0) NULL DEFAULT NULL,
  `str` decimal(11, 0) NULL DEFAULT NULL,
  `con` decimal(11, 0) NULL DEFAULT NULL,
  `dex` decimal(11, 0) NULL DEFAULT NULL,
  `_int` decimal(11, 0) NULL DEFAULT NULL,
  `men` decimal(11, 0) NULL DEFAULT NULL,
  `wit` decimal(11, 0) NULL DEFAULT NULL,
  `face` decimal(11, 0) NULL DEFAULT NULL,
  `hairStyle` decimal(11, 0) NULL DEFAULT NULL,
  `hairColor` decimal(11, 0) NULL DEFAULT NULL,
  `sex` decimal(11, 0) NULL DEFAULT NULL,
  `heading` decimal(11, 0) NULL DEFAULT NULL,
  `x` decimal(11, 0) NULL DEFAULT NULL,
  `y` decimal(11, 0) NULL DEFAULT NULL,
  `z` decimal(11, 0) NULL DEFAULT NULL,
  `movement_multiplier` decimal(9, 8) NULL DEFAULT NULL,
  `attack_speed_multiplier` decimal(10, 9) NULL DEFAULT NULL,
  `colRad` decimal(10, 3) NULL DEFAULT NULL,
  `colHeight` decimal(10, 3) NULL DEFAULT NULL,
  `exp` decimal(20, 0) NULL DEFAULT NULL,
  `expBeforeDeath` decimal(20, 0) NULL DEFAULT 0,
  `sp` decimal(11, 0) NULL DEFAULT NULL,
  `karma` decimal(11, 0) NULL DEFAULT NULL,
  `pvpkills` decimal(11, 0) NULL DEFAULT NULL,
  `pkkills` decimal(11, 0) NULL DEFAULT NULL,
  `clanid` decimal(11, 0) NULL DEFAULT NULL,
  `maxload` decimal(11, 0) NULL DEFAULT NULL,
  `race` decimal(11, 0) NULL DEFAULT NULL,
  `classid` decimal(11, 0) NULL DEFAULT NULL,
  `base_class` int(2) NOT NULL DEFAULT 0,
  `deletetime` decimal(20, 0) NULL DEFAULT NULL,
  `cancraft` decimal(11, 0) NULL DEFAULT NULL,
  `title` varchar(16) CHARACTER SET latin1 COLLATE latin1_swedish_ci NULL DEFAULT NULL,
  `rec_have` int(3) NOT NULL DEFAULT 0,
  `rec_left` int(3) NOT NULL DEFAULT 0,
  `accesslevel` decimal(4, 0) NULL DEFAULT NULL,
  `online` decimal(1, 0) NULL DEFAULT NULL,
  `onlinetime` decimal(20, 0) NULL DEFAULT NULL,
  `char_slot` decimal(1, 0) NULL DEFAULT NULL,
  `newbie` decimal(1, 0) NULL DEFAULT 1,
  `lastAccess` decimal(20, 0) NULL DEFAULT NULL,
  `clan_privs` int(11) NULL DEFAULT 0,
  `wantspeace` decimal(1, 0) NULL DEFAULT 0,
  `isin7sdungeon` decimal(1, 0) NOT NULL DEFAULT 0,
  `punish_level` int(3) UNSIGNED NOT NULL DEFAULT 0,
  `punish_timer` int(10) UNSIGNED NOT NULL DEFAULT 0,
  `power_grade` decimal(11, 0) NULL DEFAULT NULL,
  `nobless` decimal(1, 0) NOT NULL DEFAULT 0,
  `subpledge` int(1) NOT NULL DEFAULT 0,
  `last_recom_date` decimal(20, 0) NOT NULL DEFAULT 0,
  `lvl_joined_academy` int(1) NOT NULL DEFAULT 0,
  `apprentice` int(1) NOT NULL DEFAULT 0,
  `sponsor` int(1) NOT NULL DEFAULT 0,
  `varka_ketra_ally` int(1) NOT NULL DEFAULT 0,
  `clan_join_expiry_time` decimal(20, 0) NOT NULL DEFAULT 0,
  `clan_create_expiry_time` decimal(20, 0) NOT NULL DEFAULT 0,
  `death_penalty_level` int(2) NOT NULL DEFAULT 0,
  `pc_point` int(5) NOT NULL DEFAULT 0,
  `name_color` varchar(8) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '\0\0\0',
  `title_color` varchar(8) CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '\0\0\0',
  `first_log` int(11) NULL DEFAULT 1,
  `aio` decimal(1, 0) NOT NULL DEFAULT 0,
  `aio_end` decimal(20, 0) NOT NULL DEFAULT 0,
  `arena_wins` decimal(1, 0) NOT NULL DEFAULT 0,
  `arena_defeats` decimal(1, 0) NOT NULL DEFAULT 0,
  `VoteTimeReward` decimal(20, 0) NOT NULL DEFAULT 0,
  `pin` int(4) NULL DEFAULT NULL,
  `pinsubmited` int(1) NULL DEFAULT 1,
  PRIMARY KEY (`obj_Id`) USING BTREE,
  INDEX `clanid`(`clanid`) USING BTREE
) ENGINE = MyISAM CHARACTER SET = latin1 COLLATE = latin1_swedish_ci ROW_FORMAT = Dynamic;

Y este es mi intento por modificarlo T.T

Código: You are not allowed to view links. Register or Login
/*
 * 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 3 of the License, 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, see <http://www.gnu.org/licenses/>.
 */
package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;

import java.security.MessageDigest;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.StringTokenizer;

import com.l2jfrozen.crypt.Base64;
import com.l2jfrozen.util.database.L2DatabaseFactory;
import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.network.serverpackets.ExShowScreenMessage;

/*
 * @Author: Unknow
 */

public class ChangePin implements IVoicedCommandHandler
{
private static final String[] _voicedCommands =
{
"changepin"
};

@Override
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
if(command.equalsIgnoreCase("ChangePin") && target != null)
{
StringTokenizer st = new StringTokenizer(target);
try
{
String curpass = null, newpass = null, repeatnewpass = null;

if(st.hasMoreTokens())
curpass = st.nextToken();
if(st.hasMoreTokens())
newpass = st.nextToken();
if(st.hasMoreTokens())
repeatnewpass = st.nextToken();

if(!(curpass == null || newpass == null || repeatnewpass == null))
{
if(!newpass.equals(repeatnewpass))
{
activeChar.sendMessage("The new pin doesn't match with the repeated one!");
return false;
}
if(newpass.length() < 4)
{
activeChar.sendMessage("The new pin is shorter than 4 characters! Please try with a longer one.");
return false;
}
if(newpass.length() > 25)
{
activeChar.sendMessage("The new pin is longer than 25 characters! Please try with a shorter one.");
return false;
}

MessageDigest md = MessageDigest.getInstance("SHA");

byte[] raw = curpass.getBytes("UTF-8");
raw = md.digest(raw);
String curpassEnc = Base64.encodeBytes(raw);
String pass = null;
int passUpdated = 0;

Connection con = null;
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = con.prepareStatement("SELECT pin FROM characters WHERE obj_id=?");
statement.setInt(1, activeChar.getObjectId());
ResultSet rset = statement.executeQuery();

if(rset.next())
{
pass = rset.getString("pin");
}

rset.close();
statement.close();

if(curpassEnc.equals(pass))
{
byte[] pin = newpass.getBytes("UTF-8");
pin = md.digest(pin);

PreparedStatement ps = con.prepareStatement("UPDATE characters SET pin=? WHERE obj_id=?");
ps.setInt(2, activeChar.getObjectId());
passUpdated = ps.executeUpdate();
ps.close();
con.close();

if(passUpdated > 0)
{
activeChar.sendMessage("You have successfully changed your pin!");
activeChar.sendPacket(new ExShowScreenMessage("You have successfully changed your pin!#Enjoy :)", 6000));
}
else
{
activeChar.sendMessage("The pin change was unsuccessful!");
activeChar.sendPacket(new ExShowScreenMessage("The pin change was unsuccessful!!#U_u)", 6000));
}
}
else
{
activeChar.sendMessage("CurrentPass doesn't match with your current one.");
return false;
}
}
else
{
activeChar.sendMessage("Invalida Pass data! el Formato es: .ChangePin PassActual NuevaPass ReNuevaPass");
return false;
}
}
catch(Exception e)
{
activeChar.sendMessage("A problem occured while changing pin!");
}
}
else
{
activeChar.sendMessage("To change your current pin, you have to type the command in the following format(without the brackets []): [.ChangePin CurrentPass NewPass NewPass]. You should also know that the pin is case sensitive.");
activeChar.sendPacket(new ExShowScreenMessage("To change your current pin, you have to type the command in the following format(without the brackets []):#[.ChangePin CurrentPass NewPass NewPass]. You should also know that the pin is case sensitive.)", 7000));
return false;
}

return true;
}

@Override
public String[] getVoicedCommandList()
{
return _voicedCommands;
}

}

Desde ya gracias por compartir el de .changepass