PostBBSManager.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /*
  2. * Copyright (C) 2004-2014 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.communitybbs.Manager;
  20. import java.text.DateFormat;
  21. import java.util.Date;
  22. import java.util.Locale;
  23. import java.util.Map;
  24. import java.util.StringTokenizer;
  25. import javolution.util.FastMap;
  26. import com.l2jserver.gameserver.communitybbs.BB.Forum;
  27. import com.l2jserver.gameserver.communitybbs.BB.Post;
  28. import com.l2jserver.gameserver.communitybbs.BB.Post.CPost;
  29. import com.l2jserver.gameserver.communitybbs.BB.Topic;
  30. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  31. import com.l2jserver.gameserver.network.serverpackets.ShowBoard;
  32. import com.l2jserver.util.StringUtil;
  33. public class PostBBSManager extends BaseBBSManager
  34. {
  35. private final Map<Topic, Post> _postByTopic = new FastMap<>();
  36. public Post getGPosttByTopic(Topic t)
  37. {
  38. Post post = _postByTopic.get(t);
  39. if (post == null)
  40. {
  41. post = new Post(t);
  42. _postByTopic.put(t, post);
  43. }
  44. return post;
  45. }
  46. /**
  47. * @param t
  48. */
  49. public void delPostByTopic(Topic t)
  50. {
  51. _postByTopic.remove(t);
  52. }
  53. public void addPostByTopic(Post p, Topic t)
  54. {
  55. if (_postByTopic.get(t) == null)
  56. {
  57. _postByTopic.put(t, p);
  58. }
  59. }
  60. @Override
  61. public void parsecmd(String command, L2PcInstance activeChar)
  62. {
  63. if (command.startsWith("_bbsposts;read;"))
  64. {
  65. StringTokenizer st = new StringTokenizer(command, ";");
  66. st.nextToken();
  67. st.nextToken();
  68. int idf = Integer.parseInt(st.nextToken());
  69. int idp = Integer.parseInt(st.nextToken());
  70. String index = null;
  71. if (st.hasMoreTokens())
  72. {
  73. index = st.nextToken();
  74. }
  75. int ind = 0;
  76. if (index == null)
  77. {
  78. ind = 1;
  79. }
  80. else
  81. {
  82. ind = Integer.parseInt(index);
  83. }
  84. showPost((TopicBBSManager.getInstance().getTopicByID(idp)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind);
  85. }
  86. else if (command.startsWith("_bbsposts;edit;"))
  87. {
  88. StringTokenizer st = new StringTokenizer(command, ";");
  89. st.nextToken();
  90. st.nextToken();
  91. int idf = Integer.parseInt(st.nextToken());
  92. int idt = Integer.parseInt(st.nextToken());
  93. int idp = Integer.parseInt(st.nextToken());
  94. showEditPost((TopicBBSManager.getInstance().getTopicByID(idt)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idp);
  95. }
  96. else
  97. {
  98. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", "101");
  99. activeChar.sendPacket(sb);
  100. activeChar.sendPacket(new ShowBoard(null, "102"));
  101. activeChar.sendPacket(new ShowBoard(null, "103"));
  102. }
  103. }
  104. /**
  105. * @param topic
  106. * @param forum
  107. * @param activeChar
  108. * @param idp
  109. */
  110. private void showEditPost(Topic topic, Forum forum, L2PcInstance activeChar, int idp)
  111. {
  112. Post p = getGPosttByTopic(topic);
  113. if ((forum == null) || (topic == null) || (p == null))
  114. {
  115. ShowBoard sb = new ShowBoard("<html><body><br><br><center>Error, this forum, topic or post does not exit !</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. showHtmlEditPost(topic, activeChar, forum, p);
  123. }
  124. }
  125. /**
  126. * @param topic
  127. * @param forum
  128. * @param activeChar
  129. * @param ind
  130. */
  131. private void showPost(Topic topic, Forum forum, L2PcInstance activeChar, int ind)
  132. {
  133. if ((forum == null) || (topic == null))
  134. {
  135. ShowBoard sb = new ShowBoard("<html><body><br><br><center>Error, this forum is not implemented yet</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 if (forum.getType() == Forum.MEMO)
  141. {
  142. showMemoPost(topic, activeChar, forum);
  143. }
  144. else
  145. {
  146. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + forum.getName() + " 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. * @param topic
  154. * @param activeChar
  155. * @param forum
  156. * @param p
  157. */
  158. private void showHtmlEditPost(Topic topic, L2PcInstance activeChar, Forum forum, Post p)
  159. {
  160. 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>");
  161. send1001(html, activeChar);
  162. send1002(activeChar, p.getCPost(0).postTxt, topic.getName(), DateFormat.getInstance().format(new Date(topic.getDate())));
  163. }
  164. /**
  165. * @param topic
  166. * @param activeChar
  167. * @param forum
  168. */
  169. private void showMemoPost(Topic topic, L2PcInstance activeChar, Forum forum)
  170. {
  171. //
  172. Post p = getGPosttByTopic(topic);
  173. Locale locale = Locale.getDefault();
  174. DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
  175. String mes = p.getCPost(0).postTxt.replace(">", "&gt;");
  176. mes = mes.replace("<", "&lt;");
  177. 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>");
  178. separateAndSend(html, activeChar);
  179. }
  180. @Override
  181. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  182. {
  183. StringTokenizer st = new StringTokenizer(ar1, ";");
  184. int idf = Integer.parseInt(st.nextToken());
  185. int idt = Integer.parseInt(st.nextToken());
  186. int idp = Integer.parseInt(st.nextToken());
  187. Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
  188. if (f == null)
  189. {
  190. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the forum: " + idf + " does not exist !</center><br><br></body></html>", "101");
  191. activeChar.sendPacket(sb);
  192. activeChar.sendPacket(new ShowBoard(null, "102"));
  193. activeChar.sendPacket(new ShowBoard(null, "103"));
  194. }
  195. else
  196. {
  197. Topic t = f.getTopic(idt);
  198. if (t == null)
  199. {
  200. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the topic: " + idt + " does not exist !</center><br><br></body></html>", "101");
  201. activeChar.sendPacket(sb);
  202. activeChar.sendPacket(new ShowBoard(null, "102"));
  203. activeChar.sendPacket(new ShowBoard(null, "103"));
  204. }
  205. else
  206. {
  207. final Post p = getGPosttByTopic(t);
  208. if (p != null)
  209. {
  210. final CPost cp = p.getCPost(idp);
  211. if (cp == null)
  212. {
  213. ShowBoard sb = new ShowBoard("<html><body><br><br><center>the post: " + idp + " 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. p.getCPost(idp).postTxt = ar4;
  221. p.updatetxt(idp);
  222. parsecmd("_bbsposts;read;" + f.getID() + ";" + t.getID(), activeChar);
  223. }
  224. }
  225. }
  226. }
  227. }
  228. public static PostBBSManager getInstance()
  229. {
  230. return SingletonHolder._instance;
  231. }
  232. private static class SingletonHolder
  233. {
  234. protected static final PostBBSManager _instance = new PostBBSManager();
  235. }
  236. }