PostBBSManager.java 13 KB

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