Logout.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.entity.L2Event;
  27. import com.l2jserver.gameserver.network.SystemMessageId;
  28. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  29. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. import com.l2jserver.gameserver.taskmanager.AttackStanceTaskManager;
  31. /**
  32. * This class ...
  33. * @version $Revision: 1.9.4.3 $ $Date: 2005/03/27 15:29:30 $
  34. */
  35. public final class Logout extends L2GameClientPacket
  36. {
  37. private static final String _C__00_LOGOUT = "[C] 00 Logout";
  38. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  39. @Override
  40. protected void readImpl()
  41. {
  42. }
  43. @Override
  44. protected void runImpl()
  45. {
  46. final L2PcInstance player = getClient().getActiveChar();
  47. if (player == null)
  48. {
  49. return;
  50. }
  51. if ((player.getActiveEnchantItemId() != L2PcInstance.ID_NONE) || (player.getActiveEnchantAttrItemId() != L2PcInstance.ID_NONE))
  52. {
  53. if (Config.DEBUG)
  54. {
  55. _log.fine("Player " + player.getName() + " tried to logout while enchanting.");
  56. }
  57. player.sendPacket(ActionFailed.STATIC_PACKET);
  58. return;
  59. }
  60. if (player.isLocked())
  61. {
  62. _log.warning("Player " + player.getName() + " tried to logout during class change.");
  63. player.sendPacket(ActionFailed.STATIC_PACKET);
  64. return;
  65. }
  66. // Don't allow leaving if player is fighting
  67. if (AttackStanceTaskManager.getInstance().hasAttackStanceTask(player))
  68. {
  69. if (player.isGM() && Config.GM_RESTART_FIGHTING)
  70. {
  71. return;
  72. }
  73. if (Config.DEBUG)
  74. {
  75. _log.fine("Player " + player.getName() + " tried to logout while fighting.");
  76. }
  77. player.sendPacket(SystemMessageId.CANT_LOGOUT_WHILE_FIGHTING);
  78. player.sendPacket(ActionFailed.STATIC_PACKET);
  79. return;
  80. }
  81. if (L2Event.isParticipant(player))
  82. {
  83. player.sendMessage("A superior power doesn't allow you to leave the event.");
  84. player.sendPacket(ActionFailed.STATIC_PACKET);
  85. return;
  86. }
  87. // Prevent player from logging out if they are a festival participant
  88. // and it is in progress, otherwise notify party members that the player
  89. // is not longer a participant.
  90. if (player.isFestivalParticipant())
  91. {
  92. if (SevenSignsFestival.getInstance().isFestivalInitialized())
  93. {
  94. player.sendMessage("You cannot log out while you are a participant in a Festival.");
  95. player.sendPacket(ActionFailed.STATIC_PACKET);
  96. return;
  97. }
  98. if (player.isInParty())
  99. {
  100. player.getParty().broadcastPacket(SystemMessage.sendString(player.getName() + " has been removed from the upcoming Festival."));
  101. }
  102. }
  103. // Remove player from Boss Zone
  104. player.removeFromBossZone();
  105. LogRecord record = new LogRecord(Level.INFO, "Disconnected");
  106. record.setParameters(new Object[]
  107. {
  108. getClient()
  109. });
  110. _logAccounting.log(record);
  111. player.logout();
  112. }
  113. @Override
  114. public String getType()
  115. {
  116. return _C__00_LOGOUT;
  117. }
  118. }