alvyxaz / barebones-masterserver

Master Server framework for Unity
476 stars 106 forks source link

IPeer losing reference after abrupt disconnect and reconnect with Master #188

Open jasielmacedo opened 6 years ago

jasielmacedo commented 6 years ago

Hi guys, I'm developing a racing-based game called Deliverace using Barebones and this framework it's awesome but: Recently we received a lot of reports from players reporting this issue and I checked the default package of Barebones (github release or unity asset store package) and i found the same issue. Basically when player disconnect from master and reconnect + LogIn the IPeer loses reference. Methods like peer.GetExtension() or message.Peer.GetExtension() returns null; The same happens with custom Extensions.

This snippet of code inside AuthModule per example, extension returns null

var extension = message.Peer.GetExtension<IUserExtension>(); if (extension == null || extension.AccountData == null) { message.Respond("Invalid session", ResponseStatus.Unauthorized); return; } I'm using the MasterServerConnector to connect.

Apparently the Peer Id is not the same between server and Client. I made a debug and Server returns 1 connection with Id 1 and Client returns connected with Id 0

Any advice?

ghost commented 6 years ago

It's only logical to lose any reference, since the account is disconnecting. Upon disconnection, I believe the AuthModule gets rid of these extensions. Though, when you reconnect, a user extension should again be created through your database. But the peer created is a new peer and should be a completely new reference than the peer before disconnecting.

Though I'm not 100% on the above, I also don't understand where your problem lies, so that's all I can say for now.