2
0

L2GameClientPacket.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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.nio.BufferUnderflowException;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import org.mmocore.network.ReceivablePacket;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.network.L2GameClient;
  23. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  24. /**
  25. * Packets received by the game server from clients
  26. * @author KenM
  27. */
  28. public abstract class L2GameClientPacket extends ReceivablePacket<L2GameClient>
  29. {
  30. protected static final Logger _log = Logger.getLogger(L2GameClientPacket.class.getName());
  31. @Override
  32. public boolean read()
  33. {
  34. //_log.info(this.getType());
  35. try
  36. {
  37. readImpl();
  38. return true;
  39. }
  40. catch (Exception e)
  41. {
  42. _log.log(Level.SEVERE, "Client: " + getClient().toString() + " - Failed reading: " + getType() + " - L2J Server Version: " + Config.SERVER_VERSION + " - DP Revision: " + Config.DATAPACK_VERSION + " ; " + e.getMessage(), e);
  43. if (e instanceof BufferUnderflowException) // only one allowed per client per minute
  44. getClient().onBufferUnderflow();
  45. }
  46. return false;
  47. }
  48. protected abstract void readImpl();
  49. @Override
  50. public void run()
  51. {
  52. try
  53. {
  54. runImpl();
  55. /* Removes onspawn protection - player has faster computer than average
  56. * Since GE: True for all packets
  57. * except RequestItemList and UseItem (in case the item is a Scroll of Escape (736)
  58. */
  59. if (triggersOnActionRequest())
  60. {
  61. final L2PcInstance actor = getClient().getActiveChar();
  62. if(actor != null && (actor.isSpawnProtected() || actor.isInvul()))
  63. {
  64. actor.onActionRequest();
  65. if (Config.DEBUG)
  66. _log.info("Spawn protection for player " + actor.getName() + " removed by packet: " + getType());
  67. }
  68. }
  69. cleanUp();
  70. }
  71. catch (Throwable t)
  72. {
  73. _log.log(Level.SEVERE, "Client: " + getClient().toString() + " - Failed running: " + getType() + " - L2J Server Version: " + Config.SERVER_VERSION + " - DP Revision: " + Config.DATAPACK_VERSION + " ; " + t.getMessage(), t);
  74. // in case of EnterWorld error kick player from game
  75. if (this instanceof EnterWorld)
  76. getClient().closeNow();
  77. }
  78. }
  79. protected abstract void runImpl();
  80. protected final void sendPacket(L2GameServerPacket gsp)
  81. {
  82. getClient().sendPacket(gsp);
  83. }
  84. /**
  85. * @return A String with this packet name for debuging purposes
  86. */
  87. public abstract String getType();
  88. /**
  89. * Overriden with true value on some packets that should disable spawn protection
  90. * (RequestItemList and UseItem only)
  91. */
  92. protected boolean triggersOnActionRequest()
  93. {
  94. return true;
  95. }
  96. protected void cleanUp()
  97. {}
  98. }