/*
* 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 .
*/
package com.l2jserver.communityserver.communityboard.boards;
import java.text.DateFormat;
import java.util.Date;
import java.util.logging.Logger;
import javolution.text.TextBuilder;
import com.l2jserver.communityserver.Config;
import com.l2jserver.communityserver.cache.HtmCache;
import com.l2jserver.communityserver.communityboard.CommunityBoard;
import com.l2jserver.communityserver.communityboard.CommunityBoardManager;
import com.l2jserver.communityserver.model.Forum;
import com.l2jserver.communityserver.model.L2Clan;
import com.l2jserver.communityserver.model.L2Player;
import com.l2jserver.communityserver.model.Post;
import com.l2jserver.communityserver.model.Topic;
import com.l2jserver.communityserver.model.Topic.ConstructorType;
import com.l2jserver.communityserver.network.writepackets.PlayerSendMessage;
import com.l2jserver.communityserver.network.writepackets.RequestWorldInfo;
public final class ClanBoard extends CommunityBoard
{
private static Logger _log = Logger.getLogger(ClanBoard.class.getName());
public ClanBoard(final CommunityBoardManager mgr)
{
super(mgr);
}
@Override
public void parseCmd(final int playerObjId, final String cmd)
{
if (cmd.equals("_bbsclan") || cmd.equals("_bbsclan;clan;0"))
showMainPage(playerObjId, 1);
else if (cmd.split(";")[1].equalsIgnoreCase("list"))
showMainPage(playerObjId, Integer.valueOf(cmd.split(";")[2]));
else if (cmd.split(";")[1].equalsIgnoreCase("clan"))
{
if (super.getCommunityBoardManager().getClan(Integer.valueOf(cmd.split(";")[2])).getClanLevel() < Config.MIN_CLAN_LVL_FOR_FORUM)
{
if (Config.MIN_CLAN_LVL_FOR_FORUM == 2)
super.getCommunityBoardManager().getGST().sendPacket(new PlayerSendMessage(playerObjId,PlayerSendMessage.NO_CB_IN_MY_CLAN,""));
else
{
String message = "There are no communities in my clan. Clan communities are allowed for clans with skill levels of " + Config.MIN_CLAN_LVL_FOR_FORUM + " and higher.";
super.getCommunityBoardManager().getGST().sendPacket(new PlayerSendMessage(playerObjId,PlayerSendMessage.TEXT_MESSAGE,message));
}
return;
}
showClanPage(playerObjId, Integer.valueOf(cmd.split(";")[2]));
}
else if (cmd.split(";")[1].equalsIgnoreCase("notice"))
{
if (cmd.split(";").length == 3)
{
boolean val = cmd.split(";")[2].equalsIgnoreCase("true");
super.getCommunityBoardManager().getPlayersClan(playerObjId).setNoticeEnabled(val);
super.getCommunityBoardManager().getGST().sendPacket(new RequestWorldInfo(RequestWorldInfo.CLAN_NOTICE_FLAG,super.getCommunityBoardManager().getPlayer(playerObjId).getClanId(),null,val));
}
showNoticePage(playerObjId);
}
else if (cmd.split(";")[1].equalsIgnoreCase("management"))
{
if (super.getCommunityBoardManager().getPlayersClan(playerObjId).getLordObjId() != playerObjId)
super.getCommunityBoardManager().getGST().sendPacket(new PlayerSendMessage(playerObjId,PlayerSendMessage.ONLY_THE_CLAN_LEADER_IS_ENABLED,""));
else
showClanManagementPage(playerObjId, Integer.valueOf(cmd.split(";")[2]));
}
else if (cmd.split(";")[1].equalsIgnoreCase("mail"))
showClanMailPage(playerObjId, Integer.valueOf(cmd.split(";")[2]));
else if (cmd.split(";")[1].equalsIgnoreCase("permission"))
{
int topicId = (cmd.split(";")[2].equalsIgnoreCase("cbb") ? Topic.BULLETIN:Topic.ANNOUNCE);
L2Player player = super.getCommunityBoardManager().getPlayer(playerObjId);
Forum clanForum = getCommunityBoardManager().getClanForum(player.getClanId());
int perNon = clanForum.gettopic(topicId).getPermissions();
int perMem = perNon % 10;
perNon = (perNon - perMem) / 10;
if (cmd.split(";")[3].equalsIgnoreCase("non"))
perNon = (perNon + 1) % 3;
else
perMem = (perMem + 1) % 3;
clanForum.gettopic(topicId).setPermissions(perNon * 10 + perMem);
showClanManagementPage(playerObjId, player.getClanId());
}
else
_log.info("Clan command missing: " + cmd.split(";")[1]);
}
public final void showMainPage(final int playerObjId, int index)
{
L2Clan ownClan = super.getCommunityBoardManager().getPlayersClan(playerObjId);
String content = HtmCache.getInstance().getHtm("data/staticfiles/html/clanlist.htm");
if (ownClan != null)
{
content = content.replaceAll("%clanid%", String.valueOf(ownClan.getClanId()));
content = content.replaceAll("%clanhomename%", ownClan.getName());
}
else
{
content = content.replaceAll("%clanid%", "0");
content = content.replaceAll("%clanhomename%", "");
}
TextBuilder cList = new TextBuilder();
int i = 0;
for (L2Clan c: super.getCommunityBoardManager().getClanList())
{
if (c == null)
continue;
if (i > ((index - 1) * 10 + 9))
{
break;
}
if (i++ >= ((index - 1) * 10))
{
cList.append("");
cList.append("
");
}
int nbp;
nbp = super.getCommunityBoardManager().getClanList().size() / 10;
if (nbp * 10 != super.getCommunityBoardManager().getClanList().size())
{
nbp++;
}
for (i = 1; i <= nbp; i++)
{
if (i == index)
{
cList.append("