RequestRestart.java 4.5 KB

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