2
0

PostBBSManager.java 14 KB

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