/* * Copyright (C) 2004-2015 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 java.util.concurrent.ConcurrentHashMap; 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.handler.CommunityBoardHandler; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.util.StringUtil; public class PostBBSManager extends BaseBBSManager { private final Map _postByTopic = new ConcurrentHashMap<>(); public Post getGPosttByTopic(Topic t) { Post post = _postByTopic.get(t); if (post == null) { post = new Post(t); _postByTopic.put(t, post); } return post; } 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 { CommunityBoardHandler.separateAndSend("

the command: " + command + " is not implemented yet


", activeChar); } } private void showEditPost(Topic topic, Forum forum, L2PcInstance activeChar, int idp) { if (topic == null) { CommunityBoardHandler.separateAndSend("

Error: This topic does not exist!
", activeChar); } else { final Post p = getGPosttByTopic(topic); if ((forum == null) || (p == null)) { CommunityBoardHandler.separateAndSend("

Error: This forum or post does not exist!
", activeChar); } else { showHtmlEditPost(topic, activeChar, forum, p); } } } private void showPost(Topic topic, Forum forum, L2PcInstance activeChar, int ind) { if ((forum == null) || (topic == null)) { CommunityBoardHandler.separateAndSend("

Error: This forum is not implemented yet!
", activeChar); } else if (forum.getType() == Forum.MEMO) { showMemoPost(topic, activeChar, forum); } else { CommunityBoardHandler.separateAndSend("

The forum: " + forum.getName() + " is not implemented yet!
", activeChar); } } 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()))); } 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("<", "<"); final String html = StringUtil.concat("

HOME > Memo Form
&$413; :  ", topic.getName(), "
&$417; :  ", topic.getOwnerName() + "&$418; :", dateFormat.format(p.getCPost(0).postDate), "

", mes, "

   



"); CommunityBoardHandler.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) { CommunityBoardHandler.separateAndSend("

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


", activeChar); } else { Topic t = f.getTopic(idt); if (t == null) { CommunityBoardHandler.separateAndSend("

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


", activeChar); } else { final Post p = getGPosttByTopic(t); if (p != null) { final CPost cp = p.getCPost(idp); if (cp == null) { CommunityBoardHandler.separateAndSend("

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


", activeChar); } 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(); } }