CharacterSelect.java 4.7 KB

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