RequestRestart.java 4.7 KB

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