L2GameServerPacket.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 net.sf.l2j.gameserver.serverpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.network.L2GameClient;
  19. import org.mmocore.network.SendablePacket;
  20. /**
  21. *
  22. * @author KenM
  23. */
  24. public abstract class L2GameServerPacket extends SendablePacket<L2GameClient>
  25. {
  26. private static final Logger _log = Logger.getLogger(L2GameServerPacket.class.getName());
  27. /**
  28. * @see com.l2jserver.mmocore.network.SendablePacket#write()
  29. */
  30. @Override
  31. protected void write()
  32. {
  33. try
  34. {
  35. //_log.info(this.getType());
  36. writeImpl();
  37. }
  38. catch (Throwable t)
  39. {
  40. _log.severe("Client: "+getClient().toString()+" - Failed writing: "+getType()+" - L2J Server Version: "+Config.SERVER_VERSION+" - DP Revision: "+Config.DATAPACK_VERSION);
  41. t.printStackTrace();
  42. }
  43. }
  44. public void runImpl()
  45. {
  46. }
  47. protected abstract void writeImpl();
  48. /**
  49. * @return A String with this packet name for debuging purposes
  50. */
  51. public abstract String getType();
  52. /**
  53. * @see org.mmocore.network.SendablePacket#getHeaderSize()
  54. */
  55. @Override
  56. protected int getHeaderSize()
  57. {
  58. return 2;
  59. }
  60. /**
  61. * @see org.mmocore.network.SendablePacket#writeHeader(int)
  62. */
  63. @Override
  64. protected void writeHeader(int dataSize)
  65. {
  66. writeH(dataSize + this.getHeaderSize());
  67. }
  68. }