2019-06-03 14:57:05 +00:00
|
|
|
using System;
|
|
|
|
using System.Threading.Tasks;
|
2019-07-05 21:37:10 +00:00
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Linq;
|
2019-07-05 18:17:09 +00:00
|
|
|
using Aurora.Proto;
|
|
|
|
using Aurora.Models;
|
|
|
|
using Aurora.Services;
|
2019-06-03 14:57:05 +00:00
|
|
|
|
2019-07-05 18:17:09 +00:00
|
|
|
namespace Aurora.RemoteImpl
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-05 15:37:44 +00:00
|
|
|
public class RemotePartyServiceImpl : RemotePartyService.RemotePartyServiceBase
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
/// Dictionary of party members. Key -> ClientId
|
|
|
|
/// </summary>
|
2019-07-05 21:37:10 +00:00
|
|
|
private ObservableCollection<PartyMember> _partyMembers;
|
2019-06-03 14:57:05 +00:00
|
|
|
|
2019-07-05 15:37:44 +00:00
|
|
|
public RemotePartyServiceImpl()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-05 21:37:10 +00:00
|
|
|
_partyMembers = new ObservableCollection<PartyMember>();
|
2019-07-05 18:17:09 +00:00
|
|
|
|
|
|
|
//Add self to members list
|
2019-07-05 21:37:10 +00:00
|
|
|
_partyMembers.Add(new PartyMember
|
2019-07-05 18:17:09 +00:00
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
UserName = SettingsService.Instance.Username,
|
2019-07-05 18:17:09 +00:00
|
|
|
Id = "asdf",
|
|
|
|
IpAddress = ServerService.Instance.Hostname,
|
2019-07-06 19:52:28 +00:00
|
|
|
Port = ServerService.Instance.Port
|
2019-07-05 18:17:09 +00:00
|
|
|
});
|
2019-06-03 14:57:05 +00:00
|
|
|
}
|
|
|
|
|
2019-07-05 21:37:10 +00:00
|
|
|
public ObservableCollection<PartyMember> PartyMembers
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
return _partyMembers;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<JoinPartyResponse> JoinParty(JoinPartyRequest request, Grpc.Core.ServerCallContext context)
|
|
|
|
{
|
2019-07-05 21:37:10 +00:00
|
|
|
_partyMembers.Add(new PartyMember()
|
2019-06-03 14:57:05 +00:00
|
|
|
{
|
2019-07-06 19:52:28 +00:00
|
|
|
UserName = request.UserName,
|
|
|
|
IpAddress = context.Host,
|
2019-06-03 14:57:05 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
JoinPartyResponse response = new JoinPartyResponse() { Status = PartyJoinedStatusEnum.Connected };
|
|
|
|
return Task.FromResult(response);
|
|
|
|
}
|
|
|
|
|
|
|
|
public override Task<LeavePartyResponse> LeaveParty(LeavePartyRequest request, Grpc.Core.ServerCallContext context)
|
|
|
|
{
|
2019-07-05 21:37:10 +00:00
|
|
|
_partyMembers.Remove(_partyMembers.Where(e => e.Id == request.ClientId).Single());
|
2019-06-03 14:57:05 +00:00
|
|
|
LeavePartyResponse response = new LeavePartyResponse() { Status = PartyJoinedStatusEnum.Disconnected };
|
|
|
|
return Task.FromResult(response);
|
|
|
|
}
|
2019-07-06 19:52:28 +00:00
|
|
|
|
|
|
|
public override Task<MembersResponse> GetPartyMembers(Empty empty, Grpc.Core.ServerCallContext context)
|
|
|
|
{
|
|
|
|
MembersResponse response = new MembersResponse();
|
|
|
|
response.Members.AddRange(_partyMembers);
|
|
|
|
return Task.FromResult(response);
|
|
|
|
}
|
2019-06-03 14:57:05 +00:00
|
|
|
}
|
|
|
|
}
|