PostBBSManager.java 13 KB

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