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
| Parameter | Type | Required | Description |
|---|---|---|---|
| table_code | string | Required | Cloud code table code |
| function_name | string | Required | Function name to execute |
| function_arguments | string | Required | Function arguments (JSON string) |
Response Data
| Field | Type | Description |
|---|---|---|
| Function | object | Executed function information |
| Logs | array | Function execution logs |
| Result | object | Function execution result |
| Error | string | Error message (when error occurs) |
| RunTimeMilliSeconds | number | Execution 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.