HomeBoard.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Copyright (C) 2004-2015 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 java.sql.Connection;
  21. import java.sql.PreparedStatement;
  22. import java.sql.ResultSet;
  23. import com.l2jserver.L2DatabaseFactory;
  24. import com.l2jserver.gameserver.cache.HtmCache;
  25. import com.l2jserver.gameserver.data.sql.impl.ClanTable;
  26. import com.l2jserver.gameserver.handler.CommunityBoardHandler;
  27. import com.l2jserver.gameserver.handler.IParseBoardHandler;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. /**
  30. * Home board.
  31. * @author Zoey76
  32. */
  33. public final class HomeBoard implements IParseBoardHandler
  34. {
  35. // SQL Queries
  36. private static final String COUNT_FAVORITES = "SELECT COUNT(*) AS favorites FROM `bbs_favorites` WHERE `playerId`=?";
  37. private static final String[] COMMANDS =
  38. {
  39. "_bbshome",
  40. "_bbstop"
  41. };
  42. @Override
  43. public String[] getCommunityBoardCommands()
  44. {
  45. return COMMANDS;
  46. }
  47. @Override
  48. public boolean parseCommunityBoardCommand(String command, L2PcInstance activeChar)
  49. {
  50. if (command.equals("_bbshome") || command.equals("_bbstop"))
  51. {
  52. CommunityBoardHandler.getInstance().addBypass(activeChar, "Home", command);
  53. String html = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/CommunityBoard/home.html");
  54. html = html.replaceAll("%fav_count%", Integer.toString(getFavoriteCount(activeChar)));
  55. html = html.replaceAll("%region_count%", Integer.toString(getRegionCount(activeChar)));
  56. html = html.replaceAll("%clan_count%", Integer.toString(ClanTable.getInstance().getClanCount()));
  57. CommunityBoardHandler.separateAndSend(html, activeChar);
  58. }
  59. else if (command.startsWith("_bbstop;"))
  60. {
  61. final String path = command.replace("_bbstop;", "");
  62. if ((path.length() > 0) && path.endsWith(".html"))
  63. {
  64. final String html = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/CommunityBoard/" + path);
  65. CommunityBoardHandler.separateAndSend(html, activeChar);
  66. }
  67. }
  68. return true;
  69. }
  70. /**
  71. * Gets the Favorite links for the given player.
  72. * @param player the player
  73. * @return the favorite links count
  74. */
  75. private static int getFavoriteCount(L2PcInstance player)
  76. {
  77. int count = 0;
  78. try (Connection con = L2DatabaseFactory.getInstance().getConnection();
  79. PreparedStatement ps = con.prepareStatement(COUNT_FAVORITES))
  80. {
  81. ps.setInt(1, player.getObjectId());
  82. try (ResultSet rs = ps.executeQuery())
  83. {
  84. if (rs.next())
  85. {
  86. count = rs.getInt("favorites");
  87. }
  88. }
  89. }
  90. catch (Exception e)
  91. {
  92. LOG.warning(FavoriteBoard.class.getSimpleName() + ": Coudn't load favorites count for player " + player.getName());
  93. }
  94. return count;
  95. }
  96. /**
  97. * Gets the registered regions count for the given player.
  98. * @param player the player
  99. * @return the registered regions count
  100. */
  101. private static int getRegionCount(L2PcInstance player)
  102. {
  103. return 0; // TODO: Implement.
  104. }
  105. }