123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- * Copyright (C) 2004-2015 L2J DataPack
- *
- * This file is part of L2J DataPack.
- *
- * L2J DataPack is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * L2J DataPack is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- package handlers.communityboard;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import com.l2jserver.L2DatabaseFactory;
- import com.l2jserver.gameserver.cache.HtmCache;
- import com.l2jserver.gameserver.data.sql.impl.ClanTable;
- import com.l2jserver.gameserver.handler.CommunityBoardHandler;
- import com.l2jserver.gameserver.handler.IParseBoardHandler;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- /**
- * Home board.
- * @author Zoey76
- */
- public final class HomeBoard implements IParseBoardHandler
- {
- // SQL Queries
- private static final String COUNT_FAVORITES = "SELECT COUNT(*) AS favorites FROM `bbs_favorites` WHERE `playerId`=?";
-
- private static final String[] COMMANDS =
- {
- "_bbshome",
- "_bbstop"
- };
-
- @Override
- public String[] getCommunityBoardCommands()
- {
- return COMMANDS;
- }
-
- @Override
- public boolean parseCommunityBoardCommand(String command, L2PcInstance activeChar)
- {
- if (command.equals("_bbshome") || command.equals("_bbstop"))
- {
- CommunityBoardHandler.getInstance().addBypass(activeChar, "Home", command);
-
- String html = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/CommunityBoard/home.html");
- html = html.replaceAll("%fav_count%", Integer.toString(getFavoriteCount(activeChar)));
- html = html.replaceAll("%region_count%", Integer.toString(getRegionCount(activeChar)));
- html = html.replaceAll("%clan_count%", Integer.toString(ClanTable.getInstance().getClanCount()));
- CommunityBoardHandler.separateAndSend(html, activeChar);
- }
- else if (command.startsWith("_bbstop;"))
- {
- final String path = command.replace("_bbstop;", "");
- if ((path.length() > 0) && path.endsWith(".html"))
- {
- final String html = HtmCache.getInstance().getHtm(activeChar.getHtmlPrefix(), "data/html/CommunityBoard/" + path);
- CommunityBoardHandler.separateAndSend(html, activeChar);
- }
- }
- return true;
- }
-
- /**
- * Gets the Favorite links for the given player.
- * @param player the player
- * @return the favorite links count
- */
- private static int getFavoriteCount(L2PcInstance player)
- {
- int count = 0;
- try (Connection con = L2DatabaseFactory.getInstance().getConnection();
- PreparedStatement ps = con.prepareStatement(COUNT_FAVORITES))
- {
- ps.setInt(1, player.getObjectId());
- try (ResultSet rs = ps.executeQuery())
- {
- if (rs.next())
- {
- count = rs.getInt("favorites");
- }
- }
- }
- catch (Exception e)
- {
- LOG.warning(FavoriteBoard.class.getSimpleName() + ": Coudn't load favorites count for player " + player.getName());
- }
- return count;
- }
-
- /**
- * Gets the registered regions count for the given player.
- * @param player the player
- * @return the registered regions count
- */
- private static int getRegionCount(L2PcInstance player)
- {
- return 0; // TODO: Implement.
- }
- }
|