/*
* Copyright (C) 2004-2013 L2J Server
*
* This file is part of L2J Server.
*
* L2J Server 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 Server 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 java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
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.gameserver.util.Comparators;
import com.l2jserver.util.StringUtil;
public class RegionBBSManager extends BaseBBSManager
{
private static final Logger _logChat = Logger.getLogger("chat");
private int _onlineCount = 0;
private int _onlineCountGm = 0;
private static Map> _onlinePlayers = new FastMap>().shared();
private static Map> _communityPages = new FastMap>().shared();
@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"));
}
}
}
/**
* Show old community player info.
* @param activeChar the active char
* @param name the player 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, "
"), "101");
activeChar.sendPacket(sb);
activeChar.sendPacket(new ShowBoard(null, "102"));
activeChar.sendPacket(new ShowBoard(null, "103"));
}
}
/**
* Show old community.
* @param activeChar the active char
* @param page the 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.isJailed())
{
activeChar.sendMessage("Player is in jail.");
return;
}
if (receiver.isChatBanned())
{
activeChar.sendMessage("Player is chat banned.");
return;
}
if (activeChar.isJailed() && 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