PostBBSManager.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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.Date;
  18. import java.util.Locale;
  19. import java.util.Map;
  20. import java.util.StringTokenizer;
  21. import javolution.text.TextBuilder;
  22. import javolution.util.FastMap;
  23. import net.sf.l2j.gameserver.communitybbs.BB.Forum;
  24. import net.sf.l2j.gameserver.communitybbs.BB.Post;
  25. import net.sf.l2j.gameserver.communitybbs.BB.Topic;
  26. import net.sf.l2j.gameserver.communitybbs.BB.Post.CPost;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  28. import net.sf.l2j.gameserver.network.serverpackets.ShowBoard;
  29. public class PostBBSManager extends BaseBBSManager
  30. {
  31. private Map<Topic, Post> _postByTopic;
  32. private static PostBBSManager _instance;
  33. public static PostBBSManager getInstance()
  34. {
  35. if (_instance == null)
  36. {
  37. _instance = new PostBBSManager();
  38. }
  39. return _instance;
  40. }
  41. public PostBBSManager()
  42. {
  43. _postByTopic = new FastMap<Topic, Post>();
  44. }
  45. public Post getGPosttByTopic(Topic t)
  46. {
  47. Post post = null;
  48. post = _postByTopic.get(t);
  49. if (post == null)
  50. {
  51. post = load(t);
  52. _postByTopic.put(t, post);
  53. }
  54. return post;
  55. }
  56. /**
  57. * @param t
  58. */
  59. public void delPostByTopic(Topic t)
  60. {
  61. _postByTopic.remove(t);
  62. }
  63. public void addPostByTopic(Post p, Topic t)
  64. {
  65. if (_postByTopic.get(t) == null)
  66. {
  67. _postByTopic.put(t, p);
  68. }
  69. }
  70. /**
  71. * @param t
  72. * @return
  73. */
  74. private Post load(Topic t)
  75. {
  76. Post p;
  77. p = new Post(t);
  78. return p;
  79. }
  80. /* (non-Javadoc)
  81. * @see net.sf.l2j.gameserver.communitybbs.Manager.BaseBBSManager#parsecmd(java.lang.String, net.sf.l2j.gameserver.model.actor.instance.L2PcInstance)
  82. */
  83. @Override
  84. public void parsecmd(String command, L2PcInstance activeChar)
  85. {
  86. if (command.startsWith("_bbsposts;read;"))
  87. {
  88. StringTokenizer st = new StringTokenizer(command, ";");
  89. st.nextToken();
  90. st.nextToken();
  91. int idf = Integer.parseInt(st.nextToken());
  92. int idp = Integer.parseInt(st.nextToken());
  93. String index = null;
  94. if (st.hasMoreTokens())
  95. {
  96. index = st.nextToken();
  97. }
  98. int ind = 0;
  99. if (index == null)
  100. {
  101. ind = 1;
  102. }
  103. else
  104. {
  105. ind = Integer.parseInt(index);
  106. }
  107. showPost((TopicBBSManager.getInstance().getTopicByID(idp)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind);
  108. }
  109. else if (command.startsWith("_bbsposts;edit;"))
  110. {
  111. StringTokenizer st = new StringTokenizer(command, ";");
  112. st.nextToken();
  113. st.nextToken();
  114. int idf = Integer.parseInt(st.nextToken());
  115. int idt = Integer.parseInt(st.nextToken());
  116. int idp = Integer.parseInt(st.nextToken());
  117. showEditPost((TopicBBSManager.getInstance().getTopicByID(idt)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idp);
  118. }
  119. else
  120. {
  121. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", "101");
  122. activeChar.sendPacket(sb);
  123. activeChar.sendPacket(new ShowBoard(null, "102"));
  124. activeChar.sendPacket(new ShowBoard(null, "103"));
  125. }
  126. }
  127. /**
  128. * @param topic
  129. * @param forumByID
  130. * @param activeChar
  131. * @param idp
  132. */
  133. private void showEditPost(Topic topic, Forum forum, L2PcInstance activeChar, int idp)
  134. {
  135. Post p = getGPosttByTopic(topic);
  136. if ((forum == null) || (topic == null) || (p == null))
  137. {
  138. ShowBoard sb = new ShowBoard("<html><body><br><br><center>Error, this forum, topic or post does not exit !</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. else
  144. {
  145. showHtmlEditPost(topic, activeChar, forum, p);
  146. }
  147. }
  148. /**
  149. * @param posttByTopic
  150. * @param forumByID
  151. * @param activeChar
  152. * @param ind
  153. * @param idf
  154. */
  155. private void showPost(Topic topic, Forum forum, L2PcInstance activeChar, int ind)
  156. {
  157. if ((forum == null) || (topic == null))
  158. {
  159. ShowBoard sb = new ShowBoard("<html><body><br><br><center>Error, this forum is not implemented yet</center><br><br></body></html>", "101");
  160. activeChar.sendPacket(sb);
  161. activeChar.sendPacket(new ShowBoard(null, "102"));
  162. activeChar.sendPacket(new ShowBoard(null, "103"));
  163. }
  164. else if (forum.getType() == Forum.MEMO)
  165. {
  166. showMemoPost(topic, activeChar, forum);
  167. }
  168. else
  169. {
  170. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName() + " is not implemented yet</center><br><br></body></html>", "101");
  171. activeChar.sendPacket(sb);
  172. activeChar.sendPacket(new ShowBoard(null, "102"));
  173. activeChar.sendPacket(new ShowBoard(null, "103"));
  174. }
  175. }
  176. /**
  177. * @param topic
  178. * @param activeChar
  179. * @param forum
  180. * @param p
  181. */
  182. private void showHtmlEditPost(Topic topic, L2PcInstance activeChar, Forum forum, Post p)
  183. {
  184. TextBuilder html = new TextBuilder("<html>");
  185. html.append("<body><br><br>");
  186. html.append("<table border=0 width=610><tr><td width=10></td><td width=600 align=left>");
  187. html.append("<a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">" + forum.getName() + " Form</a>");
  188. html.append("</td></tr>");
  189. html.append("</table>");
  190. html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">");
  191. html.append("<center>");
  192. html.append("<table border=0 cellspacing=0 cellpadding=0>");
  193. 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>");
  194. html.append("</table>");
  195. html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
  196. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr>");
  197. html.append("<tr>");
  198. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  199. html.append("<td align=center FIXWIDTH=60 height=29>&$413;</td>");
  200. html.append("<td FIXWIDTH=540>" + topic.getName() + "</td>");
  201. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  202. html.append("</tr></table>");
  203. html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
  204. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
  205. html.append("<tr>");
  206. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  207. html.append("<td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td>");
  208. html.append("<td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td>");
  209. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  210. html.append("</tr>");
  211. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
  212. html.append("</table>");
  213. html.append("<table fixwidth=610 border=0 cellspacing=0 cellpadding=0>");
  214. html.append("<tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr>");
  215. html.append("<tr>");
  216. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  217. html.append("<td align=center FIXWIDTH=60 height=29>&nbsp;</td>");
  218. html.append("<td align=center FIXWIDTH=70><button value=\"&$140;\" action=\"Write Post " + forum.getID() + ";" + topic.getID()
  219. + ";0 _ Content Content Content\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>");
  220. 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>");
  221. html.append("<td align=center FIXWIDTH=400>&nbsp;</td>");
  222. html.append("<td><img src=\"l2ui.mini_logo\" width=5 height=1></td>");
  223. html.append("</tr></table>");
  224. html.append("</center>");
  225. html.append("</body>");
  226. html.append("</html>");
  227. send1001(html.toString(), activeChar);
  228. send1002(activeChar, p.getCPost(0).postTxt, topic.getName(), DateFormat.getInstance().format(new Date(topic.getDate())));
  229. }
  230. /**
  231. * @param topic
  232. * @param activeChar
  233. * @param forum
  234. */
  235. private void showMemoPost(Topic topic, L2PcInstance activeChar, Forum forum)
  236. {
  237. //
  238. Post p = getGPosttByTopic(topic);
  239. Locale locale = Locale.getDefault();
  240. DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
  241. TextBuilder html = new TextBuilder("<html><body><br><br>");
  242. html.append("<table border=0 width=610><tr><td width=10></td><td width=600 align=left>");
  243. html.append("<a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a>");
  244. html.append("</td></tr>");
  245. html.append("</table>");
  246. html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">");
  247. html.append("<center>");
  248. html.append("<table border=0 cellspacing=0 cellpadding=0 bgcolor=333333>");
  249. html.append("<tr><td height=10></td></tr>");
  250. html.append("<tr>");
  251. html.append("<td fixWIDTH=55 align=right valign=top>&$413; : &nbsp;</td>");
  252. html.append("<td fixWIDTH=380 valign=top>" + topic.getName() + "</td>");
  253. html.append("<td fixwidth=5></td>");
  254. html.append("<td fixwidth=50></td>");
  255. html.append("<td fixWIDTH=120></td>");
  256. html.append("</tr>");
  257. html.append("<tr><td height=10></td></tr>");
  258. html.append("<tr>");
  259. html.append("<td align=right><font color=\"AAAAAA\" >&$417; : &nbsp;</font></td>");
  260. html.append("<td><font color=\"AAAAAA\">" + topic.getOwnerName() + "</font></td>");
  261. html.append("<td></td>");
  262. html.append("<td><font color=\"AAAAAA\">&$418; :</font></td>");
  263. html.append("<td><font color=\"AAAAAA\">" + dateFormat.format(p.getCPost(0).postDate) + "</font></td>");
  264. html.append("</tr>");
  265. html.append("<tr><td height=10></td></tr>");
  266. html.append("</table>");
  267. html.append("<br>");
  268. html.append("<table border=0 cellspacing=0 cellpadding=0>");
  269. html.append("<tr>");
  270. html.append("<td fixwidth=5></td>");
  271. String Mes = p.getCPost(0).postTxt.replace(">", "&gt;");
  272. Mes = Mes.replace("<", "&lt;");
  273. Mes = Mes.replace("\n", "<br1>");
  274. html.append("<td FIXWIDTH=600 align=left>" + Mes + "</td>");
  275. html.append("<td fixqqwidth=5></td>");
  276. html.append("</tr>");
  277. html.append("</table>");
  278. html.append("<br>");
  279. html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"5\">");
  280. html.append("<img src=\"L2UI.squaregray\" width=\"610\" height=\"1\">");
  281. html.append("<img src=\"L2UI.squareblank\" width=\"1\" height=\"5\">");
  282. html.append("<table border=0 cellspacing=0 cellpadding=0 FIXWIDTH=610>");
  283. html.append("<tr>");
  284. html.append("<td width=50>");
  285. html.append("<button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\">");
  286. html.append("</td>");
  287. html.append("<td width=560 align=right><table border=0 cellspacing=0><tr>");
  288. html.append("<td FIXWIDTH=300></td><td><button value = \"&$424;\" action=\"bypass _bbsposts;edit;" + forum.getID() + ";" + topic.getID()
  289. + ";0\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>&nbsp;");
  290. html.append("<td><button value = \"&$425;\" action=\"bypass _bbstopics;del;" + forum.getID() + ";" + topic.getID() + "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>&nbsp;");
  291. html.append("<td><button value = \"&$421;\" action=\"bypass _bbstopics;crea;" + forum.getID() + "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>&nbsp;");
  292. html.append("</tr></table>");
  293. html.append("</td>");
  294. html.append("</tr>");
  295. html.append("</table>");
  296. html.append("<br>");
  297. html.append("<br>");
  298. html.append("<br></center>");
  299. html.append("</body>");
  300. html.append("</html>");
  301. separateAndSend(html.toString(), activeChar);
  302. }
  303. /* (non-Javadoc)
  304. * @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)
  305. */
  306. @Override
  307. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  308. {
  309. StringTokenizer st = new StringTokenizer(ar1, ";");
  310. int idf = Integer.parseInt(st.nextToken());
  311. int idt = Integer.parseInt(st.nextToken());
  312. int idp = Integer.parseInt(st.nextToken());
  313. Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
  314. if (f == null)
  315. {
  316. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf + " does not exist !</center><br><br></body></html>", "101");
  317. activeChar.sendPacket(sb);
  318. activeChar.sendPacket(new ShowBoard(null, "102"));
  319. activeChar.sendPacket(new ShowBoard(null, "103"));
  320. }
  321. else
  322. {
  323. Topic t = f.gettopic(idt);
  324. if (t == null)
  325. {
  326. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + idt + " does not exist !</center><br><br></body></html>", "101");
  327. activeChar.sendPacket(sb);
  328. activeChar.sendPacket(new ShowBoard(null, "102"));
  329. activeChar.sendPacket(new ShowBoard(null, "103"));
  330. }
  331. else
  332. {
  333. CPost cp = null;
  334. Post p = getGPosttByTopic(t);
  335. if (p != null)
  336. {
  337. cp = p.getCPost(idp);
  338. }
  339. if (cp == null)
  340. {
  341. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the post: " + idp + " does not exist !</center><br><br></body></html>", "101");
  342. activeChar.sendPacket(sb);
  343. activeChar.sendPacket(new ShowBoard(null, "102"));
  344. activeChar.sendPacket(new ShowBoard(null, "103"));
  345. }
  346. else
  347. {
  348. p.getCPost(idp).postTxt = ar4;
  349. p.updatetxt(idp);
  350. parsecmd("_bbsposts;read;" + f.getID() + ";" + t.getID(), activeChar);
  351. }
  352. }
  353. }
  354. }
  355. }