ProtocolVersion.java 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.serverpackets.KeyPacket;
  19. /**
  20. * This class ...
  21. *
  22. * @version $Revision: 1.5.2.8.2.8 $ $Date: 2005/04/02 10:43:04 $
  23. */
  24. public final class ProtocolVersion extends L2GameClientPacket
  25. {
  26. private static final String _C__00_PROTOCOLVERSION = "[C] 00 ProtocolVersion";
  27. static Logger _log = Logger.getLogger(ProtocolVersion.class.getName());
  28. private int _version;
  29. @Override
  30. protected void readImpl()
  31. {
  32. _version = readD();
  33. }
  34. @Override
  35. protected void runImpl()
  36. {
  37. // this packet is never encrypted
  38. if (_version == -2)
  39. {
  40. if (Config.DEBUG) _log.info("Ping received");
  41. // this is just a ping attempt from the new C2 client
  42. getClient().closeNow();
  43. }
  44. else if (_version < Config.MIN_PROTOCOL_REVISION || _version > Config.MAX_PROTOCOL_REVISION)
  45. {
  46. _log.info("Client: "+getClient().toString()+" -> Protocol Revision: " + _version + " is invalid. Minimum is "+Config.MIN_PROTOCOL_REVISION+" and Maximum is "+Config.MAX_PROTOCOL_REVISION+" are supported. Closing connection.");
  47. _log.warning("Wrong Protocol Version "+_version);
  48. getClient().closeNow();
  49. }
  50. else
  51. {
  52. if (Config.DEBUG)
  53. {
  54. _log.fine("Client Protocol Revision is ok: "+_version);
  55. }
  56. KeyPacket pk = new KeyPacket(getClient().enableCrypt());
  57. getClient().sendPacket(pk);
  58. }
  59. }
  60. /* (non-Javadoc)
  61. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  62. */
  63. @Override
  64. public String getType()
  65. {
  66. return _C__00_PROTOCOLVERSION;
  67. }
  68. }