RequestRestart.java 4.8 KB

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