Author Topic: Reconnecting to existing playerID  (Read 2621 times)

Zapgun

  • Guest
Reconnecting to existing playerID
« on: April 27, 2013, 10:01:22 AM »
Security concerns aside, I was wondering if there was an already existing strategy in place for reconnecting to a server and regaining ownership of persistent objects created with TNet?

If not, my current thinking is to have a unique client id stored in the playerPrefs on the client side, and then check against it in each object's OnNetworkJoinChannel() to pass back ownership when needed. Does anyone have any better strategy?

Ownership in this case doesn't necessarily mean TNet ownership - I just want it to appear as if the original player still has full control over those objects, although gaining access to TNManager.isThisMyObject() does make things more handy.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reconnecting to existing playerID
« Reply #1 on: April 27, 2013, 03:16:44 PM »
Generally the only really important object that should be owned by the player is the player's avatar, which should be removed when the player leaves anyway. Can you give an example of what you are trying to do in the game?

Zapgun

  • Guest
Re: Reconnecting to existing playerID
« Reply #2 on: April 27, 2013, 03:27:39 PM »
Hi Aren,

Thanks for the quick reply, always impressed by your support.

Changing the ownership of the player's avatar is exactly what I want to do! Imagine this scenario:

- Two teams, (Team A and B) with two players each.
- Each player controls one persistent player-piece (or avatar).
- If a player gets disconnected, I'd like to allow the other player to take control of his avatar until he reconnects.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Reconnecting to existing playerID
« Reply #3 on: April 27, 2013, 04:22:12 PM »
Sounds like you need to make TNObject.mOwner public so that you can modify it and set it to the player of your choice. Add this to TNObject:
  1. /// <summary>
  2.         /// ID of the player that owns this object.
  3.         /// </summary>
  4.  
  5.         public int ownerID
  6.         {
  7.                 get
  8.                 {
  9.                         return mOwner;
  10.                 }
  11.                 set
  12.                 {
  13.                         if (mOwner != value)
  14.                         {
  15.                                 mOwner = value;
  16.                                 Send("SetOwner", Target.Others, value);
  17.                         }
  18.                 }
  19.         }
  20.  
  21.         [RFC] void SetOwner (int val) { mOwner = val; }

Zapgun

  • Guest
Re: Reconnecting to existing playerID
« Reply #4 on: April 27, 2013, 04:56:34 PM »
Thanks Aren... exactly what I was looking for.

- Z