/* * Copyright (C) 2004-2014 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.Calendar; import java.util.Date; import java.util.List; import java.util.Map; import java.util.StringTokenizer; import javolution.util.FastList; import javolution.util.FastMap; import com.l2jserver.gameserver.communitybbs.BB.Forum; import com.l2jserver.gameserver.communitybbs.BB.Post; import com.l2jserver.gameserver.communitybbs.BB.Topic; import com.l2jserver.gameserver.datatables.ClanTable; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.network.serverpackets.ShowBoard; import com.l2jserver.util.StringUtil; public class TopicBBSManager extends BaseBBSManager { private final List _table; private final Map _maxId; protected TopicBBSManager() { _table = new FastList<>(); _maxId = new FastMap().shared(); } public void addTopic(Topic tt) { _table.add(tt); } /** * @param topic */ public void delTopic(Topic topic) { _table.remove(topic); } public void setMaxID(int id, Forum f) { _maxId.put(f, id); } public int getMaxID(Forum f) { Integer i = _maxId.get(f); if (i == null) { return 0; } return i; } public Topic getTopicByID(int idf) { for (Topic t : _table) { if (t.getID() == idf) { return t; } } return null; } @Override public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar) { if (ar1.equals("crea")) { Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2)); if (f == null) { ShowBoard sb = new ShowBoard("

the forum: " + ar2 + " is not implemented yet


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } else { f.vload(); Topic t = new Topic(Topic.ConstructorType.CREATE, TopicBBSManager.getInstance().getMaxID(f) + 1, Integer.parseInt(ar2), ar5, Calendar.getInstance().getTimeInMillis(), activeChar.getName(), activeChar.getObjectId(), Topic.MEMO, 0); f.addTopic(t); TopicBBSManager.getInstance().setMaxID(t.getID(), f); Post p = new Post(activeChar.getName(), activeChar.getObjectId(), Calendar.getInstance().getTimeInMillis(), t.getID(), f.getID(), ar4); PostBBSManager.getInstance().addPostByTopic(p, t); parsecmd("_bbsmemo", activeChar); } } else if (ar1.equals("del")) { Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2)); if (f == null) { ShowBoard sb = new ShowBoard("

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


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

the topic: " + ar3 + " 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 = PostBBSManager.getInstance().getGPosttByTopic(t); if (p != null) { p.deleteme(t); } t.deleteme(f); parsecmd("_bbsmemo", activeChar); } } } else { ShowBoard sb = new ShowBoard("

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


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } } @Override public void parsecmd(String command, L2PcInstance activeChar) { if (command.equals("_bbsmemo")) { showTopics(activeChar.getMemo(), activeChar, 1, activeChar.getMemo().getID()); } else if (command.startsWith("_bbstopics;read")) { StringTokenizer st = new StringTokenizer(command, ";"); st.nextToken(); st.nextToken(); int idf = 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); } showTopics(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind, idf); } else if (command.startsWith("_bbstopics;crea")) { StringTokenizer st = new StringTokenizer(command, ";"); st.nextToken(); st.nextToken(); int idf = Integer.parseInt(st.nextToken()); showNewTopic(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idf); } else if (command.startsWith("_bbstopics;del")) { StringTokenizer st = new StringTokenizer(command, ";"); st.nextToken(); st.nextToken(); int idf = Integer.parseInt(st.nextToken()); int idt = 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 = PostBBSManager.getInstance().getGPosttByTopic(t); if (p != null) { p.deleteme(t); } t.deleteme(f); parsecmd("_bbsmemo", activeChar); } } } 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 forum * @param activeChar * @param idf */ private void showNewTopic(Forum forum, L2PcInstance activeChar, int idf) { if (forum == null) { ShowBoard sb = new ShowBoard("

the forum: " + idf + " 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) { showMemoNewTopics(forum, activeChar); } 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 forum * @param activeChar */ private void showMemoNewTopics(Forum forum, L2PcInstance activeChar) { final String html = StringUtil.concat("

HOME > Memo Form
&$413;
&$427;
  
"); send1001(html, activeChar); send1002(activeChar); } /** * @param forum * @param activeChar * @param index * @param idf */ private void showTopics(Forum forum, L2PcInstance activeChar, int index, int idf) { if (forum == null) { ShowBoard sb = new ShowBoard("

the forum: " + idf + " 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) { showMemoTopics(forum, activeChar, index); } 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 forum * @param activeChar * @param index */ private void showMemoTopics(Forum forum, L2PcInstance activeChar, int index) { forum.vload(); final StringBuilder html = StringUtil.startAppend(2000, "

HOME > Memo Form
&$413;&$418;
"); final DateFormat dateFormat = DateFormat.getInstance(); for (int i = 0, j = getMaxID(forum) + 1; i < (12 * index); j--) { if (j < 0) { break; } Topic t = forum.getTopic(j); if (t != null) { if (i++ >= (12 * (index - 1))) { StringUtil.append(html, "
", t.getName(), "", dateFormat.format(new Date(t.getDate())), "
"); } } } html.append("
"); if (index == 1) { html.append(""); } else { StringUtil.append(html, ""); } int nbp; nbp = forum.getTopicSize() / 8; if ((nbp * 8) != ClanTable.getInstance().getClans().length) { nbp++; } for (int i = 1; i <= nbp; i++) { if (i == index) { StringUtil.append(html, ""); } else { StringUtil.append(html, ""); } } if (index == nbp) { html.append(""); } else { StringUtil.append(html, ""); } StringUtil.append(html, "
", String.valueOf(i), " ", String.valueOf(i), "



"); separateAndSend(html.toString(), activeChar); } public static TopicBBSManager getInstance() { return SingletonHolder._instance; } private static class SingletonHolder { protected static final TopicBBSManager _instance = new TopicBBSManager(); } }