/*
* Copyright (C) 2004-2013 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server 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.
*
* L2J Server 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.gameserver.communitybbs.Manager;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.StringTokenizer;
import javolution.util.FastMap;
import com.l2jserver.gameserver.communitybbs.BB.Forum;
import com.l2jserver.gameserver.communitybbs.BB.Post;
import com.l2jserver.gameserver.communitybbs.BB.Post.CPost;
import com.l2jserver.gameserver.communitybbs.BB.Topic;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
import com.l2jserver.util.StringUtil;
public class PostBBSManager extends BaseBBSManager
{
private final Map _postByTopic = new FastMap<>();
public Post getGPosttByTopic(Topic t)
{
Post post = _postByTopic.get(t);
if (post == null)
{
post = new Post(t);
_postByTopic.put(t, post);
}
return post;
}
/**
* @param t
*/
public void delPostByTopic(Topic t)
{
_postByTopic.remove(t);
}
public void addPostByTopic(Post p, Topic t)
{
if (_postByTopic.get(t) == null)
{
_postByTopic.put(t, p);
}
}
@Override
public void parsecmd(String command, L2PcInstance activeChar)
{
if (command.startsWith("_bbsposts;read;"))
{
StringTokenizer st = new StringTokenizer(command, ";");
st.nextToken();
st.nextToken();
int idf = Integer.parseInt(st.nextToken());
int idp = Integer.parseInt(st.nextToken());
String index = null;
if (st.hasMoreTokens())
{
index = st.nextToken();
}
int ind = 0;
if (index == null)
{
ind = 1;
}
else
{
ind = Integer.parseInt(index);
}
showPost((TopicBBSManager.getInstance().getTopicByID(idp)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind);
}
else if (command.startsWith("_bbsposts;edit;"))
{
StringTokenizer st = new StringTokenizer(command, ";");
st.nextToken();
st.nextToken();
int idf = Integer.parseInt(st.nextToken());
int idt = Integer.parseInt(st.nextToken());
int idp = Integer.parseInt(st.nextToken());
showEditPost((TopicBBSManager.getInstance().getTopicByID(idt)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idp);
}
else
{
ShowBoard sb = new ShowBoard("
the command: " + command + " is not implemented yet
", "101");
activeChar.sendPacket(sb);
activeChar.sendPacket(new ShowBoard(null, "102"));
activeChar.sendPacket(new ShowBoard(null, "103"));
}
}
/**
* @param topic
* @param forum
* @param activeChar
* @param idp
*/
private void showEditPost(Topic topic, Forum forum, L2PcInstance activeChar, int idp)
{
Post p = getGPosttByTopic(topic);
if ((forum == null) || (topic == null) || (p == null))
{
ShowBoard sb = new ShowBoard("
Error, this forum, topic or post does not exit !
", "101");
activeChar.sendPacket(sb);
activeChar.sendPacket(new ShowBoard(null, "102"));
activeChar.sendPacket(new ShowBoard(null, "103"));
}
else
{
showHtmlEditPost(topic, activeChar, forum, p);
}
}
/**
* @param topic
* @param forum
* @param activeChar
* @param ind
*/
private void showPost(Topic topic, Forum forum, L2PcInstance activeChar, int ind)
{
if ((forum == null) || (topic == null))
{
ShowBoard sb = new ShowBoard("