You are correct about Godot not having explicit public and private functions. However, that’s not actually related to RPCs and network security at all.
RPCs (Remote Procedure Calls) simply are a way to tell other machines over the network to either do something and/or send simple data like strings, bools, integers, etc.
For security, you really don’t have to worry. Just NEVER allow peers to send files over an RPC themselves. Which is called serialization.
Also, for RPC calls, there are a few arguments that determine which peer can call a function on another peer’s machine.
Firstly, Use your_function.rpc() to tell all other clients to perform a function.
Secondly, use your_function.rpc_id(client_id) to tell a specific client to perform a function. The client is marked by their unique id given when they join a server.
An RPC’s arguments are the following: mode, sync, transfer_mode, and transfer_channel
mode controls what clients can call the function as an RPC.
- If it’s
authority, then only the multiplayer authority (usually the server or host) can call this function on other clients.
- if it’s
any_peer, then any client can call this function on other clients.
sync controls what instances the RPC are called on. (This is confusing AF at first)
- If it’s
call_remote, the function will ONLY trigger for the client you called the RPC to.
- If it’s
call_local, the function will trigger for BOTH the client that called it and the client you called the RPC to.
I recommend only using call_remote, then do the local function for the sending client/server.
transfer_mode determines how the packet (information) is transmitted over the internet.
reliable means that the packet is guaranteed to reach the other client. However, it is slower than the other transfer modes. Use this for data that HAS to sync in order for your game to work.
unreliable means that the packet sends itself as fast as possible, but has a chance of being lost in transit or being out of order.
unreliable_ordered means that the packet sends itself as fast as possible, but will always be received in the correct order. This is great for syncing player movement.
transfer_channel is a little hard to explain. Imagine a channel being a road, each road can only send one RPC at a time. So having multiple roads will allow you to send multiple RPCs as once.
The channel is determined by a number starting from 0. As a brief example:
- Channel
0 is the main gameplay functions.
- Channel
1 is the non-gameplay functions like text chat.
- Channel
2is for non-time-sensitive data transfer like stats.
- Etc. You can be as creative as you want.
There’s a lot more to RPC, as every game has specific needs, but I hope this helps.