#Access control
1 messages ยท Page 1 of 1 (latest)
Hey! Yes you are. You havent yet hit the point of access control mattering. what is your server-side cloud-code?
What this is saying (probably) is that whatever signature you have is not currently supported by the binding generation. It is either the signature of your method or the signature of a class taken or received by it. Do you mind sharing it?
yea sure! thank you
using Unity.Services.CloudCode.Apis;
using Unity.Services.CloudCode.Core;
using Unity.Services.CloudCode.Shared;
using Unity.Services.Economy.Model;
using Microsoft.Extensions.DependencyInjection;
namespace BeggarCloudCode;
public class MyModule
{
[CloudCodeFunction("AddMoney")]
public async Task<ApiResponse<CurrencyBalanceResponse>> AddMoney(IExecutionContext ctx, IGameApiClient gameApiClient, int value)
{
try
{
return await gameApiClient.EconomyCurrencies.IncrementPlayerCurrencyBalanceAsync(ctx, ctx.ServiceToken,
ctx.ProjectId, ctx.PlayerId, "MONEY", new CurrencyModifyBalanceRequest("MONEY", value));
}
catch (ApiException ex)
{
throw new System.Exception($"Failed to get increment MONEY currency for player: {ctx.PlayerId}. Error: {ex.Message}");
}
}
public class ModuleConfig : ICloudCodeSetup
{
public void Setup(ICloudCodeConfig config)
{
config.Dependencies.AddSingleton(GameApiClient.Create());
}
}
}```
as I said it is based on the example script here :
https://docs.unity.com/ugs/en-us/manual/cloud-code/manual/modules/how-to-guides/access-control
atm I am trying to call this method via CloudCodeService.Instance.CallModuleEndpointAsync and it's working. I just don't understand from where should I get the gameApiClient. I am digging this right now.
About the access control, I needed it to deny the players to increment their "MONEY". My goal is to prevent cheating and validate every gain via cloud script.
ah I got it... the GameApiClient is not a parameter that I pass from the client. That is made in the cloud code in the ModuleConfig... then I have different scripting error
THE CLOUD CODE IS WORKING VIA CallModuleEndpointAsync
However I couldn't get a response yet, but the money value of the player is increasing...
I understand the need for Access Control, I'm just saying let's do stuff one at the time ๐
Ok so, IGameClientApi is fed via dependency injection, so it is ignored from generation, it contains the way to call the game apis, what's the error you're getting?
why are you returning "CurrencyBalanceResponse"
That class is probably generated from the economy api specification, it could have any number of random things in it, probably some we can't break down. Extract the part that matters to you into a class, and transfer the data and return it.
Then the binding generation will likely work, and you'll be off to the races
Specially bcs you're returning an ApiResponse generic, im not sure we support generics at all.
Basically, you should always return objects or primitives you have yourself declared and have control over
Well strange. I will definitely do that. I was blindly following the guide above. Thanks for the help! ๐
And it worked perfectly. Code bindings are generated! Thank you! ๐