RequestAnswerJoinAlly.java 3.5 KB

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