Jump to content
  • 0

VoicedCommandHandler for aCis [EXAMPLE .online]


numl0ckas

Question

2 answers to this question

Recommended Posts

  • 0

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;
}
}

Link to comment
Share on other sites

  • 0

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.");

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...