Exemplo n.º 1
0
        public override bool Equals(object otherRelation)
        {
            if (!(otherRelation is BaseRelation))
            {
                return(false);
            }
            BaseRelation baseRelation = otherRelation as BaseRelation;

            if ((int)CharacterId == (int)baseRelation.CharacterId &&
                (int)RelatedCharacterId == (int)baseRelation.RelatedCharacterId)
            {
                return(Type == baseRelation.Type);
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds a character relation
        /// </summary>
        /// <param name="character">The first character in the relation</param>
        /// <param name="relatedCharName">The related character name</param>
        /// <param name="note">A note describing the relation. Used for Friend only relation types</param>
        /// <param name="relationType">The relation type</param>
        internal void AddRelation(Character character, string relatedCharName, string note,
                                  CharacterRelationType relationType)
        {
            var             target = World.GetCharacter(relatedCharName, false);
            CharacterRecord relatedCharInfo;

            if (target != null)
            {
                relatedCharInfo = target.Record;
            }
            else
            {
                relatedCharInfo = CharacterRecord.GetRecordByName(relatedCharName);
            }

            if (relatedCharInfo != null)
            {
                BaseRelation relation = CreateRelation(character.EntityId.Low, relatedCharInfo.EntityLowId, relationType);
                relation.Note = note;

                RelationResult relResult;
                if (!relation.Validate(character.Record, relatedCharInfo, out relResult))
                {
                    _log.Debug(Resources.CharacterRelationValidationFailed, character.Name,
                               character.EntityId, relatedCharName, relatedCharInfo.EntityLowId, relationType, relResult);
                }
                else
                {
                    AddRelation(relation);
                }

                //Send relation status to the client
                if (relResult == RelationResult.FRIEND_ADDED_ONLINE)
                {
                    SendFriendOnline(character, target, note, true);
                }
                else
                {
                    SendFriendStatus(character, relatedCharInfo.EntityLowId, note, relResult);
                }
            }
            else
            {
                //Send relation status to the client
                SendFriendStatus(character, 0, note, RelationResult.FRIEND_NOT_FOUND);
            }
        }
Exemplo n.º 3
0
        /// <summary>Adds a character relation</summary>
        /// <param name="relation">The relation to be added</param>
        public void AddRelation(BaseRelation relation)
        {
            try
            {
                if (relation is PersistedRelation)
                {
                    (relation as PersistedRelation).SaveToDB();
                }
                m_lock.EnterWriteLock();
                try
                {
                    HashSet <IBaseRelation> baseRelationSet1;
                    if (!m_activeRelations[(int)relation.Type]
                        .TryGetValue(relation.CharacterId, out baseRelationSet1))
                    {
                        m_activeRelations[(int)relation.Type].Add(relation.CharacterId,
                                                                  baseRelationSet1 = new HashSet <IBaseRelation>());
                    }
                    HashSet <IBaseRelation> baseRelationSet2;
                    if (!m_passiveRelations[(int)relation.Type]
                        .TryGetValue(relation.RelatedCharacterId, out baseRelationSet2))
                    {
                        m_passiveRelations[(int)relation.Type].Add(relation.RelatedCharacterId,
                                                                   baseRelationSet2 = new HashSet <IBaseRelation>());
                    }
                    baseRelationSet1.Add(relation);
                    baseRelationSet2.Add(relation);
                }
                finally
                {
                    m_lock.ExitWriteLock();
                }

                _log.Debug(WCell_RealmServer.CharacterRelationAdded, (object)string.Empty,
                           (object)relation.CharacterId, (object)string.Empty, (object)relation.RelatedCharacterId,
                           (object)relation.Type, (object)0);
            }
            catch (Exception ex)
            {
                LogUtil.ErrorException(ex,
                                       string.Format(WCell_RealmServer.CharacterRelationAddedFailed, (object)string.Empty,
                                                     (object)relation.CharacterId, (object)string.Empty, (object)relation.RelatedCharacterId,
                                                     (object)relation.Type, (object)0));
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets a relation note text
        /// </summary>
        /// <param name="charId">The first character EntityId</param>
        /// <param name="relatedCharId">The related character low EntityId</param>
        /// <param name="note">The note to be assigned to the relation</param>
        /// <param name="relationType">The relationship type</param>
        public void SetRelationNote(uint charId, uint relatedCharId, string note, CharacterRelationType relationType)
        {
            if (charId == 0 || relatedCharId == 0 || string.IsNullOrEmpty(note) || relationType == CharacterRelationType.Invalid)
            {
                return;
            }

            BaseRelation relation = GetRelation(charId, relatedCharId, relationType);

            if (relation != null)
            {
                relation.Note = note;

                if (relation is PersistedRelation)
                {
                    ((PersistedRelation)relation).SaveToDB();
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a character relation
        /// </summary>
        /// <param name="relation">The relation to be added</param>
        public void AddRelation(BaseRelation relation)
        {
            try
            {
                //Persists the relation to the db if persistable
                if (relation is PersistedRelation)
                {
                    (relation as PersistedRelation).SaveToDB();
                }

                HashSet <IBaseRelation> relations, relatedRelations;

                m_lock.EnterWriteLock();
                try
                {
                    if (!m_activeRelations[(int)relation.Type].TryGetValue(relation.CharacterId, out relations))
                    {
                        m_activeRelations[(int)relation.Type].Add(relation.CharacterId, relations = new HashSet <IBaseRelation>());
                    }

                    if (!m_passiveRelations[(int)relation.Type].TryGetValue(relation.RelatedCharacterId, out relatedRelations))
                    {
                        m_passiveRelations[(int)relation.Type].Add(relation.RelatedCharacterId, relatedRelations = new HashSet <IBaseRelation>());
                    }

                    relations.Add(relation);
                    relatedRelations.Add(relation);
                }
                finally
                {
                    m_lock.ExitWriteLock();
                }

                _log.Debug(Resources.CharacterRelationAdded, string.Empty, relation.CharacterId,
                           string.Empty, relation.RelatedCharacterId, relation.Type, 0);
            }
            catch (Exception ex)
            {
                LogUtil.ErrorException(ex, string.Format(Resources.CharacterRelationAddedFailed, string.Empty, relation.CharacterId,
                                                         string.Empty, relation.RelatedCharacterId, relation.Type, 0));
            }
        }
Exemplo n.º 6
0
        /// <summary>Adds a character relation</summary>
        /// <param name="character">The first character in the relation</param>
        /// <param name="relatedCharName">The related character name</param>
        /// <param name="note">A note describing the relation. Used for Friend only relation types</param>
        /// <param name="relationType">The relation type</param>
        internal void AddRelation(Character character, string relatedCharName, string note,
                                  CharacterRelationType relationType)
        {
            Character       character1      = World.GetCharacter(relatedCharName, false);
            CharacterRecord relatedCharInfo =
                character1 == null?CharacterRecord.GetRecordByName(relatedCharName) : character1.Record;

            if (relatedCharInfo != null)
            {
                BaseRelation relation =
                    CreateRelation(character.EntityId.Low, relatedCharInfo.EntityLowId, relationType);
                relation.Note = note;
                RelationResult relResult;
                if (!relation.Validate(character.Record, relatedCharInfo, out relResult))
                {
                    _log.Debug(WCell_RealmServer.CharacterRelationValidationFailed, (object)character.Name,
                               (object)character.EntityId, (object)relatedCharName, (object)relatedCharInfo.EntityLowId,
                               (object)relationType, (object)relResult);
                }
                else
                {
                    AddRelation(relation);
                }
                if (relResult == RelationResult.FRIEND_ADDED_ONLINE)
                {
                    SendFriendOnline(character, character1, note, true);
                }
                else
                {
                    SendFriendStatus(character, relatedCharInfo.EntityLowId, note, relResult);
                }
            }
            else
            {
                SendFriendStatus(character, 0U, note, RelationResult.FRIEND_NOT_FOUND);
            }
        }