public static void SetSenderInfo(StreamEntry entry, AllianceMemberEntry member) { entry.SetSenderAvatarId(member.GetAvatarId()); entry.SetSenderHomeId(member.GetHomeId()); entry.SetSenderName(member.GetName()); entry.SetSenderLevel(member.GetExpLevel()); entry.SetSenderLeagueType(member.GetLeagueType()); entry.SetSenderRole(member.GetAllianceRole()); }
private void OnSendAllianceInvitationMessageReceived(SendAllianceInvitationMessage message) { if (this.m_session.Alliance != null) { Alliance alliance = this.m_session.Alliance; AllianceMemberEntry memberEntry = alliance.Members[this.m_session.AccountId]; if (memberEntry.GetAllianceRole() == LogicAvatarAllianceRole.MEMBER) { AllianceInvitationSendFailedMessage allianceInvitationSendFailedMessage = new AllianceInvitationSendFailedMessage(); allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.NO_RIGHTS); this.m_session.SendPiranhaMessage(allianceInvitationSendFailedMessage, 1); return; } if (memberEntry.GetAllianceRole() == LogicAvatarAllianceRole.ELDER) { AllianceInvitationSendFailedMessage allianceInvitationSendFailedMessage = new AllianceInvitationSendFailedMessage(); allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.USER_BANNED); this.m_session.SendPiranhaMessage(allianceInvitationSendFailedMessage, 1); return; } AllianceInvitationAvatarStreamEntry allianceInvitationAvatarStreamEntry = new AllianceInvitationAvatarStreamEntry(); allianceInvitationAvatarStreamEntry.SetSenderAvatarId(memberEntry.GetAvatarId()); allianceInvitationAvatarStreamEntry.SetSenderHomeId(memberEntry.GetHomeId()); allianceInvitationAvatarStreamEntry.SetSenderName(memberEntry.GetName()); allianceInvitationAvatarStreamEntry.SetSenderLevel(memberEntry.GetExpLevel()); allianceInvitationAvatarStreamEntry.SetSenderLeagueType(memberEntry.GetLeagueType()); allianceInvitationAvatarStreamEntry.SetAllianceId(alliance.Id); allianceInvitationAvatarStreamEntry.SetAllianceName(alliance.Header.GetAllianceName()); allianceInvitationAvatarStreamEntry.SetAllianceBadgeId(alliance.Header.GetAllianceBadgeId()); allianceInvitationAvatarStreamEntry.SetAllianceLevel(alliance.Header.GetAllianceLevel()); ServerRequestManager.Create(new GameCreateAllianceInvitationRequestMessage { AccountId = message.GetAvatarId(), Entry = allianceInvitationAvatarStreamEntry }, ServerManager.GetDocumentSocket(9, message.GetAvatarId())).OnComplete = args => { if (this.m_session.IsDestructed()) { return; } if (args.ErrorCode == ServerRequestError.Success) { GameCreateAllianceInvitationResponseMessage responseMessage = (GameCreateAllianceInvitationResponseMessage)args.ResponseMessage; if (responseMessage.Success) { this.m_session.SendPiranhaMessage(new AllianceInvitationSentOkMessage(), 1); } else { AllianceInvitationSendFailedMessage allianceInvitationSendFailedMessage = new AllianceInvitationSendFailedMessage(); switch (responseMessage.ErrorReason) { case GameCreateAllianceInvitationResponseMessage.Reason.GENERIC: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.GENERIC); break; case GameCreateAllianceInvitationResponseMessage.Reason.NO_CASTLE: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.NO_CASTLE); break; case GameCreateAllianceInvitationResponseMessage.Reason.ALREADY_IN_ALLIANCE: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.ALREADY_IN_ALLIANCE); break; case GameCreateAllianceInvitationResponseMessage.Reason.ALREADY_HAS_AN_INVITE: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.ALREADY_HAS_AN_INVITE); break; case GameCreateAllianceInvitationResponseMessage.Reason.HAS_TOO_MANY_INVITES: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.HAS_TOO_MANY_INVITES); break; } this.m_session.SendPiranhaMessage(allianceInvitationSendFailedMessage, 1); } } else { AllianceInvitationSendFailedMessage allianceInvitationSendFailedMessage = new AllianceInvitationSendFailedMessage(); allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.GENERIC); this.m_session.SendPiranhaMessage(allianceInvitationSendFailedMessage, 1); } }; } }
private void OnRespondToAllianceJoinRequestMessageReceived(RespondToAllianceJoinRequestMessage message) { if (this.m_session.Alliance != null) { Alliance alliance = this.m_session.Alliance; AllianceMemberEntry memberEntry = alliance.Members[this.m_session.AccountId]; if (memberEntry.GetAllianceRole() == LogicAvatarAllianceRole.MEMBER) { AllianceInvitationSendFailedMessage allianceInvitationSendFailedMessage = new AllianceInvitationSendFailedMessage(); allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.NO_RIGHTS); this.m_session.SendPiranhaMessage(allianceInvitationSendFailedMessage, 1); return; } LogicLong streamId = message.GetStreamEntryId(); if (alliance.StreamEntryList.IndexOf(streamId) != -1) { StreamEntry streamEntry = StreamManager.GetAllianceStream(message.GetStreamEntryId()); if (streamEntry.GetStreamEntryType() == StreamEntryType.JOIN_REQUEST) { JoinRequestAllianceStreamEntry joinRequestAllianceStreamEntry = (JoinRequestAllianceStreamEntry)streamEntry; if (joinRequestAllianceStreamEntry.GetState() == 1) { if (message.IsAccepted()) { ServerRequestManager.Create(new GameJoinAllianceRequestMessage { AccountId = joinRequestAllianceStreamEntry.GetSenderAvatarId(), AllianceId = alliance.Id, Invited = true }, ServerManager.GetDocumentSocket(9, joinRequestAllianceStreamEntry.GetSenderAvatarId())).OnComplete = args => { if (this.m_session.IsDestructed()) { return; } if (args.ErrorCode == ServerRequestError.Success) { if (args.ResponseMessage.Success) { joinRequestAllianceStreamEntry.SetState(2); joinRequestAllianceStreamEntry.SetResponderName(memberEntry.GetName()); alliance.UpdateStreamEntry(joinRequestAllianceStreamEntry); StreamManager.Save(joinRequestAllianceStreamEntry); } else { GameJoinAllianceResponseMessage gameJoinAllianceResponseMessage = (GameJoinAllianceResponseMessage)args.ResponseMessage; AllianceInvitationSendFailedMessage allianceInvitationSendFailedMessage = new AllianceInvitationSendFailedMessage(); switch (gameJoinAllianceResponseMessage.ErrorReason) { case GameJoinAllianceResponseMessage.Reason.NO_CASTLE: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.NO_CASTLE); if (joinRequestAllianceStreamEntry.GetState() == 1) { alliance.RemoveStreamEntry(joinRequestAllianceStreamEntry.GetId()); AllianceManager.Save(alliance); } break; case GameJoinAllianceResponseMessage.Reason.ALREADY_IN_ALLIANCE: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.ALREADY_IN_ALLIANCE); if (joinRequestAllianceStreamEntry.GetState() == 1) { alliance.RemoveStreamEntry(joinRequestAllianceStreamEntry.GetId()); AllianceManager.Save(alliance); } break; default: allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.GENERIC); break; } this.m_session.SendPiranhaMessage(allianceInvitationSendFailedMessage, 1); } } else { AllianceInvitationSendFailedMessage allianceInvitationSendFailedMessage = new AllianceInvitationSendFailedMessage(); allianceInvitationSendFailedMessage.SetReason(AllianceInvitationSendFailedMessage.Reason.GENERIC); this.m_session.SendPiranhaMessage(allianceInvitationSendFailedMessage, 1); } }; } else { joinRequestAllianceStreamEntry.SetState(0); joinRequestAllianceStreamEntry.SetResponderName(memberEntry.GetName()); alliance.UpdateStreamEntry(joinRequestAllianceStreamEntry); StreamManager.Save(joinRequestAllianceStreamEntry); JoinAllianceResponseAvatarStreamEntry joinAllianceResponseAvatarStreamEntry = new JoinAllianceResponseAvatarStreamEntry(); joinAllianceResponseAvatarStreamEntry.SetSenderAvatarId(memberEntry.GetAvatarId()); joinAllianceResponseAvatarStreamEntry.SetSenderHomeId(memberEntry.GetHomeId()); joinAllianceResponseAvatarStreamEntry.SetSenderName(memberEntry.GetName()); joinAllianceResponseAvatarStreamEntry.SetSenderLevel(memberEntry.GetExpLevel()); joinAllianceResponseAvatarStreamEntry.SetSenderLeagueType(memberEntry.GetLeagueType()); joinAllianceResponseAvatarStreamEntry.SetAllianceId(alliance.Id); joinAllianceResponseAvatarStreamEntry.SetAllianceName(alliance.Header.GetAllianceName()); joinAllianceResponseAvatarStreamEntry.SetAllianceBadgeId(alliance.Header.GetAllianceBadgeId()); ServerMessageManager.SendMessage(new CreateAvatarStreamMessage { AccountId = joinRequestAllianceStreamEntry.GetSenderAvatarId(), Entry = joinAllianceResponseAvatarStreamEntry }, 9); } } } } } }