private void OnJoinAllianceUsingInvitationMessageReceived(JoinAllianceUsingInvitationMessage message) { if (this.CanJoinAlliance()) { ServerRequestManager.Create(new LoadAvatarStreamRequestMessage { Id = message.GetAvatarStreamEntryId() }, ServerManager.GetDocumentSocket(11, this.m_session.AccountId), 5).OnComplete = args => { if (this.m_session.IsDestructed()) { return; } if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success) { LoadAvatarStreamResponseMessage responseMessage = (LoadAvatarStreamResponseMessage)args.ResponseMessage; AllianceInvitationAvatarStreamEntry allianceInvitationAvatarStreamEntry = (AllianceInvitationAvatarStreamEntry)responseMessage.Entry; LogicLong allianceId = allianceInvitationAvatarStreamEntry.GetAllianceId(); ServerRequestManager.Create(new GameJoinAllianceRequestMessage { AccountId = this.m_session.AccountId, AllianceId = allianceId, AvatarStreamId = allianceInvitationAvatarStreamEntry.GetId(), Invited = true }, ServerManager.GetDocumentSocket(9, this.m_session.AccountId)).OnComplete = this.OnGameAllianceJoin; } else { AllianceJoinFailedMessage allianceJoinFailedMessage = new AllianceJoinFailedMessage(); allianceJoinFailedMessage.SetReason(AllianceJoinFailedMessage.Reason.ALREADY_IN_ALLIANCE); this.m_session.SendPiranhaMessage(allianceJoinFailedMessage, 1); } }; } else { AllianceJoinFailedMessage allianceJoinFailedMessage = new AllianceJoinFailedMessage(); allianceJoinFailedMessage.SetReason(AllianceJoinFailedMessage.Reason.ALREADY_IN_ALLIANCE); this.m_session.SendPiranhaMessage(allianceJoinFailedMessage, 1); } }
private static void OnGameCreateAllianceInvitationRequestMessageReceived(GameCreateAllianceInvitationRequestMessage message) { if (GameAvatarManager.TryGet(message.AccountId, out GameAvatar avatar)) { if (avatar.LogicClientAvatar.IsInAlliance() || avatar.HasServerCommandOfType(LogicCommandType.JOIN_ALLIANCE) || avatar.PendingAllianceJoinResponse) { ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage { ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.ALREADY_IN_ALLIANCE }, message); return; } if (!avatar.LogicClientAvatar.HasAllianceCastle()) { ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage { ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.NO_CASTLE }, message); return; } ServerRequestManager.Create(new LoadAvatarStreamOfTypeRequestMessage { StreamIds = avatar.AvatarStreamList, SenderAvatarId = message.Entry.GetSenderAvatarId(), Type = AvatarStreamEntryType.ALLIANCE_INVITATION }, ServerManager.GetDocumentSocket(11, avatar.Id), 5).OnComplete = args => { if (args.ErrorCode == ServerRequestError.Success && args.ResponseMessage.Success) { LoadAvatarStreamOfTypeResponseMessage loadAvatarStreamOfTypeResponseMessage = (LoadAvatarStreamOfTypeResponseMessage)args.ResponseMessage; for (int i = 0; i < loadAvatarStreamOfTypeResponseMessage.StreamList.Size(); i++) { AllianceInvitationAvatarStreamEntry allianceInvitationAvatarStreamEntry = (AllianceInvitationAvatarStreamEntry)loadAvatarStreamOfTypeResponseMessage.StreamList[i]; if (allianceInvitationAvatarStreamEntry.GetAllianceId().Equals(message.Entry.GetAllianceId())) { ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage { ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.ALREADY_HAS_AN_INVITE }, message); return; } } if (loadAvatarStreamOfTypeResponseMessage.StreamList.Size() >= 10) { ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage { ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.HAS_TOO_MANY_INVITES }, message); } ServerMessageManager.SendMessage(new CreateAvatarStreamMessage { AccountId = message.AccountId, Entry = message.Entry }, 9); ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage { Success = true }, message); } else { ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage { ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.GENERIC }, message); } }; } else { ServerRequestManager.SendResponse(new GameCreateAllianceInvitationResponseMessage { ErrorReason = GameCreateAllianceInvitationResponseMessage.Reason.GENERIC }, message); } }