Author Topic: Ownership OnNetworkPlayerLeave  (Read 3295 times)

Suvu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Ownership OnNetworkPlayerLeave
« on: February 20, 2013, 10:59:58 AM »
I came across this issue when a player leaves the channel :

Each player that joins creates an instance of an object for managing some information about that player. (Each player 'owns' thier own InfoObject as they create it through TNManager.Create())
When a player leaves, the host tries to delete the InfoObject for the leaving player but ends up deleting it's own.
The problem seems to be that the Player returned by OnNetworkPlayerLeave(Player) always has the HostID.

I checked on TNObject.cs and saw this :

  1.     void OnNetworkPlayerLeave (Player p) { if (p.id == mOwner) p.id = TNManager.hostID; }
  2.  

Is that a bug? Should that be this instead?

  1.     void OnNetworkPlayerLeave (Player p) { if (p.id == mOwner) mOwner = TNManager.hostID; }
  2.  

Cheers

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ownership OnNetworkPlayerLeave
« Reply #1 on: February 20, 2013, 07:32:40 PM »
This is intentional. Ownership is transferred to the host when the player leaves. You need to save the owner player on the script attached to your object, then implement OnNetworkPlayerLeave and destroy the object if the player matches the one who just left.

Suvu

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 11
    • View Profile
Re: Ownership OnNetworkPlayerLeave
« Reply #2 on: February 21, 2013, 04:02:32 AM »
But the code I pasted (from TNObject.cs) doesn't change the ownership of the TNObject back to the host, instead it changes the PlayerID of the passed Player parameter to the HostID...

For example :
  • Player "Dave" joins the game as Host (PlayerID 1)
  • Player "James" joins the game as Client (PlayerID 2)
  • James leaves the game
  • OnNetworkPlayerLeave(Player p) is called on all GameObjects
  • p.name = "James" which is correct, but! p.id = 1 (It should still be 2 right?)
Hope that makes sense, and thanks for the help Aren!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ownership OnNetworkPlayerLeave
« Reply #3 on: February 21, 2013, 04:28:25 AM »
If that's the case, then it's indeed a bug I should fix.