CharacterSelect.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * Copyright © 2004-2019 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 static com.l2jserver.gameserver.network.L2GameClient.GameClientState.JOINING;
  21. import java.util.logging.Level;
  22. import java.util.logging.LogRecord;
  23. import java.util.logging.Logger;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.data.sql.impl.CharNameTable;
  26. import com.l2jserver.gameserver.data.xml.impl.SecondaryAuthData;
  27. import com.l2jserver.gameserver.instancemanager.AntiFeedManager;
  28. import com.l2jserver.gameserver.instancemanager.PunishmentManager;
  29. import com.l2jserver.gameserver.model.CharSelectInfoPackage;
  30. import com.l2jserver.gameserver.model.L2World;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.model.events.Containers;
  33. import com.l2jserver.gameserver.model.events.EventDispatcher;
  34. import com.l2jserver.gameserver.model.events.impl.character.player.OnPlayerSelect;
  35. import com.l2jserver.gameserver.model.events.returns.TerminateReturn;
  36. import com.l2jserver.gameserver.model.punishment.PunishmentAffect;
  37. import com.l2jserver.gameserver.model.punishment.PunishmentType;
  38. import com.l2jserver.gameserver.network.L2GameClient;
  39. import com.l2jserver.gameserver.network.serverpackets.CharSelected;
  40. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  41. import com.l2jserver.gameserver.network.serverpackets.SSQInfo;
  42. import com.l2jserver.gameserver.network.serverpackets.ServerClose;
  43. public class CharacterSelect extends L2GameClientPacket {
  44. private static final String _C__12_CHARACTERSELECT = "[C] 12 CharacterSelect";
  45. protected static final Logger _logAccounting = Logger.getLogger("accounting");
  46. // cd
  47. private int _charSlot;
  48. @SuppressWarnings("unused")
  49. private int _unk1; // new in C4
  50. @SuppressWarnings("unused")
  51. private int _unk2; // new in C4
  52. @SuppressWarnings("unused")
  53. private int _unk3; // new in C4
  54. @SuppressWarnings("unused")
  55. private int _unk4; // new in C4
  56. @Override
  57. protected void readImpl() {
  58. _charSlot = readD();
  59. _unk1 = readH();
  60. _unk2 = readD();
  61. _unk3 = readD();
  62. _unk4 = readD();
  63. }
  64. @Override
  65. protected void runImpl() {
  66. final L2GameClient client = getClient();
  67. if (!client.getFloodProtectors().getCharacterSelect().tryPerformAction("CharacterSelect")) {
  68. return;
  69. }
  70. if (SecondaryAuthData.getInstance().isEnabled() && !client.getSecondaryAuth().isAuthed()) {
  71. client.getSecondaryAuth().openDialog();
  72. return;
  73. }
  74. // We should always be able to acquire the lock
  75. // But if we can't lock then nothing should be done (i.e. repeated packet)
  76. if (client.getActiveCharLock().tryLock()) {
  77. try {
  78. // should always be null
  79. // but if not then this is repeated packet and nothing should be done here
  80. if (client.getActiveChar() == null) {
  81. final CharSelectInfoPackage info = client.getCharSelection(_charSlot);
  82. if (info == null) {
  83. return;
  84. }
  85. // Banned?
  86. if (PunishmentManager.getInstance().hasPunishment(info.getObjectId(), PunishmentAffect.CHARACTER, PunishmentType.BAN) || PunishmentManager.getInstance().hasPunishment(client.getAccountName(), PunishmentAffect.ACCOUNT, PunishmentType.BAN)
  87. || PunishmentManager.getInstance().hasPunishment(client.getConnectionAddress().getHostAddress(), PunishmentAffect.IP, PunishmentType.BAN)) {
  88. client.close(ServerClose.STATIC_PACKET);
  89. return;
  90. }
  91. // Selected character is banned (compatibility with previous versions).
  92. if (info.getAccessLevel() < 0) {
  93. client.close(ServerClose.STATIC_PACKET);
  94. return;
  95. }
  96. 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)) {
  97. final NpcHtmlMessage msg = new NpcHtmlMessage();
  98. msg.setFile(info.getHtmlPrefix(), "data/html/mods/IPRestriction.htm");
  99. msg.replace("%max%", String.valueOf(AntiFeedManager.getInstance().getLimit(client, Config.L2JMOD_DUALBOX_CHECK_MAX_PLAYERS_PER_IP)));
  100. client.sendPacket(msg);
  101. return;
  102. }
  103. // The L2PcInstance must be created here, so that it can be attached to the L2GameClient
  104. if (Config.DEBUG) {
  105. _log.fine("selected slot:" + _charSlot);
  106. }
  107. // load up character from disk
  108. final L2PcInstance cha = client.loadCharFromDisk(_charSlot);
  109. if (cha == null) {
  110. return; // handled in L2GameClient
  111. }
  112. L2World.getInstance().addPlayerToWorld(cha);
  113. CharNameTable.getInstance().addName(cha);
  114. cha.setClient(client);
  115. client.setActiveChar(cha);
  116. cha.setOnlineStatus(true, true);
  117. final TerminateReturn terminate = EventDispatcher.getInstance().notifyEvent(new OnPlayerSelect(cha, cha.getObjectId(), cha.getName(), getClient()), Containers.Players(), TerminateReturn.class);
  118. if ((terminate != null) && terminate.terminate()) {
  119. cha.deleteMe();
  120. return;
  121. }
  122. sendPacket(new SSQInfo());
  123. client.setState(JOINING);
  124. CharSelected cs = new CharSelected(cha, client.getSessionId().playOkID1);
  125. sendPacket(cs);
  126. }
  127. }
  128. finally {
  129. client.getActiveCharLock().unlock();
  130. }
  131. LogRecord record = new LogRecord(Level.INFO, "Logged in");
  132. record.setParameters(new Object[] {
  133. client
  134. });
  135. _logAccounting.log(record);
  136. }
  137. }
  138. @Override
  139. public String getType() {
  140. return _C__12_CHARACTERSELECT;
  141. }
  142. }