TopicBBSManager.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  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.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. /* (non-Javadoc)
  86. * @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)
  87. */
  88. @Override
  89. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  90. {
  91. if (ar1.equals("crea"))
  92. {
  93. Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
  94. if (f == null)
  95. {
  96. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + ar2
  97. + " 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,
  106. TopicBBSManager.getInstance().getMaxID(f) + 1,
  107. Integer.parseInt(ar2), ar5,
  108. Calendar.getInstance().getTimeInMillis(), activeChar.getName(),
  109. activeChar.getObjectId(), Topic.MEMO, 0);
  110. f.addtopic(t);
  111. TopicBBSManager.getInstance().setMaxID(t.getID(), f);
  112. Post p = new Post(activeChar.getName(), activeChar.getObjectId(),
  113. Calendar.getInstance().getTimeInMillis(), t.getID(), f.getID(), ar4);
  114. PostBBSManager.getInstance().addPostByTopic(p, t);
  115. parsecmd("_bbsmemo", activeChar);
  116. }
  117. }
  118. else if (ar1.equals("del"))
  119. {
  120. Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
  121. if (f == null)
  122. {
  123. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + ar2
  124. + " does not exist !</center><br><br></body></html>", "101");
  125. activeChar.sendPacket(sb);
  126. activeChar.sendPacket(new ShowBoard(null, "102"));
  127. activeChar.sendPacket(new ShowBoard(null, "103"));
  128. }
  129. else
  130. {
  131. Topic t = f.gettopic(Integer.parseInt(ar3));
  132. if (t == null)
  133. {
  134. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + ar3
  135. + " does not exist !</center><br><br></body></html>", "101");
  136. activeChar.sendPacket(sb);
  137. activeChar.sendPacket(new ShowBoard(null, "102"));
  138. activeChar.sendPacket(new ShowBoard(null, "103"));
  139. }
  140. else
  141. {
  142. //CPost cp = null;
  143. Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
  144. if (p != null)
  145. {
  146. p.deleteme(t);
  147. }
  148. t.deleteme(f);
  149. parsecmd("_bbsmemo", activeChar);
  150. }
  151. }
  152. }
  153. else
  154. {
  155. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + ar1
  156. + " is not implemented yet</center><br><br></body></html>", "101");
  157. activeChar.sendPacket(sb);
  158. activeChar.sendPacket(new ShowBoard(null, "102"));
  159. activeChar.sendPacket(new ShowBoard(null, "103"));
  160. }
  161. }
  162. /* (non-Javadoc)
  163. * @see net.sf.l2j.gameserver.communitybbs.Manager.BaseBBSManager#parsecmd(java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
  164. */
  165. @Override
  166. public void parsecmd(String command, L2PcInstance activeChar)
  167. {
  168. if (command.equals("_bbsmemo"))
  169. {
  170. showTopics(activeChar.getMemo(), activeChar, 1, activeChar.getMemo().getID());
  171. }
  172. else if (command.startsWith("_bbstopics;read"))
  173. {
  174. StringTokenizer st = new StringTokenizer(command, ";");
  175. st.nextToken();
  176. st.nextToken();
  177. int idf = Integer.parseInt(st.nextToken());
  178. String index = null;
  179. if (st.hasMoreTokens())
  180. {
  181. index = st.nextToken();
  182. }
  183. int ind = 0;
  184. if (index == null)
  185. {
  186. ind = 1;
  187. }
  188. else
  189. {
  190. ind = Integer.parseInt(index);
  191. }
  192. showTopics(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind, idf);
  193. }
  194. else if (command.startsWith("_bbstopics;crea"))
  195. {
  196. StringTokenizer st = new StringTokenizer(command, ";");
  197. st.nextToken();
  198. st.nextToken();
  199. int idf = Integer.parseInt(st.nextToken());
  200. showNewTopic(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idf);
  201. }
  202. else if (command.startsWith("_bbstopics;del"))
  203. {
  204. StringTokenizer st = new StringTokenizer(command, ";");
  205. st.nextToken();
  206. st.nextToken();
  207. int idf = Integer.parseInt(st.nextToken());
  208. int idt = Integer.parseInt(st.nextToken());
  209. Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
  210. if (f == null)
  211. {
  212. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
  213. + " does not exist !</center><br><br></body></html>", "101");
  214. activeChar.sendPacket(sb);
  215. activeChar.sendPacket(new ShowBoard(null, "102"));
  216. activeChar.sendPacket(new ShowBoard(null, "103"));
  217. }
  218. else
  219. {
  220. Topic t = f.gettopic(idt);
  221. if (t == null)
  222. {
  223. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + idt
  224. + " does not exist !</center><br><br></body></html>", "101");
  225. activeChar.sendPacket(sb);
  226. activeChar.sendPacket(new ShowBoard(null, "102"));
  227. activeChar.sendPacket(new ShowBoard(null, "103"));
  228. }
  229. else
  230. {
  231. //CPost cp = null;
  232. Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
  233. if (p != null)
  234. {
  235. p.deleteme(t);
  236. }
  237. t.deleteme(f);
  238. parsecmd("_bbsmemo", activeChar);
  239. }
  240. }
  241. }
  242. else
  243. {
  244. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command
  245. + " is not implemented yet</center><br><br></body></html>", "101");
  246. activeChar.sendPacket(sb);
  247. activeChar.sendPacket(new ShowBoard(null, "102"));
  248. activeChar.sendPacket(new ShowBoard(null, "103"));
  249. }
  250. }
  251. /**
  252. * @param forumByID
  253. * @param activeChar
  254. * @param idf
  255. */
  256. private void showNewTopic(Forum forum, L2PcInstance activeChar, int idf)
  257. {
  258. if (forum == null)
  259. {
  260. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
  261. + " 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. else if (forum.getType() == Forum.MEMO)
  267. {
  268. showMemoNewTopics(forum, activeChar);
  269. }
  270. else
  271. {
  272. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName()
  273. + " 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. }
  279. /**
  280. * @param forum
  281. * @param activeChar
  282. */
  283. private void showMemoNewTopics(Forum forum, L2PcInstance activeChar)
  284. {
  285. TextBuilder html = new TextBuilder("<html>");
  286. html.append("<body><br><br>");
  287. html.append("<table border=0 width=610><tr><td width=10></td><td width=600 align=left>");
  288. html.append("<a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a>");
  289. html.append("</td></tr>");
  290. html.append("</table>");
  291. html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">");
  292. html.append("<center>");
  293. html.append("<table border=0 cellspacing=0 cellpadding=0>");
  294. 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>");
  295. html.append("</table>");
  296. html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
  297. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr>");
  298. html.append("<tr>");
  299. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  300. html.append("<td align=center FIXWIDTH=60 height=29>&$413;</td>");
  301. html.append("<td FIXWIDTH=540><edit var = \"Title\" width=540 height=13></td>");
  302. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  303. html.append("</tr></table>");
  304. html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
  305. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
  306. html.append("<tr>");
  307. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  308. html.append("<td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td>");
  309. html.append("<td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td>");
  310. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  311. html.append("</tr>");
  312. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
  313. html.append("</table>");
  314. html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
  315. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
  316. html.append("<tr>");
  317. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  318. html.append("<td align=center FIXWIDTH=60 height=29>&nbsp;</td>");
  319. html.append("<td align=center FIXWIDTH=70><button value=\"&$140;\" action=\"Write Topic crea "
  320. + forum.getID()
  321. + " Title Content Title\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>");
  322. 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>");
  323. html.append("<td align=center FIXWIDTH=400>&nbsp;</td>");
  324. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  325. html.append("</tr></table>");
  326. html.append("</center>");
  327. html.append("</body>");
  328. html.append("</html>");
  329. send1001(html.toString(), activeChar);
  330. send1002(activeChar);
  331. }
  332. /**
  333. * @param memo
  334. */
  335. private void showTopics(Forum forum, L2PcInstance activeChar, int index, int idf)
  336. {
  337. if (forum == null)
  338. {
  339. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
  340. + " is not implemented yet</center><br><br></body></html>", "101");
  341. activeChar.sendPacket(sb);
  342. activeChar.sendPacket(new ShowBoard(null, "102"));
  343. activeChar.sendPacket(new ShowBoard(null, "103"));
  344. }
  345. else if (forum.getType() == Forum.MEMO)
  346. {
  347. showMemoTopics(forum, activeChar, index);
  348. }
  349. else
  350. {
  351. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName()
  352. + " is not implemented yet</center><br><br></body></html>", "101");
  353. activeChar.sendPacket(sb);
  354. activeChar.sendPacket(new ShowBoard(null, "102"));
  355. activeChar.sendPacket(new ShowBoard(null, "103"));
  356. }
  357. }
  358. /**
  359. * @param forum
  360. * @param activeChar
  361. */
  362. private void showMemoTopics(Forum forum, L2PcInstance activeChar, int index)
  363. {
  364. forum.vload();
  365. TextBuilder html = new TextBuilder("<html><body><br><br>");
  366. html.append("<table border=0 width=610><tr><td width=10></td><td width=600 align=left>");
  367. html.append("<a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a>");
  368. html.append("</td></tr>");
  369. html.append("</table>");
  370. html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">");
  371. html.append("<center>");
  372. html.append("<table border=0 cellspacing=0 cellpadding=2 bgcolor=888888 width=610>");
  373. html.append("<tr>");
  374. html.append("<td FIXWIDTH=5></td>");
  375. html.append("<td FIXWIDTH=415 align=center>&$413;</td>");
  376. html.append("<td FIXWIDTH=120 align=center></td>");
  377. html.append("<td FIXWIDTH=70 align=center>&$418;</td>");
  378. html.append("</tr>");
  379. html.append("</table>");
  380. for (int i = 0, j = getMaxID(forum) + 1; i < 12 * index; j--)
  381. {
  382. if (j < 0)
  383. {
  384. break;
  385. }
  386. Topic t = forum.gettopic(j);
  387. if (t != null)
  388. {
  389. if (i >= 12 * (index - 1))
  390. {
  391. html.append("<table border=0 cellspacing=0 cellpadding=5 WIDTH=610>");
  392. html.append("<tr>");
  393. html.append("<td FIXWIDTH=5></td>");
  394. html.append("<td FIXWIDTH=415><a action=\"bypass _bbsposts;read;" + forum.getID()
  395. + ";" + t.getID() + "\">" + t.getName() + "</a></td>");
  396. html.append("<td FIXWIDTH=120 align=center></td>");
  397. html.append("<td FIXWIDTH=70 align=center>"
  398. + DateFormat.getInstance().format(new Date(t.getDate())) + "</td>");
  399. html.append("</tr>");
  400. html.append("</table>");
  401. html.append("<img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");
  402. }
  403. i++;
  404. }
  405. }
  406. html.append("<br>");
  407. html.append("<table width=610 cellspace=0 cellpadding=0>");
  408. html.append("<tr>");
  409. html.append("<td width=50>");
  410. html.append("<button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  411. html.append("</td>");
  412. html.append("<td width=510 align=center>");
  413. html.append("<table border=0><tr>");
  414. if (index == 1)
  415. {
  416. html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  417. }
  418. else
  419. {
  420. html.append("<td><button action=\"bypass _bbstopics;read;" + forum.getID() + ";"
  421. + (index - 1)
  422. + "\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  423. }
  424. int nbp;
  425. nbp = forum.getTopicSize() / 8;
  426. if (nbp * 8 != ClanTable.getInstance().getClans().length)
  427. {
  428. nbp++;
  429. }
  430. for (int i = 1; i <= nbp; i++)
  431. {
  432. if (i == index)
  433. {
  434. html.append("<td> " + i + " </td>");
  435. }
  436. else
  437. {
  438. html.append("<td><a action=\"bypass _bbstopics;read;" + forum.getID() + ";" + i + "\"> "
  439. + i + " </a></td>");
  440. }
  441. }
  442. if (index == nbp)
  443. {
  444. html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  445. }
  446. else
  447. {
  448. html.append("<td><button action=\"bypass _bbstopics;read;" + forum.getID() + ";"
  449. + (index + 1)
  450. + "\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  451. }
  452. html.append("</tr></table> </td> ");
  453. html.append("<td align=right><button value = \"&$421;\" action=\"bypass _bbstopics;crea;"
  454. + forum.getID()
  455. + "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td></tr>");
  456. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
  457. html.append("<tr> ");
  458. html.append("<td></td>");
  459. html.append("<td align=center><table border=0><tr><td></td><td><edit var = \"Search\" width=130 height=11></td>");
  460. 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>");
  461. html.append("</tr>");
  462. html.append("</table>");
  463. html.append("<br>");
  464. html.append("<br>");
  465. html.append("<br>");
  466. html.append("</center>");
  467. html.append("</body>");
  468. html.append("</html>");
  469. separateAndSend(html.toString(), activeChar);
  470. }
  471. }