Skip to content

WebRTCMultiplayerPeer reports as server when initialized with create_client #98802

Open
@jkirsteins

Description

@jkirsteins

Tested versions

  • Reproduced in v4.3.stable.official [77dcf97]

System information

Godot v4.3.stable - macOS 15.0.0 - GLES3 (Compatibility) - Intel(R) Iris(TM) Plus Graphics OpenGL Engine - Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz (8 Threads)

Issue description

tldr: When using WebRTCMultiplayerPeer initialized with create_client, the multiplayer.is_server() call can return true after the connection to the server is closed.

This seems to happen if a client-server connection is established, and then the server is disconnected. WebRTCMultiplayerPeer::get_unique_id() will return 1, regardless of the network mode. Before the disconnect, multiplayer.is_server() will return false. When a disconnect happens, it will start returning true ( because it compares the result of get_unique_id to 1 )

Two issues with this are:

  • this is undocumented
  • there seems to be an inconsistency in behaviour with other multiplayer peers (e.g. WebSocketMultiplayerPeer will never flip; ENetMultiplayerPeer I think would flip in the opposite direction when inactive)

I spotted this because I was relying on multiplayer.is_server() to determine when to make some RPC calls, or which signals to subscribe to. There is an error message about the disconnect state, but it was not obvious that it would affect the network mode reporting.

While this seems like a bug to me, I don't know enough about Godot or WebRTC to be confident this needs a change. If you think this is not an issue, I'm happy to open a godot-docs PR to clarify this behaviour.

Steps to reproduce

  • Create a new multiplayer peer: var rtc_mp = WebRTCMultiplayerPeer.new()
  • Initialize as a client: rtc_mp.create_client(2)
  • Assign to multiplayer multiplayer.multiplayer_peer = rtc_mp
  • multiplayer.is_server() will return false until the server disconnects
  • Disconnect server
  • Verify that multiplayer.is_server() returns true (but it should return false, because we initialized with create_client)

There is an attached MRP, which you can just run and wait a few seconds, and see the console output.

Minimal reproduction project (MRP)

webrtcrepro.zip

To run this locally you might need the webrtc-native extension. I'm not including it in the MRP cause it's ~300 mb with all the libs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions