2
0

CharacterSelect.java 4.0 KB

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