Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: sdk7 renderer restricted actions #5033

Merged
merged 16 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { RpcClientPort } from '@dcl/rpc'
import * as codegen from '@dcl/rpc/dist/codegen'
import { RestrictedActionsServiceDefinition } from 'shared/protocol/decentraland/renderer/renderer_services/restricted_actions.gen'
import defaultLogger from 'lib/logger'

// eslint-disable-next-line @typescript-eslint/ban-types
export function registerRestrictedActionsService<Context extends {}>(
clientPort: RpcClientPort
): codegen.RpcClientModule<RestrictedActionsServiceDefinition, Context> | undefined {
try {
return codegen.loadService<Context, RestrictedActionsServiceDefinition>(clientPort, RestrictedActionsServiceDefinition)
} catch (e) {
defaultLogger.error('EmotesService could not be loaded')
return undefined
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ export function registerRestrictedActionsServiceServerImplementation(port: RpcSe
ctx.logger.error('Error: Player is not inside of scene', lastPlayerPosition)
return { success: false }
}
// TODO: implement this fn in renderer-protocol RPC
const success = false // await unity.openExternalUrl(sceneId, req.message, req.realm)
return { success }
const response = await getRendererModules(store.getState())?.restrictedActions?.
openExternalUrl({url: req.url, sceneNumber: ctx.sceneData.sceneNumber})
return { success: response?.success?? false }
},
async openNftDialog(req: OpenNftDialogRequest, ctx: PortContext) {
if (!ctx.sdk7) throw new Error('API only available for SDK7')
Expand All @@ -140,9 +140,8 @@ export function registerRestrictedActionsServiceServerImplementation(port: RpcSe
return { success: false }
}

// TODO: implement this fn in renderer-protocol RPC
const success = false // await unity.openExternalUrl(sceneId, req.urn)
return { success }
const response = await getRendererModules(store.getState())?.restrictedActions?.openNftDialog({urn: req.urn})
return { success: response?.success?? false }
},
async setCommunicationsAdapter(req: CommsAdapterRequest, ctx: PortContext) {
if (!ctx.sdk7) throw new Error('API only available for SDK7')
Expand Down
4 changes: 3 additions & 1 deletion browser-interface/packages/shared/renderer/sagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { call, fork, put, select, take, takeEvery, takeLatest } from 'redux-saga
import { createRendererRpcClient } from 'renderer-protocol/rpcClient'
import { registerEmotesService } from 'renderer-protocol/services/emotesService'
import { registerFriendRequestRendererService } from 'renderer-protocol/services/friendRequestService'
import { registerRestrictedActionsService } from 'renderer-protocol/services/restrictedActionsService'
import { createRpcTransportService } from 'renderer-protocol/services/transportService'
import { trackEvent } from 'shared/analytics/trackEvent'
import { receivePeerUserData } from 'shared/comms/peers'
Expand Down Expand Up @@ -81,7 +82,8 @@ function* handleRegisterRpcPort() {
if (createRpcTransportService(port)) {
const modules: RendererModules = {
emotes: registerEmotesService(port),
friendRequest: registerFriendRequestRendererService(port)
friendRequest: registerFriendRequestRendererService(port),
restrictedActions: registerRestrictedActionsService(port)
}

yield put(registerRendererModules(modules))
Expand Down
2 changes: 2 additions & 0 deletions browser-interface/packages/shared/renderer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const AVATAR_SCENE_INITIALIZED = '[RENDERER] Avatar initialized correctly
export const PARCEL_LOADING_STARTED = '[RENDERER] Parcel loading started'
export const RENDERER_INITIALIZE = '[RENDERER] Initializing'
import * as codegen from '@dcl/rpc/dist/codegen'
import { RestrictedActionsServiceDefinition } from 'shared/protocol/decentraland/renderer/renderer_services/restricted_actions.gen'
import { EmotesRendererServiceDefinition } from 'shared/protocol/decentraland/renderer/renderer_services/emotes_renderer.gen'
import { FriendRequestRendererServiceDefinition } from 'shared/protocol/decentraland/renderer/renderer_services/friend_request_renderer.gen'

Expand All @@ -20,6 +21,7 @@ export type RendererState = {
export type RendererModules = {
emotes: codegen.RpcClientModule<EmotesRendererServiceDefinition, any> | undefined
friendRequest: codegen.RpcClientModule<FriendRequestRendererServiceDefinition, any> | undefined
restrictedActions: codegen.RpcClientModule<RestrictedActionsServiceDefinition, any> | undefined
}

export type RootRendererState = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
syntax = "proto3";
package decentraland.renderer.renderer_services;

message OpenExternalUrlRequest {
string url = 1;
int32 scene_number = 2;
}

message OpenNftDialogRequest {
string urn = 1;
}

message OpenModalResponse {
bool success = 1;
}

service RestrictedActionsService {
// OpenExternalUrl prompts the user to open an external link
rpc OpenExternalUrl(OpenExternalUrlRequest) returns (OpenModalResponse) {}

// OpenNftDialog opens an NFT dialog.
rpc OpenNftDialog(OpenNftDialogRequest) returns (OpenModalResponse) {}
}
1 change: 1 addition & 0 deletions renderer-protocol/public/renderer-interface.proto
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import public "decentraland/renderer/renderer_services/transport.proto";
import public "decentraland/renderer/renderer_services/emotes_renderer.proto";
import public "decentraland/renderer/renderer_services/scene_controller.proto";
import public "decentraland/renderer/renderer_services/friend_request_renderer.proto";
import public "decentraland/renderer/renderer_services/restricted_actions.proto";
import public "decentraland/renderer/kernel_services/emotes_kernel.proto";
import public "decentraland/renderer/kernel_services/analytics.proto";
import public "decentraland/renderer/kernel_services/friend_request_kernel.proto";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"GUID:b2d6307f60c24030b1a4d7880416029a",
"GUID:f334064a9ed3462091d1b06f9e981366",
"GUID:75786085fa5b640a7bbd1a630221ed4c",
"GUID:2fe821e179184cbb98ebf1f449612fb4"
"GUID:2fe821e179184cbb98ebf1f449612fb4",
"GUID:fd239a454d9a4039b164f90867ea3216"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public ECSSystemsController(ECS7System componentWriteSystem, SystemsContext cont
context.internalEcsComponents.PointerEventsComponent,
interactionHoverCanvas,
Environment.i.world.state,
DataStore.i.ecs7),
DataStore.i.ecs7,
DataStore.i.rpc.context.restrictedActions),
billboardSystem.Update,
videoPlayerSystem.Update,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"GUID:2c34ba02f1f344b79b6820d6a72de170",
"GUID:fb529e4714eec4e4da9a3ff3e4da8eee",
"GUID:a871c50d0a774d2b8594d36cb4766e5e",
"GUID:4973650d2444c4561a15d50f24d91cd9"
"GUID:4973650d2444c4561a15d50f24d91cd9",
"GUID:fd239a454d9a4039b164f90867ea3216"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using DCL.ECSComponents;
using DCL.ECSRuntime;
using DCL.Interface;
using RPC.Context;
using System;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -24,6 +25,7 @@ private class State
public IWorldState worldState;
public IECSInteractionHoverCanvas interactionHoverCanvas;
public bool[] inputActionState;
public RestrictedActionsContext RestrictedActionsRpcContext;
}

private class EntityInput
Expand All @@ -42,7 +44,8 @@ public static Action CreateSystem(
IInternalECSComponent<InternalPointerEvents> pointerEvents,
IECSInteractionHoverCanvas interactionHoverCanvas,
IWorldState worldState,
DataStore_ECS7 dataStoreEcs)
DataStore_ECS7 dataStoreEcs,
RestrictedActionsContext restrictedActionsRpcContext)
{
var state = new State()
{
Expand All @@ -54,6 +57,7 @@ public static Action CreateSystem(
dataStoreEcs7 = dataStoreEcs,
lastHoverFeedback = new EntityInput() { hasValue = false },
inputActionState = new bool[INPUT_ACTION_ENUM.Length],
RestrictedActionsRpcContext = restrictedActionsRpcContext
};
return () => Update(state);
}
Expand Down Expand Up @@ -113,6 +117,13 @@ private static void Update(State state)

// update
prevState[i] = curState[i];

// set current frame count since input is required to prompt modals
// for externalUrl and Nft
if (curState[i] && IsValidInputForUnlockingUiPrompts(inputAction))
{
state.RestrictedActionsRpcContext.LastFrameWithInput = Time.frameCount;
}
}
}

Expand Down Expand Up @@ -338,5 +349,16 @@ private static void ShowHoverTooltips(this IECSInteractionHoverCanvas canvas,
canvas.Hide();
}
}

private static bool IsValidInputForUnlockingUiPrompts(InputAction inputAction)
{
return inputAction == InputAction.IaPointer
|| inputAction == InputAction.IaPrimary
|| inputAction == InputAction.IaSecondary
|| inputAction == InputAction.IaAction3
|| inputAction == InputAction.IaAction4
|| inputAction == InputAction.IaAction5
|| inputAction == InputAction.IaAction6;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"GUID:1320d33ea2522ba4e8e60cf9e6a351dd",
"GUID:a871c50d0a774d2b8594d36cb4766e5e",
"GUID:4973650d2444c4561a15d50f24d91cd9",
"GUID:ac62e852826a4b36aeb22931dad73edb"
"GUID:ac62e852826a4b36aeb22931dad73edb",
"GUID:fd239a454d9a4039b164f90867ea3216"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ECSSystems.PointerInputSystem;
using NSubstitute;
using NUnit.Framework;
using RPC.Context;
using System;
using System.Collections.Generic;
using UnityEngine;
Expand All @@ -30,6 +31,7 @@ public class ECSPointerInputSystemShould
private IECSInteractionHoverCanvas interactionHoverCanvas;
private ECSComponentsManager componentsManager;
private InternalECSComponents internalComponents;
private RestrictedActionsContext restrictedActionsRpcContext;

private Collider colliderEntity1;
private Collider colliderEntity2;
Expand Down Expand Up @@ -58,20 +60,17 @@ public void SetUp()
interactionHoverCanvas = Substitute.For<IECSInteractionHoverCanvas>();
interactionHoverCanvas.tooltipsCount.Returns(MAX_TOOLTIPS);

restrictedActionsRpcContext = new RestrictedActionsContext();
restrictedActionsRpcContext.LastFrameWithInput = -1;

systemUpdate = ECSPointerInputSystem.CreateSystem(
internalComponents.onPointerColliderComponent,
internalComponents.inputEventResultsComponent,
internalComponents.PointerEventsComponent,
interactionHoverCanvas,
worldState,
dataStoreEcs7);

// systemUpdate = () =>
// {
// internalComponents.MarkDirtyComponentsUpdate();
// inputSystemUpdate();
// internalComponents.ResetDirtyComponentsUpdate();
// };
dataStoreEcs7,
restrictedActionsRpcContext);

testUtils = new ECS7TestUtilsScenesAndEntities(componentsManager, executors);
inputEventResultsComponent = internalComponents.inputEventResultsComponent;
Expand Down Expand Up @@ -679,5 +678,28 @@ public void EnsureWebInterfaceAndProtobufInputEnumsMatch()
Assert.AreEqual(inputActionsWebInterface[i], inputActionsProto[i]);
}
}

[Test]
[TestCase(InputAction.IaAction3, ExpectedResult = true)]
[TestCase(InputAction.IaAction4, ExpectedResult = true)]
[TestCase(InputAction.IaAction5, ExpectedResult = true)]
[TestCase(InputAction.IaAction6, ExpectedResult = true)]
[TestCase(InputAction.IaPrimary, ExpectedResult = true)]
[TestCase(InputAction.IaSecondary, ExpectedResult = true)]
[TestCase(InputAction.IaPointer, ExpectedResult = true)]
[TestCase(InputAction.IaAny, ExpectedResult = false)]
[TestCase(InputAction.IaForward, ExpectedResult = false)]
[TestCase(InputAction.IaBackward, ExpectedResult = false)]
[TestCase(InputAction.IaRight, ExpectedResult = false)]
[TestCase(InputAction.IaLeft, ExpectedResult = false)]
[TestCase(InputAction.IaJump, ExpectedResult = false)]
[TestCase(InputAction.IaWalk, ExpectedResult = false)]
public bool SetCurrentFrameWhenInputActionIsValid(InputAction inputAction)
{
int currentFrame = Time.frameCount;
dataStoreEcs7.inputActionState[(int)inputAction] = true;
systemUpdate();
return currentFrame == restrictedActionsRpcContext.LastFrameWithInput;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
"GUID:2ac9dcbe2d83f4e4e8718930a56a2791",
"GUID:0663fad624d836944b40ae27c3414652",
"GUID:a1cf976a7c506454885f68dea2cdd7c3",
"GUID:3b80b0b562b1cbc489513f09fc1b8f69"
"GUID:3b80b0b562b1cbc489513f09fc1b8f69",
"GUID:fd239a454d9a4039b164f90867ea3216",
"GUID:28f74c468a54948bfa9f625c5d428f56"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using DCL.Interface;
using DCL.Helpers;
using RPC.Context;
using Environment = DCL.Environment;

public class ExternalUrlPromptHUDController : IHUD
Expand All @@ -13,14 +14,19 @@ public class ExternalUrlPromptHUDController : IHUD

internal Dictionary<int, HashSet<string>> trustedDomains = new Dictionary<int, HashSet<string>>();

public ExternalUrlPromptHUDController()
private readonly RestrictedActionsContext restrictedActionsServiceContext;

public ExternalUrlPromptHUDController(RestrictedActionsContext restrictedActionsContext)
{
view = UnityEngine.Object.Instantiate(Resources.Load<GameObject>("ExternalUrlPromptHUD")).GetComponent<ExternalUrlPromptView>();
view.name = "_ExternalUrlPromptHUD";
view.content.SetActive(false);

if (Environment.i != null)
Environment.i.world.sceneController.OnOpenExternalUrlRequest += ProcessOpenUrlRequest;

restrictedActionsServiceContext = restrictedActionsContext;
restrictedActionsServiceContext.OpenExternalUrlPrompt += ProcessOpenUrlRequest;
}

public void SetVisibility(bool visible)
Expand Down Expand Up @@ -51,17 +57,24 @@ public void Dispose()

if (view != null)
UnityEngine.Object.Destroy(view.gameObject);

restrictedActionsServiceContext.OpenExternalUrlPrompt -= ProcessOpenUrlRequest;
}

internal void ProcessOpenUrlRequest(IParcelScene scene, string url)
{
ProcessOpenUrlRequest(url, scene.sceneData.sceneNumber);
}

internal bool ProcessOpenUrlRequest(string url, int sceneNumber)
{
Uri uri;
if (Uri.TryCreate(url, UriKind.Absolute, out uri))
{
if (trustedDomains.ContainsKey(scene.sceneData.sceneNumber) && trustedDomains[scene.sceneData.sceneNumber].Contains(uri.Host))
if (trustedDomains.ContainsKey(sceneNumber) && trustedDomains[sceneNumber].Contains(uri.Host))
{
OpenUrl(url);
return;
return true;
}

SetVisibility(true);
Expand All @@ -71,12 +84,12 @@ internal void ProcessOpenUrlRequest(IParcelScene scene, string url)
switch (result)
{
case ExternalUrlPromptView.ResultType.APPROVED_TRUSTED:
if (!trustedDomains.ContainsKey(scene.sceneData.sceneNumber))
if (!trustedDomains.ContainsKey(sceneNumber))
{
trustedDomains.Add(scene.sceneData.sceneNumber, new HashSet<string>());
trustedDomains.Add(sceneNumber, new HashSet<string>());
}

trustedDomains[scene.sceneData.sceneNumber].Add(uri.Host);
trustedDomains[sceneNumber].Add(uri.Host);
OpenUrl(url);
break;
case ExternalUrlPromptView.ResultType.APPROVED:
Expand All @@ -86,12 +99,16 @@ internal void ProcessOpenUrlRequest(IParcelScene scene, string url)

SetVisibility(false);
});

return true;
}

return false;
}

private void OpenUrl(string url)
{
WebInterface.OpenURL(url);
AnalyticsHelper.SendExternalLinkAnalytic(url);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"GUID:555c1f3c6d18648df910b7a1de75b424",
"GUID:97d8897529779cb49bebd400c7f402a6",
"GUID:d7f1765642f0c22cda30addd0275b5e1",
"GUID:44a9db8f655ab05409802e5476cf9dd3"
"GUID:44a9db8f655ab05409802e5476cf9dd3",
"GUID:fd239a454d9a4039b164f90867ea3216"
],
"includePlatforms": [],
"excludePlatforms": [],
Expand Down
Loading