TopicBBSManager.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.communitybbs.Manager;
  20. import java.text.DateFormat;
  21. import java.util.Calendar;
  22. import java.util.Date;
  23. import java.util.List;
  24. import java.util.Map;
  25. import java.util.StringTokenizer;
  26. import javolution.util.FastList;
  27. import javolution.util.FastMap;
  28. import com.l2jserver.gameserver.communitybbs.BB.Forum;
  29. import com.l2jserver.gameserver.communitybbs.BB.Post;
  30. import com.l2jserver.gameserver.communitybbs.BB.Topic;
  31. import com.l2jserver.gameserver.datatables.ClanTable;
  32. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  33. import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
  34. import com.l2jserver.util.StringUtil;
  35. public class TopicBBSManager extends BaseBBSManager
  36. {
  37. private final List<Topic> _table;
  38. private final Map<Forum, Integer> _maxId;
  39. protected TopicBBSManager()
  40. {
  41. _table = new FastList<>();
  42. _maxId = new FastMap<Forum, Integer>().shared();
  43. }
  44. public void addTopic(Topic tt)
  45. {
  46. _table.add(tt);
  47. }
  48. /**
  49. * @param topic
  50. */
  51. public void delTopic(Topic topic)
  52. {
  53. _table.remove(topic);
  54. }
  55. public void setMaxID(int id, Forum f)
  56. {
  57. _maxId.put(f, id);
  58. }
  59. public int getMaxID(Forum f)
  60. {
  61. Integer i = _maxId.get(f);
  62. if (i == null)
  63. {
  64. return 0;
  65. }
  66. return i;
  67. }
  68. public Topic getTopicByID(int idf)
  69. {
  70. for (Topic t : _table)
  71. {
  72. if (t.getID() == idf)
  73. {
  74. return t;
  75. }
  76. }
  77. return null;
  78. }
  79. @Override
  80. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  81. {
  82. if (ar1.equals("crea"))
  83. {
  84. Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
  85. if (f == null)
  86. {
  87. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + ar2 + " is not implemented yet</center><br><br></body></html>", "101");
  88. activeChar.sendPacket(sb);
  89. activeChar.sendPacket(new ShowBoard(null, "102"));
  90. activeChar.sendPacket(new ShowBoard(null, "103"));
  91. }
  92. else
  93. {
  94. f.vload();
  95. 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);
  96. f.addTopic(t);
  97. TopicBBSManager.getInstance().setMaxID(t.getID(), f);
  98. Post p = new Post(activeChar.getName(), activeChar.getObjectId(), Calendar.getInstance().getTimeInMillis(), t.getID(), f.getID(), ar4);
  99. PostBBSManager.getInstance().addPostByTopic(p, t);
  100. parsecmd("_bbsmemo", activeChar);
  101. }
  102. }
  103. else if (ar1.equals("del"))
  104. {
  105. Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
  106. if (f == null)
  107. {
  108. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + ar2 + " does not exist !</center><br><br></body></html>", "101");
  109. activeChar.sendPacket(sb);
  110. activeChar.sendPacket(new ShowBoard(null, "102"));
  111. activeChar.sendPacket(new ShowBoard(null, "103"));
  112. }
  113. else
  114. {
  115. Topic t = f.getTopic(Integer.parseInt(ar3));
  116. if (t == null)
  117. {
  118. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + ar3 + " does not exist !</center><br><br></body></html>", "101");
  119. activeChar.sendPacket(sb);
  120. activeChar.sendPacket(new ShowBoard(null, "102"));
  121. activeChar.sendPacket(new ShowBoard(null, "103"));
  122. }
  123. else
  124. {
  125. // CPost cp = null;
  126. Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
  127. if (p != null)
  128. {
  129. p.deleteme(t);
  130. }
  131. t.deleteme(f);
  132. parsecmd("_bbsmemo", activeChar);
  133. }
  134. }
  135. }
  136. else
  137. {
  138. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + ar1 + " is not implemented yet</center><br><br></body></html>", "101");
  139. activeChar.sendPacket(sb);
  140. activeChar.sendPacket(new ShowBoard(null, "102"));
  141. activeChar.sendPacket(new ShowBoard(null, "103"));
  142. }
  143. }
  144. @Override
  145. public void parsecmd(String command, L2PcInstance activeChar)
  146. {
  147. if (command.equals("_bbsmemo"))
  148. {
  149. showTopics(activeChar.getMemo(), activeChar, 1, activeChar.getMemo().getID());
  150. }
  151. else if (command.startsWith("_bbstopics;read"))
  152. {
  153. StringTokenizer st = new StringTokenizer(command, ";");
  154. st.nextToken();
  155. st.nextToken();
  156. int idf = Integer.parseInt(st.nextToken());
  157. String index = null;
  158. if (st.hasMoreTokens())
  159. {
  160. index = st.nextToken();
  161. }
  162. int ind = 0;
  163. if (index == null)
  164. {
  165. ind = 1;
  166. }
  167. else
  168. {
  169. ind = Integer.parseInt(index);
  170. }
  171. showTopics(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind, idf);
  172. }
  173. else if (command.startsWith("_bbstopics;crea"))
  174. {
  175. StringTokenizer st = new StringTokenizer(command, ";");
  176. st.nextToken();
  177. st.nextToken();
  178. int idf = Integer.parseInt(st.nextToken());
  179. showNewTopic(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idf);
  180. }
  181. else if (command.startsWith("_bbstopics;del"))
  182. {
  183. StringTokenizer st = new StringTokenizer(command, ";");
  184. st.nextToken();
  185. st.nextToken();
  186. int idf = Integer.parseInt(st.nextToken());
  187. int idt = Integer.parseInt(st.nextToken());
  188. Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
  189. if (f == null)
  190. {
  191. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf + " does not exist !</center><br><br></body></html>", "101");
  192. activeChar.sendPacket(sb);
  193. activeChar.sendPacket(new ShowBoard(null, "102"));
  194. activeChar.sendPacket(new ShowBoard(null, "103"));
  195. }
  196. else
  197. {
  198. Topic t = f.getTopic(idt);
  199. if (t == null)
  200. {
  201. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + idt + " does not exist !</center><br><br></body></html>", "101");
  202. activeChar.sendPacket(sb);
  203. activeChar.sendPacket(new ShowBoard(null, "102"));
  204. activeChar.sendPacket(new ShowBoard(null, "103"));
  205. }
  206. else
  207. {
  208. // CPost cp = null;
  209. Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
  210. if (p != null)
  211. {
  212. p.deleteme(t);
  213. }
  214. t.deleteme(f);
  215. parsecmd("_bbsmemo", activeChar);
  216. }
  217. }
  218. }
  219. else
  220. {
  221. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", "101");
  222. activeChar.sendPacket(sb);
  223. activeChar.sendPacket(new ShowBoard(null, "102"));
  224. activeChar.sendPacket(new ShowBoard(null, "103"));
  225. }
  226. }
  227. /**
  228. * @param forum
  229. * @param activeChar
  230. * @param idf
  231. */
  232. private void showNewTopic(Forum forum, L2PcInstance activeChar, int idf)
  233. {
  234. if (forum == null)
  235. {
  236. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf + " is not implemented yet</center><br><br></body></html>", "101");
  237. activeChar.sendPacket(sb);
  238. activeChar.sendPacket(new ShowBoard(null, "102"));
  239. activeChar.sendPacket(new ShowBoard(null, "103"));
  240. }
  241. else if (forum.getType() == Forum.MEMO)
  242. {
  243. showMemoNewTopics(forum, activeChar);
  244. }
  245. else
  246. {
  247. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName() + " is not implemented yet</center><br><br></body></html>", "101");
  248. activeChar.sendPacket(sb);
  249. activeChar.sendPacket(new ShowBoard(null, "102"));
  250. activeChar.sendPacket(new ShowBoard(null, "103"));
  251. }
  252. }
  253. /**
  254. * @param forum
  255. * @param activeChar
  256. */
  257. private void showMemoNewTopics(Forum forum, L2PcInstance activeChar)
  258. {
  259. final String html = StringUtil.concat("<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=0><tr><td width=610><img src=\"sek.cbui355\" width=\"610\" height=\"1\"><br1><img src=\"sek.cbui355\" width=\"610\" height=\"1\"></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29>&$413;</td><td FIXWIDTH=540><edit var = \"Title\" width=540 height=13></td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td><td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29>&nbsp;</td><td align=center FIXWIDTH=70><button value=\"&$140;\" action=\"Write Topic crea ", String.valueOf(forum.getID()), " Title Content Title\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td><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><td align=center FIXWIDTH=400>&nbsp;</td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table></center></body></html>");
  260. send1001(html, activeChar);
  261. send1002(activeChar);
  262. }
  263. /**
  264. * @param forum
  265. * @param activeChar
  266. * @param index
  267. * @param idf
  268. */
  269. private void showTopics(Forum forum, L2PcInstance activeChar, int index, int idf)
  270. {
  271. if (forum == null)
  272. {
  273. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf + " is not implemented yet</center><br><br></body></html>", "101");
  274. activeChar.sendPacket(sb);
  275. activeChar.sendPacket(new ShowBoard(null, "102"));
  276. activeChar.sendPacket(new ShowBoard(null, "103"));
  277. }
  278. else if (forum.getType() == Forum.MEMO)
  279. {
  280. showMemoTopics(forum, activeChar, index);
  281. }
  282. else
  283. {
  284. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName() + " is not implemented yet</center><br><br></body></html>", "101");
  285. activeChar.sendPacket(sb);
  286. activeChar.sendPacket(new ShowBoard(null, "102"));
  287. activeChar.sendPacket(new ShowBoard(null, "103"));
  288. }
  289. }
  290. /**
  291. * @param forum
  292. * @param activeChar
  293. * @param index
  294. */
  295. private void showMemoTopics(Forum forum, L2PcInstance activeChar, int index)
  296. {
  297. forum.vload();
  298. final StringBuilder html = StringUtil.startAppend(2000, "<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=2 bgcolor=888888 width=610><tr><td FIXWIDTH=5></td><td FIXWIDTH=415 align=center>&$413;</td><td FIXWIDTH=120 align=center></td><td FIXWIDTH=70 align=center>&$418;</td></tr></table>");
  299. final DateFormat dateFormat = DateFormat.getInstance();
  300. for (int i = 0, j = getMaxID(forum) + 1; i < (12 * index); j--)
  301. {
  302. if (j < 0)
  303. {
  304. break;
  305. }
  306. Topic t = forum.getTopic(j);
  307. if (t != null)
  308. {
  309. if (i++ >= (12 * (index - 1)))
  310. {
  311. StringUtil.append(html, "<table border=0 cellspacing=0 cellpadding=5 WIDTH=610><tr><td FIXWIDTH=5></td><td FIXWIDTH=415><a action=\"bypass _bbsposts;read;", String.valueOf(forum.getID()), ";", String.valueOf(t.getID()), "\">", t.getName(), "</a></td><td FIXWIDTH=120 align=center></td><td FIXWIDTH=70 align=center>", dateFormat.format(new Date(t.getDate())), "</td></tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");
  312. }
  313. }
  314. }
  315. html.append("<br><table width=610 cellspace=0 cellpadding=0><tr><td width=50><button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"></td><td width=510 align=center><table border=0><tr>");
  316. if (index == 1)
  317. {
  318. html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  319. }
  320. else
  321. {
  322. StringUtil.append(html, "<td><button action=\"bypass _bbstopics;read;", String.valueOf(forum.getID()), ";", String.valueOf(index - 1), "\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  323. }
  324. int nbp;
  325. nbp = forum.getTopicSize() / 8;
  326. if ((nbp * 8) != ClanTable.getInstance().getClans().length)
  327. {
  328. nbp++;
  329. }
  330. for (int i = 1; i <= nbp; i++)
  331. {
  332. if (i == index)
  333. {
  334. StringUtil.append(html, "<td> ", String.valueOf(i), " </td>");
  335. }
  336. else
  337. {
  338. StringUtil.append(html, "<td><a action=\"bypass _bbstopics;read;", String.valueOf(forum.getID()), ";", String.valueOf(i), "\"> ", String.valueOf(i), " </a></td>");
  339. }
  340. }
  341. if (index == nbp)
  342. {
  343. html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  344. }
  345. else
  346. {
  347. StringUtil.append(html, "<td><button action=\"bypass _bbstopics;read;", String.valueOf(forum.getID()), ";", String.valueOf(index + 1), "\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  348. }
  349. StringUtil.append(html, "</tr></table> </td> <td align=right><button value = \"&$421;\" action=\"bypass _bbstopics;crea;", String.valueOf(forum.getID()), "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr> <td></td><td align=center><table border=0><tr><td></td><td><edit var = \"Search\" width=130 height=11></td><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></tr></table><br><br><br></center></body></html>");
  350. separateAndSend(html.toString(), activeChar);
  351. }
  352. public static TopicBBSManager getInstance()
  353. {
  354. return SingletonHolder._instance;
  355. }
  356. private static class SingletonHolder
  357. {
  358. protected static final TopicBBSManager _instance = new TopicBBSManager();
  359. }
  360. }