2
0

ProtocolVersion.java 2.5 KB

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