PostBBSManager.java 13 KB

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