Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Shifty Geezer on November 28, 2016, 11:28:01 AM

Title: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: Shifty Geezer on November 28, 2016, 11:28:01 AM
  1.         IEnumerator Start ()    {
  2.                 while (TNManager.IsJoiningChannel(2)) yield return null;
  3.                 // When joined -->
  4.                 print ("Joined channel 2 "+TNManager.IsInChannel(2)+"    "+TNManager.lastChannelID);
Returns '0' for lastChannelID, not '2', the most recent channel joined. As a result, TNManager.isHosting fails if I leave the previous Channel.

That is, staying in the previous Channel 1
Quote
            TNManager.JoinChannel(2, "", false, AiaVG_GameManager.netMaxNumPlayers, "", false);
            TNManager.LoadLevel (2, "Adventuring");
means TNManager.isHosting returns true, lastChannelID == 1.
Quote
            TNManager.JoinChannel(2, "", false, AiaVG_GameManager.netMaxNumPlayers, "", true);
            TNManager.LoadLevel (2, "Adventuring");
means TNManager.isHosting returns false with lastChannelID == 0.

Even if I set the host manually, TNManager.isHosting fails...

  1.                 TNManager.JoinChannel(2, "", false, AiaVG_GameManager.netMaxNumPlayers, "", false);
  2.                 if (TNServerInstance.isActive){
  3.                         TNManager.SetHost (2, TNManager.player);
  4.                 }
  5.                 TNManager.LoadLevel (2, "Adventuring");
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: ArenMook on November 28, 2016, 11:34:11 AM
Last channel is the last channel from which a message was received IIRC. Not the last channel you joined.

You get join channel notifications for a reason :P
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: Shifty Geezer on November 28, 2016, 11:37:55 AM
Why does 'isHosting' use it then? If you create a channel, are the only person there and haven't received any notifications yet, surely you're the host?
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: ArenMook on November 28, 2016, 11:38:58 AM
TNManager.isHosting works if you only use 1 channel.

Use TNManager.GetHost(channelID) instead.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: Shifty Geezer on November 28, 2016, 11:41:13 AM
Yep. Just created a simple method:
  1.         public static bool AmIHosting(int channel){
  2.                 // returns if the host player of this channel
  3.                 return TNManager.player == TNManager.GetHost (channel);
  4.         }
  5.  
Now I know.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: ArenMook on November 28, 2016, 11:44:48 AM
I'll add TNManager.IsHosting(channelID) and put a warning in TNManager.isHosting to make this more obvious.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: ArenMook on November 28, 2016, 12:41:34 PM
Just put up 3.0.6b with the TNManager.IsHosting change in place.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: Shifty Geezer on November 29, 2016, 05:55:50 AM
Target.Host isn't working in tno.sends when I leave Channel 1 and remain in Channel 2. I can use a player id of 1 to communicate with the host, or GetHost(2), but all my networking is now broke! None of my RFCs are being called etc. and changing the references to GetHost/IsHosting() is breaking other aspects.

Target.Host doesn't seem reliable, and I'm not sure if the other Target options will be as a result.

For the moment I'll revert to operating two channels in parallel and try to work a solution around that. Any suggestions for how to do drop-in drop-out coop with a player selection screen (think Diablo 3 with its player selection while other players can be in a map) would be very appreciated!
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: ArenMook on November 29, 2016, 01:37:51 PM
Target.Host isn't working for you with the latest? Do you receive the ResponseSetHost packet telling you who the new host is?
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: devomage on November 29, 2016, 04:58:19 PM
Any suggestions for how to do drop-in drop-out coop with a player selection screen (think Diablo 3 with its player selection while other players can be in a map) would be very appreciated!

The game ive been working on, I use a new persistent channel for each match/guild/private chat room.  I added extra TNet code so the creator of the channel can delete the channel and also the channel expires after XX seconds (3600).  Everything revolves around a central "lobby" channel (aka menus in D3).  A few extra's like broadcasting deleted channels from the server are also required.  Keep in mind, this is all one scene.  My GUI is a D3 hybrid, works and looks great!  There is a lot more to it, but these are the highlights.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: Shifty Geezer on November 30, 2016, 10:01:12 AM
Target.Host isn't working for you with the latest? Do you receive the ResponseSetHost packet telling you who the new host is?
Seems to be working.

Another issues has arisen though, and that's objects already present in a scene being assigned to Channel 1 instead of Channel 2 which was the channel specified when the scene was loaded.

Quote
TNManager.LoadLevel (2, "Adventuring");
The scene is loaded and new network objects are created in Channel 2. However, the already present Player and GameControl objects with fixed TN ids 1 through 10 are in channel 1.

I've tried transferring them to Channel 2 when the level is loaded but that doesn't work - they remain in Channel 1.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: ArenMook on November 30, 2016, 03:17:14 PM
Loading of levels is an asynchronous operation, and the "last channel" ID is set once at start. It can change during the loading process. TNObjects assign the ID in their Awake() function when the scene finishes loading to whatever the latest is.

I really don't recommend using static objects with a multi-scene setup. Consider simply having the first player instantiate an object in the explicit channel you need if that object doesn't already exist. I do that in W2 for chat for example -- player joins, gets the "joined channel" notification and checks -- is there already a global chat object? If not, instantiate one in the chat's channel.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: Shifty Geezer on November 30, 2016, 04:20:41 PM
I really don't recommend using static objects with a multi-scene setup. Consider simply having the first player instantiate an object in the explicit channel you need if that object doesn't already exist.
Probably not a realistic option at this point. There's 18 months work around the current structure which was created before multiple channel subscriptions was a feature of TNet and it's not a feature my game will benefit from AFAICS.

Is there a reliable point I can force a transfer to a specified channel? Could a function/parameter be provided to specify the TNO channel that an object is instantiated in?

Thinking aloud, I suppose I can swap my channels and have the default the game and the subsequent channel for player management.
Title: Re: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel
Post by: ArenMook on November 30, 2016, 04:43:09 PM
Just check TNObject's Awake() function. It sets the channel ID inside. You could add a new field "explicit channel ID" or something to that extent, and have it use that value, if it has been set.