freehuntx / godot-matcha

Easy webrtc matchmaking using WebTorrent tracker
MIT License
89 stars 4 forks source link

In Server/Client connections the assigned authority ID given with the "multiplayer.connected" signal is not synced between both parties. #12

Open person-615 opened 3 months ago

person-615 commented 3 months ago

Using Godot 4.3 Stable

With the "multiplayer.connected" signal, the id given is not synced when using Matcha.

ENet example for control, how it should work:

func join():
    var enet = ENetMultiplayerPeer.new()
    enet.create_client("lobalhost",135)
    multiplayer_multiplayer_peer = enet

    print(multiplayer.get_unique_id())       # Hypothetically prints 80498123

func host():
    var enet = ENetMultiplayerPeer.new()
    enet.create_server(135)
    multiplayer_multiplayer_peer = enet

    multiplayer.peer_connected.connect(func(id):
        print(id)        # Would print 80498123, synced with the client
    )

How it is currently behaving:

func join():
    var room = MatchaRoom.create_client_room( [HOST ID HERE] )
    multiplayer_multiplayer_peer = room

    print(multiplayer.get_unique_id())       # Hypothetically prints 58129612

func host():
    var room = MatchaRoom.create_server_room()
    multiplayer_multiplayer_peer = room

    multiplayer.peer_connected.connect(func(id):
        print(id)        # Hypothetically prints 91286332, NOT synced with client.
    )

I have replicated this issue and it is present in an example project.

person-615 commented 2 months ago

Did not mean to close this, it is still an issue. I checked and it occurs in 4.2 as well, not just 4.3

masterthdev commented 2 months ago

I solved this on one of my projects, but it was using an old version of matcha(I don't remember which commit). It was also spamming errors, I don't remember if I fixed that.

I created a branch and copied changes from my project, feel free to have a look: https://github.com/masterthdev/godot-matcha/tree/sync-peer-ids

freehuntx commented 2 months ago

Im currently at vacation. I take a look when im back. Sorry.

person-615 commented 2 months ago

masterthdev commented

Late reply, but this works without a hitch on 4.3 stable, thanks

jlemke commented 1 month ago

This fix can also work for mesh rooms with some tweaking. I don't know a lot about networking so there might be a cleaner solution, but I changed _on_got_offer() to create a new offer_peer if the offer_id doesn't match the answerer's rpc_id. Then the other peer creates the answer peer since the offer id matches. I also had to change Utils.gen_id() to take in an optional rpc_id, which it would use instead of the peer_id masterthdev added.

edit: still have an issue where it sometimes doesn't seem to answer offers correctly