Logout.java 4.2 KB

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