Jump to content
  • 0

VoicedCommandHandler for aCis [EXAMPLE .online]


Question

2 answers to this question

Recommended Posts

  • 0
Posted

command сode .info

package ru.la2betdream.gameserver.handler.voicedcommandhandlers;


import ru.la2betdream.gameserver.cache.HtmCache;
import ru.la2betdream.gameserver.handler.IVoicedCommandHandler;
import ru.la2betdream.gameserver.model.actor.instance.L2PcInstance;
import ru.la2betdream.gameserver.model.olympiad.Olympiad;
import ru.la2betdream.gameserver.network.serverpackets.NpcHtmlMessage;

public class info
  implements IVoicedCommandHandler
{
  private static String[] VOICED_COMMANDS = { "info" };

  public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  {
    String htmFile = "data/html/info.htm";
    String htmContent = HtmCache.getInstance().getHtm(htmFile);

    if ((activeChar.isInOlympiadMode()) || (Olympiad.getInstance().isOlympiadEnd()))
    {
      activeChar.sendMessage("You can not use the command when Olympiad");
      return false;
    }
    if (activeChar.isDead())
    {
      activeChar.sendMessage("You can not use a command when you are dead");
      return false;
    }

    if (htmContent != null)
    {
      NpcHtmlMessage Html = new NpcHtmlMessage(1);

      Html.setHtml(htmContent);
      activeChar.sendPacket(Html);
    }
    else
    {
      activeChar.sendMessage("Missing " + htmFile + " !");
    }

    return true;
  }

  public String[] getVoicedCommandList()
  {
    return VOICED_COMMANDS;
  }
}

 

command сode .online

 

package ru.la2betdream.gameserver.handler.voicedcommandhandlers;

import ru.la2betdream.gameserver.handler.IVoicedCommandHandler;
import ru.la2betdream.gameserver.model.L2World;
import ru.la2betdream.gameserver.model.actor.instance.L2PcInstance;
import ru.la2betdream.gameserver.network.SystemMessageId;
import ru.la2betdream.gameserver.network.serverpackets.SystemMessage;
import java.util.Collection;

public class Online
  implements IVoicedCommandHandler
{
  private static final String[] VOICED_COMMANDS = { "online" };

  public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  {
    if (command.startsWith("online"))
    {
      showPlayers(activeChar, target);
    }
    return true;
  }

  public String[] getVoicedCommandList()
  {
    return VOICED_COMMANDS;
  }

  public void showPlayers(L2PcInstance player, String target)
  {
    SystemMessage sm = new SystemMessage(SystemMessageId.S1_S2);
    sm = new SystemMessage(SystemMessageId.S1_S2);
    sm.addString("======<Players Online>======");
    player.sendPacket(sm);
    sm = new SystemMessage(SystemMessageId.S1_S2);
    sm.addString("Players online:");
    sm.addNumber(L2World.getInstance().getAllPlayers().size());
    player.sendPacket(sm);
    sm = new SystemMessage(SystemMessageId.S1_S2);
    sm.addString("=======================");
    player.sendPacket(sm);
  }
}

 

command сode password

 

/**
* Created with IntelliJ IDEA.
* User: La2BetDream
* Date: 22.04.13
* Time: 11:14
* To change this template use File | Settings | File Templates.
*/
package ru.la2betdream.gameserver.handler.voicedcommandhandlers;

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

import ru.la2betdream.Base64;
import ru.la2betdream.L2DatabaseFactory;
import ru.la2betdream.gameserver.handler.IVoicedCommandHandler;
import ru.la2betdream.gameserver.model.actor.instance.L2PcInstance;

public class password implements IVoicedCommandHandler
{
private static final String[] VOICED_COMMANDS = { "password" };

public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
{
	if (command.equalsIgnoreCase("password") && 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 does not coincide with the former!");
					return false;
				}
				if (newpass.length() < 6)
				{
					activeChar.sendMessage("Your password should not be shorter than 6 characters!");
					return false;
				}
				if (newpass.length() > 30)
				{
					activeChar.sendMessage("Your password should not be more than 30 characters!");
					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();
			        L2DatabaseFactory.close(con);
					_log.log(Level.INFO, "Character "+activeChar.getName()+" has changed his password from "+curpassEnc+" to "+Base64.encodeBytes(password));
			        if (passUpdated > 0)
					{
						activeChar.sendMessage("Your password was successfully changed!");
					}
					else
					{
						activeChar.sendMessage("Change password failed!");
					}

				}
				else
				{
					activeChar.sendMessage("Passwords do not match.");
					return false;
				}
			}
			else
			{
				activeChar.sendMessage("Not pravelno fill! Format: .password Your Password New Password Confirm New Password");
				return false;
			}
		}
		catch (Exception e)
		{
			activeChar.sendMessage("A problem occured while changing password!");
			_log.log(Level.WARNING, "", e);
		}
	}
	else
	{
	activeChar.sendMessage("To change your password, follow the rule : .password your password is  new password  Confirm New Password. Well as passwords is case sensitive.");
		return false;
	}
	return true;
}

public String[] getVoicedCommandList()
{
	return VOICED_COMMANDS;
}
}

  • 0
Posted

command сode .info

Lol.

 

/*
* 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 net.sf.l2j.gameserver.handler;

import gnu.trove.map.hash.TIntObjectHashMap;

import java.util.logging.Logger;

import net.sf.l2j.Config;

public class VoicedCommandHandler
{
private static Logger _log = Logger.getLogger(VoicedCommandHandler.class.getName());
private final TIntObjectHashMap<IVoicedCommandHandler> _datatable;

public static VoicedCommandHandler getInstance()
{
	return SingletonHolder._instance;
}

protected VoicedCommandHandler()
{
	_datatable = new TIntObjectHashMap<>();

}

public void registerVoicedCommandHandler(IVoicedCommandHandler handler)
{
	String[] ids = handler.getVoicedCommandList();
	for (String id : ids)
	{
		if (Config.DEBUG)
			_log.fine("Adding handler for command " + id);
		_datatable.put(id.hashCode(), handler);
	}
}

public IVoicedCommandHandler getVoicedCommandHandler(String voicedCommand)
{
	String command = voicedCommand;

	if (voicedCommand.indexOf(" ") != -1)
		command = voicedCommand.substring(0, voicedCommand.indexOf(" "));

	if (Config.DEBUG)
		_log.fine("getting handler for command: " + command + " -> " + (_datatable.get(command.hashCode()) != null));
	return _datatable.get(command.hashCode());
}

/**
 * @return
 */
public int size()
{
	return _datatable.size();
}

private static class SingletonHolder
{
	protected static final VoicedCommandHandler _instance = new VoicedCommandHandler();
}
}

 

/*
* 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 net.sf.l2j.gameserver.handler;

import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;

public interface IVoicedCommandHandler
{
public boolean useVoicedCommand(String command, L2PcInstance activeChar);

public String[] getVoicedCommandList();
}

 

/*
* 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 net.sf.l2j.gameserver.handler.chathandlers;

import java.util.StringTokenizer;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.handler.IChatHandler;
import net.sf.l2j.gameserver.handler.IVoicedCommandHandler;
import net.sf.l2j.gameserver.handler.VoicedCommandHandler;
import net.sf.l2j.gameserver.model.BlockList;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;

/**
* A chat handler
* @author durgus
*/
public class ChatAll implements IChatHandler
{
private static final int[] COMMAND_IDS =
{
	0
};

/**
 * Handle chat type 'all'
 * @see net.sf.l2j.gameserver.handler.IChatHandler#handleChat(int, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance, java.lang.String, java.lang.String)
 */
@Override
public void handleChat(int type, L2PcInstance activeChar, String params, String text)
{
	boolean vcd_used = false;
	if (text.startsWith("."))
	{
		StringTokenizer st = new StringTokenizer(text);
		IVoicedCommandHandler vch;
		String command = "";

		if (st.countTokens() > 1)
		{
			command = st.nextToken().substring(1);
			params = text.substring(command.length() + 2);
			vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
		}
		else
		{
			command = text.substring(1);
			if (Config.DEBUG)
				System.out.println("Command: " + command);
			vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
		}

		if (vch != null)
		{
			vch.useVoicedCommand(command, activeChar);
			vcd_used = true;
		}
		else
		{
			if (Config.DEBUG)
				System.out.println("No handler registered for bypass '" + command + "'");
		}
	}

	if (!vcd_used)
	{
		CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);

		for (L2PcInstance player : activeChar.getKnownList().getKnownPlayers())
		{
			if (activeChar.isInsideRadius(player, 1250, false, true) && !BlockList.isBlocked(player, activeChar))
				player.sendPacket(cs);
		}

		activeChar.sendPacket(cs);
	}
}

/**
 * Returns the chat types registered to this handler
 * @see net.sf.l2j.gameserver.handler.IChatHandler#getChatTypeList()
 */
@Override
public int[] getChatTypeList()
{
	return COMMAND_IDS;
}
}

 

And add in GameServer:

_log.config("VoicedCommandHandler: Loaded " + VoicedCommandHandler.getInstance().size() + " handlers.");

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Posts

    • Hlep i need pack full last van GF 
    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
    • Dear friends! We are constantly growing and developing, and we are finally ready to offer you the opportunity to integrate advertising across all SOCNET projects! Our service provides the opportunity to place ads on the website socnet.store, in our SMM panel socnet.pro, in Telegram bots socnet.shop and socnet.cc (celebrity bot), as well as in another new (currently secret) project. Each platform provides detailed analytics and information about available ad banners. The document below contains all detailed information in two languages — Russian and English. Here you will find answers to frequently asked questions about exact ad placement locations, integration costs, purchasing process, restrictions, and many other details. The document also contains a table with the current advertising placement queue in our projects. Document with detailed information: https://docs.google.com/document/d/1u4ro3fLkjfyvcp1Eu64rkgQy2Xl5lj87_1W25cVsqPM/edit?usp=sharing Thank you for your attention and support! Sincerely, the SOCNET team. Active project links: Digital Goods Store (Website): Go Store Telegram Bot: Go – convenient access to the store through Telegram messenger. Telegram Bot for purchasing Telegram Stars: Go – fast and profitable purchase of stars in Telegram. SMM Panel: Go – promotion of your social media accounts. We would like to present to you the current list of promotions and special offers for purchasing goods and services from our platform: 1. Promo code OCTOBER2025 (8% discount) for purchases in our store (Website, Bot) during October! You can also use the promo code for your first purchase: SOCNET (15% discount) 2. Get $1 credited to your store balance or a 10–20% discount — simply post your username after registration on our website using the following format: "SEND ME BONUS, MY USERNAME IS..." — post it in our forum thread! 3. Get $1 for your first SMM Panel trial — just open a ticket titled "Get Trial Bonus" on our website (Support). 4. Weekly Telegram Stars giveaways in our Telegram channel and in our Stars purchasing bot! News: ➡ Telegram Channel: https://t.me/accsforyou_shop ➡ WhatsApp Channel: https://chat.whatsapp.com/K8rBy500nA73z27PxgaJUw?mode=ems_copy_t ➡ Discord Server: https://discord.gg/y9AStFFsrh Contacts and Support: ➡ Telegram: https://t.me/socnet_support ➡ WhatsApp: https://wa.me/79051904467 ➡ Discord: socnet_support ➡ ✉ Email: solomonbog@socnet.store
  • Topics

×
×
  • Create New...

AdBlock Extension Detected!

Our website is made possible by displaying online advertisements to our members.

Please disable AdBlock browser extension first, to be able to use our community.

I've Disabled AdBlock