TopicBBSManager.java 16 KB

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