Author Topic: TNManager.isHosting fails. TNManager.lastChannelID = 0 after joining channel  (Read 572 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 7
  • Posts: 216
    • View Profile
  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");

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 297
  • -Receive: 1136
  • Posts: 21,937
  • Toronto, Canada
    • View Profile
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

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 7
  • Posts: 216
    • View Profile
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?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 297
  • -Receive: 1136
  • Posts: 21,937
  • Toronto, Canada
    • View Profile
TNManager.isHosting works if you only use 1 channel.

Use TNManager.GetHost(channelID) instead.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 7
  • Posts: 216
    • View Profile
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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 297
  • -Receive: 1136
  • Posts: 21,937
  • Toronto, Canada
    • View Profile
I'll add TNManager.IsHosting(channelID) and put a warning in TNManager.isHosting to make this more obvious.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 297
  • -Receive: 1136
  • Posts: 21,937
  • Toronto, Canada
    • View Profile
Just put up 3.0.6b with the TNManager.IsHosting change in place.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 7
  • Posts: 216
    • View Profile
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!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 297
  • -Receive: 1136
  • Posts: 21,937
  • Toronto, Canada
    • View Profile
Target.Host isn't working for you with the latest? Do you receive the ResponseSetHost packet telling you who the new host is?

devomage

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 62
  • Posts: 232
    • View Profile
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.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 7
  • Posts: 216
    • View Profile
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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 297
  • -Receive: 1136
  • Posts: 21,937
  • Toronto, Canada
    • View Profile
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.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 7
  • Posts: 216
    • View Profile
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.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 297
  • -Receive: 1136
  • Posts: 21,937
  • Toronto, Canada
    • View Profile
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.