Skip to main content

Cloud Code Execution

Execute a cloud code function registered on the server.

Verify URL

This API uses the service-api.playnanoo.com domain.

API Information

  • URL: https://service-api.playnanoo.com/cloudcode/v20210901/run
  • Method: PUT
  • Authentication Required: Yes

Request Parameters

ParameterTypeRequiredDescription
table_codestringRequiredCloud code table code
function_namestringRequiredFunction name to execute
function_argumentsstringRequiredFunction arguments (JSON string)

Response Data

FieldTypeDescription
FunctionobjectExecuted function information
LogsarrayFunction execution logs
ResultobjectFunction execution result
ErrorstringError message (when error occurs)
RunTimeMilliSecondsnumberExecution time (milliseconds)

Code Example

void UMyGame::ExecuteCloudCode(const FString& TableCode, const FString& FunctionName)
{
// Create function arguments as JSON string
TSharedPtr<FJsonObject> ArgsObject = MakeShareable(new FJsonObject);
ArgsObject->SetStringField(TEXT("InputValue1"), TEXT("value1"));
ArgsObject->SetStringField(TEXT("InputValue2"), TEXT("value2"));

FString ArgsJson;
TSharedRef<TJsonWriter<>> ArgsWriter = TJsonWriterFactory<>::Create(&ArgsJson);
FJsonSerializer::Serialize(ArgsObject.ToSharedRef(), ArgsWriter);

// Create request body with player information
TSharedPtr<FJsonObject> Body = FPlayNANOOHelper::CreateRequestBody();
Body->SetStringField(TEXT("table_code"), TableCode);
Body->SetStringField(TEXT("function_name"), FunctionName);
Body->SetStringField(TEXT("function_arguments"), ArgsJson);

// Convert to JSON string
FString JsonBody = FPlayNANOOHelper::ToJsonString(Body);

// HTTP request
TSharedRef<IHttpRequest> Request = FHttpModule::Get().CreateRequest();
Request->SetURL(TEXT("https://service-api.playnanoo.com/cloudcode/v20210901/run"));
Request->SetVerb(TEXT("PUT"));
FPlayNANOOHelper::SetCommonHeaders(Request, true); // Include auth token
Request->SetContentAsString(JsonBody);

Request->OnProcessRequestComplete().BindLambda(
[](FHttpRequestPtr Req, FHttpResponsePtr Res, bool bSuccess)
{
if (bSuccess && Res.IsValid())
{
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(Res->GetContentAsString());

if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
int32 RunTime = JsonObject->GetIntegerField(TEXT("RunTimeMilliSeconds"));
UE_LOG(LogTemp, Log, TEXT("Cloud code execution complete (%dms)"), RunTime);
}
}
});

Request->ProcessRequest();
}
Cloud Code Usage

Cloud code allows you to execute game logic on the server to prevent client manipulation and safely handle complex calculations or data validation.

Execution Time

If the cloud code function execution time is too long, a timeout may occur. Efficient code writing is recommended.