using System;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
using System.Linq;
using Aurora.Proto.Party;
using Aurora.Proto.Events;
using Aurora.Services.EventManager;
namespace Aurora.RemoteImpl
{
public class RemotePartyServiceImpl : RemotePartyService.RemotePartyServiceBase
{
///
/// Dictionary of party members. Key -> ClientId
///
private ObservableCollection _partyMembers;
public RemotePartyServiceImpl()
{
_partyMembers = new ObservableCollection();
}
public ObservableCollection PartyMembers
{
get
{
return _partyMembers;
}
}
public override Task JoinParty(JoinPartyRequest request, Grpc.Core.ServerCallContext context)
{
PartyMember partyMember = new PartyMember("")
{
UserName = request.UserName,
IpAddress = context.Host,
};
Console.WriteLine("SERVER - Client joined party: " + partyMember.Id);
_partyMembers.Add(partyMember);
BaseEvent e = new BaseEvent
{
EventType = EventType.PartyMemberJoined,
PartyMemberJoinedEvent = new PartyMemberJoinedEvent
{
Member = partyMember,
}
};
EventManager.Instance.FireEvent(e);
JoinPartyResponse response = new JoinPartyResponse() { Status = PartyJoinedStatusEnum.Connected, ClientId = partyMember.Id };
return Task.FromResult(response);
}
public override Task LeaveParty(LeavePartyRequest request, Grpc.Core.ServerCallContext context)
{
PartyMember partyMember = _partyMembers.Where(e => e.Id == request.ClientId).Single();
_partyMembers.Remove(partyMember);
BaseEvent bv = new BaseEvent
{
EventType = EventType.PartyMemberJoined,
PartyMemberLeftEvent = new PartyMemberLeftEvent
{
Member = partyMember,
}
};
EventManager.Instance.FireEvent(bv);
LeavePartyResponse response = new LeavePartyResponse() { Status = PartyJoinedStatusEnum.Disconnected };
return Task.FromResult(response);
}
public override Task GetPartyMembers(Proto.General.Empty empty, Grpc.Core.ServerCallContext context)
{
MembersResponse response = new MembersResponse();
response.Members.AddRange(_partyMembers);
return Task.FromResult(response);
}
}
}