/*
* 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 com.l2jserver.gameserver.communitybbs;
import java.util.StringTokenizer;
import com.l2jserver.Config;
import com.l2jserver.gameserver.communitybbs.Manager.BuffBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.ClanBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.ClassBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.PostBBSManager;
import com.l2jserver.gameserver.network.serverpackets.ExShowScreenMessage;
import com.l2jserver.gameserver.model.L2Clan;
import com.l2jserver.gameserver.network.serverpackets.WareHouseDepositList;
import com.l2jserver.gameserver.network.serverpackets.WareHouseWithdrawalList;
import com.l2jserver.gameserver.communitybbs.Manager.RegionBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.TeleportBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.TopBBSManager;
import com.l2jserver.gameserver.communitybbs.Manager.TopicBBSManager;
import com.l2jserver.gameserver.datatables.MultiSell;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.entity.TvTEvent;
import com.l2jserver.gameserver.network.L2GameClient;
import com.l2jserver.gameserver.network.SystemMessageId;
import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
public class CommunityBoard
{
private CommunityBoard()
{
}
public static CommunityBoard getInstance()
{
return SingletonHolder._instance;
}
public void handleCommands(L2GameClient client, String command)
{
L2PcInstance activeChar = client.getActiveChar();
if (activeChar == null)
return;
if(activeChar.isDead() || activeChar.isAlikeDead() || activeChar.isCastingNow() || activeChar.isInCombat() || activeChar.isAttackingNow() || activeChar.isFlying() || activeChar.isInSiege() || activeChar.isCombatFlagEquipped())
{
}
if(activeChar.isInJail())
{
activeChar.sendMessage("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0432 \u0442\u044E\u0440\u043C\u0435.");
return;
}
if(activeChar.isInDuel())
{
activeChar.sendMessage("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0432\u043E \u0432\u0440\u0435\u043C\u044F \u0434\u0443\u0435\u043B\u0438.");
return;
}
if(activeChar.isInOlympiadMode())
{
activeChar.sendMessage("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0432\u043E \u0432\u0440\u0435\u043C\u044F \u041E\u043B\u0438\u043C\u043F\u0438\u0430\u0434\u044B.");
return;
}
if(activeChar.getPvpFlag() != 0 || activeChar.getKarma() > 0)
{
activeChar.sendMessage("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C CommunityBoard \u0432 \u0442\u0430\u043A\u043E\u043C \u0441\u043E\u0441\u0442\u043E\u044F\u043D\u0438\u0438.");
return;
}
if(TvTEvent.isStarted())
{
activeChar.sendMessage("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0432\u043E \u0432\u0440\u0435\u043C\u044F TVT \u0435\u0432\u0435\u043D\u0442\u0430.");
return;
}
if(activeChar.isInsideZone((byte)0))
{
activeChar.sendMessage("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0432 \u0431\u043E\u0435\u0432\u043E\u0439 \u0437\u043E\u043D\u0435.");
return;
}
if(activeChar.isInsideZone((byte)2))
{
activeChar.sendMessage("\u041D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u043D\u043E \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C \u0432 \u0437\u043E\u043D\u0435 \u043E\u0441\u0430\u0434\u044B.");
return;
}
switch (Config.COMMUNITY_TYPE)
{
default:
case 0: //disabled
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CB_OFFLINE));
break;
case 1: // old
RegionBBSManager.getInstance().parsecmd(command, activeChar);
break;
case 2: // new
if (command.startsWith("_bbsclan"))
{
ClanBBSManager.getInstance().parsecmd(command, activeChar);
}
else if (command.startsWith("_bbsmemo"))
{
TopicBBSManager.getInstance().parsecmd(command, activeChar);
}
else if (command.startsWith("_bbstopics"))
{
TopicBBSManager.getInstance().parsecmd(command, activeChar);
}
else if (command.startsWith("_bbsposts"))
{
PostBBSManager.getInstance().parsecmd(command, activeChar);
}
else if (command.startsWith("_bbsMyWD"))
{
if (Config.ALLOW_WAREHOUSE_CB)
{
activeChar.setActiveWarehouse(activeChar.getWarehouse());
activeChar.sendPacket(new WareHouseDepositList(activeChar, WareHouseDepositList.PRIVATE));
}
else
{
activeChar.sendPacket(new ExShowScreenMessage("Эта функция отключена администратором!", 3000));
}
}
else if (command.startsWith("_bbsMyWW"))
{
if (Config.ALLOW_WAREHOUSE_CB)
{
activeChar.setActiveWarehouse(activeChar.getWarehouse());
if (activeChar.getActiveWarehouse().getSize() == 0)
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.NO_ITEM_DEPOSITED_IN_WH));
return;
}
else
activeChar.sendPacket(new WareHouseWithdrawalList(activeChar, WareHouseWithdrawalList.PRIVATE));
}
else
{
activeChar.sendPacket(new ExShowScreenMessage("Эта функция отключена администратором!", 3000));
}
}
else if (command.startsWith("_bbsClanWD"))
{
if (Config.ALLOW_WAREHOUSE_CB)
{
if (activeChar.getClan() != null)
{
if (activeChar.getClan().getLevel() == 0)
activeChar.sendPacket(new SystemMessage(SystemMessageId.ONLY_LEVEL_1_CLAN_OR_HIGHER_CAN_USE_WAREHOUSE));
else
{
activeChar.setActiveWarehouse(activeChar.getClan().getWarehouse());
WareHouseDepositList dl = new WareHouseDepositList(activeChar, WareHouseDepositList.CLAN);
activeChar.sendPacket(dl);
}
}
else
activeChar.sendPacket(new ExShowScreenMessage("Вы не являетесь членом какого-либо клана!", 3000));
}
else
{
activeChar.sendPacket(new ExShowScreenMessage("Эта функция отключена администратором!", 3000));
}
}
else if (command.startsWith("_bbsClanWW"))
{
if (Config.ALLOW_WAREHOUSE_CB)
{
if (activeChar.getClan() != null)
{
if ((activeChar.getClanPrivileges() & L2Clan.CP_CL_VIEW_WAREHOUSE) != L2Clan.CP_CL_VIEW_WAREHOUSE)
{
activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_DO_NOT_HAVE_THE_RIGHT_TO_USE_CLAN_WAREHOUSE));
return;
}
else
{
if (activeChar.getClan().getLevel() == 0)
activeChar.sendPacket(new SystemMessage(SystemMessageId.ONLY_LEVEL_1_CLAN_OR_HIGHER_CAN_USE_WAREHOUSE));
else
{
activeChar.setActiveWarehouse(activeChar.getClan().getWarehouse());
activeChar.sendPacket(new WareHouseWithdrawalList(activeChar, WareHouseWithdrawalList.CLAN));
}
}
}
else
activeChar.sendPacket(new ExShowScreenMessage("Вы не являетесь членом какого-либо клана!", 3000));
}
else
{
activeChar.sendPacket(new ExShowScreenMessage("Эта функция отключена администратором!", 3000));
}
}
else if (command.startsWith("_bbstop"))
{
TopBBSManager.getInstance().parsecmd(command, activeChar);
}
else if (command.startsWith("_bbshome"))
{
TopBBSManager.getInstance().parsecmd(command, activeChar);
}
else if(command.startsWith("_bbsclass"))
{
ClassBBSManager.getInstance().parsecmd(command, activeChar);
break;
}
else if (command.startsWith("_bbs_buff"))
{
BuffBBSManager.getInstance().parsecmd(command, activeChar);
}
else if (command.startsWith("_bbsteleport;"))
{
TeleportBBSManager.getInstance().parsecmd(command, activeChar);
}
else if (command.startsWith("_bbsmultisell;"))
{
if(activeChar.isDead() || activeChar.isAlikeDead() || TvTEvent.isStarted() || activeChar.isInSiege() || activeChar.isCastingNow() || activeChar.isInCombat() || activeChar.isAttackingNow() || activeChar.isInOlympiadMode() || activeChar.isInJail() || activeChar.isFlying() || activeChar.getKarma() > 0 || activeChar.isInDuel()){
activeChar.sendMessage("В данных условиях использовать Шоп запрещено");
return;
}
StringTokenizer st = new StringTokenizer(command, ";");
st.nextToken();
TopBBSManager.getInstance().parsecmd("_bbstop;" + st.nextToken(), activeChar);
int multisell = Integer.parseInt(st.nextToken());
MultiSell.getInstance().separateAndSend(multisell, activeChar, null, false);
}
else if (command.startsWith("_bbsloc"))
{
RegionBBSManager.getInstance().parsecmd(command, activeChar);
}
else
{
ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command
+ " is not implemented yet</center><br><br></body></html>", "101");
activeChar.sendPacket(sb);
activeChar.sendPacket(new ShowBoard(null, "102"));
activeChar.sendPacket(new ShowBoard(null, "103"));
}
break;
}
}
/**
* @param client
* @param url
* @param arg1
* @param arg2
* @param arg3
* @param arg4
* @param arg5
*/
public void handleWriteCommands(L2GameClient client, String url, String arg1, String arg2, String arg3, String arg4, String arg5)
{
L2PcInstance activeChar = client.getActiveChar();
if (activeChar == null)
return;
switch (Config.COMMUNITY_TYPE)
{
case 2:
if (url.equals("Topic"))
{
TopicBBSManager.getInstance().parsewrite(arg1, arg2, arg3, arg4, arg5, activeChar);
}
else if (url.equals("Post"))
{
PostBBSManager.getInstance().parsewrite(arg1, arg2, arg3, arg4, arg5, activeChar);
}
else if (url.equals("Region"))
{
RegionBBSManager.getInstance().parsewrite(arg1, arg2, arg3, arg4, arg5, activeChar);
}
else if (url.equals("Notice"))
{
ClanBBSManager.getInstance().parsewrite(arg1, arg2, arg3, arg4, arg5, activeChar);
}
else
{
ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + url
+ " is not implemented yet</center><br><br></body></html>", "101");
activeChar.sendPacket(sb);
activeChar.sendPacket(new ShowBoard(null, "102"));
activeChar.sendPacket(new ShowBoard(null, "103"));
}
break;
case 1:
RegionBBSManager.getInstance().parsewrite(arg1, arg2, arg3, arg4, arg5, activeChar);
break;
default:
case 0:
ShowBoard sb = new ShowBoard("<html><body><br><br><center>The Community board is currently disabled</center><br><br></body></html>", "101");
activeChar.sendPacket(sb);
activeChar.sendPacket(new ShowBoard(null, "102"));
activeChar.sendPacket(new ShowBoard(null, "103"));
break;
}
}
@SuppressWarnings("synthetic-access")
private static class SingletonHolder
{
protected static final CommunityBoard _instance = new CommunityBoard();
}
}