CharacterSelect.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J Server is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.l2jserver.gameserver.network.clientpackets;
  20. import java.util.logging.Level;
  21. import java.util.logging.LogRecord;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
  25. import com.l2jserver.gameserver.data.xml.impl.SecondaryAuthData;
  26. import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
  27. import com.l2jserver.gameserver.instancemanager.PunishmentManager;
  28. import com.l2jserver.gameserver.model.CharSelectInfoPackage;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.events.Containers;
  31. import com.l2jserver.gameserver.model.events.EventDispatcher;
  32. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSelect;
  33. import com.l2jserver.gameserver.model.events.returns.TerminateReturn;
  34. import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
  35. import com.l2jserver.gameserver.model.punishment.PunishmentType;
  36. import com.l2jserver.gameserver.network.L2GameClient;
  37. import com.l2jserver.gameserver.network.L2GameClient.GameClientState;
  38. import com.l2jserver.gameserver.network.serverpackets.CharSelected;
  39. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  40. import com.l2jserver.gameserver.network.serverpackets.SSQInfo;
  41. import com.l2jserver.gameserver.network.serverpackets.ServerClose;
  42. /**
  43. * This class ...
  44. * @version $Revision: 1.5.2.1.2.5 $ $Date: 2005/03/27 15:29:30 $
  45. */
  46. public class CharacterSelect extends L2GameClientPacket
  47. {
  48. private static final String _C__12_CHARACTERSELECT = "[C] 12 CharacterSelect";
  49. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  50. // cd
  51. private int _charSlot;
  52. @SuppressWarnings("unused")
  53. private int _unk1; // new in C4
  54. @SuppressWarnings("unused")
  55. private int _unk2; // new in C4
  56. @SuppressWarnings("unused")
  57. private int _unk3; // new in C4
  58. @SuppressWarnings("unused")
  59. private int _unk4; // new in C4
  60. @Override
  61. protected void readImpl()
  62. {
  63. _charSlot = readD();
  64. _unk1 = readH();
  65. _unk2 = readD();
  66. _unk3 = readD();
  67. _unk4 = readD();
  68. }
  69. @Override
  70. protected void runImpl()
  71. {
  72. final L2GameClient client = getClient();
  73. if (!client.getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterSelect"))
  74. {
  75. return;
  76. }
  77. if (SecondaryAuthData.getInstance().isEnabled() && !client.getSecondaryAuth().isAuthed())
  78. {
  79. client.getSecondaryAuth().openDialog();
  80. return;
  81. }
  82. // We should always be able to acquire the lock
  83. // But if we can't lock then nothing should be done (i.e. repeated packet)
  84. if (client.getActiveCharLock().tryLock())
  85. {
  86. try
  87. {
  88. // should always be null
  89. // but if not then this is repeated packet and nothing should be done here
  90. if (client.getActiveChar() == null)
  91. {
  92. final CharSelectInfoPackage info = client.getCharSelection(_charSlot);
  93. if (info == null)
  94. {
  95. return;
  96. }
  97. // Banned?
  98. if (PunishmentManager.getInstance().hasPunishment(info.getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.BAN) || PunishmentManager.getInstance().hasPunishment(client.getAccountName(), PunishmentAffect.ACCOUNT, PunishmentType.BAN) || PunishmentManager.getInstance().hasPunishment(client.getConnectionAddress().getHostAddress(), PunishmentAffect.IP, PunishmentType.BAN))
  99. {
  100. client.close(ServerClose.STATIC_PACKET);
  101. return;
  102. }
  103. // Selected character is banned (compatibility with previous versions).
  104. if (info.getAccessLevel() < 0)
  105. {
  106. client.close(ServerClose.STATIC_PACKET);
  107. return;
  108. }
  109. if ((Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP > 0) && !AntiFeedManager.getInstance().tryAddClient(AntiFeedManager.GAME_ID, client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP))
  110. {
  111. final NpcHtmlMessage msg = new NpcHtmlMessage();
  112. msg.setFile(info.getHtmlPrefix(), "data/html/mods/IPRestriction.htm");
  113. msg.replace("%max%", String.valueOf(AntiFeedManager.getInstance().getLimit(client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP)));
  114. client.sendPacket(msg);
  115. return;
  116. }
  117. // The L2PcInstance must be created here, so that it can be attached to the L2GameClient
  118. if (Config.DEBUG)
  119. {
  120. _log.fine("selected slot:" + _charSlot);
  121. }
  122. // load up character from disk
  123. final L2PcInstance cha = client.loadCharFromDisk(_charSlot);
  124. if (cha == null)
  125. {
  126. return; // handled in L2GameClient
  127. }
  128. CharNameTable.getInstance().addName(cha);
  129. cha.setClient(client);
  130. client.setActiveChar(cha);
  131. cha.setOnlineStatus(true, true);
  132. final TerminateReturn terminate = EventDispatcher.getInstance().notifyEvent(new OnPlayerSelect(cha, cha.getObjectId(), cha.getName(), getClient()), Containers.Players(), TerminateReturn.class);
  133. if ((terminate != null) && terminate.terminate())
  134. {
  135. cha.deleteMe();
  136. return;
  137. }
  138. sendPacket(new SSQInfo());
  139. client.setState(GameClientState.IN_GAME);
  140. CharSelected cs = new CharSelected(cha, client.getSessionId().playOkID1);
  141. sendPacket(cs);
  142. }
  143. }
  144. finally
  145. {
  146. client.getActiveCharLock().unlock();
  147. }
  148. LogRecord record = new LogRecord(Level.INFO, "Logged in");
  149. record.setParameters(new Object[]
  150. {
  151. client
  152. });
  153. _logAccounting.log(record);
  154. }
  155. }
  156. @Override
  157. public String getType()
  158. {
  159. return _C__12_CHARACTERSELECT;
  160. }
  161. }