I am currently writing all the cloud functions we need for a server authorative solution.
Use Case:
if (await TryUpgrade(priceList,cloudSave,projectId,playerId..)) {
return true;
} else {
//TODO seperate cloud function for logging suspicious attempts
return false;
}
Almost all of my cloud functions evaluate if an action really can be done, the client should have always known this since it has the requirements from the remote config.
So it is suspicious that there was a call of the cloud function in this case.
I want to log this suspicious attempts in a cloudsave entry that is also created from a cloud function.
But I dont want to add this code to every single cloud function if I dont have to.
So here the question:
Can I call a cloud function from a cloud function?
So I can have the suspicious logging function at one place and have all other functions call it?
If It is possible would you suggest to do so or warn about it? (too many calls, even if it shouldnt happen for none cheaters)
(awaiting the result of called cloud function would not be required)
The examples are great and the documentation aswell even tough javascript was a new world initially.
Overall I am pretty happy with the new services and how feedback gathered and included.
Thank you for that!
David
Just to confirm, my understanding of the problem, you are wanting is to not have the same code in multiple scripts? While this isn’t currently possible to do, we’re looking into a file-based workflow that will enable this to be done through the editor. I will pass this over to our developers as a use case, in the meantime, you will need to put the suspicious logging function in each script you are wanting to run.
Thanks for your feedback on the products, we are constantly trying to improve the products having the use-cases you have provided now and in the past has helped but the features are useful to you.
I agree with OP in that it would be useful to be able to call cloud code functions from cloud code itself. For example in my situation, I have one script that generates a list of shop items periodically, but I also have another script that creates new user data + generates a new list of shop items. Instead of having to copy/paste a whole bunch of code into my 2nd script, being able to just call it like a function would be easier and cleaner.
Is there any update regarding this feature? Otherwise it might be possible to achieve that with webpack maybe.
EDIT:
I created a batch script that merge js files to be able to reuse code.
Put your shared code in the Shared folder.
Put your endpoints code in the Endpoints folder.
Create a .bat file with the following code and run it.
::===============================================================
:: Merge files in Endpoints/ and Shared/ to create the final backend endpoints.
:: Allow to reuse code between endpoints by adding types and functions in the Shared folder.
::===============================================================
@echo off
setlocal enableextensions enabledelayedexpansion
if exist "%~dp0Dist" rd /s /q "%~dp0Dist"
if not exist "%~dp0Dist" mkdir "%~dp0Dist"
for %%i in ("%~dp0Endpoints\*.js") do (
Set path=%%i
Set filedrive=%%~di
Set filepath=%%~pi
Set filename=%%~ni
Set fileextension=%%~xi
copy /y NUL "%~dp0Dist\!filename!.js" >NUL
copy /b "%~dp0Dist\!filename!.js"+"%~dp0Shared\*.js" "%~dp0Dist\!filename!.js" >NUL
copy /b "%~dp0Dist\!filename!.js"+"%~dp0Endpoints\!filename!.js" "%~dp0Dist\!filename!.js" >NUL
echo !filename! Done
)
Since the initial post, we’ve launched CCC# modules and Observability which I believe would help resolve some of the issues of code reuse and logging suspicous activity.
For Cloud Code scripts, there is currently some partial support for bundling via the Unity Editor (see JavaScript Project | Cloud Code | 2.7.1) which would allow you to include additional scripts.