TopicBBSManager.java 17 KB

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