ClanBBSManager.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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.util.StringTokenizer;
  17. import com.l2jserver.gameserver.datatables.ClanTable;
  18. import com.l2jserver.gameserver.model.L2Clan;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.util.StringUtil;
  22. public class ClanBBSManager extends BaseBBSManager
  23. {
  24. private ClanBBSManager()
  25. {
  26. }
  27. public static ClanBBSManager getInstance()
  28. {
  29. return SingletonHolder._instance;
  30. }
  31. /**
  32. * @param command
  33. * @param activeChar
  34. */
  35. @Override
  36. public void parsecmd(String command, L2PcInstance activeChar)
  37. {
  38. if (command.equals("_bbsclan"))
  39. {
  40. if (activeChar.getClan() == null || activeChar.getClan().getLevel() < 2)
  41. clanlist(activeChar, 1);
  42. else
  43. clanhome(activeChar);
  44. }
  45. else if (command.startsWith("_bbsclan_clanlist"))
  46. {
  47. if (command.equals("_bbsclan_clanlist"))
  48. {
  49. clanlist(activeChar, 1);
  50. }
  51. else if (command.startsWith("_bbsclan_clanlist;"))
  52. {
  53. StringTokenizer st = new StringTokenizer(command, ";");
  54. st.nextToken();
  55. int index = Integer.parseInt(st.nextToken());
  56. clanlist(activeChar, index);
  57. }
  58. }
  59. else if (command.startsWith("_bbsclan_clanhome"))
  60. {
  61. if (command.equals("_bbsclan_clanhome"))
  62. {
  63. clanhome(activeChar);
  64. }
  65. else if (command.startsWith("_bbsclan_clanhome;"))
  66. {
  67. StringTokenizer st = new StringTokenizer(command, ";");
  68. st.nextToken();
  69. int index = Integer.parseInt(st.nextToken());
  70. clanhome(activeChar, index);
  71. }
  72. }
  73. else if (command.startsWith("_bbsclan_clannotice_edit;"))
  74. {
  75. clanNotice(activeChar, activeChar.getClanId());
  76. }
  77. else if (command.startsWith("_bbsclan_clannotice_enable"))
  78. {
  79. if (activeChar.getClan() != null)
  80. activeChar.getClan().setNoticeEnabled(true);
  81. clanNotice(activeChar, activeChar.getClanId());
  82. }
  83. else if (command.startsWith("_bbsclan_clannotice_disable"))
  84. {
  85. if (activeChar.getClan() != null)
  86. activeChar.getClan().setNoticeEnabled(false);
  87. clanNotice(activeChar, activeChar.getClanId());
  88. }
  89. else
  90. {
  91. separateAndSend("<html><body><br><br><center>Command : " + command + " needs core development</center><br><br></body></html>", activeChar);
  92. }
  93. }
  94. private void clanNotice(L2PcInstance activeChar, int clanId)
  95. {
  96. final L2Clan cl = ClanTable.getInstance().getClan(clanId);
  97. if (cl != null)
  98. {
  99. if (cl.getLevel() < 2)
  100. {
  101. activeChar.sendPacket(SystemMessageId.NO_CB_IN_MY_CLAN);
  102. parsecmd("_bbsclan_clanlist", activeChar);
  103. }
  104. else
  105. {
  106. final StringBuilder html = StringUtil.startAppend(2000, "<html><body><br><br>"
  107. + "<table border=0 width=610><tr><td width=10></td><td width=600 align=left>"
  108. + "<a action=\"bypass _bbshome\">HOME</a> &gt; "
  109. + "<a action=\"bypass _bbsclan_clanlist\"> CLAN COMMUNITY </a> &gt; " + "<a action=\"bypass _bbsclan_clanhome;", String.valueOf(clanId), "\"> &amp;$802; </a>"
  110. + "</td></tr>" + "</table>");
  111. if (activeChar.isClanLeader())
  112. {
  113. StringUtil.append(html, "<br><br><center>"
  114. + "<table width=610 border=0 cellspacing=0 cellpadding=0>"
  115. + "<tr><td fixwidth=610><font color=\"AAAAAA\">The Clan Notice function allows the clan leader to send messages through a pop-up window to clan members at login.</font> </td></tr>"
  116. + "<tr><td height=20></td></tr>");
  117. if (activeChar.getClan().isNoticeEnabled())
  118. StringUtil.append(html, "<tr><td fixwidth=610> Clan Notice Function:&nbsp;&nbsp;&nbsp;on&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;<a action=\"bypass _bbsclan_clannotice_disable\">off</a>");
  119. else
  120. StringUtil.append(html, "<tr><td fixwidth=610> Clan Notice Function:&nbsp;&nbsp;&nbsp;<a action=\"bypass _bbsclan_clannotice_enable\">on</a>&nbsp;&nbsp;&nbsp;/&nbsp;&nbsp;&nbsp;off");
  121. StringUtil.append(html, "</td></tr>"
  122. + "</table>"
  123. + "<img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">"
  124. + "<br> <br>"
  125. + "<table width=610 border=0 cellspacing=2 cellpadding=0>"
  126. + "<tr><td>Edit Notice: </td></tr>"
  127. + "<tr><td height=5></td></tr>"
  128. + "<tr><td>"
  129. + "<MultiEdit var =\"Content\" width=610 height=100>"
  130. + "</td></tr>"
  131. + "</table>"
  132. + "<br>"
  133. + "<table width=610 border=0 cellspacing=0 cellpadding=0>"
  134. + "<tr><td height=5></td></tr>"
  135. + "<tr>"
  136. + "<td align=center FIXWIDTH=65><button value=\"&$140;\" action=\"Write Notice Set _ Content Content Content\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td>"
  137. + "<td align=center FIXWIDTH=45></td>" + "<td align=center FIXWIDTH=500></td>" + "</tr>" + "</table>"
  138. + "</center>" + "</body>" + "</html>");
  139. send1001(html.toString(), activeChar);
  140. send1002(activeChar, activeChar.getClan().getNotice(), " ", "0");
  141. }
  142. else
  143. {
  144. StringUtil.append(html, "<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\">" + "<center>"
  145. + "<table border=0 cellspacing=0 cellpadding=0><tr>"
  146. + "<td>You are not your clan's leader, and therefore cannot change the clan notice</td>" + "</tr></table>");
  147. if (activeChar.getClan().isNoticeEnabled())
  148. {
  149. StringUtil.append(html, "<table border=0 cellspacing=0 cellpadding=0>" + "<tr>"
  150. + "<td>The current clan notice:</td>" + "</tr>" + "<tr><td fixwidth=5></td>"
  151. + "<td FIXWIDTH=600 align=left>" + activeChar.getClan().getNotice() + "</td>" + "<td fixqqwidth=5></td>"
  152. + "</tr>" + "</table>");
  153. }
  154. StringUtil.append(html, "</center>" + "</body>" + "</html>");
  155. separateAndSend(html.toString(), activeChar);
  156. }
  157. }
  158. }
  159. }
  160. /**
  161. * @param activeChar
  162. * @param index
  163. */
  164. private void clanlist(L2PcInstance activeChar, int index)
  165. {
  166. if (index < 1)
  167. {
  168. index = 1;
  169. }
  170. //header
  171. final StringBuilder html = StringUtil.startAppend(2000, "<html><body><br><br><center>"
  172. + "<br1><br1><table border=0 cellspacing=0 cellpadding=0>" + "<tr><td FIXWIDTH=15>&nbsp;</td>"
  173. + "<td width=610 height=30 align=left>" + "<a action=\"bypass _bbsclan_clanlist\"> CLAN COMMUNITY </a>"
  174. + "</td></tr></table>" + "<table border=0 cellspacing=0 cellpadding=0 width=610 bgcolor=434343>"
  175. + "<tr><td height=10></td></tr>" + "<tr>" + "<td fixWIDTH=5></td>" + "<td fixWIDTH=600>"
  176. + "<a action=\"bypass _bbsclan_clanhome;", String.valueOf((activeChar.getClan() != null) ? activeChar.getClan().getClanId() : 0), "\">[GO TO MY CLAN]</a>&nbsp;&nbsp;"
  177. + "</td>"
  178. + "<td fixWIDTH=5></td>"
  179. + "</tr>"
  180. + "<tr><td height=10></td></tr>"
  181. + "</table>"
  182. + "<br>"
  183. + "<table border=0 cellspacing=0 cellpadding=2 bgcolor=5A5A5A width=610>"
  184. + "<tr>"
  185. + "<td FIXWIDTH=5></td>"
  186. + "<td FIXWIDTH=200 align=center>CLAN NAME</td>"
  187. + "<td FIXWIDTH=200 align=center>CLAN LEADER</td>"
  188. + "<td FIXWIDTH=100 align=center>CLAN LEVEL</td>"
  189. + "<td FIXWIDTH=100 align=center>CLAN MEMBERS</td>"
  190. + "<td FIXWIDTH=5></td>" + "</tr>" + "</table>" + "<img src=\"L2UI.Squareblank\" width=\"1\" height=\"5\">");
  191. int i = 0;
  192. for (L2Clan cl : ClanTable.getInstance().getClans())
  193. {
  194. if (i > (index + 1) * 7)
  195. {
  196. break;
  197. }
  198. if (i++ >= (index - 1) * 7)
  199. {
  200. StringUtil.append(html, "<img src=\"L2UI.SquareBlank\" width=\"610\" height=\"3\">"
  201. + "<table border=0 cellspacing=0 cellpadding=0 width=610>" + "<tr> " + "<td FIXWIDTH=5></td>"
  202. + "<td FIXWIDTH=200 align=center><a action=\"bypass _bbsclan_clanhome;", String.valueOf(cl.getClanId()), "\">", cl.getName(), "</a></td>"
  203. + "<td FIXWIDTH=200 align=center>", cl.getLeaderName(), "</td>" + "<td FIXWIDTH=100 align=center>", String.valueOf(cl.getLevel()), "</td>"
  204. + "<td FIXWIDTH=100 align=center>", String.valueOf(cl.getMembersCount()), "</td>" + "<td FIXWIDTH=5></td>"
  205. + "</tr>" + "<tr><td height=5></td></tr>" + "</table>"
  206. + "<img src=\"L2UI.SquareBlank\" width=\"610\" height=\"3\">"
  207. + "<img src=\"L2UI.SquareGray\" width=\"610\" height=\"1\">");
  208. }
  209. }
  210. html.append("<img src=\"L2UI.SquareBlank\" width=\"610\" height=\"2\">" + "<table cellpadding=0 cellspacing=2 border=0><tr>");
  211. if (index == 1)
  212. {
  213. html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  214. }
  215. else
  216. {
  217. StringUtil.append(html, "<td><button action=\"_bbsclan_clanlist;", String.valueOf(index - 1), "\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  218. }
  219. i = 0;
  220. int nbp;
  221. nbp = ClanTable.getInstance().getClans().length / 8;
  222. if (nbp * 8 != ClanTable.getInstance().getClans().length)
  223. {
  224. nbp++;
  225. }
  226. for (i = 1; i <= nbp; i++)
  227. {
  228. if (i == index)
  229. {
  230. StringUtil.append(html, "<td> ", String.valueOf(i), " </td>");
  231. }
  232. else
  233. {
  234. StringUtil.append(html, "<td><a action=\"bypass _bbsclan_clanlist;", String.valueOf(i), "\"> ", String.valueOf(i), " </a></td>");
  235. }
  236. }
  237. if (index == nbp)
  238. {
  239. html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  240. }
  241. else
  242. {
  243. StringUtil.append(html, "<td><button action=\"bypass _bbsclan_clanlist;", String.valueOf(index + 1), "\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  244. }
  245. html.append("</tr></table>"
  246. + "<table border=0 cellspacing=0 cellpadding=0>"
  247. + "<tr><td width=610><img src=\"sek.cbui141\" width=\"610\" height=\"1\"></td></tr>"
  248. + "</table>"
  249. + "<table border=0><tr><td><combobox width=65 var=keyword list=\"Name;Ruler\"></td><td><edit var = \"Search\" width=130 height=11 length=\"16\"></td>"
  250. +
  251. //TODO: search (Write in BBS)
  252. "<td><button value=\"&$420;\" action=\"Write 5 -1 0 Search keyword keyword\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"> </td> </tr></table>"
  253. + "<br>" + "<br>" + "</center>" + "</body>" + "</html>");
  254. separateAndSend(html.toString(), activeChar);
  255. }
  256. /**
  257. * @param activeChar
  258. */
  259. private void clanhome(L2PcInstance activeChar)
  260. {
  261. clanhome(activeChar, activeChar.getClan().getClanId());
  262. }
  263. @SuppressWarnings("synthetic-access")
  264. private static class SingletonHolder
  265. {
  266. protected static final ClanBBSManager _instance = new ClanBBSManager();
  267. }
  268. /**
  269. * @param activeChar
  270. * @param clanId
  271. */
  272. private void clanhome(L2PcInstance activeChar, int clanId)
  273. {
  274. L2Clan cl = ClanTable.getInstance().getClan(clanId);
  275. if (cl != null)
  276. {
  277. if (cl.getLevel() < 2)
  278. {
  279. activeChar.sendPacket(SystemMessageId.NO_CB_IN_MY_CLAN);
  280. parsecmd("_bbsclan_clanlist", activeChar);
  281. }
  282. else
  283. {
  284. final String html = StringUtil.concat("<html><body><center><br><br>"
  285. + "<br1><br1><table border=0 cellspacing=0 cellpadding=0>"
  286. + "<tr><td FIXWIDTH=15>&nbsp;</td>"
  287. + "<td width=610 height=30 align=left>"
  288. + "<a action=\"bypass _bbshome\">HOME</a> &gt; <a action=\"bypass _bbsclan_clanlist\"> CLAN COMMUNITY </a> &gt; <a action=\"bypass _bbsclan_clanhome;", String.valueOf(clanId), "\"> &amp;$802; </a>"
  289. + "</td></tr></table>"
  290. + "<table border=0 cellspacing=0 cellpadding=0 width=610 bgcolor=434343>"
  291. + "<tr><td height=10></td></tr>"
  292. + "<tr>"
  293. + "<td fixWIDTH=5></td>"
  294. + "<td fixwidth=600>"
  295. + "<a action=\"bypass _bbsclan_clanhome;", String.valueOf(clanId), ";announce\">[CLAN ANNOUNCEMENT]</a> <a action=\"bypass _bbsclan_clanhome;", String.valueOf(clanId), ";cbb\">[CLAN BULLETIN BOARD]</a>"
  296. + "<a action=\"bypass _bbsclan_clanhome;", String.valueOf(clanId), ";cmail\">[CLAN MAIL]</a>&nbsp;&nbsp;"
  297. + "<a action=\"bypass _bbsclan_clannotice_edit;", String.valueOf(clanId), ";cnotice\">[CLAN NOTICE]</a>&nbsp;&nbsp;"
  298. + "</td>"
  299. + "<td fixWIDTH=5></td>"
  300. + "</tr>"
  301. + "<tr><td height=10></td></tr>"
  302. + "</table>"
  303. + "<table border=0 cellspacing=0 cellpadding=0 width=610>"
  304. + "<tr><td height=10></td></tr>"
  305. + "<tr><td fixWIDTH=5></td>"
  306. + "<td fixwidth=290 valign=top>"
  307. + "</td>"
  308. + "<td fixWIDTH=5></td>"
  309. + "<td fixWIDTH=5 align=center valign=top><img src=\"l2ui.squaregray\" width=2 height=128></td>"
  310. + "<td fixWIDTH=5></td>"
  311. + "<td fixwidth=295>"
  312. + "<table border=0 cellspacing=0 cellpadding=0 width=295>"
  313. + "<tr>"
  314. + "<td fixWIDTH=100 align=left>CLAN NAME</td>" + "<td fixWIDTH=195 align=left>", cl.getName(), "</td>" + "</tr>"
  315. + "<tr><td height=7></td></tr>" + "<tr>" + "<td fixWIDTH=100 align=left>CLAN LEVEL</td>"
  316. + "<td fixWIDTH=195 align=left height=16>", String.valueOf(cl.getLevel()), "</td>" + "</tr>"
  317. + "<tr><td height=7></td></tr>" + "<tr>" + "<td fixWIDTH=100 align=left>CLAN MEMBERS</td>"
  318. + "<td fixWIDTH=195 align=left height=16>", String.valueOf(cl.getMembersCount()), "</td>" + "</tr>"
  319. + "<tr><td height=7></td></tr>" + "<tr>" + "<td fixWIDTH=100 align=left>CLAN LEADER</td>"
  320. + "<td fixWIDTH=195 align=left height=16>", cl.getLeaderName(), "</td>" + "</tr>" + "<tr><td height=7></td></tr>"
  321. +
  322. //ADMINISTRATOR ??
  323. /*html.append("<tr>");
  324. html.append("<td fixWIDTH=100 align=left>ADMINISTRATOR</td>");
  325. html.append("<td fixWIDTH=195 align=left height=16>"+cl.getLeaderName()+"</td>");
  326. html.append("</tr>");*/
  327. "<tr><td height=7></td></tr>" + "<tr>" + "<td fixWIDTH=100 align=left>ALLIANCE</td>"
  328. + "<td fixWIDTH=195 align=left height=16>", (cl.getAllyName() != null) ? cl.getAllyName() : "", "</td>" + "</tr>"
  329. + "</table>" + "</td>" + "<td fixWIDTH=5></td>"
  330. + "</tr>"
  331. + "<tr><td height=10></td></tr>"
  332. + "</table>"
  333. +
  334. //TODO: the BB for clan :)
  335. //html.append("<table border=0 cellspacing=0 cellpadding=0 width=610 bgcolor=333333>");
  336. "<img src=\"L2UI.squareblank\" width=\"1\" height=\"5\">"
  337. + "<img src=\"L2UI.squaregray\" width=\"610\" height=\"1\">" + "<br>" + "</center>" + "<br> <br>" + "</body>"
  338. + "</html>");
  339. separateAndSend(html, activeChar);
  340. }
  341. }
  342. }
  343. @Override
  344. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  345. {
  346. if (ar1.equals("Set"))
  347. {
  348. activeChar.getClan().setNotice(ar4);
  349. parsecmd("_bbsclan_clanhome;" + activeChar.getClan().getClanId(), activeChar);
  350. }
  351. }
  352. }