CharacterSelect.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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.datatables.CharNameTable;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  23. import com.l2jserver.gameserver.network.serverpackets.CharSelected;
  24. import com.l2jserver.gameserver.network.serverpackets.SSQInfo;
  25. /**
  26. * This class ...
  27. *
  28. * @version $Revision: 1.5.2.1.2.5 $ $Date: 2005/03/27 15:29:30 $
  29. */
  30. public class CharacterSelect extends L2GameClientPacket
  31. {
  32. private static final String _C__0D_CHARACTERSELECT = "[C] 0D CharacterSelect";
  33. private static final Logger _log = Logger.getLogger(CharacterSelect.class.getName());
  34. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  35. // cd
  36. private int _charSlot;
  37. @SuppressWarnings("unused")
  38. private int _unk1; // new in C4
  39. @SuppressWarnings("unused")
  40. private int _unk2; // new in C4
  41. @SuppressWarnings("unused")
  42. private int _unk3; // new in C4
  43. @SuppressWarnings("unused")
  44. private int _unk4; // new in C4
  45. @Override
  46. protected void readImpl()
  47. {
  48. _charSlot = readD();
  49. _unk1 = readH();
  50. _unk2 = readD();
  51. _unk3 = readD();
  52. _unk4 = readD();
  53. }
  54. @Override
  55. protected void runImpl()
  56. {
  57. if (!getClient().getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterSelect"))
  58. return;
  59. // we should always be abble to acquire the lock
  60. // but if we cant lock then nothing should be done (ie repeated packet)
  61. if (this.getClient().getActiveCharLock().tryLock())
  62. {
  63. try
  64. {
  65. // should always be null
  66. // but if not then this is repeated packet and nothing should be done here
  67. if (this.getClient().getActiveChar() == null)
  68. {
  69. // The L2PcInstance must be created here, so that it can be attached to the L2GameClient
  70. if (Config.DEBUG)
  71. {
  72. _log.fine("selected slot:" + _charSlot);
  73. }
  74. //load up character from disk
  75. L2PcInstance cha = getClient().loadCharFromDisk(_charSlot);
  76. if (cha == null)
  77. return; // handled in L2GameClient
  78. if (cha.getAccessLevel().getLevel() < 0)
  79. {
  80. cha.logout();
  81. return;
  82. }
  83. CharNameTable.getInstance().addName(cha);
  84. cha.setClient(this.getClient());
  85. getClient().setActiveChar(cha);
  86. sendPacket(new SSQInfo());
  87. this.getClient().setState(GameClientState.IN_GAME);
  88. CharSelected cs = new CharSelected(cha, getClient().getSessionId().playOkID1);
  89. sendPacket(cs);
  90. }
  91. }
  92. finally
  93. {
  94. this.getClient().getActiveCharLock().unlock();
  95. }
  96. LogRecord record = new LogRecord(Level.INFO, "Logged in");
  97. record.setParameters(new Object[]{this.getClient()});
  98. _logAccounting.log(record);
  99. }
  100. }
  101. /* (non-Javadoc)
  102. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  103. */
  104. @Override
  105. public String getType()
  106. {
  107. return _C__0D_CHARACTERSELECT;
  108. }
  109. }