2
0

TopicBBSManager.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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 com.l2jserver.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 com.l2jserver.gameserver.communitybbs.BB.Forum;
  23. import com.l2jserver.gameserver.communitybbs.BB.Post;
  24. import com.l2jserver.gameserver.communitybbs.BB.Topic;
  25. import com.l2jserver.gameserver.datatables.ClanTable;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
  28. import com.l2jserver.gameserver.util.StringUtil;
  29. import javolution.util.FastList;
  30. import javolution.util.FastMap;
  31. public class TopicBBSManager extends BaseBBSManager
  32. {
  33. private List<Topic> _table;
  34. private Map<Forum, Integer> _maxId;
  35. public static TopicBBSManager getInstance()
  36. {
  37. return SingletonHolder._instance;
  38. }
  39. private TopicBBSManager()
  40. {
  41. _table = new FastList<Topic>();
  42. _maxId = new FastMap<Forum, Integer>();
  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.remove(f);
  58. _maxId.put(f, id);
  59. }
  60. public int getMaxID(Forum f)
  61. {
  62. Integer i = _maxId.get(f);
  63. if (i == null)
  64. {
  65. return 0;
  66. }
  67. return i;
  68. }
  69. public Topic getTopicByID(int idf)
  70. {
  71. for (Topic t : _table)
  72. {
  73. if (t.getID() == idf)
  74. {
  75. return t;
  76. }
  77. }
  78. return null;
  79. }
  80. /**
  81. *
  82. * @see com.l2jserver.gameserver.communitybbs.Manager.BaseBBSManager#parsewrite(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  83. */
  84. @Override
  85. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  86. {
  87. if (ar1.equals("crea"))
  88. {
  89. Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
  90. if (f == null)
  91. {
  92. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + ar2
  93. + " is not implemented yet</center><br><br></body></html>", "101");
  94. activeChar.sendPacket(sb);
  95. activeChar.sendPacket(new ShowBoard(null, "102"));
  96. activeChar.sendPacket(new ShowBoard(null, "103"));
  97. }
  98. else
  99. {
  100. f.vload();
  101. 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);
  102. f.addTopic(t);
  103. TopicBBSManager.getInstance().setMaxID(t.getID(), f);
  104. Post p = new Post(activeChar.getName(), activeChar.getObjectId(), Calendar.getInstance().getTimeInMillis(), t.getID(), f.getID(), ar4);
  105. PostBBSManager.getInstance().addPostByTopic(p, t);
  106. parsecmd("_bbsmemo", activeChar);
  107. }
  108. }
  109. else if (ar1.equals("del"))
  110. {
  111. Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
  112. if (f == null)
  113. {
  114. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + ar2
  115. + " does not exist !</center><br><br></body></html>", "101");
  116. activeChar.sendPacket(sb);
  117. activeChar.sendPacket(new ShowBoard(null, "102"));
  118. activeChar.sendPacket(new ShowBoard(null, "103"));
  119. }
  120. else
  121. {
  122. Topic t = f.getTopic(Integer.parseInt(ar3));
  123. if (t == null)
  124. {
  125. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + ar3
  126. + " does not exist !</center><br><br></body></html>", "101");
  127. activeChar.sendPacket(sb);
  128. activeChar.sendPacket(new ShowBoard(null, "102"));
  129. activeChar.sendPacket(new ShowBoard(null, "103"));
  130. }
  131. else
  132. {
  133. //CPost cp = null;
  134. Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
  135. if (p != null)
  136. {
  137. p.deleteme(t);
  138. }
  139. t.deleteme(f);
  140. parsecmd("_bbsmemo", activeChar);
  141. }
  142. }
  143. }
  144. else
  145. {
  146. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + ar1
  147. + " is not implemented yet</center><br><br></body></html>", "101");
  148. activeChar.sendPacket(sb);
  149. activeChar.sendPacket(new ShowBoard(null, "102"));
  150. activeChar.sendPacket(new ShowBoard(null, "103"));
  151. }
  152. }
  153. /**
  154. *
  155. * @see com.l2jserver.gameserver.communitybbs.Manager.BaseBBSManager#parsecmd(java.lang.String, com.l2jserver.gameserver.model.actor.instance.L2PcInstance)
  156. */
  157. @Override
  158. public void parsecmd(String command, L2PcInstance activeChar)
  159. {
  160. if (command.equals("_bbsmemo"))
  161. {
  162. showTopics(activeChar.getMemo(), activeChar, 1, activeChar.getMemo().getID());
  163. }
  164. else if (command.startsWith("_bbstopics;read"))
  165. {
  166. StringTokenizer st = new StringTokenizer(command, ";");
  167. st.nextToken();
  168. st.nextToken();
  169. int idf = Integer.parseInt(st.nextToken());
  170. String index = null;
  171. if (st.hasMoreTokens())
  172. {
  173. index = st.nextToken();
  174. }
  175. int ind = 0;
  176. if (index == null)
  177. {
  178. ind = 1;
  179. }
  180. else
  181. {
  182. ind = Integer.parseInt(index);
  183. }
  184. showTopics(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind, idf);
  185. }
  186. else if (command.startsWith("_bbstopics;crea"))
  187. {
  188. StringTokenizer st = new StringTokenizer(command, ";");
  189. st.nextToken();
  190. st.nextToken();
  191. int idf = Integer.parseInt(st.nextToken());
  192. showNewTopic(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idf);
  193. }
  194. else if (command.startsWith("_bbstopics;del"))
  195. {
  196. StringTokenizer st = new StringTokenizer(command, ";");
  197. st.nextToken();
  198. st.nextToken();
  199. int idf = Integer.parseInt(st.nextToken());
  200. int idt = Integer.parseInt(st.nextToken());
  201. Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
  202. if (f == null)
  203. {
  204. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
  205. + " 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
  216. + " does not exist !</center><br><br></body></html>", "101");
  217. activeChar.sendPacket(sb);
  218. activeChar.sendPacket(new ShowBoard(null, "102"));
  219. activeChar.sendPacket(new ShowBoard(null, "103"));
  220. }
  221. else
  222. {
  223. //CPost cp = null;
  224. Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
  225. if (p != null)
  226. {
  227. p.deleteme(t);
  228. }
  229. t.deleteme(f);
  230. parsecmd("_bbsmemo", activeChar);
  231. }
  232. }
  233. }
  234. else
  235. {
  236. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command
  237. + " is not implemented yet</center><br><br></body></html>", "101");
  238. activeChar.sendPacket(sb);
  239. activeChar.sendPacket(new ShowBoard(null, "102"));
  240. activeChar.sendPacket(new ShowBoard(null, "103"));
  241. }
  242. }
  243. /**
  244. * @param forumByID
  245. * @param activeChar
  246. * @param idf
  247. */
  248. private void showNewTopic(Forum forum, L2PcInstance activeChar, int idf)
  249. {
  250. if (forum == null)
  251. {
  252. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
  253. + " is not implemented yet</center><br><br></body></html>", "101");
  254. activeChar.sendPacket(sb);
  255. activeChar.sendPacket(new ShowBoard(null, "102"));
  256. activeChar.sendPacket(new ShowBoard(null, "103"));
  257. }
  258. else if (forum.getType() == Forum.MEMO)
  259. {
  260. showMemoNewTopics(forum, activeChar);
  261. }
  262. else
  263. {
  264. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName()
  265. + " is not implemented yet</center><br><br></body></html>", "101");
  266. activeChar.sendPacket(sb);
  267. activeChar.sendPacket(new ShowBoard(null, "102"));
  268. activeChar.sendPacket(new ShowBoard(null, "103"));
  269. }
  270. }
  271. /**
  272. * @param forum
  273. * @param activeChar
  274. */
  275. private void showMemoNewTopics(Forum forum, L2PcInstance activeChar)
  276. {
  277. final String html = StringUtil.concat("<html>"
  278. + "<body><br><br>"
  279. + "<table border=0 width=610><tr><td width=10></td><td width=600 align=left>"
  280. + "<a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a>"
  281. + "</td></tr>"
  282. + "</table>"
  283. + "<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">"
  284. + "<center>"
  285. + "<table border=0 cellspacing=0 cellpadding=0>"
  286. + "<tr><td width=610><img src=\"sek.cbui355\" width=\"610\" height=\"1\"><br1><img src=\"sek.cbui355\" width=\"610\" height=\"1\"></td></tr>"
  287. + "</table>" + "<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>"
  288. + "<tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr>" + "<tr>"
  289. + "<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>" + "<td align=center FIXWIDTH=60 height=29>&$413;</td>"
  290. + "<td FIXWIDTH=540><edit var = \"Title\" width=540 height=13></td>"
  291. + "<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>" + "</tr></table>"
  292. + "<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>"
  293. + "<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>" + "<tr>"
  294. + "<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>"
  295. + "<td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td>"
  296. + "<td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td>"
  297. + "<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>" + "</tr>"
  298. + "<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>" + "</table>"
  299. + "<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>"
  300. + "<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>" + "<tr>"
  301. + "<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>" + "<td align=center FIXWIDTH=60 height=29>&nbsp;</td>"
  302. + "<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>"
  303. + "<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>"
  304. + "<td align=center FIXWIDTH=400>&nbsp;</td>"
  305. + "<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>"
  306. + "</tr></table>"
  307. + "</center>" + "</body>" + "</html>");
  308. send1001(html, activeChar);
  309. send1002(activeChar);
  310. }
  311. /**
  312. * @param memo
  313. */
  314. private void showTopics(Forum forum, L2PcInstance activeChar, int index, int idf)
  315. {
  316. if (forum == null)
  317. {
  318. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf
  319. + " is not implemented yet</center><br><br></body></html>", "101");
  320. activeChar.sendPacket(sb);
  321. activeChar.sendPacket(new ShowBoard(null, "102"));
  322. activeChar.sendPacket(new ShowBoard(null, "103"));
  323. }
  324. else if (forum.getType() == Forum.MEMO)
  325. {
  326. showMemoTopics(forum, activeChar, index);
  327. }
  328. else
  329. {
  330. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName()
  331. + " is not implemented yet</center><br><br></body></html>", "101");
  332. activeChar.sendPacket(sb);
  333. activeChar.sendPacket(new ShowBoard(null, "102"));
  334. activeChar.sendPacket(new ShowBoard(null, "103"));
  335. }
  336. }
  337. /**
  338. * @param forum
  339. * @param activeChar
  340. */
  341. private void showMemoTopics(Forum forum, L2PcInstance activeChar, int index)
  342. {
  343. forum.vload();
  344. final StringBuilder html = StringUtil.startAppend(2000, "<html><body><br><br>"
  345. + "<table border=0 width=610><tr><td width=10></td><td width=600 align=left>"
  346. + "<a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a>" + "</td></tr>"
  347. + "</table>" + "<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">" + "<center>"
  348. + "<table border=0 cellspacing=0 cellpadding=2 bgcolor=888888 width=610>" + "<tr>" + "<td FIXWIDTH=5></td>"
  349. + "<td FIXWIDTH=415 align=center>&$413;</td>" + "<td FIXWIDTH=120 align=center></td>"
  350. + "<td FIXWIDTH=70 align=center>&$418;</td>" + "</tr>" + "</table>");
  351. final DateFormat dateFormat = DateFormat.getInstance();
  352. for (int i = 0, j = getMaxID(forum) + 1; i < 12 * index; j--)
  353. {
  354. if (j < 0)
  355. {
  356. break;
  357. }
  358. Topic t = forum.getTopic(j);
  359. if (t != null)
  360. {
  361. if (i++ >= 12 * (index - 1))
  362. {
  363. StringUtil.append(html, "<table border=0 cellspacing=0 cellpadding=5 WIDTH=610>" + "<tr>" + "<td FIXWIDTH=5></td>"
  364. + "<td FIXWIDTH=415><a action=\"bypass _bbsposts;read;", String.valueOf(forum.getID()), ";", String.valueOf(t.getID()), "\">", t.getName(), "</a></td>"
  365. + "<td FIXWIDTH=120 align=center></td>" + "<td FIXWIDTH=70 align=center>", dateFormat.format(new Date(t.getDate())), "</td>"
  366. + "</tr>" + "</table>" + "<img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");
  367. }
  368. }
  369. }
  370. html.append("<br>"
  371. + "<table width=610 cellspace=0 cellpadding=0>"
  372. + "<tr>"
  373. + "<td width=50>"
  374. + "<button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">"
  375. + "</td>" + "<td width=510 align=center>" + "<table border=0><tr>");
  376. if (index == 1)
  377. {
  378. html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  379. }
  380. else
  381. {
  382. 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>");
  383. }
  384. int nbp;
  385. nbp = forum.getTopicSize() / 8;
  386. if (nbp * 8 != ClanTable.getInstance().getClans().length)
  387. {
  388. nbp++;
  389. }
  390. for (int i = 1; i <= nbp; i++)
  391. {
  392. if (i == index)
  393. {
  394. StringUtil.append(html, "<td> ", String.valueOf(i), " </td>");
  395. }
  396. else
  397. {
  398. StringUtil.append(html, "<td><a action=\"bypass _bbstopics;read;", String.valueOf(forum.getID()), ";", String.valueOf(i), "\"> ", String.valueOf(i), " </a></td>");
  399. }
  400. }
  401. if (index == nbp)
  402. {
  403. html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  404. }
  405. else
  406. {
  407. 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>");
  408. }
  409. 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>"
  410. + "<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>"
  411. + "<tr> "
  412. + "<td></td>"
  413. + "<td align=center><table border=0><tr><td></td><td><edit var = \"Search\" width=130 height=11></td>"
  414. + "<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>"
  415. + "</tr>" + "</table>" + "<br>" + "<br>" + "<br>" + "</center>" + "</body>" + "</html>");
  416. separateAndSend(html.toString(), activeChar);
  417. }
  418. @SuppressWarnings("synthetic-access")
  419. private static class SingletonHolder
  420. {
  421. protected static final TopicBBSManager _instance = new TopicBBSManager();
  422. }
  423. }