PostBBSManager.java 13 KB

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