RequestPetition.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.network.clientpackets;
  16. import com.l2jserver.Config;
  17. import com.l2jserver.gameserver.GmListTable;
  18. import com.l2jserver.gameserver.instancemanager.PetitionManager;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.SystemMessageId;
  21. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  22. /**
  23. * <p>Format: (c) Sd
  24. * <ul>
  25. * <li>S: content</li>
  26. * <li>d: type</li>
  27. * </ul></p>
  28. * @author -Wooden-, TempyIncursion
  29. *
  30. */
  31. public final class RequestPetition extends L2GameClientPacket
  32. {
  33. private static final String _C__7F_RequestPetition = "[C] 7F RequestPetition";
  34. //private static Logger _log = Logger.getLogger(RequestPetition.class.getName());
  35. private String _content;
  36. private int _type; // 1 = on : 0 = off;
  37. @Override
  38. protected void readImpl()
  39. {
  40. _content = readS();
  41. _type = readD();
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. L2PcInstance activeChar = getClient().getActiveChar();
  47. if (activeChar == null)
  48. return;
  49. if (!GmListTable.getInstance().isGmOnline(false))
  50. {
  51. activeChar.sendPacket(new SystemMessage(SystemMessageId.NO_GM_PROVIDING_SERVICE_NOW));
  52. return;
  53. }
  54. if (!PetitionManager.getInstance().isPetitioningAllowed())
  55. {
  56. activeChar.sendPacket(new SystemMessage(SystemMessageId.GAME_CLIENT_UNABLE_TO_CONNECT_TO_PETITION_SERVER));
  57. return;
  58. }
  59. if (PetitionManager.getInstance().isPlayerPetitionPending(activeChar))
  60. {
  61. activeChar.sendPacket(new SystemMessage(SystemMessageId.ONLY_ONE_ACTIVE_PETITION_AT_TIME));
  62. return;
  63. }
  64. if (PetitionManager.getInstance().getPendingPetitionCount() == Config.MAX_PETITIONS_PENDING)
  65. {
  66. activeChar.sendPacket(new SystemMessage(SystemMessageId.PETITION_SYSTEM_CURRENT_UNAVAILABLE));
  67. return;
  68. }
  69. int totalPetitions = PetitionManager.getInstance().getPlayerTotalPetitionCount(activeChar) + 1;
  70. if (totalPetitions > Config.MAX_PETITIONS_PER_PLAYER)
  71. {
  72. SystemMessage sm = new SystemMessage(SystemMessageId.WE_HAVE_RECEIVED_S1_PETITIONS_TODAY);
  73. sm.addNumber(totalPetitions);
  74. activeChar.sendPacket(sm);
  75. sm = null;
  76. return;
  77. }
  78. if (_content.length() > 255)
  79. {
  80. activeChar.sendPacket(new SystemMessage(SystemMessageId.PETITION_MAX_CHARS_255));
  81. return;
  82. }
  83. int petitionId = PetitionManager.getInstance().submitPetition(activeChar, _content, _type);
  84. SystemMessage sm = new SystemMessage(SystemMessageId.PETITION_ACCEPTED_RECENT_NO_S1);
  85. sm.addNumber(petitionId);
  86. activeChar.sendPacket(sm);
  87. sm = new SystemMessage(SystemMessageId.SUBMITTED_YOU_S1_TH_PETITION_S2_LEFT);
  88. sm.addNumber(totalPetitions);
  89. sm.addNumber(Config.MAX_PETITIONS_PER_PLAYER - totalPetitions);
  90. activeChar.sendPacket(sm);
  91. sm = new SystemMessage(SystemMessageId.S1_PETITION_ON_WAITING_LIST);
  92. sm.addNumber(PetitionManager.getInstance().getPendingPetitionCount());
  93. activeChar.sendPacket(sm);
  94. sm = null;
  95. }
  96. /* (non-Javadoc)
  97. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  98. */
  99. @Override
  100. public String getType()
  101. {
  102. return _C__7F_RequestPetition;
  103. }
  104. }