Problem with removing players from lists on leave/disconnect

The whole answer can be found below.

Please note: The Photon forum is closed permanently. After many dedicated years of service we have made the decision to retire our forum and switch to read-only: we've saved the best to last! And we offer you support through these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

Problem with removing players from lists on leave/disconnect

petersenjmp
2021-05-23 09:13:37

Hi,
(Using PUN)
When a match starts in my game, all players are gathered on a list and shown on a highscoretable via RPC. The highscoretable is PhotonNetwork.Instatiate(d) once in the begininning of each tournament and it has a dont destroy on load on it. Players are removed from the highscoretable list when they exit to main menu or disconnect.

The problem is that when I start a new tournament all other clients names that were in the previous tournament still appear on the highscoretable list.

I've read that photon autamically cleares rpc buffers, but I guess. I've tried clearing rpc cahce with the following but I get errors on each of them (does not contain definition for...)

PhotonNetwork.OpCleanActorRpcBuffer (int actorNumber)
PhotonNetwork.CleanRpcBufferIfMine (PhotonView view)
PhotonNetwork.OpCleanRpcBuffer (PhotonView view)

How do I clear buffered rpcs with PUN? I'm guessing that that's the issue since the players that have already left haven't been told that the other players should be removed from the list.
I want it to be a clean start on awake with no old buffered player names etc. But all of the above is not working. I'd like a specific example on how to use the above lines of codes as this is not provided anywhere by photon

Comments

JohnTube
2021-05-24 10:01:09

Hi @petersenjmp,

So you use a single Photon room for multiple tournaments?
Otherwise I would expect the highscoretable networked object created using PhotonNetwork.Instantiate to be destroyed when the local client leaves the room.
And I would instantiate it as a room object as it does not belong to any player.

Maybe you are creating rooms with RoomOptions.CleanupCacheOnLeave = false? (Room.AutoCleanup = false)?

To make things simple, easy and clear I would keep CleanupCacheOnLeave default true and I would join a Photon room per tournament, this way the highscoretable will be instantiated with each new room.

petersenjmp
2021-05-25 05:17:13

Hi @JohnTube

Thank you, I'll experiment with CleanupCacheOnLeave.
Sorry I wasn't very clear in my post, no I use one room per tournament. But the issue is that the buffered rpc's that put the players names on the highscore table aren't cleared, so duplicates occur when restarting new tournaments.

Is: PhotonNetwork.OpCleanRpcBuffer (PhotonView view) for PUN or PUN2 because I get an error saying does not contain definition for OpCleanRpcBuffer ?

Would you recommend CleanupCacheOnLeave in room options rather than the last player to disconnect from the tournament commanding something like PhotonNetwork.OpCleanRpcBuffer (PhotonView view) (A working version of this of course) on the highscoretables photon view?

Tobias
2021-05-25 11:18:17

Let us know which PUN version you are using. It is confusing if your refer to Pun Classic and PUN 2.

Using OpCleanRpcBuffer(PhotonView view) should be correct.
You can also PhotonNetwork.Destroy(view) the view, then create a new one.

Overall, I think you want to use Custom Properties instead of RPCs. The highscore has not much to do with some networked object and the order in which the RPCs happened isn't relevant, most likely. Custom Properties do that job.

petersenjmp
2021-05-26 05:26:40

I'm using PUN classic. And I still don't know if OpCleanRpcBuffer(PhotonView view) is for PUN or PUN2 as you never answered that. I'm getting the error mentioned in my previous post so I assume it's not for PUN classic...

I have now experimented with custom properties by using RoomOptions.CleanupCacheOnLeave = true but am still seing old names on the list (highscore table) when starting a new tournament for a second playthrough.

I RPC each players name as a new list entry on start, and players are removed when they disconnect which doesn't happen at once. So the first ones to disconnect still see the names of players from previous matches even though I RPC for them to be removed from the list when they disconnect. I've tried roomOptions.CleanupCacheOnLeave = true; and PhotonNetwork.RemoveRPCs(ViewID); But duplicates still happen?

petersenjmp
2021-05-26 06:21:23

So I found a solution, kind of: I'm clearing the list locally for the player that leaves, that way that player doesn't see players who left after him on the list in a new tourney, but I'm worried theres an uncleared buffer that builds up over time and causes problems.

Tobias
2021-05-28 10:02:47

Glad you found a solution. Sorry for the late reaction here. Busy days.
How long is the room in use for a tournament (max)?

I'm using PUN classic. [...] I'm getting the error mentioned in my previous post so I assume it's not for PUN classic...

How is that working? You use PUN Classic and think you get errors that are not from PUN Classic?
Look up the PhotonNetwork.versionPUN / PhotonNetwork.PunVersion string please.

If it's PUN Classic, please update to PUN 2, no matter how painful that is. With PUN Classic you are running an outdated version which is missing mayor updates!
https://doc.photonengine.com/en-us/pun/v2/getting-started/migration-notes

I still don't know if OpCleanRpcBuffer(PhotonView view) is for PUN or PUN2 as you never answered that.

If that method is in the API you got, it's usable and should work as described in the reference. If it does not, let us know.

Again, I think that buffered RPCs are bad practicce, if you want to use a room for somewhat longer. Use Custom Properties and you will be able to clean then properly.

Back to top