61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using Aurora.Proto;
|
|
using Aurora.Models;
|
|
using Aurora.Services;
|
|
|
|
namespace Aurora.RemoteImpl
|
|
{
|
|
public class RemotePartyServiceImpl : RemotePartyService.RemotePartyServiceBase
|
|
{
|
|
/// <summary>
|
|
/// Dictionary of party members. Key -> ClientId
|
|
/// </summary>
|
|
private ObservableCollection<PartyMember> _partyMembers;
|
|
|
|
public RemotePartyServiceImpl()
|
|
{
|
|
_partyMembers = new ObservableCollection<PartyMember>();
|
|
|
|
//Add self to members list
|
|
_partyMembers.Add(new PartyMember
|
|
{
|
|
Username = SettingsService.Instance.Username,
|
|
Id = "asdf",
|
|
IpAddress = ServerService.Instance.Hostname,
|
|
Port = ServerService.Instance.Port.ToString()
|
|
});
|
|
}
|
|
|
|
public ObservableCollection<PartyMember> PartyMembers
|
|
{
|
|
get
|
|
{
|
|
return _partyMembers;
|
|
}
|
|
}
|
|
|
|
public override Task<JoinPartyResponse> JoinParty(JoinPartyRequest request, Grpc.Core.ServerCallContext context)
|
|
{
|
|
_partyMembers.Add(new PartyMember()
|
|
{
|
|
Username = request.UserName,
|
|
Id = request.ClientId,
|
|
IpAddress = request.IpAddress,
|
|
Port = request.Port,
|
|
});
|
|
|
|
JoinPartyResponse response = new JoinPartyResponse() { Status = PartyJoinedStatusEnum.Connected };
|
|
return Task.FromResult(response);
|
|
}
|
|
|
|
public override Task<LeavePartyResponse> LeaveParty(LeavePartyRequest request, Grpc.Core.ServerCallContext context)
|
|
{
|
|
_partyMembers.Remove(_partyMembers.Where(e => e.Id == request.ClientId).Single());
|
|
LeavePartyResponse response = new LeavePartyResponse() { Status = PartyJoinedStatusEnum.Disconnected };
|
|
return Task.FromResult(response);
|
|
}
|
|
}
|
|
} |