public void ChangeMemberRole(AllianceMemberEntry allianceMemberEntry, LogicAvatarAllianceRole allianceRole, LogicLong eventAvatarId, string eventAvatarName)
        {
            if (allianceMemberEntry.GetAllianceRole() != allianceRole)
            {
                bool isPromoted = allianceMemberEntry.HasLowerRoleThan(allianceRole);

                allianceMemberEntry.SetAllianceRole(allianceRole);

                LogicChangeAllianceRoleCommand logicChangeAllianceRoleCommand = new LogicChangeAllianceRoleCommand();
                logicChangeAllianceRoleCommand.SetData(this.Id, allianceRole);
                ServerMessageManager.SendMessage(new GameAllowServerCommandMessage
                {
                    AccountId     = allianceMemberEntry.GetAvatarId(),
                    ServerCommand = logicChangeAllianceRoleCommand
                }, 9);

                AllianceEventStreamEntry allianceEventStreamEntry = new AllianceEventStreamEntry();
                AllianceStreamEntryUtil.SetSenderInfo(allianceEventStreamEntry, allianceMemberEntry);

                allianceEventStreamEntry.SetEventAvatarId(eventAvatarId);
                allianceEventStreamEntry.SetEventAvatarName(eventAvatarName);
                allianceEventStreamEntry.SetEventType(isPromoted ? AllianceEventStreamEntryType.PROMOTED : AllianceEventStreamEntryType.DEMOTED);

                StreamManager.Create(this.Id, allianceEventStreamEntry);

                this.AddStreamEntry(allianceEventStreamEntry);
            }
        }
        private void OnChangeAllianceMemberRoleMessageReceived(ChangeAllianceMemberRoleMessage message)
        {
            if (this.m_session.Alliance != null)
            {
                LogicLong memberId = message.RemoveMemberId();

                if (!this.m_session.Alliance.Members.TryGetValue(memberId, out AllianceMemberEntry memberEntry))
                {
                    return;
                }

                AllianceMemberEntry eventMemberEntry = this.m_session.Alliance.Members[this.m_session.AccountId];

                if (message.GetMemberRole() == LogicAvatarAllianceRole.MEMBER ||
                    message.GetMemberRole() == LogicAvatarAllianceRole.LEADER ||
                    message.GetMemberRole() == LogicAvatarAllianceRole.ELDER ||
                    message.GetMemberRole() == LogicAvatarAllianceRole.CO_LEADER)
                {
                    if (memberEntry.HasLowerRoleThan(eventMemberEntry.GetAllianceRole()) &&
                        !eventMemberEntry.HasLowerRoleThan(message.GetMemberRole()))
                    {
                        if (message.GetMemberRole() == LogicAvatarAllianceRole.LEADER)
                        {
                            this.m_session.Alliance.ChangeMemberRole(eventMemberEntry, LogicAvatarAllianceRole.CO_LEADER, eventMemberEntry.GetAvatarId(), eventMemberEntry.GetName());
                        }
                        this.m_session.Alliance.ChangeMemberRole(memberEntry, message.GetMemberRole(), memberEntry.GetAvatarId(), memberEntry.GetName());

                        AllianceManager.Save(this.m_session.Alliance);
                    }
                }
            }
        }
Exemple #3
0
 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 OnLeaveAllianceMessageReceived(LeaveAllianceMessage 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.LEADER)
                {
                    AllianceMemberEntry     higherMemberEntry = null;
                    LogicAvatarAllianceRole higherMemberRole  = 0;

                    foreach (AllianceMemberEntry member in alliance.Members.Values)
                    {
                        if (member != memberEntry && (higherMemberEntry == null || !member.HasLowerRoleThan(higherMemberRole)))
                        {
                            higherMemberEntry = member;
                            higherMemberRole  = member.GetAllianceRole();
                        }
                    }

                    if (higherMemberEntry != null)
                    {
                        alliance.ChangeMemberRole(higherMemberEntry, LogicAvatarAllianceRole.LEADER, memberEntry.GetAvatarId(), memberEntry.GetName());
                    }
                }

                AllianceEventStreamEntry allianceEventStreamEntry = new AllianceEventStreamEntry();
                AllianceStreamEntryUtil.SetSenderInfo(allianceEventStreamEntry, memberEntry);

                allianceEventStreamEntry.SetEventType(AllianceEventStreamEntryType.LEFT);
                allianceEventStreamEntry.SetEventAvatarId(memberEntry.GetAvatarId());
                allianceEventStreamEntry.SetEventAvatarName(memberEntry.GetName());

                StreamManager.Create(alliance.Id, allianceEventStreamEntry);

                alliance.AddStreamEntry(allianceEventStreamEntry);
                alliance.RemoveMember(this.m_session.AccountId);

                ServerMessageManager.SendMessage(new AllianceLeavedMessage
                {
                    AccountId  = this.m_session.AccountId,
                    AllianceId = alliance.Id
                }, 9);

                AllianceManager.Save(alliance);
            }
        }
        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);
                            }
                        }
                    }
                }
            }
        }