Jump to content
  • 0

Question

Posted

Hello, can someone help to me? I added voicedcommands, changed ChatAll.java and now only working my voicedcommands, example i say .online, okey its working, no errors in gameserver, also i see how much online players so all okey all working, BUT then i say example I LOVE ACIS without . - I get error and also nothing in game, i cant chat:D heres error:

Client: [Character: L2Strobe - Account: slavkute - IP: 192.168.0.100] - Failed r
eading: [C] Say2 ; null
null

 

and here mine ChatAll.java:

/*
* 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 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;

import java.util.Collection;
import java.util.StringTokenizer;
import java.util.logging.Logger;


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

private static Logger _log = Logger.getLogger(ChatAll.class.getName());

/**
 * 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)
		          						_log.info("Command: " + command);
		          					vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
		          				}
		          				
		          				if (vch != null)
		          				{
		          					vch.useVoicedCommand(command, activeChar, params);
		          					vcd_used = true;
		          				}
		          				else
		          				{
		          					if (Config.DEBUG)
		          						_log.warning("No handler registered for bypass '" + command + "'");
		          					vcd_used = false;
		          				}
		          			}
		          			
		          			if (!vcd_used)
		          			{
		          				CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
		          				Collection<L2PcInstance> plrs = activeChar.getKnownList().getKnownPlayers();
		          	
		          				for (L2PcInstance player : plrs)
		          				{
		          					if (player != null && 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;
}
}

8 answers to this question

Recommended Posts

  • 0
Posted

You have a trashy mod that makes the chat voicecommand if it starts with .

also its bad coded, clean it and use

 

if (command.startsWith(".")

{

//voicecommand

return;

}

//chat

sendPacket(new say2(...));

  • 0
Posted

getKnownPlayers() doesn't exist anymore, how do you manage to make it work at first hit ?

 

Should be

getKnownTypeInRadius(L2PcInstance.class, 1250)

 

And you do

if (text.startsWith("."))

but you don't put any case if != of (or until I see it bad because of poor indentation of your file).

  • 0
Posted

			          			if (!vcd_used)
		          			{
		          				CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
		          				Collection<L2PcInstance> plrs = activeChar.getKnownList().getKnownTypeInRadius(L2PcInstance.class, 1250);
		          	
		          				for (L2PcInstance player : plrs)
		          				{
		          					if (player != null && activeChar.isInsideRadius(player, 1250, false, true) && !BlockList.isBlocked(player, activeChar))
		          						player.sendPacket(cs);
		          				}

 

make like this?

  • 0
Posted

You don't need that anymore

activeChar.isInsideRadius(player, 1250, false, true)

as plrs already make the cleaning for you. That's the point of inRadius, it minimizes sizes of temporary Collections.

 

The advantage of that new method getKnownTypeInRadius( is you can use with any type of instance type. Before there was one method per type, and even there were many cases which weren't taken in consideration so you had to make

instance of

checks. Now all those checks are gone. You want all wedding managers in a radius 2000, you can have them in one line.

 

Anyway, it doesn't solve your chat problem.

  • 0
Posted

Thanks, Tryskell, but how solve the problems?

 

clean or revert say2.java

 

then if you want costum commands add this code

if (text.startsWith("."))

{

  //your command handler

  return;

}

 

about the command handler, Use a simple class like this:

 

public class commandHandler

{

 

  public void handleCommand(L2PcInstance player, String text)

  {

      if (text.equalsIgnoreCase(" ") blablabla

    }

}

  • 0
Posted

ChatAll.java:

/*
* 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 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;

import java.util.Collection;
import java.util.StringTokenizer;
import java.util.logging.Logger;


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

private static Logger _log = Logger.getLogger(ChatAll.class.getName());

/**
 * 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)
		          						_log.info("Command: " + command);
		          					vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(command);
		          				}
		          				
		          				if (vch != null)
		          				{
		          					vch.useVoicedCommand(command, activeChar, params);
		          					vcd_used = true;
		          				}
		          				else
		          				{
		          					if (Config.DEBUG)
		          						_log.warning("No handler registered for bypass '" + command + "'");
		          					vcd_used = false;
		          				}
		          			}
		          			
		          			if (!vcd_used)
		          			{
		          				CreatureSay cs = new CreatureSay(activeChar.getObjectId(), type, activeChar.getName(), text);
		          				Collection<L2PcInstance> plrs = activeChar.getKnownList().getKnownPlayers();
		          	
		          				for (L2PcInstance player : plrs)
		          				{
		          					if (player != null && 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;
}
}

 

say2.java:

/*
* 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.network.clientpackets;

import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

import net.sf.l2j.Config;
import net.sf.l2j.gameserver.handler.ChatHandler;
import net.sf.l2j.gameserver.handler.IChatHandler;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.network.SystemMessageId;
import net.sf.l2j.gameserver.network.serverpackets.ActionFailed;
import net.sf.l2j.gameserver.util.IllegalPlayerAction;
import net.sf.l2j.gameserver.util.Util;

public final class Say2 extends L2GameClientPacket
{
private static Logger _logChat = Logger.getLogger("chat");

public final static int ALL = 0;
public final static int SHOUT = 1; // !
public final static int TELL = 2;
public final static int PARTY = 3; // #
public final static int CLAN = 4; // @
public final static int GM = 5;
public final static int PETITION_PLAYER = 6;
public final static int PETITION_GM = 7;
public final static int TRADE = 8; // +
public final static int ALLIANCE = 9; // $
public final static int ANNOUNCEMENT = 10;
public final static int BOAT = 11;
public final static int L2FRIEND = 12;
public final static int MSNCHAT = 13;
public final static int PARTYMATCH_ROOM = 14;
public final static int PARTYROOM_COMMANDER = 15; // (Yellow)
public final static int PARTYROOM_ALL = 16; // (Red)
public final static int HERO_VOICE = 17;

private final static String[] CHAT_NAMES =
{
	"ALL",
	"SHOUT",
	"TELL",
	"PARTY",
	"CLAN",
	"GM",
	"PETITION_PLAYER",
	"PETITION_GM",
	"TRADE",
	"ALLIANCE",
	"ANNOUNCEMENT", // 10
	"BOAT",
	"WILLCRASHCLIENT:)",
	"FAKEALL?",
	"PARTYMATCH_ROOM",
	"PARTYROOM_COMMANDER",
	"PARTYROOM_ALL",
	"HERO_VOICE"
};

private static final String[] WALKER_COMMAND_LIST =
{
	"USESKILL",
	"USEITEM",
	"BUYITEM",
	"SELLITEM",
	"SAVEITEM",
	"LOADITEM",
	"MSG",
	"DELAY",
	"LABEL",
	"JMP",
	"CALL",
	"RETURN",
	"MOVETO",
	"NPCSEL",
	"NPCDLG",
	"DLGSEL",
	"CHARSTATUS",
	"POSOUTRANGE",
	"POSINRANGE",
	"GOHOME",
	"SAY",
	"EXIT",
	"PAUSE",
	"STRINDLG",
	"STRNOTINDLG",
	"CHANGEWAITTYPE",
	"FORCEATTACK",
	"ISMEMBER",
	"REQUESTJOINPARTY",
	"REQUESTOUTPARTY",
	"QUITPARTY",
	"MEMBERSTATUS",
	"CHARBUFFS",
	"ITEMCOUNT",
	"FOLLOWTELEPORT"
};

private String _text;
private int _type;
private String _target;

@Override
protected void readImpl()
{
	_text = readS();
	_type = readD();
	_target = (_type == TELL) ? readS() : null;
}

@Override
protected void runImpl()
{
	if (Config.DEBUG)
		_log.info("Say2: Msg Type = '" + _type + "' Text = '" + _text + "'.");

	L2PcInstance activeChar = getClient().getActiveChar();
	if (activeChar == null)
		return;

	if (_type < 0 || _type >= CHAT_NAMES.length)
	{
		_log.warning("Say2: Invalid type: " + _type + " Player : " + activeChar.getName() + " text: " + String.valueOf(_text));
		activeChar.sendPacket(ActionFailed.STATIC_PACKET);
		activeChar.logout();
		return;
	}

	if (_text.isEmpty())
	{
		_log.warning(activeChar.getName() + ": sending empty text. Possible packet hack.");
		activeChar.sendPacket(ActionFailed.STATIC_PACKET);
		activeChar.logout();
		return;
	}

	if (_text.length() >= 100)
		return;

	if (Config.L2WALKER_PROTECTION && _type == TELL && checkBot(_text))
	{
		Util.handleIllegalPlayerAction(activeChar, "Client Emulator Detect: " + activeChar.getName() + " is using L2Walker.", Config.DEFAULT_PUNISH);
		return;
	}

	if (!activeChar.isGM() && _type == ANNOUNCEMENT)
	{
		Util.handleIllegalPlayerAction(activeChar, activeChar.getName() + " tried to announce without GM statut.", IllegalPlayerAction.PUNISH_BROADCAST);
		_log.warning(activeChar.getName() + " tried to use announcements without GM statut.");
		return;
	}

	if (activeChar.isChatBanned() || (activeChar.isInJail() && !activeChar.isGM()))
	{
		activeChar.sendPacket(SystemMessageId.CHATTING_PROHIBITED);
		return;
	}

	if (_type == PETITION_PLAYER && activeChar.isGM())
		_type = PETITION_GM;

	if (Config.LOG_CHAT)
	{
		LogRecord record = new LogRecord(Level.INFO, _text);
		record.setLoggerName("chat");

		if (_type == TELL)
			record.setParameters(new Object[]
			{
				CHAT_NAMES[_type],
				"[" + activeChar.getName() + " to " + _target + "]"
			});
		else
			record.setParameters(new Object[]
			{
				CHAT_NAMES[_type],
				"[" + activeChar.getName() + "]"
			});

		_logChat.log(record);
	}

	_text = _text.replaceAll("\\\\n", "");

	IChatHandler handler = ChatHandler.getInstance().getChatHandler(_type);
	if (handler != null)
		handler.handleChat(_type, activeChar, _target, _text);
	else
		_log.warning(activeChar.getName() + " tried to use unregistred chathandler type: " + _type + ".");
}

private static boolean checkBot(String text)
{
	for (String botCommand : WALKER_COMMAND_LIST)
	{
		if (text.startsWith(botCommand))
			return true;
	}
	return false;
}

@Override
protected boolean triggersOnActionRequest()
{
	return false;
}
}

 

VoicedCommandHandler.java

/*
* 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 java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import net.sf.l2j.gameserver.handler.voicedcommandhandlers.getstats;
import net.sf.l2j.gameserver.handler.voicedcommandhandlers.help;
import net.sf.l2j.gameserver.handler.voicedcommandhandlers.kill;
import net.sf.l2j.gameserver.handler.voicedcommandhandlers.menu;
import net.sf.l2j.gameserver.handler.voicedcommandhandlers.online;
import net.sf.l2j.gameserver.handler.voicedcommandhandlers.time;

import javolution.util.FastMap;

public class VoicedCommandHandler
{
private static Logger _log = Logger.getLogger(VoicedCommandHandler.class.getName());

private static VoicedCommandHandler _instance;
private final Map<String, IVoicedCommandHandler> _datatable;

public static VoicedCommandHandler getInstance()
{
	if (_instance == null)
	{
		_instance = new VoicedCommandHandler();
	}
	return _instance;
}

private VoicedCommandHandler()
{
	_datatable = new FastMap<String, IVoicedCommandHandler>();
	registerVoicedCommandHandler(new time());
	registerVoicedCommandHandler(new online());
	registerVoicedCommandHandler(new getstats());
	registerVoicedCommandHandler(new menu());
	registerVoicedCommandHandler(new kill());
	registerVoicedCommandHandler(new help());

	_log.log(Level.INFO, getClass().getSimpleName() + ": Loaded " + size() + " Handlers in total.");
}

public void registerVoicedCommandHandler(IVoicedCommandHandler handler)
{
	String[] ids = handler.getVoicedCommandList();
	for (int i = 0; i < ids.length; i++)
	{
		_datatable.put(ids[i], handler);
	}
}

public IVoicedCommandHandler getVoicedCommandHandler(String voicedCommand)
{
	String command = voicedCommand;
	if (voicedCommand.indexOf(" ") != -1)
	{
		command = voicedCommand.substring(0, voicedCommand.indexOf(" "));
	}
	return _datatable.get(command);
}

public int size()
{
	return _datatable.size();
}
}

 

IVoicedCommandHandler.java

/*
* 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
{
/**
 * this is the worker method that is called when someone uses an admin
 * command.
 * 
 * @param activeChar
 * @param command
 * @return command success
 */
public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target);

/**
 * this method is called at initialization to register all the item ids
 * automatically
 * 
 * @return all known itemIds
 */
public String[] getVoicedCommandList();
}

 

WHAT TO DO? Because i dont understand:(

Guest
This topic is now closed to further replies.


×
×
  • Create New...