2018-10-17 19:15:50 +02:00
|
|
|
using Ryujinx.Common.Logging;
|
2020-05-15 03:14:38 +02:00
|
|
|
using Ryujinx.HLE.HOS.Services.Arp;
|
|
|
|
using System;
|
2018-02-10 01:14:55 +01:00
|
|
|
|
2019-09-19 02:45:11 +02:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Pctl.ParentalControlServiceFactory
|
2018-02-10 01:14:55 +01:00
|
|
|
{
|
2018-03-19 19:58:46 +01:00
|
|
|
class IParentalControlService : IpcService
|
2018-02-10 01:14:55 +01:00
|
|
|
{
|
2020-05-15 03:14:38 +02:00
|
|
|
private int _permissionFlag;
|
|
|
|
private ulong _titleId;
|
|
|
|
private bool _freeCommunicationEnabled;
|
|
|
|
private int[] _ratingAge;
|
2018-06-12 20:28:45 +02:00
|
|
|
|
2020-05-15 03:14:38 +02:00
|
|
|
public IParentalControlService(ServiceCtx context, bool withInitialize, int permissionFlag)
|
2018-02-10 01:14:55 +01:00
|
|
|
{
|
2020-05-15 03:14:38 +02:00
|
|
|
_permissionFlag = permissionFlag;
|
|
|
|
|
|
|
|
if (withInitialize)
|
|
|
|
{
|
|
|
|
Initialize(context);
|
|
|
|
}
|
2018-02-10 01:14:55 +01:00
|
|
|
}
|
2018-06-12 20:28:45 +02:00
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(1)] // 4.0.0+
|
|
|
|
// Initialize()
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode Initialize(ServiceCtx context)
|
2018-06-12 20:28:45 +02:00
|
|
|
{
|
2020-05-15 03:14:38 +02:00
|
|
|
if ((_permissionFlag & 0x8001) == 0)
|
2018-06-13 02:51:59 +02:00
|
|
|
{
|
2020-05-15 03:14:38 +02:00
|
|
|
return ResultCode.PermissionDenied;
|
2018-06-13 02:51:59 +02:00
|
|
|
}
|
2020-05-15 03:14:38 +02:00
|
|
|
|
|
|
|
ResultCode resultCode = ResultCode.InvalidPid;
|
|
|
|
|
|
|
|
if (context.Process.Pid != 0)
|
2018-06-13 02:51:59 +02:00
|
|
|
{
|
2020-05-15 03:14:38 +02:00
|
|
|
if ((_permissionFlag & 0x40) == 0)
|
|
|
|
{
|
|
|
|
ulong titleId = ApplicationLaunchProperty.GetByPid(context).TitleId;
|
|
|
|
|
|
|
|
if (titleId != 0)
|
|
|
|
{
|
|
|
|
_titleId = titleId;
|
|
|
|
|
|
|
|
// TODO: Call nn::arp::GetApplicationControlProperty here when implemented, if it return ResultCode.Success we assign fields.
|
2020-05-15 08:16:46 +02:00
|
|
|
_ratingAge = Array.ConvertAll(context.Device.Application.ControlData.Value.RatingAge.ToArray(), Convert.ToInt32);
|
|
|
|
_freeCommunicationEnabled = context.Device.Application.ControlData.Value.ParentalControl == LibHac.Ns.ParentalControlFlagValue.FreeCommunication;
|
2020-05-15 03:14:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_titleId != 0)
|
|
|
|
{
|
|
|
|
// TODO: Service store some private fields in another static object.
|
|
|
|
|
|
|
|
if ((_permissionFlag & 0x8040) == 0)
|
|
|
|
{
|
|
|
|
// TODO: Service store TitleId and FreeCommunicationEnabled in another static object.
|
|
|
|
// When it's done it signal an event in this static object.
|
|
|
|
Logger.PrintStub(LogClass.ServicePctl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resultCode = ResultCode.Success;
|
2018-06-13 02:51:59 +02:00
|
|
|
}
|
2018-06-12 20:28:45 +02:00
|
|
|
|
2020-05-15 03:14:38 +02:00
|
|
|
return resultCode;
|
2018-06-12 20:28:45 +02:00
|
|
|
}
|
2019-04-22 08:54:47 +02:00
|
|
|
|
2019-07-12 03:13:43 +02:00
|
|
|
[Command(1001)]
|
|
|
|
// CheckFreeCommunicationPermission()
|
2019-07-14 21:04:38 +02:00
|
|
|
public ResultCode CheckFreeCommunicationPermission(ServiceCtx context)
|
2019-04-22 08:54:47 +02:00
|
|
|
{
|
|
|
|
Logger.PrintStub(LogClass.ServicePctl);
|
|
|
|
|
2020-05-15 03:14:38 +02:00
|
|
|
if (!_freeCommunicationEnabled)
|
|
|
|
{
|
|
|
|
return ResultCode.FreeCommunicationDisabled;
|
|
|
|
}
|
|
|
|
|
2019-07-14 21:04:38 +02:00
|
|
|
return ResultCode.Success;
|
2019-04-22 08:54:47 +02:00
|
|
|
}
|
2018-02-10 01:14:55 +01:00
|
|
|
}
|
|
|
|
}
|