ProtocolVersion.java 2.4 KB

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