/*
* 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.L2Player;
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 MailBoard extends CommunityBoard
{
private static Logger _log = Logger.getLogger(MailBoard.class.getName());
public MailBoard(final CommunityBoardManager mgr)
{
super(mgr);
}
@Override
public void parseCmd(final int playerObjId, final String cmd)
{
Forum playerForum = getCommunityBoardManager().getPlayerForum(playerObjId);
if (playerForum == null)
{
String content = HtmCache.getInstance().getHtm("data/staticfiles/html/nopage.htm");
super.send(playerObjId, content);
}
if (cmd.equals("_bbsmail"))
showPage(playerObjId, playerForum, Topic.INBOX, 1);
else if (cmd.split(";")[1].equalsIgnoreCase("sent"))
showPage(playerObjId, playerForum, Topic.OUTBOX, 1);
else if (cmd.split(";")[1].equalsIgnoreCase("archive"))
showPage(playerObjId, playerForum, Topic.ARCHIVE, 1);
else if (cmd.split(";")[1].equalsIgnoreCase("tarchive"))
showPage(playerObjId, playerForum, Topic.TEMP_ARCHIVE, 1);
else if (cmd.split(";")[1].equalsIgnoreCase("crea"))
showWrite(playerObjId, null, 0);
else if (cmd.split(";")[1].equalsIgnoreCase("reply"))
{
Topic t = playerForum.gettopic(Integer.valueOf(cmd.split(";")[2]));
Post p = t.getPost(Integer.valueOf(cmd.split(";")[3]));
showWrite(playerObjId, p, 1);
}
else if (cmd.split(";")[1].equalsIgnoreCase("forward"))
{
Topic t = playerForum.gettopic(Integer.valueOf(cmd.split(";")[2]));
Post p = t.getPost(Integer.valueOf(cmd.split(";")[3]));
showWrite(playerObjId, p, 2);
}
else if (cmd.split(";")[1].equalsIgnoreCase("store"))
{
Topic t = playerForum.gettopic(Integer.valueOf(cmd.split(";")[2]));
Post p = t.getPost(Integer.valueOf(cmd.split(";")[3]));
t.rmPostByID(p.getID());
int postId = playerForum.gettopic(Topic.OUTBOX).getNewPostId();
p.setTopic(Topic.ARCHIVE, postId);
playerForum.gettopic(Topic.ARCHIVE).addPost(p);
showPage(playerObjId, playerForum, Topic.INBOX, 1);
}
else if (cmd.split(";")[1].equalsIgnoreCase("del"))
{
playerForum.gettopic(Integer.valueOf(cmd.split(";")[2])).rmPostByID(Integer.valueOf(cmd.split(";")[3]));
showPage(playerObjId, playerForum, Topic.INBOX, 1);
}
else if (cmd.split(";")[1].equalsIgnoreCase("read"))
{
Topic t = playerForum.gettopic(Integer.valueOf(cmd.split(";")[2]));
Post p = t.getPost(Integer.valueOf(cmd.split(";")[3]));
showMail(playerObjId, playerForum, t, p);
}
else
_log.info("Mail command missing: " + cmd.split(";")[1]);
}
public final void showPage(final int playerObjId, Forum f, int topicType, int index)
{
String content = HtmCache.getInstance().getHtm("data/staticfiles/html/mail.htm");
switch (topicType)
{
case Topic.INBOX:
content = content.replaceAll("%maillink%", "Inbox");
content = content.replaceAll("%authrecive%", "Author");
break;
case Topic.OUTBOX:
content = content.replaceAll("%maillink%", "Sent Box");
content = content.replaceAll("%authrecive%", "Recipient");
break;
case Topic.ARCHIVE:
content = content.replaceAll("%maillink%", "Mail Archive");
content = content.replaceAll("%authrecive%", "Author");
break;
case Topic.TEMP_ARCHIVE:
content = content.replaceAll("%maillink%", "Temporary Mail Archive");
content = content.replaceAll("%authrecive%", "Recipient");
break;
}
content = content.replaceAll("%inbox%", String.valueOf(f.gettopic(Topic.INBOX).getAllPosts().size()));
content = content.replaceAll("%outbox%", String.valueOf(f.gettopic(Topic.OUTBOX).getAllPosts().size()));
content = content.replaceAll("%archive%", String.valueOf(f.gettopic(Topic.ARCHIVE).getAllPosts().size()));
content = content.replaceAll("%tarchive%", String.valueOf(f.gettopic(Topic.TEMP_ARCHIVE).getAllPosts().size()));
Topic t = f.gettopic(topicType);
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("
");
}
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("