SessionKey.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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.loginserver;
  16. import com.l2jserver.Config;
  17. /**
  18. * <p>
  19. * This class is used to represent session keys used by the client to authenticate in the gameserver
  20. * </p>
  21. * <p>
  22. * A SessionKey is made up of two 8 bytes keys. One is send in the {@link com.l2jserver.loginserver.network.serverpackets.LoginOk#LoginOk} packet and the other is sent in {@link com.l2jserver.loginserver.network.serverpackets.PlayOk#PlayOk}
  23. * </p>
  24. * @author -Wooden-
  25. */
  26. public class SessionKey
  27. {
  28. public int playOkID1;
  29. public int playOkID2;
  30. public int loginOkID1;
  31. public int loginOkID2;
  32. public SessionKey(int loginOK1, int loginOK2, int playOK1, int playOK2)
  33. {
  34. playOkID1 = playOK1;
  35. playOkID2 = playOK2;
  36. loginOkID1 = loginOK1;
  37. loginOkID2 = loginOK2;
  38. }
  39. @Override
  40. public String toString()
  41. {
  42. return "PlayOk: " + playOkID1 + " " + playOkID2 + " LoginOk:" + loginOkID1 + " " + loginOkID2;
  43. }
  44. public boolean checkLoginPair(int loginOk1, int loginOk2)
  45. {
  46. return (loginOkID1 == loginOk1) && (loginOkID2 == loginOk2);
  47. }
  48. /**
  49. * Only checks the PlayOk part of the session key if server doesn't show the license when player logs in.
  50. * @param o
  51. * @return true if keys are equal.
  52. */
  53. @Override
  54. public boolean equals(Object o)
  55. {
  56. if (this == o)
  57. {
  58. return true;
  59. }
  60. if (!(o instanceof SessionKey))
  61. {
  62. return false;
  63. }
  64. final SessionKey key = (SessionKey) o;
  65. // when server doesn't show license it doesn't send the LoginOk packet, client doesn't have this part of the key then.
  66. if (Config.SHOW_LICENCE)
  67. {
  68. return ((playOkID1 == key.playOkID1) && (loginOkID1 == key.loginOkID1) && (playOkID2 == key.playOkID2) && (loginOkID2 == key.loginOkID2));
  69. }
  70. return ((playOkID1 == key.playOkID1) && (playOkID2 == key.playOkID2));
  71. }
  72. }