Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
Rename.java
#1
Будьте добры дайте файлик благодаря которому можно менять в сервисах ник со спец символами. Либо поправьте мой
Код:
package services;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;

import l2r.commons.dbutils.DbUtils;
import l2r.gameserver.Config;
import l2r.gameserver.cache.Msg;
import l2r.gameserver.dao.CharacterDAO;
import l2r.gameserver.database.DatabaseFactory;
import l2r.gameserver.database.mysql;
import l2r.gameserver.model.Player;
import l2r.gameserver.model.SubClass;
import l2r.gameserver.model.base.ClassId;
import l2r.gameserver.model.base.PlayerClass;
import l2r.gameserver.model.base.Race;
import l2r.gameserver.model.entity.events.impl.SiegeEvent;
import l2r.gameserver.model.entity.olympiad.Olympiad;
import l2r.gameserver.model.pledge.Clan;
import l2r.gameserver.model.pledge.SubUnit;
import l2r.gameserver.network.serverpackets.SystemMessage;
import l2r.gameserver.network.serverpackets.components.CustomMessage;
import l2r.gameserver.network.serverpackets.components.SystemMsg;
import l2r.gameserver.scripts.Functions;
import l2r.gameserver.tables.ClanTable;
import l2r.gameserver.utils.Log;
import l2r.gameserver.utils.Util;

public class Rename extends Functions
{
    private static final String CNAME_TEMPLATE = "[0-9A-Za-z]{3,16})|([0-9\u0410-\u044f]{3,16}";
    public void rename_page()
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_CHANGE_NICK_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        String append = "!Смена ника";
        append += "<br>";
        append += "<font color=\"LEVEL\">" + new CustomMessage("scripts.services.Rename.RenameFor",

getSelf()).addString(Util.formatAdena(Config.SERVICES_CHANGE_NICK_PRICE)).addItemName

(Config.SERVICES_CHANGE_NICK_ITEM) + "</font>";
        append += "<table>";
        append += "<tr><td>" + new CustomMessage("scripts.services.Rename.NewName", getSelf()) + "

<edit var=\"new_name\" width=80></td></tr>";
        append += "<tr><td></td></tr>";
        append += "<tr><td><button value=\"" + new CustomMessage

("scripts.services.Rename.RenameButton", getSelf()) + "\" action=\"bypass -h scripts_services.Rename:rename

$new_name\" width=80 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>";
        append += "</table>";
        show(append, player);
    }

    public void changesex_page()
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_CHANGE_SEX_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(!player.isInPeaceZone())
        {
            show("Посетите город для использования данного сервиса.", player);
            return;
        }

        String append = "Смена пола:";
        append += "<br>";
        append += "<font color=\"LEVEL\">" + new CustomMessage

("scripts.services.SexChange.SexChangeFor", player).addString(Util.formatAdena

(Config.SERVICES_CHANGE_SEX_PRICE)).addItemName(Config.SERVICES_CHANGE_SEX_ITEM) + "</font>";
        append += "<table>";
        append += "<tr><td><button value=\"" + new CustomMessage("scripts.services.SexChange.Button",

player) + "\" action=\"bypass -h scripts_services.Rename:changesex\" width=80 height=15 back=

\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>";
        append += "</table>";
        show(append, player);
    }

    public void separate_page()
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_SEPARATE_SUB_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(player.isHero())
        {
            show("Не доступно для героев.", player);
            return;
        }

        if(player.getSubClasses().size() == 1)
        {
            show("Вы должны иметь хотя бы 1 подкласс.", player);
            return;
        }

        if(!player.getActiveClass().isBase())
        {
            show("Вы должны быть на основным классе.", player);
            return;
        }

        if(player.getActiveClass().getLevel() < 75)
        {
            show("Вы должны иметь 75 уровень саб класса.", player);
            return;
        }

        String append = "Отделение Сабкласса:";
        append += "<br>";
        append += "<font color=\"LEVEL\">" + new CustomMessage("scripts.services.Separate.Price",

player).addString(Util.formatAdena(Config.SERVICES_SEPARATE_SUB_PRICE)).addItemName

(Config.SERVICES_SEPARATE_SUB_ITEM) + "</font>&nbsp;";
        append += "<edit var=\"name\" width=80 height=15 /><br>";
        append += "<table>";

        for(SubClass s : player.getSubClasses().values())
            if(!s.isBase() && s.getClassId() != ClassId.inspector.getId() && s.getClassId() !=

ClassId.judicator.getId())
                append += "<tr><td><button value=\"" + new CustomMessage

("scripts.services.Separate.Button", player).addString(ClassId.VALUES[s.getClassId()].toString()) + "\"

action=\"bypass -h scripts_services.Rename:separate " + s.getClassId() + " $name\" width=200 height=15 back=

\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>";

        append += "</table>";
        show(append, player);
    }

    public void separate(String[] param)
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_SEPARATE_SUB_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(player.isHero())
        {
            show("Не доступно для героев.", player);
            return;
        }

        if(player.getSubClasses().size() == 1)
        {
            show("Вы должны иметь хотя бы 1 подкласс.", player);
            return;
        }

        if(!player.getActiveClass().isBase())
        {
            show("Вы должны быть на основным классе.", player);
            return;
        }

        if(player.getActiveClass().getLevel() < 75)
        {
            show("Вы должны иметь 75 уровень саб класса.", player);
            return;
        }

        if(param.length < 2)
        {
            show("Вы должны указать цель.", player);
            return;
        }

        if(getItemCount(player, Config.SERVICES_SEPARATE_SUB_ITEM) <

Config.SERVICES_SEPARATE_SUB_PRICE)
        {
            if(Config.SERVICES_SEPARATE_SUB_ITEM == 57)
                player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
            else
                player.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
            return;
        }

        int classtomove = Integer.parseInt(param[0]);
        int newcharid = 0;
        for(Entry<Integer, String> e : player.getAccountChars().entrySet())
            if(e.getValue().equalsIgnoreCase(param[1]))
                newcharid = e.getKey();

        if(newcharid == 0)
        {
            show("Цель не существует.", player);
            return;
        }

        if(mysql.simple_get_int("level", "character_subclasses", "char_obj_id=" + newcharid + " AND

level > 1") > 1)
        {
            show("Цель должна иметь уровень 1.", player);
            return;
        }

        mysql.set("DELETE FROM character_subclasses WHERE char_obj_id=" + newcharid);
        mysql.set("DELETE FROM character_skills WHERE char_obj_id=" + newcharid);
        mysql.set("DELETE FROM character_skills_save WHERE char_obj_id=" + newcharid);
        mysql.set("DELETE FROM character_effects_save WHERE object_id=" + newcharid);
        mysql.set("DELETE FROM character_hennas WHERE char_obj_id=" + newcharid);
        mysql.set("DELETE FROM character_shortcuts WHERE char_obj_id=" + newcharid);
        mysql.set("DELETE FROM character_variables WHERE obj_id=" + newcharid);

        mysql.set("UPDATE character_subclasses SET char_obj_id=" + newcharid + ", isBase=1,

certification=0 WHERE char_obj_id=" + player.getObjectId() + " AND class_id=" + classtomove);
        mysql.set("UPDATE character_skills SET char_obj_id=" + newcharid + " WHERE char_obj_id=" +

player.getObjectId() + " AND class_index=" + classtomove);
        mysql.set("UPDATE character_skills_save SET char_obj_id=" + newcharid + " WHERE char_obj_id=" +

player.getObjectId() + " AND class_index=" + classtomove);
        mysql.set("UPDATE character_effects_save SET object_id=" + newcharid + " WHERE object_id=" +

player.getObjectId() + " AND id=" + classtomove);
        mysql.set("UPDATE character_hennas SET char_obj_id=" + newcharid + " WHERE char_obj_id=" +

player.getObjectId() + " AND class_index=" + classtomove);
        mysql.set("UPDATE character_shortcuts SET char_obj_id=" + newcharid + " WHERE char_obj_id=" +

player.getObjectId() + " AND class_index=" + classtomove);

        mysql.set("UPDATE character_variables SET obj_id=" + newcharid + " WHERE obj_id=" +

player.getObjectId() + " AND name like 'TransferSkills%'");

        player.modifySubClass(classtomove, 0);

        removeItem(player, Config.SERVICES_CHANGE_BASE_ITEM, Config.SERVICES_CHANGE_BASE_PRICE);
        player.logout();
        //Log.add("Character " + player + " base changed to " + target, "services");
    }

    public void changebase_page()
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_CHANGE_BASE_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(!player.isInPeaceZone())
        {
            show("Вы должны быть в мирной зоне, чтобы воспользоваться этой услугой.", player);
            return;
        }

        if(player.isHero())
        {
            sendMessage("Не доступно для героев.", player);
            return;
        }

        String append = "Смена Базового класса:";
        append += "<br>";
        append += "<font color=\"LEVEL\">" + new CustomMessage("scripts.services.BaseChange.Price",

player).addString(Util.formatAdena(Config.SERVICES_CHANGE_BASE_PRICE)).addItemName

(Config.SERVICES_CHANGE_BASE_ITEM) + "</font>";
        append += "<table>";

        List<SubClass> possible = new ArrayList<SubClass>();
        if(player.getActiveClass().isBase())
        {
            possible.addAll(player.getSubClasses().values());
            possible.remove(player.getSubClasses().get(player.getBaseClassId()));

            for(SubClass s : player.getSubClasses().values())
                for(SubClass s2 : player.getSubClasses().values())
                    if(s != s2 && !PlayerClass.areClassesComportable(PlayerClass.values()

[s.getClassId()], PlayerClass.values()[s2.getClassId()]) || s2.getLevel() < 75)
                        possible.remove(s2);
        }

        if(possible.isEmpty())
            append += "<tr><td width=300>" + new CustomMessage

("scripts.services.BaseChange.NotPossible", player) + "</td></tr>";
        else
            for(SubClass s : possible)
                append += "<tr><td><button value=\"" + new CustomMessage

("scripts.services.BaseChange.Button", player).addString(ClassId.VALUES[s.getClassId()].toString()) + "\"

action=\"bypass -h scripts_services.Rename:changebase " + s.getClassId() + "\" width=200 height=15 back=

\"L2UI_CT1.Button_DF_Down\" fore=\"L2UI_CT1.Button_DF\"></td></tr>";
        append += "</table>";
        show(append, player);
    }

    public void changebase(String[] param)
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_CHANGE_BASE_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(!player.isInPeaceZone())
        {
            show("Вы должны быть в мирной зоне, чтобы воспользоваться этой услугой.", player);
            return;
        }

        if(!player.getActiveClass().isBase())
        {
            show("Вы должны быть на основном классе, чтобы воспользоваться этой услугой.", player);
            return;
        }

        if(player.isHero())
        {
            show("Не доступно для героев.", player);
            return;
        }

        if(getItemCount(player, Config.SERVICES_CHANGE_BASE_ITEM) < Config.SERVICES_CHANGE_BASE_PRICE)
        {
            if(Config.SERVICES_CHANGE_BASE_ITEM == 57)
                player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
            else
                player.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
            return;
        }

        int target = Integer.parseInt(param[0]);
        SubClass newBase = player.getSubClasses().get(target);

        player.getActiveClass().setBase(false);
        player.getActiveClass().setCertification(newBase.getCertification());

        newBase.setCertification(0);
        player.getActiveClass().setExp(player.getExp());
        player.checkSkills();

        newBase.setBase(true);

        player.setBaseClass(target);

        player.setHairColor(0);
        player.setHairStyle(0);
        player.setFace(0);
        Olympiad.unRegisterNoble(player);
        removeItem(player, Config.SERVICES_CHANGE_BASE_ITEM, Config.SERVICES_CHANGE_BASE_PRICE);
        player.logout();
        //Log.add("Character " + player + " base changed to " + target, "services");
    }

    public void rename(String[] args)
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_CHANGE_NICK_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(player.isHero())
        {
            sendMessage("Не доступно для героев.", player);
            return;
        }

        if(args.length != 1)
        {
            show(new CustomMessage("scripts.services.Rename.incorrectinput", player), player);
            return;
        }

        if(player.getEvent(SiegeEvent.class) != null)
        {
            show(new CustomMessage("scripts.services.Rename.SiegeNow", player), player);
            return;
        }

        String name = args[0];
        {
    show(new CustomMessage("scripts.services.Rename.incorrectinput", player), player);
    

            return;
        
        }

        if(getItemCount(player, Config.SERVICES_CHANGE_NICK_ITEM) < Config.SERVICES_CHANGE_NICK_PRICE)
        {
            if(Config.SERVICES_CHANGE_NICK_ITEM == 57)
                player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
            else
                player.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
            return;
        }

        if(CharacterDAO.getInstance().getObjectIdByName(name) > 0)
        {
            show(new CustomMessage("scripts.services.Rename.Thisnamealreadyexists", player),

player);
            return;
        }

        removeItem(player, Config.SERVICES_CHANGE_NICK_ITEM, Config.SERVICES_CHANGE_NICK_PRICE);

        String oldName = player.getName();
        player.reName(name, true);
        Log.add("Character " + oldName + " renamed to " + name, "renames");
        show(new CustomMessage("scripts.services.Rename.changedname", player).addString

(oldName).addString(name), player);
    }

    public void changesex()
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_CHANGE_SEX_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(player.getRace() == Race.kamael)
        {
            show("Не доступно для Kamael.", player);
            return;
        }

        if(!player.isInPeaceZone())
        {
            show("Вы должны быть в мирной зоне, чтобы воспользоваться этой услугой.", player);
            return;
        }

        if(getItemCount(player, Config.SERVICES_CHANGE_SEX_ITEM) < Config.SERVICES_CHANGE_SEX_PRICE)
        {
            if(Config.SERVICES_CHANGE_SEX_ITEM == 57)
                player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
            else
                player.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
            return;
        }

        Connection con = null;
        PreparedStatement offline = null;
        try
        {
            con = DatabaseFactory.getInstance().getConnection();
            offline = con.prepareStatement("UPDATE characters SET sex = ? WHERE obj_Id = ?");
            offline.setInt(1, player.getSex() == 1 ? 0 : 1);
            offline.setInt(2, player.getObjectId());
            offline.executeUpdate();
        }
        catch(Exception e)
        {
            e.printStackTrace();
            show(new CustomMessage("common.Error", player), player);
            return;
        }
        finally
        {
            DbUtils.closeQuietly(con, offline);
        }

        player.setHairColor(0);
        player.setHairStyle(0);
        player.setFace(0);
        removeItem(player, Config.SERVICES_CHANGE_SEX_ITEM, Config.SERVICES_CHANGE_SEX_PRICE);
        player.logout();
        Log.add("Character " + player + " sex changed to " + (player.getSex() == 1 ? "male" :

"female"), "renames");
    }

    public void rename_clan_page()
    {
        Player player = getSelf();
        if(player == null)
            return;
        if (!Config.SERVICES_CHANGE_CLAN_NAME_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(player.getClan() == null || !player.isClanLeader())
        {
            player.sendPacket(new SystemMessage(SystemMessage.S1_IS_NOT_A_CLAN_LEADER).addName

(player));
            return;
        }

        String append = "!Смена имени клана:";
        append += "<br>";
        append += "<font color=\"LEVEL\">" + new CustomMessage("scripts.services.Rename.RenameFor",

getSelf()).addString(Util.formatAdena(Config.SERVICES_CHANGE_CLAN_NAME_PRICE)).addItemName

(Config.SERVICES_CHANGE_CLAN_NAME_ITEM) + "</font>";
        append += "<table>";
        append += "<tr><td>" + new CustomMessage("scripts.services.Rename.NewName", getSelf()) + ":

<edit var=\"new_name\" width=80></td></tr>";
        append += "<tr><td></td></tr>";
        append += "<tr><td><button value=\"" + new CustomMessage

("scripts.services.Rename.RenameButton", getSelf()) + "\" action=\"bypass -h

scripts_services.Rename:rename_clan $new_name\" width=80 height=15 back=\"L2UI_CT1.Button_DF_Down\" fore=

\"L2UI_CT1.Button_DF\"></td></tr>";
        append += "</table>";
        show(append, player);
    }

    public void rename_clan(String[] param)
    {
        Player player = getSelf();
        if(player == null || param == null || param.length == 0)
            return;
        if (!Config.SERVICES_CHANGE_CLAN_NAME_ENABLED)
        {
            show("Сервис отключен.", player);
            return;
        }
        if(player.getClan() == null || !player.isClanLeader())
        {
            player.sendPacket(new SystemMessage(SystemMessage.S1_IS_NOT_A_CLAN_LEADER).addName

(player));
            return;
        }

        if(player.getEvent(SiegeEvent.class) != null)
        {
            show(new CustomMessage("scripts.services.Rename.SiegeNow", player), player);
            return;
        }

        if(!Util.isMatchingRegexp(param[0], Config.CLAN_NAME_TEMPLATE))
        {
            player.sendPacket(Msg.CLAN_NAME_IS_INCORRECT);
            return;
        }
        if(ClanTable.getInstance().getClanByName(param[0]) != null)
        {
            player.sendPacket(Msg.THIS_NAME_ALREADY_EXISTS);
            return;
        }

        if(getItemCount(player, Config.SERVICES_CHANGE_CLAN_NAME_ITEM) <

Config.SERVICES_CHANGE_CLAN_NAME_PRICE)
        {
            if(Config.SERVICES_CHANGE_CLAN_NAME_ITEM == 57)
                player.sendPacket(Msg.YOU_DO_NOT_HAVE_ENOUGH_ADENA);
            else
                player.sendPacket(SystemMsg.INCORRECT_ITEM_COUNT);
            return;
        }

        show(new CustomMessage("scripts.services.Rename.changedname", player).addString(player.getClan

().getName()).addString(param[0]), player);
        SubUnit sub = player.getClan().getSubUnit(Clan.SUBUNIT_MAIN_CLAN);
        sub.setName(param[0], true);

        removeItem(player, Config.SERVICES_CHANGE_CLAN_NAME_ITEM,

Config.SERVICES_CHANGE_CLAN_NAME_PRICE);
        player.getClan().broadcastClanStatus(true, true, false);
    }
}
Ответ
#2
ALANEX Написал:Будьте добры дайте файлик благодаря которому можно менять в сервисах ник со спец символами. Либо поправьте мой
Открыть спойлер
Вот эта строчка отвечает за допустимые символы
Код:
private static final String CNAME_TEMPLATE = "[0-9A-Za-z]{3,16})|([0-9\u0410-\u044f]{3,16}";
.
Только это сервис для комуньки. Тебе еще надо кодировку в MySQL на UTF-8 выставить и в конфиге с геймсервером по-моему тоже надо править аналогичную строчку(если не путаю с лс).
Ответ
#3
тс не умеет ждать :redlol:
в аське рабочий вариант, тему в топку :Olen':
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  Lineage2 java Chronicle3 сборка AlexBayev 0 268 07-20-2024, 05:23 PM
Последний пост: AlexBayev
  Порекомендуйте хорошую Java сборку L2 GF (PTS не потяну ибо навыков 0 ) Force 0 839 10-28-2023, 12:02 PM
Последний пост: Force
  Java dev hired! Krasib 0 1,095 08-15-2022, 10:00 AM
Последний пост: Krasib
  SVN ссылки Java серверов. PROGRAMMATOR 284 233,993 11-19-2020, 08:50 PM
Последний пост: AbsolutePower
  Java координаты, различия PTS и Java, какие сборки хороши (iL) varted 5 2,478 09-12-2018, 08:29 AM
Последний пост: varted
  l2 c4 java estorq 0 1,310 08-17-2018, 10:07 PM
Последний пост: estorq
  Топовая Java сборка под х3 и х1200 NovaPlanet 32 8,306 11-22-2016, 11:38 AM
Последний пост: 6bit
  Java в Class virusoflove 1 1,732 10-17-2016, 09:04 AM
Последний пост: Rolfer
  Помогите поставить Java сервер la2 c3! Winst 0 1,172 10-16-2016, 12:34 PM
Последний пост: Winst
  Ищу стабильную сборка java сервера HF introzorn 12 6,137 10-14-2016, 09:34 PM
Последний пост: Mangol

Перейти к форуму:


Пользователи, просматривающие эту тему: 1 Гость(ей)