From 8b29a76d1dd0706a95d38afe0d106a261f25a7b8 Mon Sep 17 00:00:00 2001 From: 4ian <1280130+4ian@users.noreply.github.com> Date: Sat, 1 Aug 2026 10:37:50 +0000 Subject: [PATCH] [Auto] [Improve] Added P2P IP-address protection and connection/disconnection/error detection to peer-to-peer documentation --- automated_updates_data.json | 4 ++++ docs/gdevelop5/all-features/p2p/index.md | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/automated_updates_data.json b/automated_updates_data.json index 2fa8e494dbb..f25bc1aff7d 100644 --- a/automated_updates_data.json +++ b/automated_updates_data.json @@ -104,6 +104,10 @@ { "date": "2026-07-07", "summary": "Improved keyboard docs: added 'Key just pressed' (held vs one-frame) and 'Any key released' conditions, control-remapping note, and a reference list of valid key names" + }, + { + "date": "2026-08-01", + "summary": "Improved P2P docs: added IP-address protection via relay/custom ICE server, and connection/disconnection/error detection conditions and expressions" } ] } diff --git a/docs/gdevelop5/all-features/p2p/index.md b/docs/gdevelop5/all-features/p2p/index.md index c348c0774a8..5c297e65a83 100644 --- a/docs/gdevelop5/all-features/p2p/index.md +++ b/docs/gdevelop5/all-features/p2p/index.md @@ -63,10 +63,29 @@ After the above has been completed, the **Use custom broker server** action is u You can also use the default server provided by PeerJS. To use that server use the action "Use the default server". +## Protecting the players' IP addresses + +As explained in the warnings above, connecting directly to another peer normally exposes both players' IP addresses to each other. To avoid this, you can force all traffic to go through a relay (TURN) server instead of a direct connection: + + * Use the **Disable IP address sharing** action (before connecting to the broker). This forces the game to only use relay servers, so peers never learn each other's IP address. + * A relay server is required for this to work. Use the **Use a custom ICE server** action to provide the URL (and optional username/password) of a STUN/TURN server. This action must also be called before connecting to a broker. + +Relaying every message through a server adds some latency and requires you to run (or pay for) a TURN server, so it is a trade-off between privacy and performance/cost. + ## Connecting To connect instances, you need to enter their ID in the other instances. The ID can be found with the expression `P2P::GetID()`. To connect, use the "Connect to other instance" action and pass as a parameter the ID of another instance. Both instances will then connect automatically. You can then send an event from one instance to the other one to make sure that the connection is established. +### Detecting connections, disconnections and errors + +Rather than assuming a connection is established, you can react to the peer-to-peer events themselves: + + * The **Peer connected** condition is true for one frame when a new peer connects. The expression `P2P::GetLastConnectedPeer()` returns the ID of that peer. + * The **Peer disconnected** condition is true for one frame when a peer disconnects. The expression `P2P::GetLastDisconnectedPeer()` returns the ID of the peer that left, which is useful to remove the corresponding player from your game. + * The **An error occurred** condition lets you handle failures (for example an unreachable broker server), and `P2P::GetLastError()` returns a description of the problem. + +You can also check that the connection to the broker is ready with the **Is P2P ready** condition before trying to connect to other clients. + ### Changing the ID generation The default P2P ID generation is very long to avoid conflicts, but if you want to have an easily shareable ID, it is not ideal. You can use a custom ID generation on your custom P2P broker by following [the instructions on the peerjs-server documentation](https://github.com/peers/peerjs-server#custom-client-id-generation).