diff --git a/automated_updates_data.json b/automated_updates_data.json index 88dd158d37e..0e936f54b84 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-09-09", + "summary": "Improved P2P docs: added sending/receiving data section (extra data, variable events, GetEventData/GetEventSender) and IP-leak mitigation via Disable IP sharing and custom ICE/TURN servers" } ] } diff --git a/docs/gdevelop5/all-features/p2p/index.md b/docs/gdevelop5/all-features/p2p/index.md index c348c0774a8..08314b9d23e 100644 --- a/docs/gdevelop5/all-features/p2p/index.md +++ b/docs/gdevelop5/all-features/p2p/index.md @@ -67,6 +67,12 @@ To use that server use the action "Use the default server". 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. +### Reducing IP address leaks + +By default, peers share their IP addresses directly with each other to establish the fastest connection possible (see the warning at the top of this page). If you want to avoid this, use the **"Disable IP address sharing"** action *before* connecting to the broker server. This forces all traffic to pass through a **TURN relay server** instead of going peer-to-peer directly. + +For this to work you must provide such a relay by adding it with the **"Use a custom ICE server"** action (also called before connecting). This action can be used several times to declare multiple STUN/TURN servers, and accepts an optional username and password for servers that require authentication. For games played over the internet rather than a local network, it is recommended to add at least one self-hosted STUN and TURN server. + ### 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). @@ -75,6 +81,17 @@ The default P2P ID generation is very long to avoid conflicts, but if you want t Once you got connected, you can trigger actions remotely. You can select another specific game instance (using its id) or send an event to all connected instances. +### Sending and receiving data + +A remote event is identified by an **event name** that you choose (for example `"playerMoved"` or `"chatMessage"`). The receiver reacts to it with the **"Event triggered by peer"** condition, using the same event name. + +You can attach data to an event when triggering it: + +* **Text data**: the "Trigger event on..." actions have an optional *extra data* text parameter. On the receiving side, read it with the `P2P::GetEventData("eventName")` expression. +* **Variable data**: use the "Trigger event on... (variable)" actions to send a whole variable (including a structure or array). On the receiving side, copy it into one of your variables with the "Get event data (variable)" action. + +To know which peer sent an event, use the `P2P::GetEventSender("eventName")` expression, which returns the ID of the client that triggered it. + ### Choosing if you want to activate data loss mode You might be wondering what the "data loss" parameter is for.