Making sure a function is executable only on the server

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dawkot
:warning: Old Version Published before Godot 3 was released.

How do you make sure that a function is only executable on the server?
I don’t want to do a simple get_tree().is_network_server() check because it doesn’t feel safe enough, I would prefer for a function to be completely unaccessible for clients.

There is no #ifdef like in C++ or C#, so if you want to make it completely unavailable, you can make two Godot projects. One for the server, and one for the client. But I find this a bit unpractical for sharing code.
If you keep the same project, whatever you do using GDScript, you’ll have to use is_network_server at some point. Either to call a function or not, or to instance a manager or another.

Zylann | 2016-10-14 22:51

:bust_in_silhouette: Reply From: godotlearner

This is what C/S does.

Can you call the remove function and remove my account on this website?
No. unless you hack this site.

You have no choice but developing a dedicated server.