/*
* 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 <http://www.gnu.org/licenses/>.
*/
package silentium.gameserver.network.clientpackets;
import silentium.gameserver.configs.PlayersConfig;
import silentium.gameserver.instancemanager.PetitionManager;
import silentium.gameserver.model.actor.instance.L2PcInstance;
import silentium.gameserver.network.SystemMessageId;
import silentium.gameserver.network.serverpackets.PlaySound;
import silentium.gameserver.network.serverpackets.SystemMessage;
import silentium.gameserver.tables.GmListTable;
/**
* <p>
* Format: (c) Sd
* <ul>
* <li>S: content</li>
* <li>d: type</li>
* </ul>
* </p>
*
* @author -Wooden-, TempyIncursion
*/
public final class RequestPetition extends L2GameClientPacket
{
private String _content;
private int _type; // 1 = on : 0 = off;
@Override
protected void readImpl()
{
_content = readS();
_type = readD();
}
@Override
protected void runImpl()
{
final L2PcInstance activeChar = getClient().getActiveChar();
if (activeChar == null)
return;
if (!GmListTable.getInstance().isGmOnline(false))
{
activeChar.sendPacket(SystemMessageId.NO_GM_PROVIDING_SERVICE_NOW);
activeChar.sendPacket(new PlaySound("systemmsg_e.702"));
return;
}
if (!PetitionManager.isPetitioningAllowed())
{
activeChar.sendPacket(SystemMessageId.GAME_CLIENT_UNABLE_TO_CONNECT_TO_PETITION_SERVER);
return;
}
if (PetitionManager.getInstance().isPlayerPetitionPending(activeChar))
{
activeChar.sendPacket(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME);
return;
}
if (PetitionManager.getInstance().getPendingPetitionCount() == PlayersConfig.MAX_PETITIONS_PENDING)
{
activeChar.sendPacket(SystemMessageId.PETITION_SYSTEM_CURRENT_UNAVAILABLE);
return;
}
int totalPetitions = PetitionManager.getInstance().getPlayerTotalPetitionCount(activeChar) + 1;
if (totalPetitions > PlayersConfig.MAX_PETITIONS_PER_PLAYER)
{
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.WE_HAVE_RECEIVED_S1_PETITIONS_TODAY).addNumber(totalPetitions));
return;
}
if (_content.length() > 255)
{
activeChar.sendPacket(SystemMessageId.PETITION_MAX_CHARS_255);
return;
}
int petitionId = PetitionManager.getInstance().submitPetition(activeChar, _content, _type);
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.PETITION_ACCEPTED_RECENT_NO_S1).addNumber(petitionId));
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.SUBMITTED_YOU_S1_TH_PETITION_S2_LEFT).addNumber(totalPetitions).addNumber(PlayersConfig.MAX_PETITIONS_PER_PLAYER - totalPetitions));
activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.S1_PETITION_ON_WAITING_LIST).addNumber(PetitionManager.getInstance().getPendingPetitionCount()));
}
}