using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; using PhoenixLib.ServiceBus; using WingsEmu.DTOs.Relations; using WingsEmu.Plugins.DistributedGameEvents.PlayerEvents; using WingsEmu.Plugins.DistributedGameEvents.Relation; namespace RelationServer.Consumer { public class RelationCharacterConnectMessageConsumer : IMessageConsumer { private readonly IMessagePublisher _messagePublisher; private readonly ICharacterRelationDAO _relationDao; public RelationCharacterConnectMessageConsumer(ICharacterRelationDAO relationDao, IMessagePublisher messagePublisher) { _relationDao = relationDao; _messagePublisher = messagePublisher; } public async Task HandleAsync(PlayerConnectedOnChannelMessage notification, CancellationToken token) { long characterId = notification.CharacterId; List relations = await _relationDao.LoadRelationsByCharacterIdAsync(characterId); if (!relations.Any()) { return; } await _messagePublisher.PublishAsync(new RelationCharacterJoinMessage { CharacterId = characterId, CharacterName = notification.CharacterName, Relations = relations }); } } }