/* * 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 net.sf.l2j.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.text.TextBuilder; import javolution.util.FastMap; import net.sf.l2j.gameserver.communitybbs.BB.Forum; import net.sf.l2j.gameserver.communitybbs.BB.Post; import net.sf.l2j.gameserver.communitybbs.BB.Topic; import net.sf.l2j.gameserver.communitybbs.BB.Post.CPost; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.serverpackets.ShowBoard; public class PostBBSManager extends BaseBBSManager { private Map _postByTopic; private static PostBBSManager _instance; public static PostBBSManager getInstance() { if (_instance == null) { _instance = new PostBBSManager(); } return _instance; } public PostBBSManager() { _postByTopic = new FastMap(); } public Post getGPosttByTopic(Topic t) { Post post = null; post = _postByTopic.get(t); if(post == null) { post = load(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); } } /** * @param t * @return */ private Post load(Topic t) { Post p; p = new Post(t); return p; } /* (non-Javadoc) * @see net.sf.l2j.gameserver.communitybbs.Manager.BaseBBSManager#parsecmd(java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance) */ @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 forumByID * @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 posttByTopic * @param forumByID * @param activeChar * @param ind * @param idf */ 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) { TextBuilder html = new TextBuilder(""); html.append("

"); html.append(""); html.append("
"); html.append("HOME > "+forum.getName()+" Form"); html.append("
"); html.append(""); html.append("
"); html.append(""); html.append(""); html.append("
"); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append("
&$413;"+ topic.getName() +"
"); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append("
&$427;
"); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append("
  
"); html.append("
"); html.append(""); html.append(""); send1001(html.toString(),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); TextBuilder html = new TextBuilder("

"); html.append(""); html.append("
"); html.append("HOME > Memo Form"); html.append("
"); html.append(""); html.append("
"); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append("
&$413; :  "+topic.getName()+"
&$417; :  "+topic.getOwnerName()+"&$418; :"+dateFormat.format(p.getCPost(0).postDate)+"
"); html.append("
"); html.append(""); html.append(""); html.append(""); String Mes = p.getCPost(0).postTxt.replace(">",">"); Mes = Mes.replace("<","<"); Mes = Mes.replace("\n",""); html.append(""); html.append(""); html.append(""); html.append("
"+ Mes +"
"); html.append("
"); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append(""); html.append("
"); html.append(""); html.append(" "); html.append(" "); html.append(" "); html.append("
"); html.append("
"); html.append("
"); html.append("
"); html.append("
"); html.append(""); html.append(""); separateAndSend(html.toString(),activeChar); } /* (non-Javadoc) * @see net.sf.l2j.gameserver.communitybbs.Manager.BaseBBSManager#parsewrite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance) */ @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 { CPost cp = null; Post p = getGPosttByTopic(t); if(p != null) { 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); } } } } }