/// <summary> /// Returns whether the Character with the given low Entityid has any passive relations of the given type /// </summary> /// <param name="charLowId"></param> /// <param name="relationType"></param> /// <returns></returns> public bool HasPassiveRelations(uint charLowId, CharacterRelationType relationType) { if (charLowId == 0 || relationType == CharacterRelationType.Invalid) { return(false); } HashSet <IBaseRelation> relations; m_lock.EnterReadLock(); try { if (m_passiveRelations[(int)relationType].TryGetValue(charLowId, out relations)) { return(relations.Count > 0); } else { return(false); } } finally { m_lock.ExitReadLock(); } }
/// <summary> /// Retrieves a current relationship between the given characters and the type /// </summary> /// <param name="charId">The first character EntityId</param> /// <param name="relatedCharId">The related character low EntityId</param> /// <param name="relationType">The relationship type</param> /// <returns>A <see cref="T:WCell.RealmServer.Interaction.BaseRelation" /> object representing the relation; /// null if the relation wasnt found.</returns> public BaseRelation GetRelation(uint charId, uint relatedCharId, CharacterRelationType relationType) { if (charId == 0U || relatedCharId == 0U || relationType == CharacterRelationType.Invalid) { return(null); } m_lock.EnterReadLock(); try { HashSet <IBaseRelation> baseRelationSet; if (m_activeRelations[(int)relationType].TryGetValue(charId, out baseRelationSet)) { foreach (BaseRelation baseRelation in baseRelationSet) { if ((int)baseRelation.RelatedCharacterId == (int)relatedCharId) { return(baseRelation); } } } } finally { m_lock.ExitReadLock(); } return(null); }
/// <summary> /// Retrieves a current relationship between the given characters and the type /// </summary> /// <param name="charId">The first character EntityId</param> /// <param name="relatedCharId">The related character low EntityId</param> /// <param name="relationType">The relationship type</param> /// <returns>A <see cref="BaseRelation"/> object representing the relation; /// null if the relation wasnt found.</returns> public BaseRelation GetRelation(uint charId, uint relatedCharId, CharacterRelationType relationType) { if (charId == 0 || relatedCharId == 0 || relationType == CharacterRelationType.Invalid) { return(null); } m_lock.EnterReadLock(); try { HashSet <IBaseRelation> relations; if (m_activeRelations[(int)relationType].TryGetValue(charId, out relations)) { foreach (BaseRelation cr in relations) { if (cr.RelatedCharacterId == relatedCharId) { return(cr); } } } } finally { m_lock.ExitReadLock(); } return(null); }
public CharacterRelationRecord(uint charId, uint relatedCharId, CharacterRelationType type) { State = RecordState.New; CharacterId = charId; RelatedCharacterId = relatedCharId; RelationType = type; CharacterRelationGuid = NextId(); }
public CharacterRelationRecord(uint charId, uint relatedCharId, CharacterRelationType type) { this.State = RecordState.New; this.CharacterId = charId; this.RelatedCharacterId = relatedCharId; this.RelationType = type; this.CharacterRelationGuid = CharacterRelationRecord.NextId(); }
public Task RelationAddAsync(long senderId, long targetId, CharacterRelationType relationType) { return(RelationAddAsync(new RelationDto { Id = Guid.NewGuid(), OwnerId = senderId, TargetId = targetId, Type = relationType })); }
public static BaseRelation CreateRelation(CharacterRelationRecord relationRecord) { if (relationRecord == null) { return(null); } EntityId charId = EntityId.GetPlayerId(relationRecord.CharacterId); EntityId relatedCharId = EntityId.GetPlayerId(relationRecord.RelatedCharacterId); CharacterRelationType relationType = relationRecord.RelationType; return(CreateRelation(charId, relatedCharId, relationType)); }
/// <summary> /// Removes all Relations that the given Character has of the given type. /// </summary> /// <returns>Whether there were any Relations of the given type</returns> public bool RemoveRelations(uint charLowId, CharacterRelationType type) { m_lock.EnterWriteLock(); try { return(m_activeRelations[(int)type].Remove(charLowId) && m_passiveRelations[(int)type].Remove(charLowId)); } finally { m_lock.ExitWriteLock(); } }
private static RelationResult GetDeleteRelationResult(CharacterRelationType relationType) { switch (relationType) { case CharacterRelationType.Friend: return(RelationResult.FRIEND_REMOVED); case CharacterRelationType.Ignored: return(RelationResult.IGNORE_REMOVED); case CharacterRelationType.Muted: return(RelationResult.MUTED_REMOVED); } throw new ArgumentOutOfRangeException("relationType"); }
public static BaseRelation CreateRelation(EntityId charId, EntityId relatedCharId, CharacterRelationType relationType) { switch (relationType) { case CharacterRelationType.Friend: return new FriendRelation(charId, relatedCharId); case CharacterRelationType.Ignored: return new IgnoredRelation(charId, relatedCharId); case CharacterRelationType.Muted: return new MutedRelation(charId, relatedCharId); case CharacterRelationType.GroupInvite: return new GroupInviteRelation(charId, relatedCharId); } return null; }
/// <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); } }
/// <summary> /// Removes all Relations that the given Character has of the given type. /// </summary> /// <returns>Whether there were any Relations of the given type</returns> public bool RemoveRelations(uint charLowId, CharacterRelationType type) { bool success = false; m_lock.EnterWriteLock(); try { success = m_activeRelations[(int)type].Remove(charLowId); success = success && m_passiveRelations[(int)type].Remove(charLowId); } finally { m_lock.ExitWriteLock(); } return(success); }
public static BaseRelation CreateRelation(EntityId charId, EntityId relatedCharId, CharacterRelationType relationType) { switch (relationType) { case CharacterRelationType.Friend: return(new FriendRelation(charId, relatedCharId)); case CharacterRelationType.Ignored: return(new IgnoredRelation(charId, relatedCharId)); case CharacterRelationType.Muted: return(new MutedRelation(charId, relatedCharId)); case CharacterRelationType.GroupInvite: return(new GroupInviteRelation(charId, relatedCharId)); } return(null); }
/// <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(); } } }
/// <summary> /// Returns whether the Character with the given low Entityid has any passive relations of the given type /// </summary> /// <param name="charLowId"></param> /// <param name="relationType"></param> /// <returns></returns> public bool HasPassiveRelations(uint charLowId, CharacterRelationType relationType) { if (charLowId == 0U || relationType == CharacterRelationType.Invalid) { return(false); } m_lock.EnterReadLock(); try { HashSet <IBaseRelation> baseRelationSet; if (m_passiveRelations[(int)relationType].TryGetValue(charLowId, out baseRelationSet)) { return(baseRelationSet.Count > 0); } return(false); } finally { m_lock.ExitReadLock(); } }
/// <summary> /// Retrieves all Relations of the given type that others have started with the given Character /// </summary> /// <param name="charLowId">The <see cref="EntityId"/> of the character wich relations are requested</param> /// <param name="relationType">The type of the relation</param> public HashSet <IBaseRelation> GetPassiveRelations(uint charLowId, CharacterRelationType relationType) { if (charLowId == 0 || relationType == CharacterRelationType.Invalid) { return(BaseRelation.EmptyRelationSet); } m_lock.EnterReadLock(); try { HashSet <IBaseRelation> relations; if (m_passiveRelations[(int)relationType].TryGetValue(charLowId, out relations)) { return(relations); } } finally { m_lock.ExitReadLock(); } return(BaseRelation.EmptyRelationSet); }
/// <summary> /// Retrieves all Relations that the given Character started with others /// </summary> /// <param name="charLowId">The <see cref="T:WCell.Core.EntityId" /> of the character wich relations are requested</param> /// <param name="relationType">The type of the relation</param> /// <returns>The list of the related characters relations.</returns> public HashSet <IBaseRelation> GetRelations(uint charLowId, CharacterRelationType relationType) { if (charLowId == 0U || relationType == CharacterRelationType.Invalid) { return(BaseRelation.EmptyRelationSet); } this.m_lock.EnterReadLock(); try { HashSet <IBaseRelation> baseRelationSet; if (this.m_activeRelations[(int)relationType].TryGetValue(charLowId, out baseRelationSet)) { return(baseRelationSet); } } finally { this.m_lock.ExitReadLock(); } return(BaseRelation.EmptyRelationSet); }
public static BaseRelation CreateRelation(uint charId, uint relatedCharId, CharacterRelationType relationType) { switch (relationType) { case CharacterRelationType.Friend: return(new FriendRelation(charId, relatedCharId)); case CharacterRelationType.Ignored: return(new IgnoredRelation(charId, relatedCharId)); case CharacterRelationType.Muted: return(new MutedRelation(charId, relatedCharId)); case CharacterRelationType.GroupInvite: return(new GroupInviteRelation(charId, relatedCharId)); case CharacterRelationType.GuildInvite: return(new GuildInviteRelation(charId, relatedCharId)); default: return(null); } }
/// <summary>Removes a character relation</summary> /// <param name="relCharId">The related character low <see cref="T:WCell.Core.EntityId" /></param> /// <param name="relationType">The relation type</param> internal void RemoveRelation(uint charId, uint relCharId, CharacterRelationType relationType) { RelationResult relResult; if (RemoveRelation(GetRelation(charId, relCharId, relationType))) { relResult = GetDeleteRelationResult(relationType); } else { relResult = RelationResult.FRIEND_DB_ERROR; _log.Debug(WCell_RealmServer.CharacterRelationRemoveFailed, (object)charId, (object)relCharId, (object)relationType, (object)relResult); } Character character = World.GetCharacter(charId); if (character == null) { return; } SendFriendStatus(character, relCharId, string.Empty, relResult); }
/// <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); } }
/// <summary> /// Removes a character relation /// </summary> /// <param name="relCharId">The related character low <see cref="EntityId"/></param> /// <param name="relationType">The relation type</param> internal void RemoveRelation(uint charId, uint relCharId, CharacterRelationType relationType) { RelationResult relResult; var relation = GetRelation(charId, relCharId, relationType); if (RemoveRelation(relation)) { relResult = GetDeleteRelationResult(relationType); } else { relResult = RelationResult.FRIEND_DB_ERROR; _log.Debug(Resources.CharacterRelationRemoveFailed, charId, relCharId, relationType, relResult); } //Send relation status to the client var remover = World.GetCharacter(charId); if (remover != null) { SendFriendStatus(remover, relCharId, string.Empty, relResult); } }
public async Task <RelationInvitationDto> RelationInviteAsync(long senderId, long targetId, CharacterRelationType relationType) { var tmp = new RelationInvitationDto { Id = Guid.NewGuid(), OwnerId = senderId, TargetId = targetId, RelationType = relationType }; await RelationInviteAsync(tmp); return(tmp); }
public BaseRelation GetRelationTo(Character chr, CharacterRelationType type) { return RelationMgr.Instance.GetRelation(EntityId.Low, chr.EntityId.Low, type); }
public BaseRelation GetRelationTo(Character chr, CharacterRelationType type) { return(Singleton <RelationMgr> .Instance.GetRelation(EntityId.Low, chr.EntityId.Low, type)); }
/// <summary> /// Returns whether the given char has the given relationType with the given relatedChar /// </summary> /// <param name="charId">The first character EntityId</param> /// <param name="relatedCharId">The related character EntityId</param> /// <param name="relationType">The relationship type</param> /// <returns>True if the relation exist. False otherwise</returns> public bool HasRelation(uint charId, uint relatedCharId, CharacterRelationType relationType) { return(GetRelation(charId, relatedCharId, relationType) != null); }