Commit graph

18 commits

Author SHA1 Message Date
Max Hilbrunner bd8380db55 Fix removing connected peer during disconnection 2024-02-25 18:44:02 +01:00
Rémi Verschelde 48a1a78390
Merge pull request #86260 from Faless/mp/fix_2way_auth
[MP] Fix auth not waiting for confirmation in some cases
2024-02-21 15:22:46 +01:00
A Thousand Ships 684752e75b
Replace error checks against size with is_empty 2024-02-09 12:50:15 +01:00
Fabio Alessandrelli 754036f82f [MP] Fix auth not waiting for confirmation in some cases
The auth implementation was treating any received packet as a remote
confirmation after the peer was confirmed locally.

It now correctly awaits for the remote confirmation packet before
admitting new peers.
2024-01-14 21:38:06 +01:00
Fabio Alessandrelli 4826c14d20 [MP] Fix complete_auth notifying the wrong peer
The SceneMultiplayer complete_auth method was not configuring the
multiplayer peer correctly, causing it to potentially send the
notification to the wrong peer, on the wrong channel, and/or with an
incorrect transfer mode.
2023-12-17 12:27:24 +01:00
Fabio Alessandrelli 311a27281f [MP] Avoid unnecessary internal ref/unrefs
Access the various internal components (cache/replicator) via pointer,
to avoid unnecessary overhead.
2023-10-10 14:42:54 +02:00
Rémi Verschelde 25b2f1780a
Style: Harmonize header includes in modules
This applies our existing style guide, and adds a new rule to that style
guide for modular components such as platform ports and modules:

Includes from the platform port or module ("local" includes) should be listed
first in their own block using relative paths, before Godot's "core" includes
which use "absolute" (project folder relative) paths, and finally thirdparty
includes.

Includes in `#ifdef`s come after their relevant section, i.e. the overall
structure is:

- Local includes
  * Conditional local includes
- Core includes
  * Conditional core includes
- Thirdparty includes
  * Conditional thirdparty includes
2023-06-15 14:35:45 +02:00
Fabio Alessandrelli f1e0d50841 [MP] Implement "watched" properties.
Checked at "delta_interval" (default = every frame), synchronized
(reliably) if changes are detected.
2023-05-24 05:21:41 +02:00
Rémi Verschelde 4d4fcd0a6f
Merge pull request #70721 from Faless/mp/4.x_fix_relay_option
[MP] Fix server_relay being unsettable.
2023-01-09 23:09:53 +01:00
Rémi Verschelde d95794ec8a
One Copyright Update to rule them all
As many open source projects have started doing it, we're removing the
current year from the copyright notice, so that we don't need to bump
it every year.

It seems like only the first year of publication is technically
relevant for copyright notices, and even that seems to be something
that many companies stopped listing altogether (in a version controlled
codebase, the commits are a much better source of date of publication
than a hardcoded copyright statement).

We also now list Godot Engine contributors first as we're collectively
the current maintainers of the project, and we clarify that the
"exclusive" copyright of the co-founders covers the timespan before
opensourcing (their further contributions are included as part of Godot
Engine contributors).

Also fixed "cf." Frenchism - it's meant as "refer to / see".
2023-01-05 13:25:55 +01:00
Fabio Alessandrelli d123b01e86 [MP] Fix server_relay being unsettable.
Clarify nuance in the docs.
2022-12-29 23:15:26 +01:00
Fabio Alessandrelli b19c1a2e4f [MP] New default multiplayer_peer acting as server.
Adds a OfflineMultiplayerPeer class which behaves like a server with no
connected peers.

Use OfflineMultiplayerPeer as default for SceneMultiplayer.

This means that the SceneTree will act as the multiplayer authority by
default.
Calls to is_server will return true, and calls to get_unique_id will
return TARGET_PEER_SERVER.
2022-11-20 14:17:20 +01:00
Fabio Alessandrelli f38e116026 [MP] Initial replication profiler.
Part of the current network profiler stack.
Tracks synchronizers, incoming/outgoing state sizes, and their
bandwidth usage.
2022-11-19 12:48:16 +01:00
Fabio Alessandrelli 92ed27d8f6 [MP] Improve network profiler.
Fix RPC profiler and add average RPC size.

Improve bandwidth debugger to account for all multiplayer traffic
(excluding the lower level peer transformations).
2022-11-17 03:14:21 +01:00
Fabio Alessandrelli 33dda2e68a [MP] Remove connection state signals from MultiplayerPeer.
Now handled directly by the MultiplayerAPI implementation.
2022-11-02 15:17:23 +01:00
Fabio Alessandrelli 9773803e4e [MP] Add optional authentication to SceneMultiplayer.
Add few methods to allow peers to exchange authentication information.

- `set_auth_callback(callback)`: Enable the authentication features.
  The callback is a `Callable` that accepts an `int` (the peer ID), and
  a `PackedByteArray` of data.
- The `peer_authenticating(id)` signal will be emitted instead of
  `peer_connected` when a new peer connects.
- Use `send_auth(id: int, data: PackedByteArray)` to exchange data.
- Call `complete_auth(id: int)` when the authentication process is
  complete and you expect to start receiving game data.
- The `peer_connected` signal will be emitted as soon as both parties
  complete the authentication.
- Use `disconnect_peer(id)` to disconnect a connected peer.
- If the `peer_connected` signal didn't fire for that peer (i.e. it was
  still in the authentication phase), the `peer_auth_failed` signal will
  be emitted instead of `peer_disconnected`.
2022-11-02 15:17:23 +01:00
Fabio Alessandrelli 7536d15fe3 [MP] Let MultiplayerAPI handle packet relaying and peer signaling.
MultiplayerPeer changes:

- Adds is_server_relay_supported virtual method

Informs the upper MultiplayerAPI layer if it can signal peers connected
to the server to other clients, and perform packet relaying among them.

- Adds get_packet_channel and get_packet_mode virtual methods

Allows the MultiplayerAPI to retrieve the channel and transfer modes to
use when relaying the last received packet.

SceneMultiplayerPeer changes:

- Implement peer signaling and packet relaying when the MultiplayerPeer
  advertise they are supported.

ENet, WebRTC, WebSocket changes:

- Removed custom code for relaying from WebSocket and ENet, and let it
  be handled by the upper layer.
- Update WebRTC to split create_client, create_server, and create_mesh,
  with the latter behaving like the old initialize with
  "server_compatibility = false", and the first two supporting the upper
  layer relaying protocol.
2022-10-27 18:08:58 +02:00
Fabio Alessandrelli ca7d572908 [Net] Modularize multiplayer, expose MultiplayerAPI to extensions.
- RPC configurations are now dictionaries.
- Script.get_rpc_methods renamed to Script.get_rpc_config.
- Node.rpc[_id] and Callable.rpc now return an Error.
- Refactor MultiplayerAPI to allow extension.
- New MultiplayerAPI.rpc method with Array argument (for scripts).
- Move the default MultiplayerAPI implementation to a module.
2022-07-26 09:31:12 +02:00