RequestRestart.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 java.util.logging.Level;
  17. import java.util.logging.LogRecord;
  18. import java.util.logging.Logger;
  19. import com.l2jserver.Config;
  20. import com.l2jserver.gameserver.SevenSignsFestival;
  21. import com.l2jserver.gameserver.model.L2Party;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.L2GameClient;
  24. import com.l2jserver.gameserver.network.SystemMessageId;
  25. import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  26. import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
  27. import com.l2jserver.gameserver.network.serverpackets.RestartResponse;
  28. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  29. import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
  30. /**
  31. * This class ...
  32. *
  33. * @version $Revision: 1.11.2.1.2.4 $ $Date: 2005/03/27 15:29:30 $
  34. */
  35. public final class RequestRestart extends L2GameClientPacket
  36. {
  37. private static final String _C__46_REQUESTRESTART = "[C] 46 RequestRestart";
  38. private static final Logger _log = Logger.getLogger(RequestRestart.class.getName());
  39. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  40. @Override
  41. protected void readImpl()
  42. {
  43. // trigger
  44. }
  45. @Override
  46. protected void runImpl()
  47. {
  48. final L2PcInstance player = getClient().getActiveChar();
  49. if (player == null)
  50. return;
  51. if(player.getActiveEnchantItem() != null || player.getActiveEnchantAttrItem() != null)
  52. {
  53. sendPacket(RestartResponse.valueOf(false));
  54. return;
  55. }
  56. if (player.isLocked())
  57. {
  58. _log.warning("Player " + player.getName() + " tried to restart during class change.");
  59. sendPacket(RestartResponse.valueOf(false));
  60. return;
  61. }
  62. if (player.getPrivateStoreType() != 0)
  63. {
  64. player.sendMessage("Cannot restart while trading");
  65. sendPacket(RestartResponse.valueOf(false));
  66. return;
  67. }
  68. if (player.getActiveRequester() != null)
  69. {
  70. player.getActiveRequester().onTradeCancel(player);
  71. player.onTradeCancel(player.getActiveRequester());
  72. }
  73. if (AttackStanceTaskManager.getInstance().getAttackStanceTask(player) && !(player.isGM() && Config.GM_RESTART_FIGHTING))
  74. {
  75. if (Config.DEBUG)
  76. _log.fine("Player " + player.getName() + " tried to logout while fighting.");
  77. player.sendPacket(new SystemMessage(SystemMessageId.CANT_RESTART_WHILE_FIGHTING));
  78. sendPacket(RestartResponse.valueOf(false));
  79. return;
  80. }
  81. // Prevent player from restarting if they are a festival participant
  82. // and it is in progress, otherwise notify party members that the player
  83. // is not longer a participant.
  84. if (player.isFestivalParticipant())
  85. {
  86. if (SevenSignsFestival.getInstance().isFestivalInitialized())
  87. {
  88. player.sendMessage("You cannot restart while you are a participant in a festival.");
  89. sendPacket(RestartResponse.valueOf(false));
  90. return;
  91. }
  92. final L2Party playerParty = player.getParty();
  93. if (playerParty != null)
  94. player.getParty().broadcastToPartyMembers(SystemMessage.sendString(player.getName() + " has been removed from the upcoming festival."));
  95. }
  96. final L2GameClient client = getClient();
  97. LogRecord record = new LogRecord(Level.INFO, "Logged out");
  98. record.setParameters(new Object[]{client});
  99. _logAccounting.log(record);
  100. // detach the client from the char so that the connection isnt closed in the deleteMe
  101. player.setClient(null);
  102. player.logout();
  103. getClient().setActiveChar(null);
  104. // return the client to the authed status
  105. client.setState(GameClientState.AUTHED);
  106. sendPacket(RestartResponse.valueOf(true));
  107. // send char list
  108. final CharSelectionInfo cl = new CharSelectionInfo(client.getAccountName(), client.getSessionId().playOkID1);
  109. sendPacket(cl);
  110. client.setCharSelection(cl.getCharInfo());
  111. }
  112. /* (non-Javadoc)
  113. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  114. */
  115. @Override
  116. public String getType()
  117. {
  118. return _C__46_REQUESTRESTART;
  119. }
  120. }