ProtocolVersion.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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.network.serverpackets.KeyPacket;
  25. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  26. /**
  27. * This class ...
  28. * @version $Revision: 1.5.2.8.2.8 $ $Date: 2005/04/02 10:43:04 $
  29. */
  30. public final class ProtocolVersion extends L2GameClientPacket
  31. {
  32. private static final String _C__0E_PROTOCOLVERSION = "[C] 0E ProtocolVersion";
  33. private static final Logger _logAccounting = Logger.getLogger("accounting");
  34. private int _version;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _version = readD();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. // this packet is never encrypted
  44. if (_version == -2)
  45. {
  46. if (Config.DEBUG)
  47. {
  48. _log.info("Ping received");
  49. }
  50. // this is just a ping attempt from the new C2 client
  51. getClient().close((L2GameServerPacket) null);
  52. }
  53. else if (!Config.PROTOCOL_LIST.contains(_version))
  54. {
  55. LogRecord record = new LogRecord(Level.WARNING, "Wrong protocol");
  56. record.setParameters(new Object[]
  57. {
  58. _version,
  59. getClient()
  60. });
  61. _logAccounting.log(record);
  62. KeyPacket pk = new KeyPacket(getClient().enableCrypt(), 0);
  63. getClient().setProtocolOk(false);
  64. getClient().close(pk);
  65. }
  66. else
  67. {
  68. if (Config.DEBUG)
  69. {
  70. _log.fine("Client Protocol Revision is ok: " + _version);
  71. }
  72. KeyPacket pk = new KeyPacket(getClient().enableCrypt(), 1);
  73. getClient().sendPacket(pk);
  74. getClient().setProtocolOk(true);
  75. }
  76. }
  77. @Override
  78. public String getType()
  79. {
  80. return _C__0E_PROTOCOLVERSION;
  81. }
  82. }