PostBBSManager.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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.Date;
  18. import java.util.Locale;
  19. import java.util.Map;
  20. import java.util.StringTokenizer;
  21. import javolution.util.FastMap;
  22. import com.l2jserver.gameserver.communitybbs.BB.Forum;
  23. import com.l2jserver.gameserver.communitybbs.BB.Post;
  24. import com.l2jserver.gameserver.communitybbs.BB.Post.CPost;
  25. import com.l2jserver.gameserver.communitybbs.BB.Topic;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
  28. import com.l2jserver.util.StringUtil;
  29. public class PostBBSManager extends BaseBBSManager
  30. {
  31. private final Map<Topic, Post> _postByTopic = new FastMap<>();
  32. public Post getGPosttByTopic(Topic t)
  33. {
  34. Post post = _postByTopic.get(t);
  35. if (post == null)
  36. {
  37. post = new Post(t);
  38. _postByTopic.put(t, post);
  39. }
  40. return post;
  41. }
  42. /**
  43. * @param t
  44. */
  45. public void delPostByTopic(Topic t)
  46. {
  47. _postByTopic.remove(t);
  48. }
  49. public void addPostByTopic(Post p, Topic t)
  50. {
  51. if (_postByTopic.get(t) == null)
  52. {
  53. _postByTopic.put(t, p);
  54. }
  55. }
  56. @Override
  57. public void parsecmd(String command, L2PcInstance activeChar)
  58. {
  59. if (command.startsWith("_bbsposts;read;"))
  60. {
  61. StringTokenizer st = new StringTokenizer(command, ";");
  62. st.nextToken();
  63. st.nextToken();
  64. int idf = Integer.parseInt(st.nextToken());
  65. int idp = Integer.parseInt(st.nextToken());
  66. String index = null;
  67. if (st.hasMoreTokens())
  68. {
  69. index = st.nextToken();
  70. }
  71. int ind = 0;
  72. if (index == null)
  73. {
  74. ind = 1;
  75. }
  76. else
  77. {
  78. ind = Integer.parseInt(index);
  79. }
  80. showPost((TopicBBSManager.getInstance().getTopicByID(idp)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind);
  81. }
  82. else if (command.startsWith("_bbsposts;edit;"))
  83. {
  84. StringTokenizer st = new StringTokenizer(command, ";");
  85. st.nextToken();
  86. st.nextToken();
  87. int idf = Integer.parseInt(st.nextToken());
  88. int idt = Integer.parseInt(st.nextToken());
  89. int idp = Integer.parseInt(st.nextToken());
  90. showEditPost((TopicBBSManager.getInstance().getTopicByID(idt)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idp);
  91. }
  92. else
  93. {
  94. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", "101");
  95. activeChar.sendPacket(sb);
  96. activeChar.sendPacket(new ShowBoard(null, "102"));
  97. activeChar.sendPacket(new ShowBoard(null, "103"));
  98. }
  99. }
  100. /**
  101. * @param topic
  102. * @param forum
  103. * @param activeChar
  104. * @param idp
  105. */
  106. private void showEditPost(Topic topic, Forum forum, L2PcInstance activeChar, int idp)
  107. {
  108. Post p = getGPosttByTopic(topic);
  109. if ((forum == null) || (topic == null) || (p == null))
  110. {
  111. ShowBoard sb = new ShowBoard("<html><body><br><br><center>Error, this forum, topic or post does not exit !</center><br><br></body></html>", "101");
  112. activeChar.sendPacket(sb);
  113. activeChar.sendPacket(new ShowBoard(null, "102"));
  114. activeChar.sendPacket(new ShowBoard(null, "103"));
  115. }
  116. else
  117. {
  118. showHtmlEditPost(topic, activeChar, forum, p);
  119. }
  120. }
  121. /**
  122. * @param topic
  123. * @param forum
  124. * @param activeChar
  125. * @param ind
  126. */
  127. private void showPost(Topic topic, Forum forum, L2PcInstance activeChar, int ind)
  128. {
  129. if ((forum == null) || (topic == null))
  130. {
  131. ShowBoard sb = new ShowBoard("<html><body><br><br><center>Error, this forum is not implemented yet</center><br><br></body></html>", "101");
  132. activeChar.sendPacket(sb);
  133. activeChar.sendPacket(new ShowBoard(null, "102"));
  134. activeChar.sendPacket(new ShowBoard(null, "103"));
  135. }
  136. else if (forum.getType() == Forum.MEMO)
  137. {
  138. showMemoPost(topic, activeChar, forum);
  139. }
  140. else
  141. {
  142. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName() + " is not implemented yet</center><br><br></body></html>", "101");
  143. activeChar.sendPacket(sb);
  144. activeChar.sendPacket(new ShowBoard(null, "102"));
  145. activeChar.sendPacket(new ShowBoard(null, "103"));
  146. }
  147. }
  148. /**
  149. * @param topic
  150. * @param activeChar
  151. * @param forum
  152. * @param p
  153. */
  154. private void showHtmlEditPost(Topic topic, L2PcInstance activeChar, Forum forum, Post p)
  155. {
  156. final String html = StringUtil.concat("<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">", forum.getName(), " Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=0><tr><td width=610><img src=\"sek.cbui355\" width=\"610\" height=\"1\"><br1><img src=\"sek.cbui355\" width=\"610\" height=\"1\"></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29>&$413;</td><td FIXWIDTH=540>", topic.getName(), "</td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td><td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29>&nbsp;</td><td align=center FIXWIDTH=70><button value=\"&$140;\" action=\"Write Post ", String.valueOf(forum.getID()), ";", String.valueOf(topic.getID()), ";0 _ Content Content Content\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td><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><td align=center FIXWIDTH=400>&nbsp;</td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table></center></body></html>");
  157. send1001(html, activeChar);
  158. send1002(activeChar, p.getCPost(0).postTxt, topic.getName(), DateFormat.getInstance().format(new Date(topic.getDate())));
  159. }
  160. /**
  161. * @param topic
  162. * @param activeChar
  163. * @param forum
  164. */
  165. private void showMemoPost(Topic topic, L2PcInstance activeChar, Forum forum)
  166. {
  167. //
  168. Post p = getGPosttByTopic(topic);
  169. Locale locale = Locale.getDefault();
  170. DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
  171. String mes = p.getCPost(0).postTxt.replace(">", "&gt;");
  172. mes = mes.replace("<", "&lt;");
  173. final String html = StringUtil.concat("<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a>&nbsp;>&nbsp;<a action=\"bypass _bbsmemo\">Memo Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=0 bgcolor=333333><tr><td height=10></td></tr><tr><td fixWIDTH=55 align=right valign=top>&$413; : &nbsp;</td><td fixWIDTH=380 valign=top>", topic.getName(), "</td><td fixwidth=5></td><td fixwidth=50></td><td fixWIDTH=120></td></tr><tr><td height=10></td></tr><tr><td align=right><font color=\"AAAAAA\" >&$417; : &nbsp;</font></td><td><font color=\"AAAAAA\">", topic.getOwnerName() + "</font></td><td></td><td><font color=\"AAAAAA\">&$418; :</font></td><td><font color=\"AAAAAA\">", dateFormat.format(p.getCPost(0).postDate), "</font></td></tr><tr><td height=10></td></tr></table><br><table border=0 cellspacing=0 cellpadding=0><tr><td fixwidth=5></td><td FIXWIDTH=600 align=left>", mes, "</td><td fixqqwidth=5></td></tr></table><br><img src=\"L2UI.squareblank\" width=\"1\" height=\"5\"><img src=\"L2UI.squaregray\" width=\"610\" height=\"1\"><img src=\"L2UI.squareblank\" width=\"1\" height=\"5\"><table border=0 cellspacing=0 cellpadding=0 FIXWIDTH=610><tr><td width=50><button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"></td><td width=560 align=right><table border=0 cellspacing=0><tr><td FIXWIDTH=300></td><td><button value = \"&$424;\" action=\"bypass _bbsposts;edit;", String.valueOf(forum.getID()), ";", String.valueOf(topic.getID()), ";0\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>&nbsp;<td><button value = \"&$425;\" action=\"bypass _bbstopics;del;", String.valueOf(forum.getID()), ";", String.valueOf(topic.getID()), "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>&nbsp;<td><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>&nbsp;</tr></table></td></tr></table><br><br><br></center></body></html>");
  174. separateAndSend(html, activeChar);
  175. }
  176. @Override
  177. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  178. {
  179. StringTokenizer st = new StringTokenizer(ar1, ";");
  180. int idf = Integer.parseInt(st.nextToken());
  181. int idt = Integer.parseInt(st.nextToken());
  182. int idp = Integer.parseInt(st.nextToken());
  183. Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
  184. if (f == null)
  185. {
  186. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf + " does not exist !</center><br><br></body></html>", "101");
  187. activeChar.sendPacket(sb);
  188. activeChar.sendPacket(new ShowBoard(null, "102"));
  189. activeChar.sendPacket(new ShowBoard(null, "103"));
  190. }
  191. else
  192. {
  193. Topic t = f.getTopic(idt);
  194. if (t == null)
  195. {
  196. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + idt + " does not exist !</center><br><br></body></html>", "101");
  197. activeChar.sendPacket(sb);
  198. activeChar.sendPacket(new ShowBoard(null, "102"));
  199. activeChar.sendPacket(new ShowBoard(null, "103"));
  200. }
  201. else
  202. {
  203. final Post p = getGPosttByTopic(t);
  204. if (p != null)
  205. {
  206. final CPost cp = p.getCPost(idp);
  207. if (cp == null)
  208. {
  209. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the post: " + idp + " does not exist !</center><br><br></body></html>", "101");
  210. activeChar.sendPacket(sb);
  211. activeChar.sendPacket(new ShowBoard(null, "102"));
  212. activeChar.sendPacket(new ShowBoard(null, "103"));
  213. }
  214. else
  215. {
  216. p.getCPost(idp).postTxt = ar4;
  217. p.updatetxt(idp);
  218. parsecmd("_bbsposts;read;" + f.getID() + ";" + t.getID(), activeChar);
  219. }
  220. }
  221. }
  222. }
  223. }
  224. public static PostBBSManager getInstance()
  225. {
  226. return SingletonHolder._instance;
  227. }
  228. private static class SingletonHolder
  229. {
  230. protected static final PostBBSManager _instance = new PostBBSManager();
  231. }
  232. }