RequestPetition.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.data.xml.impl.AdminData;
  22. import com.l2jserver.gameserver.instancemanager.PetitionManager;
  23. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  26. /**
  27. * <p>
  28. * Format: (c) Sd
  29. * <ul>
  30. * <li>S: content</li>
  31. * <li>d: type</li>
  32. * </ul>
  33. * </p>
  34. * @author -Wooden-, TempyIncursion
  35. */
  36. public final class RequestPetition extends L2GameClientPacket
  37. {
  38. private static final String _C__89_RequestPetition = "[C] 89 RequestPetition";
  39. private String _content;
  40. private int _type; // 1 = on : 0 = off;
  41. @Override
  42. protected void readImpl()
  43. {
  44. _content = readS();
  45. _type = readD();
  46. }
  47. @Override
  48. protected void runImpl()
  49. {
  50. L2PcInstance activeChar = getClient().getActiveChar();
  51. if (activeChar == null)
  52. {
  53. return;
  54. }
  55. if (!AdminData.getInstance().isGmOnline(false))
  56. {
  57. activeChar.sendPacket(SystemMessageId.NO_GM_PROVIDING_SERVICE_NOW);
  58. return;
  59. }
  60. if (!PetitionManager.getInstance().isPetitioningAllowed())
  61. {
  62. activeChar.sendPacket(SystemMessageId.GAME_CLIENT_UNABLE_TO_CONNECT_TO_PETITION_SERVER);
  63. return;
  64. }
  65. if (PetitionManager.getInstance().isPlayerPetitionPending(activeChar))
  66. {
  67. activeChar.sendPacket(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME);
  68. return;
  69. }
  70. if (PetitionManager.getInstance().getPendingPetitionCount() == Config.MAX_PETITIONS_PENDING)
  71. {
  72. activeChar.sendPacket(SystemMessageId.PETITION_SYSTEM_CURRENT_UNAVAILABLE);
  73. return;
  74. }
  75. int totalPetitions = PetitionManager.getInstance().getPlayerTotalPetitionCount(activeChar) + 1;
  76. if (totalPetitions > Config.MAX_PETITIONS_PER_PLAYER)
  77. {
  78. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.WE_HAVE_RECEIVED_S1_PETITIONS_TODAY);
  79. sm.addInt(totalPetitions);
  80. activeChar.sendPacket(sm);
  81. return;
  82. }
  83. if (_content.length() > 255)
  84. {
  85. activeChar.sendPacket(SystemMessageId.PETITION_MAX_CHARS_255);
  86. return;
  87. }
  88. int petitionId = PetitionManager.getInstance().submitPetition(activeChar, _content, _type);
  89. SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.PETITION_ACCEPTED_RECENT_NO_S1);
  90. sm.addInt(petitionId);
  91. activeChar.sendPacket(sm);
  92. sm = SystemMessage.getSystemMessage(SystemMessageId.SUBMITTED_YOU_S1_TH_PETITION_S2_LEFT);
  93. sm.addInt(totalPetitions);
  94. sm.addInt(Config.MAX_PETITIONS_PER_PLAYER - totalPetitions);
  95. activeChar.sendPacket(sm);
  96. sm = SystemMessage.getSystemMessage(SystemMessageId.S1_PETITION_ON_WAITING_LIST);
  97. sm.addInt(PetitionManager.getInstance().getPendingPetitionCount());
  98. activeChar.sendPacket(sm);
  99. }
  100. @Override
  101. public String getType()
  102. {
  103. return _C__89_RequestPetition;
  104. }
  105. }