ClanBBSManager.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. public static ClanBBSManager getInstance()
  25. {
  26. return SingletonHolder._instance;
  27. }
  28. /**
  29. * @param command
  30. * @param activeChar
  31. */
  32. @Override
  33. public void parsecmd(String command, L2PcInstance activeChar)
  34. {
  35. if (command.equals("_bbsclan"))
  36. {
  37. if ((activeChar.getClan() == null) || (activeChar.getClan().getLevel() < 2))
  38. {
  39. clanlist(activeChar, 1);
  40. }
  41. else
  42. {
  43. clanhome(activeChar);
  44. }
  45. }
  46. else if (command.startsWith("_bbsclan_clanlist"))
  47. {
  48. if (command.equals("_bbsclan_clanlist"))
  49. {
  50. clanlist(activeChar, 1);
  51. }
  52. else if (command.startsWith("_bbsclan_clanlist;"))
  53. {
  54. StringTokenizer st = new StringTokenizer(command, ";");
  55. st.nextToken();
  56. int index = Integer.parseInt(st.nextToken());
  57. clanlist(activeChar, index);
  58. }
  59. }
  60. else if (command.startsWith("_bbsclan_clanhome"))
  61. {
  62. if (command.equals("_bbsclan_clanhome"))
  63. {
  64. clanhome(activeChar);
  65. }
  66. else if (command.startsWith("_bbsclan_clanhome;"))
  67. {
  68. StringTokenizer st = new StringTokenizer(command, ";");
  69. st.nextToken();
  70. int index = Integer.parseInt(st.nextToken());
  71. clanhome(activeChar, index);
  72. }
  73. }
  74. else if (command.startsWith("_bbsclan_clannotice_edit;"))
  75. {
  76. clanNotice(activeChar, activeChar.getClanId());
  77. }
  78. else if (command.startsWith("_bbsclan_clannotice_enable"))
  79. {
  80. if (activeChar.getClan() != null)
  81. {
  82. activeChar.getClan().setNoticeEnabled(true);
  83. }
  84. clanNotice(activeChar, activeChar.getClanId());
  85. }
  86. else if (command.startsWith("_bbsclan_clannotice_disable"))
  87. {
  88. if (activeChar.getClan() != null)
  89. {
  90. activeChar.getClan().setNoticeEnabled(false);
  91. }
  92. clanNotice(activeChar, activeChar.getClanId());
  93. }
  94. else
  95. {
  96. separateAndSend("<html><body><br><br><center>Command : " + command + " needs core development</center><br><br></body></html>", activeChar);
  97. }
  98. }
  99. private void clanNotice(L2PcInstance activeChar, int clanId)
  100. {
  101. final L2Clan cl = ClanTable.getInstance().getClan(clanId);
  102. if (cl != null)
  103. {
  104. if (cl.getLevel() < 2)
  105. {
  106. activeChar.sendPacket(SystemMessageId.NO_CB_IN_MY_CLAN);
  107. parsecmd("_bbsclan_clanlist", activeChar);
  108. }
  109. else
  110. {
  111. final StringBuilder html = StringUtil.startAppend(2000, "<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><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></td></tr></table>");
  112. if (activeChar.isClanLeader())
  113. {
  114. StringUtil.append(html, "<br><br><center><table width=610 border=0 cellspacing=0 cellpadding=0><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><tr><td height=20></td></tr>");
  115. if (activeChar.getClan().isNoticeEnabled())
  116. {
  117. 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>");
  118. }
  119. else
  120. {
  121. 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");
  122. }
  123. StringUtil.append(html, "</td></tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\"><br> <br><table width=610 border=0 cellspacing=2 cellpadding=0><tr><td>Edit Notice: </td></tr><tr><td height=5></td></tr><tr><td><MultiEdit var =\"Content\" width=610 height=100></td></tr></table><br><table width=610 border=0 cellspacing=0 cellpadding=0><tr><td height=5></td></tr><tr><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><td align=center FIXWIDTH=45></td><td align=center FIXWIDTH=500></td></tr></table></center></body></html>");
  124. send1001(html.toString(), activeChar);
  125. send1002(activeChar, activeChar.getClan().getNotice(), " ", "0");
  126. }
  127. else
  128. {
  129. StringUtil.append(html, "<img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=0><tr><td>You are not your clan's leader, and therefore cannot change the clan notice</td></tr></table>");
  130. if (activeChar.getClan().isNoticeEnabled())
  131. {
  132. StringUtil.append(html, "<table border=0 cellspacing=0 cellpadding=0><tr><td>The current clan notice:</td></tr><tr><td fixwidth=5></td><td FIXWIDTH=600 align=left>" + activeChar.getClan().getNotice() + "</td><td fixqqwidth=5></td></tr></table>");
  133. }
  134. StringUtil.append(html, "</center></body></html>");
  135. separateAndSend(html.toString(), activeChar);
  136. }
  137. }
  138. }
  139. }
  140. /**
  141. * @param activeChar
  142. * @param index
  143. */
  144. private void clanlist(L2PcInstance activeChar, int index)
  145. {
  146. if (index < 1)
  147. {
  148. index = 1;
  149. }
  150. // header
  151. final StringBuilder html = StringUtil.startAppend(2000, "<html><body><br><br><center><br1><br1><table border=0 cellspacing=0 cellpadding=0><tr><td FIXWIDTH=15>&nbsp;</td><td width=610 height=30 align=left><a action=\"bypass _bbsclan_clanlist\"> CLAN COMMUNITY </a></td></tr></table><table border=0 cellspacing=0 cellpadding=0 width=610 bgcolor=434343><tr><td height=10></td></tr><tr><td fixWIDTH=5></td><td fixWIDTH=600><a action=\"bypass _bbsclan_clanhome;", String.valueOf((activeChar.getClan() != null) ? activeChar.getClan().getClanId() : 0), "\">[GO TO MY CLAN]</a>&nbsp;&nbsp;</td><td fixWIDTH=5></td></tr><tr><td height=10></td></tr></table><br><table border=0 cellspacing=0 cellpadding=2 bgcolor=5A5A5A width=610><tr><td FIXWIDTH=5></td><td FIXWIDTH=200 align=center>CLAN NAME</td><td FIXWIDTH=200 align=center>CLAN LEADER</td><td FIXWIDTH=100 align=center>CLAN LEVEL</td><td FIXWIDTH=100 align=center>CLAN MEMBERS</td><td FIXWIDTH=5></td></tr></table><img src=\"L2UI.Squareblank\" width=\"1\" height=\"5\">");
  152. int i = 0;
  153. for (L2Clan cl : ClanTable.getInstance().getClans())
  154. {
  155. if (i > ((index + 1) * 7))
  156. {
  157. break;
  158. }
  159. if (i++ >= ((index - 1) * 7))
  160. {
  161. StringUtil.append(html, "<img src=\"L2UI.SquareBlank\" width=\"610\" height=\"3\"><table border=0 cellspacing=0 cellpadding=0 width=610><tr> <td FIXWIDTH=5></td><td FIXWIDTH=200 align=center><a action=\"bypass _bbsclan_clanhome;", String.valueOf(cl.getClanId()), "\">", cl.getName(), "</a></td><td FIXWIDTH=200 align=center>", cl.getLeaderName(), "</td><td FIXWIDTH=100 align=center>", String.valueOf(cl.getLevel()), "</td><td FIXWIDTH=100 align=center>", String.valueOf(cl.getMembersCount()), "</td><td FIXWIDTH=5></td></tr><tr><td height=5></td></tr></table><img src=\"L2UI.SquareBlank\" width=\"610\" height=\"3\"><img src=\"L2UI.SquareGray\" width=\"610\" height=\"1\">");
  162. }
  163. }
  164. html.append("<img src=\"L2UI.SquareBlank\" width=\"610\" height=\"2\"><table cellpadding=0 cellspacing=2 border=0><tr>");
  165. if (index == 1)
  166. {
  167. html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  168. }
  169. else
  170. {
  171. 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>");
  172. }
  173. i = 0;
  174. int nbp;
  175. nbp = ClanTable.getInstance().getClans().length / 8;
  176. if ((nbp * 8) != ClanTable.getInstance().getClans().length)
  177. {
  178. nbp++;
  179. }
  180. for (i = 1; i <= nbp; i++)
  181. {
  182. if (i == index)
  183. {
  184. StringUtil.append(html, "<td> ", String.valueOf(i), " </td>");
  185. }
  186. else
  187. {
  188. StringUtil.append(html, "<td><a action=\"bypass _bbsclan_clanlist;", String.valueOf(i), "\"> ", String.valueOf(i), " </a></td>");
  189. }
  190. }
  191. if (index == nbp)
  192. {
  193. html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  194. }
  195. else
  196. {
  197. 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>");
  198. }
  199. html.append("</tr></table><table border=0 cellspacing=0 cellpadding=0><tr><td width=610><img src=\"sek.cbui141\" width=\"610\" height=\"1\"></td></tr></table><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>" +
  200. // TODO: search (Write in BBS)
  201. "<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><br><br></center></body></html>");
  202. separateAndSend(html.toString(), activeChar);
  203. }
  204. /**
  205. * @param activeChar
  206. */
  207. private void clanhome(L2PcInstance activeChar)
  208. {
  209. clanhome(activeChar, activeChar.getClan().getClanId());
  210. }
  211. private static class SingletonHolder
  212. {
  213. protected static final ClanBBSManager _instance = new ClanBBSManager();
  214. }
  215. /**
  216. * @param activeChar
  217. * @param clanId
  218. */
  219. private void clanhome(L2PcInstance activeChar, int clanId)
  220. {
  221. L2Clan cl = ClanTable.getInstance().getClan(clanId);
  222. if (cl != null)
  223. {
  224. if (cl.getLevel() < 2)
  225. {
  226. activeChar.sendPacket(SystemMessageId.NO_CB_IN_MY_CLAN);
  227. parsecmd("_bbsclan_clanlist", activeChar);
  228. }
  229. else
  230. {
  231. final String html = StringUtil.concat("<html><body><center><br><br><br1><br1><table border=0 cellspacing=0 cellpadding=0><tr><td FIXWIDTH=15>&nbsp;</td><td width=610 height=30 align=left><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></td></tr></table><table border=0 cellspacing=0 cellpadding=0 width=610 bgcolor=434343><tr><td height=10></td></tr><tr><td fixWIDTH=5></td><td fixwidth=600><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><a action=\"bypass _bbsclan_clanhome;", String.valueOf(clanId), ";cmail\">[CLAN MAIL]</a>&nbsp;&nbsp;<a action=\"bypass _bbsclan_clannotice_edit;", String.valueOf(clanId), ";cnotice\">[CLAN NOTICE]</a>&nbsp;&nbsp;</td><td fixWIDTH=5></td></tr><tr><td height=10></td></tr></table><table border=0 cellspacing=0 cellpadding=0 width=610><tr><td height=10></td></tr><tr><td fixWIDTH=5></td><td fixwidth=290 valign=top></td><td fixWIDTH=5></td><td fixWIDTH=5 align=center valign=top><img src=\"l2ui.squaregray\" width=2 height=128></td><td fixWIDTH=5></td><td fixwidth=295><table border=0 cellspacing=0 cellpadding=0 width=295><tr><td fixWIDTH=100 align=left>CLAN NAME</td><td fixWIDTH=195 align=left>", cl.getName(), "</td></tr><tr><td height=7></td></tr><tr><td fixWIDTH=100 align=left>CLAN LEVEL</td><td fixWIDTH=195 align=left height=16>", String.valueOf(cl.getLevel()), "</td></tr><tr><td height=7></td></tr><tr><td fixWIDTH=100 align=left>CLAN MEMBERS</td><td fixWIDTH=195 align=left height=16>", String.valueOf(cl.getMembersCount()), "</td></tr><tr><td height=7></td></tr><tr><td fixWIDTH=100 align=left>CLAN LEADER</td><td fixWIDTH=195 align=left height=16>", cl.getLeaderName(), "</td></tr><tr><td height=7></td></tr>" +
  232. // ADMINISTRATOR ??
  233. /*
  234. * html.append("<tr>"); html.append("<td fixWIDTH=100 align=left>ADMINISTRATOR</td>"); html.append("<td fixWIDTH=195 align=left height=16>"+cl.getLeaderName()+"</td>"); html.append("</tr>");
  235. */
  236. "<tr><td height=7></td></tr><tr><td fixWIDTH=100 align=left>ALLIANCE</td><td fixWIDTH=195 align=left height=16>", (cl.getAllyName() != null) ? cl.getAllyName() : "", "</td></tr></table></td><td fixWIDTH=5></td></tr><tr><td height=10></td></tr></table>" +
  237. // TODO: the BB for clan :)
  238. // html.append("<table border=0 cellspacing=0 cellpadding=0 width=610 bgcolor=333333>");
  239. "<img src=\"L2UI.squareblank\" width=\"1\" height=\"5\"><img src=\"L2UI.squaregray\" width=\"610\" height=\"1\"><br></center><br> <br></body></html>");
  240. separateAndSend(html, activeChar);
  241. }
  242. }
  243. }
  244. @Override
  245. public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
  246. {
  247. if (ar1.equals("Set"))
  248. {
  249. activeChar.getClan().setNotice(ar4);
  250. parsecmd("_bbsclan_clanhome;" + activeChar.getClan().getClanId(), activeChar);
  251. }
  252. }
  253. }