/* * This program 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. * * This program 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 . */ package com.l2jserver.gameserver.communitybbs.Manager; import gnu.trove.iterator.TIntObjectIterator; import java.util.Collections; import java.util.Comparator; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; import javolution.util.FastList; import javolution.util.FastMap; import com.l2jserver.Config; import com.l2jserver.gameserver.GameServer; import com.l2jserver.gameserver.datatables.ClassListData; import com.l2jserver.gameserver.datatables.ExperienceTable; import com.l2jserver.gameserver.model.BlockList; import com.l2jserver.gameserver.model.L2World; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.model.itemcontainer.PcInventory; import com.l2jserver.gameserver.network.SystemMessageId; import com.l2jserver.gameserver.network.clientpackets.Say2; import com.l2jserver.gameserver.network.serverpackets.CreatureSay; import com.l2jserver.gameserver.network.serverpackets.ShowBoard; import com.l2jserver.gameserver.network.serverpackets.SystemMessage; import com.l2jserver.util.StringUtil; public class RegionBBSManager extends BaseBBSManager { private static Logger _logChat = Logger.getLogger("chat"); private static final Comparator playerNameComparator = new Comparator() { @Override public int compare(L2PcInstance p1, L2PcInstance p2) { return p1.getName().compareToIgnoreCase(p2.getName()); } }; private RegionBBSManager() { } @Override public void parsecmd(String command, L2PcInstance activeChar) { if (command.equals("_bbsloc")) { showOldCommunity(activeChar, 1); } else if (command.startsWith("_bbsloc;page;")) { StringTokenizer st = new StringTokenizer(command, ";"); st.nextToken(); st.nextToken(); int page = 0; try { page = Integer.parseInt(st.nextToken()); } catch (NumberFormatException nfe) { } showOldCommunity(activeChar, page); } else if (command.startsWith("_bbsloc;playerinfo;")) { StringTokenizer st = new StringTokenizer(command, ";"); st.nextToken(); st.nextToken(); String name = st.nextToken(); showOldCommunityPI(activeChar, name); } else { if (Config.COMMUNITY_TYPE == 1) { showOldCommunity(activeChar, 1); } else { ShowBoard sb = new ShowBoard("

the command: " + command + " is not implemented yet


", "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } } } /** * @param activeChar * @param name */ private void showOldCommunityPI(L2PcInstance activeChar, String name) { final StringBuilder htmlCode = StringUtil.startAppend(1000, "
" + "
L2J Community Board
"); L2PcInstance player = L2World.getInstance().getPlayer(name); if (player != null) { String sex = "Male"; if (player.getAppearance().getSex()) { sex = "Female"; } String levelApprox = "low"; if (player.getLevel() >= 60) levelApprox = "very high"; else if (player.getLevel() >= 40) levelApprox = "high"; else if (player.getLevel() >= 20) levelApprox = "medium"; StringUtil.append(htmlCode, "" + "" + ""); if (activeChar != null && (activeChar.isGM() || player.getObjectId() == activeChar.getObjectId() || Config.SHOW_LEVEL_COMMUNITYBOARD)) { long nextLevelExp = 0; long nextLevelExpNeeded = 0; if (player.getLevel() < (ExperienceTable.getInstance().getMaxLevel() - 1)) { nextLevelExp = ExperienceTable.getInstance().getExpForLevel(player.getLevel() + 1); nextLevelExpNeeded = nextLevelExp - player.getExp(); } StringUtil.append(htmlCode, "" + "" + "" + ""); } int uptime = (int) player.getUptime() / 1000; int h = uptime / 3600; int m = (uptime - (h * 3600)) / 60; int s = ((uptime - (h * 3600)) - (m * 60)); StringUtil.append(htmlCode, "" + ""); if (player.getClan() != null) { StringUtil.append(htmlCode, "" + ""); } StringUtil.append(htmlCode, "
", player.getName(), " (", sex, " ", ClassListData.getInstance().getClass(player.getClassId()).getClientCode(), "):
Level: ", levelApprox, "

Level: ", String.valueOf(player.getLevel()), "
Experience: ", String.valueOf(player.getExp()), "/", String.valueOf(nextLevelExp), "
Experience needed for level up: ", String.valueOf(nextLevelExpNeeded), "

Uptime: ", String.valueOf(h), "h ", String.valueOf(m), "m ", String.valueOf(s), "s

Clan: ", player.getClan().getName(), "


" + "
" + ""); separateAndSend(htmlCode.toString(), activeChar); } else { ShowBoard sb = new ShowBoard(StringUtil.concat("

No player with name ", name, "


"), "101"); activeChar.sendPacket(sb); activeChar.sendPacket(new ShowBoard(null, "102")); activeChar.sendPacket(new ShowBoard(null, "103")); } } /** * @param activeChar * @param page */ private void showOldCommunity(L2PcInstance activeChar, int page) { separateAndSend(getCommunityPage(page, activeChar.isGM() ? "gm" : "pl"), activeChar); } @Override public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar) { if (activeChar == null) return; if (ar1.equals("PM")) { final StringBuilder htmlCode = StringUtil.startAppend(500, "
" + "
L2J Community Board
"); try { L2PcInstance receiver = L2World.getInstance().getPlayer(ar2); if (receiver == null) { StringUtil.append(htmlCode, "Player not found!
"); separateAndSend(htmlCode.toString(), activeChar); return; } if (Config.JAIL_DISABLE_CHAT && receiver.isInJail()) { activeChar.sendMessage("Player is in jail."); return; } if (receiver.isChatBanned()) { activeChar.sendMessage("Player is chat banned."); return; } if (activeChar.isInJail() && Config.JAIL_DISABLE_CHAT) { activeChar.sendMessage("You can not chat while in jail."); return; } if (activeChar.isChatBanned()) { activeChar.sendMessage("You are banned from using chat"); return; } if (Config.LOG_CHAT) { LogRecord record = new LogRecord(Level.INFO, ar3); record.setLoggerName("chat"); record.setParameters(new Object[] { "TELL", "[" + activeChar.getName() + " to " + receiver.getName() + "]" }); _logChat.log(record); } CreatureSay cs = new CreatureSay(activeChar.getObjectId(), Say2.TELL, activeChar.getName(), ar3); if (!receiver.isSilenceMode(activeChar.getObjectId()) && !BlockList.isBlocked(receiver, activeChar) ) { receiver.sendPacket(cs); activeChar.sendPacket(new CreatureSay(activeChar.getObjectId(), Say2.TELL, "->" + receiver.getName(), ar3)); StringUtil.append(htmlCode, "Message Sent