/*
* 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.Collection;
import java.util.Date;
import java.util.logging.Logger;
import javolution.text.TextBuilder;
import javolution.util.FastList;
import com.l2jserver.communityserver.cache.HtmCache;
import com.l2jserver.communityserver.communityboard.CommunityBoard;
import com.l2jserver.communityserver.communityboard.CommunityBoardManager;
import com.l2jserver.communityserver.model.Comment;
import com.l2jserver.communityserver.model.Forum;
import com.l2jserver.communityserver.model.Topic;
import com.l2jserver.communityserver.model.Post;
import com.l2jserver.communityserver.model.Topic.ConstructorType;
import com.l2jserver.communityserver.network.writepackets.PlayerSendMessage;
public final class ClanPostBoard extends CommunityBoard
{
private static Logger _log = Logger.getLogger(ClanPostBoard.class.getName());
public ClanPostBoard(final CommunityBoardManager mgr)
{
super(mgr);
}
@Override
public void parseCmd(final int playerObjId, final String cmd)
{
int clanId = Integer.valueOf(cmd.split(";")[3]);
Forum clanForum = getCommunityBoardManager().getClanForum(clanId);
int type;
if (cmd.split(";")[2].equalsIgnoreCase("announce"))
type = Topic.ANNOUNCE;
else if (cmd.split(";")[2].equalsIgnoreCase("cbb"))
type = Topic.BULLETIN;
else
{
_log.info("Clan Post Board command error: " + cmd);
return;
}
int perNon = clanForum.gettopic(type).getPermissions();
int perMem = perNon % 10;
perNon = (perNon - perMem) / 10;
boolean isPlayerMember = getCommunityBoardManager().getPlayer(playerObjId).getClanId() == clanId;
boolean isLeader = getCommunityBoardManager().getClan(clanId).getLordObjId() == playerObjId;
if (!isLeader && ((isPlayerMember && perMem == 0) || (!isPlayerMember && perNon == 0)))
{
// TODO: this way Clan Post Board command missing part could be missed
super.getCommunityBoardManager().getGST().sendPacket(new PlayerSendMessage(playerObjId,PlayerSendMessage.NO_READ_PERMISSION,""));
return;
}
if (cmd.split(";")[1].equalsIgnoreCase("list"))
{
int index = 1;
if (cmd.split(";").length == 5)
index = Integer.valueOf(cmd.split(";")[4]);
showPage(playerObjId, clanForum, type, index);
}
else if (cmd.split(";")[1].equalsIgnoreCase("read"))
{
Topic t = clanForum.gettopic(type);
Post p = t.getPost(Integer.valueOf(cmd.split(";")[4]));
if (p == null)
_log.info("Missing post: " + cmd);
else
{
if (cmd.split(";").length > 5)
{
_log.info("Index: " + cmd.split(";")[5] + ";" + cmd.split(";")[6]);
showPost(playerObjId, t, p, clanId, type, Integer.valueOf(cmd.split(";")[5]), Integer.valueOf(cmd.split(";")[6]));
}
else
showPost(playerObjId, t, p, clanId, type, 1, 1);
}
}
else if (!isLeader && ((isPlayerMember && perMem == 1) || (!isPlayerMember && perNon == 1)))
{
// TODO: this way Clan Post Board command missing part could be missed
super.getCommunityBoardManager().getGST().sendPacket(new PlayerSendMessage(playerObjId,PlayerSendMessage.NO_WRITE_PERMISSION,""));
return;
}
else if (cmd.split(";")[1].equalsIgnoreCase("crea"))
{
showWrite(playerObjId, null, clanId, type);
}
else if (cmd.split(";")[1].equalsIgnoreCase("del"))
{
clanForum.gettopic(type).rmPostByID(Integer.valueOf(cmd.split(";")[4]));
showPage(playerObjId, clanForum, type, 1);
}
else if (cmd.split(";")[1].equalsIgnoreCase("delcom"))
{
Topic t = clanForum.gettopic(type);
Post p = t.getPost(Integer.valueOf(cmd.split(";")[4]));
p.rmCommentByID(Integer.valueOf(cmd.split(";")[5]));
showPost(playerObjId, t, p, clanId, type, 1, 1);
}
else if (cmd.split(";")[1].equalsIgnoreCase("edit"))
{
Post p = clanForum.gettopic(type).getPost(Integer.valueOf(cmd.split(";")[4]));
showWrite(playerObjId, p, clanId, type);
}
else if (cmd.split(";")[1].equalsIgnoreCase("reply"))
{
Post p = clanForum.gettopic(type).getPost(Integer.valueOf(cmd.split(";")[4]));
showReply(playerObjId, p, clanId, type);
}
else
_log.info("Clan Post Board command missing: " + cmd.split(";")[1]);
}
private String replace(String txt, int type)
{
String content = txt;
switch (type)
{
case Topic.ANNOUNCE:
content = content.replaceAll("%link%", "Announcement");
content = content.replaceAll("%type%", "announce");
content = content.replaceAll("%topicId%", String.valueOf(Topic.ANNOUNCE));
content = content.replaceAll("%combobox%", "Advertise;Miscellaneous");
break;
case Topic.BULLETIN:
content = content.replaceAll("%link%", "Free Community");
content = content.replaceAll("%type%", "cbb");
content = content.replaceAll("%topicId%", String.valueOf(Topic.BULLETIN));
content = content.replaceAll("%combobox%", "Information;Miscellaneous");
break;
}
return content;
}
public final void showPage(final int playerObjId, Forum f, int type, int index)
{
String content = HtmCache.getInstance().getHtm("data/staticfiles/html/clanpost.htm");
if (f == null)
{
_log.info("Forum is NULL!!!");
super.send(playerObjId, content);
return;
}
Topic t = f.gettopic(type);
TextBuilder mList = new TextBuilder();
int i = 0;
for (Post p : t.getAllPosts())
{
if (i > ((index - 1) * 10 + 9))
{
break;
}
if (i++ >= ((index - 1) * 10))
{
mList.append("");
mList.append("
");
}
int nbp;
nbp = t.getAllPosts().size() / 10;
if (nbp * 10 != t.getAllPosts().size())
{
nbp++;
}
for (i = 1; i <= nbp; i++)
{
if (i == index)
{
mList.append("