Player activeChar = getClient().getActiveChar();
if (activeChar == null)
{
return;
}
Request request = activeChar.getRequest();
if ((request == null) || !request.isTypeOf(L2RequestType.CHANNEL))
{
return;
}
if (!request.isInProgress())
{
request.cancel();
activeChar.sendActionFailed();
return;
}
if (activeChar.isOutOfControl())
{
request.cancel();
activeChar.sendActionFailed();
return;
}
Player requestor = request.getRequestor();
if (requestor == null)
{
request.cancel();
activeChar.sendPacket(Msg.THAT_PLAYER_IS_NOT_ONLINE);
activeChar.sendActionFailed();
return;
}
if (requestor.getRequest() != request)
{
request.cancel();
activeChar.sendActionFailed();
return;
}
if (_response == 0)
{
request.cancel();
requestor.sendPacket(new SystemMessage(SystemMessage.S1_HAS_DECLINED_THE_CHANNEL_INVITATION).addString(activeChar.getName()));
return;
}
if (!requestor.isInParty() || !activeChar.isInParty() || activeChar.getParty().isInCommandChannel())
{
request.cancel();
requestor.sendPacket(Msg.NO_USER_HAS_BEEN_INVITED_TO_THE_COMMAND_CHANNEL);
return;
}
if (activeChar.isTeleporting())
{
request.cancel();
activeChar.sendPacket(Msg.YOU_CANNOT_JOIN_A_COMMAND_CHANNEL_WHILE_TELEPORTING);
requestor.sendPacket(Msg.NO_USER_HAS_BEEN_INVITED_TO_THE_COMMAND_CHANNEL);
return;
}
try
{
if (requestor.getParty().isInCommandChannel())
{
requestor.getParty().getCommandChannel().addParty(activeChar.getParty());
}
else if (CommandChannel.checkAuthority(requestor))
{
boolean haveSkill = requestor.getSkillLevel(CommandChannel.CLAN_IMPERIUM_ID) > 0;
boolean haveItem = false;
if (!haveSkill)
{
haveItem = requestor.getInventory().destroyItemByItemId(CommandChannel.STRATEGY_GUIDE_ID, 1);
if (haveItem)
{
requestor.sendPacket(SystemMessage2.removeItems(CommandChannel.STRATEGY_GUIDE_ID, 1));
}
}
if (!haveSkill && !haveItem)
{
return;
}
CommandChannel channel = new CommandChannel(requestor);
requestor.sendPacket(Msg.THE_COMMAND_CHANNEL_HAS_BEEN_FORMED);
channel.addParty(activeChar.getParty());
}
}
finally
{
request.done();
}
}