123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493 |
- /*
- * 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 <http://www.gnu.org/licenses/>.
- */
- package net.sf.l2j.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.text.TextBuilder;
- import javolution.util.FastList;
- 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.datatables.ClanTable;
- import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
- import net.sf.l2j.gameserver.serverpackets.ShowBoard;
- public class TopicBBSManager extends BaseBBSManager
- {
- private List<Topic> _table;
- private Map<Forum, Integer> _maxId;
- private static TopicBBSManager _instance;
- public static TopicBBSManager getInstance()
- {
- if (_instance == null)
- {
- _instance = new TopicBBSManager();
- }
- return _instance;
- }
- private TopicBBSManager()
- {
- _table = new FastList<Topic>();
- _maxId = new FastMap<Forum, Integer>();
- }
- 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.remove(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;
- }
- /* (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)
- {
- if (ar1.equals("crea"))
- {
- Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
- if (f == null)
- {
- ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + ar2
- + " is not implemented yet</center><br><br></body></html>", "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("<html><body><br><br><center>the forum: " + ar2
- + " does not exist !</center><br><br></body></html>", "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("<html><body><br><br><center>the topic: " + ar3
- + " does not exist !</center><br><br></body></html>", "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("<html><body><br><br><center>the command: " + ar1
- + " is not implemented yet</center><br><br></body></html>", "101");
- activeChar.sendPacket(sb);
- activeChar.sendPacket(new ShowBoard(null, "102"));
- activeChar.sendPacket(new ShowBoard(null, "103"));
- }
- }
- /* (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.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("<html><body><br><br><center>the forum: " + idf
- + " does not exist !</center><br><br></body></html>", "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("<html><body><br><br><center>the topic: " + idt
- + " does not exist !</center><br><br></body></html>", "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("<html><body><br><br><center>the command: " + command
- + " is not implemented yet</center><br><br></body></html>", "101");
- activeChar.sendPacket(sb);
- activeChar.sendPacket(new ShowBoard(null, "102"));
- activeChar.sendPacket(new ShowBoard(null, "103"));
- }
- }
- /**
- * @param forumByID
- * @param activeChar
- * @param idf
- */
- private void showNewTopic(Forum forum, L2PcInstance activeChar, int idf)
- {
- if (forum == null)
- {
- ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
- + " is not implemented yet</center><br><br></body></html>", "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("<html><body><br><br><center>the forum: " + forum.getName()
- + " is not implemented yet</center><br><br></body></html>", "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)
- {
- TextBuilder html = new TextBuilder("<html>");
- html.append("<body><br><br>");
- html.append("<table border=0 width=610><tr><td width=10></td><td width=600 align=left>");
- html.append("<a action=\"bypass _bbshome\">HOME</a> > <a action=\"bypass _bbsmemo\">Memo Form</a>");
- html.append("</td></tr>");
- html.append("</table>");
- html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">");
- html.append("<center>");
- html.append("<table border=0 cellspacing=0 cellpadding=0>");
- html.append("<tr><td width=610><img src=\"sek.cbui355\" width=\"610\" height=\"1\"><br1><img src=\"sek.cbui355\" width=\"610\" height=\"1\"></td></tr>");
- html.append("</table>");
- html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
- html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr>");
- html.append("<tr>");
- html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
- html.append("<td align=center FIXWIDTH=60 height=29>&$413;</td>");
- html.append("<td FIXWIDTH=540><edit var = \"Title\" width=540 height=13></td>");
- html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
- html.append("</tr></table>");
- html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
- html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
- html.append("<tr>");
- html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
- html.append("<td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td>");
- html.append("<td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td>");
- html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
- html.append("</tr>");
- html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
- html.append("</table>");
- html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
- html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
- html.append("<tr>");
- html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
- html.append("<td align=center FIXWIDTH=60 height=29> </td>");
- html.append("<td align=center FIXWIDTH=70><button value=\"&$140;\" action=\"Write Topic crea "
- + forum.getID()
- + " Title Content Title\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>");
- html.append("<td align=center FIXWIDTH=70><button value = \"&$141;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"> </td>");
- html.append("<td align=center FIXWIDTH=400> </td>");
- html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
- html.append("</tr></table>");
- html.append("</center>");
- html.append("</body>");
- html.append("</html>");
- send1001(html.toString(), activeChar);
- send1002(activeChar);
- }
- /**
- * @param memo
- */
- private void showTopics(Forum forum, L2PcInstance activeChar, int index, int idf)
- {
- if (forum == null)
- {
- ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
- + " is not implemented yet</center><br><br></body></html>", "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("<html><body><br><br><center>the forum: " + forum.getName()
- + " is not implemented yet</center><br><br></body></html>", "101");
- activeChar.sendPacket(sb);
- activeChar.sendPacket(new ShowBoard(null, "102"));
- activeChar.sendPacket(new ShowBoard(null, "103"));
- }
- }
- /**
- * @param forum
- * @param activeChar
- */
- private void showMemoTopics(Forum forum, L2PcInstance activeChar, int index)
- {
- forum.vload();
- TextBuilder html = new TextBuilder("<html><body><br><br>");
- html.append("<table border=0 width=610><tr><td width=10></td><td width=600 align=left>");
- html.append("<a action=\"bypass _bbshome\">HOME</a> > <a action=\"bypass _bbsmemo\">Memo Form</a>");
- html.append("</td></tr>");
- html.append("</table>");
- html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">");
- html.append("<center>");
- html.append("<table border=0 cellspacing=0 cellpadding=2 bgcolor=888888 width=610>");
- html.append("<tr>");
- html.append("<td FIXWIDTH=5></td>");
- html.append("<td FIXWIDTH=415 align=center>&$413;</td>");
- html.append("<td FIXWIDTH=120 align=center></td>");
- html.append("<td FIXWIDTH=70 align=center>&$418;</td>");
- html.append("</tr>");
- html.append("</table>");
- 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))
- {
- html.append("<table border=0 cellspacing=0 cellpadding=5 WIDTH=610>");
- html.append("<tr>");
- html.append("<td FIXWIDTH=5></td>");
- html.append("<td FIXWIDTH=415><a action=\"bypass _bbsposts;read;" + forum.getID()
- + ";" + t.getID() + "\">" + t.getName() + "</a></td>");
- html.append("<td FIXWIDTH=120 align=center></td>");
- html.append("<td FIXWIDTH=70 align=center>"
- + DateFormat.getInstance().format(new Date(t.getDate())) + "</td>");
- html.append("</tr>");
- html.append("</table>");
- html.append("<img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");
- }
- i++;
- }
- }
- html.append("<br>");
- html.append("<table width=610 cellspace=0 cellpadding=0>");
- html.append("<tr>");
- html.append("<td width=50>");
- html.append("<button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
- html.append("</td>");
- html.append("<td width=510 align=center>");
- html.append("<table border=0><tr>");
- if (index == 1)
- {
- html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
- }
- else
- {
- html.append("<td><button action=\"bypass _bbstopics;read;" + forum.getID() + ";"
- + (index - 1)
- + "\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
- }
- int nbp;
- nbp = forum.getTopicSize() / 8;
- if (nbp * 8 != ClanTable.getInstance().getClans().length)
- {
- nbp++;
- }
- for (int i = 1; i <= nbp; i++)
- {
- if (i == index)
- {
- html.append("<td> " + i + " </td>");
- }
- else
- {
- html.append("<td><a action=\"bypass _bbstopics;read;" + forum.getID() + ";" + i + "\"> "
- + i + " </a></td>");
- }
- }
- if (index == nbp)
- {
- html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
- }
- else
- {
- html.append("<td><button action=\"bypass _bbstopics;read;" + forum.getID() + ";"
- + (index + 1)
- + "\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
- }
- html.append("</tr></table> </td> ");
- html.append("<td align=right><button value = \"&$421;\" action=\"bypass _bbstopics;crea;"
- + forum.getID()
- + "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td></tr>");
- html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
- html.append("<tr> ");
- html.append("<td></td>");
- html.append("<td align=center><table border=0><tr><td></td><td><edit var = \"Search\" width=130 height=11></td>");
- html.append("<td><button value=\"&$420;\" action=\"Write 5 -2 0 Search _ _\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"> </td> </tr></table> </td>");
- html.append("</tr>");
- html.append("</table>");
- html.append("<br>");
- html.append("<br>");
- html.append("<br>");
- html.append("</center>");
- html.append("</body>");
- html.append("</html>");
- separateAndSend(html.toString(), activeChar);
- }
- }
|