ClanBoard.java 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.communityboard;
  20. import com.l2jserver.gameserver.datatables.ClanTable;
  21. import com.l2jserver.gameserver.handler.CommunityBoardHandler;
  22. import com.l2jserver.gameserver.handler.IWriteBoardHandler;
  23. import com.l2jserver.gameserver.model.L2Clan;
  24. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  25. import com.l2jserver.gameserver.network.SystemMessageId;
  26. import com.l2jserver.gameserver.util.Util;
  27. import com.l2jserver.util.StringUtil;
  28. /**
  29. * Clan board.
  30. * @author Zoey76
  31. */
  32. public class ClanBoard implements IWriteBoardHandler
  33. {
  34. private static final String[] COMMANDS =
  35. {
  36. "_bbsclan",
  37. "_bbsclan_list",
  38. "_bbsclan_clanhome"
  39. };
  40. @Override
  41. public String[] getCommunityBoardCommands()
  42. {
  43. return COMMANDS;
  44. }
  45. @Override
  46. public boolean parseCommunityBoardCommand(String command, L2PcInstance activeChar)
  47. {
  48. if (command.equals("_bbsclan"))
  49. {
  50. CommunityBoardHandler.getInstance().addBypass(activeChar, "Clan", command);
  51. if ((activeChar.getClan() == null) || (activeChar.getClan().getLevel() < 2))
  52. {
  53. clanList(activeChar, 1);
  54. }
  55. else
  56. {
  57. clanHome(activeChar);
  58. }
  59. }
  60. else if (command.startsWith("_bbsclan_clanlist"))
  61. {
  62. CommunityBoardHandler.getInstance().addBypass(activeChar, "Clan List", command);
  63. if (command.equals("_bbsclan_clanlist"))
  64. {
  65. clanList(activeChar, 1);
  66. }
  67. else if (command.startsWith("_bbsclan_clanlist;"))
  68. {
  69. try
  70. {
  71. clanList(activeChar, Integer.parseInt(command.split(";")[1]));
  72. }
  73. catch (Exception e)
  74. {
  75. clanList(activeChar, 1);
  76. LOG.warning(ClanBoard.class.getSimpleName() + ": Player " + activeChar + " send invalid clan list bypass " + command + "!");
  77. }
  78. }
  79. }
  80. else if (command.startsWith("_bbsclan_clanhome"))
  81. {
  82. CommunityBoardHandler.getInstance().addBypass(activeChar, "Clan Home", command);
  83. if (command.equals("_bbsclan_clanhome"))
  84. {
  85. clanHome(activeChar);
  86. }
  87. else if (command.startsWith("_bbsclan_clanhome;"))
  88. {
  89. try
  90. {
  91. clanHome(activeChar, Integer.parseInt(command.split(";")[1]));
  92. }
  93. catch (Exception e)
  94. {
  95. clanHome(activeChar);
  96. LOG.warning(ClanBoard.class.getSimpleName() + ": Player " + activeChar + " send invalid clan home bypass " + command + "!");
  97. }
  98. }
  99. }
  100. else if (command.startsWith("_bbsclan_clannotice_edit;"))
  101. {
  102. CommunityBoardHandler.getInstance().addBypass(activeChar, "Clan Edit", command);
  103. clanNotice(activeChar, activeChar.getClanId());
  104. }
  105. else if (command.startsWith("_bbsclan_clannotice_enable"))
  106. {
  107. CommunityBoardHandler.getInstance().addBypass(activeChar, "Clan Notice Enable", command);
  108. if (activeChar.getClan() != null)
  109. {
  110. activeChar.getClan().setNoticeEnabled(true);
  111. }
  112. clanNotice(activeChar, activeChar.getClanId());
  113. }
  114. else if (command.startsWith("_bbsclan_clannotice_disable"))
  115. {
  116. CommunityBoardHandler.getInstance().addBypass(activeChar, "Clan Notice Disable", command);
  117. if (activeChar.getClan() != null)
  118. {
  119. activeChar.getClan().setNoticeEnabled(false);
  120. }
  121. clanNotice(activeChar, activeChar.getClanId());
  122. }
  123. else
  124. {
  125. CommunityBoardHandler.separateAndSend("<html><body><br><br><center>Command " + command + " need development.</center><br><br></body></html>", activeChar);
  126. }
  127. return true;
  128. }
  129. private void clanNotice(L2PcInstance activeChar, int clanId)
  130. {
  131. final L2Clan cl = ClanTable.getInstance().getClan(clanId);
  132. if (cl != null)
  133. {
  134. if (cl.getLevel() < 2)
  135. {
  136. activeChar.sendPacket(SystemMessageId.NO_CB_IN_MY_CLAN);
  137. parseCommunityBoardCommand("_bbsclan_clanlist", activeChar);
  138. }
  139. else
  140. {
  141. 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>");
  142. if (activeChar.isClanLeader())
  143. {
  144. 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>");
  145. if (activeChar.getClan().isNoticeEnabled())
  146. {
  147. 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>");
  148. }
  149. else
  150. {
  151. 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");
  152. }
  153. 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>");
  154. Util.sendCBHtml(activeChar, html.toString(), activeChar.getClan().getNotice());
  155. }
  156. else
  157. {
  158. 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>");
  159. if (activeChar.getClan().isNoticeEnabled())
  160. {
  161. 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>");
  162. }
  163. StringUtil.append(html, "</center></body></html>");
  164. CommunityBoardHandler.separateAndSend(html.toString(), activeChar);
  165. }
  166. }
  167. }
  168. }
  169. private void clanList(L2PcInstance activeChar, int index)
  170. {
  171. if (index < 1)
  172. {
  173. index = 1;
  174. }
  175. // header
  176. 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().getId() : 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\">");
  177. int i = 0;
  178. for (L2Clan cl : ClanTable.getInstance().getClans())
  179. {
  180. if (i > ((index + 1) * 7))
  181. {
  182. break;
  183. }
  184. if (i++ >= ((index - 1) * 7))
  185. {
  186. 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.getId()), "\">", 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\">");
  187. }
  188. }
  189. html.append("<img src=\"L2UI.SquareBlank\" width=\"610\" height=\"2\"><table cellpadding=0 cellspacing=2 border=0><tr>");
  190. if (index == 1)
  191. {
  192. html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
  193. }
  194. else
  195. {
  196. 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>");
  197. }
  198. i = 0;
  199. int nbp;
  200. nbp = ClanTable.getInstance().getClans().length / 8;
  201. if ((nbp * 8) != ClanTable.getInstance().getClans().length)
  202. {
  203. nbp++;
  204. }
  205. for (i = 1; i <= nbp; i++)
  206. {
  207. if (i == index)
  208. {
  209. StringUtil.append(html, "<td> ", String.valueOf(i), " </td>");
  210. }
  211. else
  212. {
  213. StringUtil.append(html, "<td><a action=\"bypass _bbsclan_clanlist;", String.valueOf(i), "\"> ", String.valueOf(i), " </a></td>");
  214. }
  215. }
  216. if (index == nbp)
  217. {
  218. html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
  219. }
  220. else
  221. {
  222. 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>");
  223. }
  224. 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>" +
  225. // TODO: search (Write in BBS)
  226. "<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>");
  227. CommunityBoardHandler.separateAndSend(html.toString(), activeChar);
  228. }
  229. private void clanHome(L2PcInstance activeChar)
  230. {
  231. clanHome(activeChar, activeChar.getClan().getId());
  232. }
  233. private void clanHome(L2PcInstance activeChar, int clanId)
  234. {
  235. L2Clan cl = ClanTable.getInstance().getClan(clanId);
  236. if (cl != null)
  237. {
  238. if (cl.getLevel() < 2)
  239. {
  240. activeChar.sendPacket(SystemMessageId.NO_CB_IN_MY_CLAN);
  241. parseCommunityBoardCommand("_bbsclan_clanlist", activeChar);
  242. }
  243. else
  244. {
  245. 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>" +
  246. // ADMINISTRATOR ??
  247. /*
  248. * 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>");
  249. */
  250. "<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>" +
  251. // TODO: the BB for clan :)
  252. // html.append("<table border=0 cellspacing=0 cellpadding=0 width=610 bgcolor=333333>");
  253. "<img src=\"L2UI.squareblank\" width=\"1\" height=\"5\"><img src=\"L2UI.squaregray\" width=\"610\" height=\"1\"><br></center><br> <br></body></html>");
  254. CommunityBoardHandler.separateAndSend(html, activeChar);
  255. }
  256. }
  257. }
  258. @Override
  259. public boolean writeCommunityBoardCommand(L2PcInstance activeChar, String arg1, String arg2, String arg3, String arg4, String arg5)
  260. {
  261. // TODO: Implement.
  262. return false;
  263. }
  264. }