Updating peer’s data remotely
Something really cool about Godot Engine’s Network API is that we can abuse RPCs to pass data around. For instance, we’ve seen that we use the player’s avatar name in our messages. But have you asked yourself how we retrieve this data in any of these steps?
You probably saw that there’s an RPC method called set_avatar_name()
, right? Since its @rpc
annotation doesn’t have any options, you can assume that it uses the default options. This is important to know because, as we saw previously, this means that it should be called remotely only by the Multiplayer Authority – in this case, the server.
Let’s open ChatServer.gd
to understand what’s happening behind the scenes. In essence, most of it is pretty much the same as in the Lobby project, but you will notice something slightly different in the retrieve_avatar()
RPC method. In line 39, we have the following instruction:
var peer_id =...