Logout.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.logging.Logger;
  19. import net.sf.l2j.Config;
  20. import net.sf.l2j.L2DatabaseFactory;
  21. import net.sf.l2j.gameserver.Olympiad;
  22. import net.sf.l2j.gameserver.SevenSignsFestival;
  23. import net.sf.l2j.gameserver.communitybbs.Manager.RegionBBSManager;
  24. import net.sf.l2j.gameserver.datatables.SkillTable;
  25. import net.sf.l2j.gameserver.model.L2Party;
  26. import net.sf.l2j.gameserver.model.L2World;
  27. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  28. import net.sf.l2j.gameserver.model.entity.TvTEvent;
  29. import net.sf.l2j.gameserver.network.SystemMessageId;
  30. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  31. import net.sf.l2j.gameserver.serverpackets.FriendList;
  32. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  33. import net.sf.l2j.gameserver.taskmanager.AttackStanceTaskManager;
  34. /**
  35. * This class ...
  36. *
  37. * @version $Revision: 1.9.4.3 $ $Date: 2005/03/27 15:29:30 $
  38. */
  39. public final class Logout extends L2GameClientPacket
  40. {
  41. private static final String _C__09_LOGOUT = "[C] 09 Logout";
  42. private static Logger _log = Logger.getLogger(Logout.class.getName());
  43. @Override
  44. protected void readImpl()
  45. {
  46. }
  47. @Override
  48. protected void runImpl()
  49. {
  50. // Dont allow leaving if player is fighting
  51. L2PcInstance player = getClient().getActiveChar();
  52. if (player == null)
  53. return;
  54. player.getInventory().updateDatabase();
  55. if(AttackStanceTaskManager.getInstance().getAttackStanceTask(player))
  56. {
  57. if (Config.DEBUG) _log.fine("Player " + player.getName() + " tried to logout while fighting");
  58. player.sendPacket(new SystemMessage(SystemMessageId.CANT_LOGOUT_WHILE_FIGHTING));
  59. player.sendPacket(ActionFailed.STATIC_PACKET);
  60. return;
  61. }
  62. if(player.atEvent)
  63. {
  64. player.sendMessage("A superior power doesn't allow you to leave the event");
  65. return;
  66. }
  67. if (player.isInOlympiadMode() || Olympiad.getInstance().isRegistered(player))
  68. {
  69. player.sendMessage("You cant logout in olympiad mode");
  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. return;
  80. }
  81. L2Party playerParty = player.getParty();
  82. if (playerParty != null)
  83. player.getParty().broadcastToPartyMembers(SystemMessage.sendString(player.getName() + " has been removed from the upcoming festival."));
  84. }
  85. if (player.isFlying())
  86. {
  87. player.removeSkill(SkillTable.getInstance().getInfo(4289, 1));
  88. }
  89. TvTEvent.onLogout(player);
  90. RegionBBSManager.getInstance().changeCommunityBoard();
  91. player.deleteMe();
  92. notifyFriends(player);
  93. }
  94. private void notifyFriends(L2PcInstance cha)
  95. {
  96. java.sql.Connection con = null;
  97. try {
  98. con = L2DatabaseFactory.getInstance().getConnection();
  99. PreparedStatement statement;
  100. statement = con.prepareStatement("SELECT friend_name FROM character_friends WHERE charId=?");
  101. statement.setInt(1, cha.getObjectId());
  102. ResultSet rset = statement.executeQuery();
  103. L2PcInstance friend;
  104. String friendName;
  105. while (rset.next())
  106. {
  107. friendName = rset.getString("friend_name");
  108. friend = L2World.getInstance().getPlayer(friendName);
  109. if (friend != null) //friend logged in.
  110. {
  111. friend.sendPacket(new FriendList(friend));
  112. }
  113. }
  114. rset.close();
  115. statement.close();
  116. }
  117. catch (Exception e) {
  118. _log.warning("could not restore friend data:"+e);
  119. }
  120. finally {
  121. try {con.close();} catch (Exception e){}
  122. }
  123. }
  124. /* (non-Javadoc)
  125. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  126. */
  127. @Override
  128. public String getType()
  129. {
  130. return _C__09_LOGOUT;
  131. }
  132. }