RequestAnswerJoinAlly.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 net.sf.l2j.gameserver.model.L2Clan;
  17. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  18. import net.sf.l2j.gameserver.network.SystemMessageId;
  19. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  20. /**
  21. * sample
  22. * 5F
  23. * 01 00 00 00
  24. *
  25. * format cdd
  26. *
  27. *
  28. * @version $Revision: 1.7.4.2 $ $Date: 2005/03/27 15:29:30 $
  29. */
  30. public final class RequestAnswerJoinAlly extends L2GameClientPacket
  31. {
  32. private static final String _C__83_REQUESTANSWERJOINALLY = "[C] 83 RequestAnswerJoinAlly";
  33. //private static Logger _log = Logger.getLogger(RequestAnswerJoinAlly.class.getName());
  34. private int _response;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _response = readD();
  39. }
  40. @Override
  41. protected void runImpl()
  42. {
  43. L2PcInstance activeChar = getClient().getActiveChar();
  44. if (activeChar == null)
  45. {
  46. return;
  47. }
  48. L2PcInstance requestor = activeChar.getRequest().getPartner();
  49. if (requestor == null)
  50. {
  51. return;
  52. }
  53. if (_response == 0)
  54. {
  55. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_DID_NOT_RESPOND_TO_ALLY_INVITATION));
  56. requestor.sendPacket(new SystemMessage(SystemMessageId.NO_RESPONSE_TO_ALLY_INVITATION));
  57. }
  58. else
  59. {
  60. if (!(requestor.getRequest().getRequestPacket() instanceof RequestJoinAlly))
  61. {
  62. return; // hax
  63. }
  64. L2Clan clan = requestor.getClan();
  65. // we must double check this cause of hack
  66. if (clan.checkAllyJoinCondition(requestor, activeChar))
  67. {
  68. //TODO: Need correct message id
  69. requestor.sendPacket(new SystemMessage(SystemMessageId.YOU_HAVE_SUCCEEDED_INVITING_FRIEND));
  70. activeChar.sendPacket(new SystemMessage(SystemMessageId.YOU_ACCEPTED_ALLIANCE));
  71. activeChar.getClan().setAllyId(clan.getAllyId());
  72. activeChar.getClan().setAllyName(clan.getAllyName());
  73. activeChar.getClan().setAllyPenaltyExpiryTime(0, 0);
  74. activeChar.getClan().setAllyCrestId(clan.getAllyCrestId());
  75. activeChar.getClan().updateClanInDB();
  76. }
  77. }
  78. activeChar.getRequest().onRequestResponse();
  79. }
  80. /* (non-Javadoc)
  81. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  82. */
  83. @Override
  84. public String getType()
  85. {
  86. return _C__83_REQUESTANSWERJOINALLY;
  87. }
  88. }