/* * 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.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 Map _postByTopic; protected PostBBSManager() { _postByTopic = new FastMap(); } public Post getGPosttByTopic(Topic t) { Post post = null; 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("

Error, this forum is not implemented yet


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } else if (forum.getType() == Forum.MEMO) { showMemoPost(topic, activeChar, forum); } else { ShowBoard sb = new ShowBoard("

the forum: " + forum.getName() + " is not implemented yet


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } } /** * @param topic * @param activeChar * @param forum * @param p */ private void showHtmlEditPost(Topic topic, L2PcInstance activeChar, Forum forum, Post p) { final String html = StringUtil.concat("" + "

" + "" + "
" + "HOME > ", forum.getName(), " Form" + "
" + "" + "
" + "" + "" + "
" + "" + "" + "" + "" + "" + "" + "" + "
&$413;", topic.getName(), "
" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
&$427;
" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
  
" + "
" + "" + ""); send1001(html, activeChar); send1002(activeChar, p.getCPost(0).postTxt, topic.getName(), DateFormat.getInstance().format(new Date(topic.getDate()))); } /** * @param topic * @param activeChar * @param forum */ private void showMemoPost(Topic topic, L2PcInstance activeChar, Forum forum) { // Post p = getGPosttByTopic(topic); Locale locale = Locale.getDefault(); DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale); String mes = p.getCPost(0).postTxt.replace(">", ">"); mes = mes.replace("<", "<"); mes = mes.replace("\n", ""); final String html = StringUtil.concat("

" + "" + "
" + "HOME > Memo Form" + "
" + "" + "
" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "" + "
&$413; :  ", topic.getName(), "
&$417; :  ", topic.getOwnerName() + "&$418; :", dateFormat.format(p.getCPost(0).postDate), "
" + "
" + "" + "" + "" + "" + "" + "" + "
", mes, "
" + "
" + "" + "" + "" + "" + "" + "" + "" + "" + "
" + "" + " " + " " + " " + "
" + "
" + "
" + "
" + "
" + "" + ""); separateAndSend(html, activeChar); } @Override public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar) { StringTokenizer st = new StringTokenizer(ar1, ";"); int idf = Integer.parseInt(st.nextToken()); int idt = Integer.parseInt(st.nextToken()); int idp = Integer.parseInt(st.nextToken()); Forum f = ForumsBBSManager.getInstance().getForumByID(idf); if (f == null) { ShowBoard sb = new ShowBoard("

the forum: " + idf + " does not exist !


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } else { Topic t = f.getTopic(idt); if (t == null) { ShowBoard sb = new ShowBoard("

the topic: " + idt + " does not exist !


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } else { final Post p = getGPosttByTopic(t); if (p != null) { final CPost cp = p.getCPost(idp); if (cp == null) { ShowBoard sb = new ShowBoard("

the post: " + idp + " does not exist !


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } else { p.getCPost(idp).postTxt = ar4; p.updatetxt(idp); parsecmd("_bbsposts;read;" + f.getID() + ";" + t.getID(), activeChar); } } } } } public static PostBBSManager getInstance() { return SingletonHolder._instance; } private static class SingletonHolder { protected static final PostBBSManager _instance = new PostBBSManager(); } }