Author Topic: TNManager.isJoiningChannel always True when creating a new channel  (Read 409 times)

Ninja

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Hello, I'm using TNet v3.0.9.

When I create a new channel using TNManager.CreateChannel, the value for TNManager.isJoiningChannel seems to always return True and never goes back to False after successfully joining the channel.

Is this a bug or am I doing something wrong? Let me know if you need more information.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 143
  • Posts: 268
  • TNet Alchemist
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #1 on: August 12, 2017, 05:29:55 AM »
Not able to reproduce this on my end.

Could you try this code:
  1. void Start()
  2. {
  3.         DontDestroyOnLoad(this.gameObject);
  4.         TNManager.onJoinChannel += TNet_OnJoinChannel;
  5. }
  6.  
  7. void OnDestroy()
  8. {
  9.         TNManager.onJoinChannel -= TNet_OnJoinChannel;
  10. }
  11.  
  12. void Update()
  13. {
  14.         if (Input.GetKeyDown(KeyCode.J))
  15.         {
  16.                 Debug.Log("IsJoiningChannel: " + TNManager.isJoiningChannel);
  17.         }
  18.         if (Input.GetKeyDown(KeyCode.C))
  19.         {
  20.                 Debug.Log("Creating channel");
  21.                 TNManager.CreateChannel("world", false, 2, "");
  22.         }
  23. }
  24.  
  25. void TNet_OnJoinChannel(int channelID, bool success, string message)
  26. {
  27.         Debug.Log(name + " [IsJoiningChannel_Test] Log: joined channel " + channelID + " (" + success + ") '" + message + "'");
  28. }
  29.  

Note that TNManager.isJoiningChannel will return true if you're joining *any* channel. You can place a BP on the call to TNManager.isJoiningChannel (properties are calls) and then step into GameClient.isJoiningChannel to check the mJoining list to see which channels you're currently joining.

Also worth noting that TNManager.CreateChannel also joins the newly created channel automatically (it's basically identical to TNManager.JoinChannel).

Ninja

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #2 on: August 12, 2017, 04:02:29 PM »
Using your code I am still getting the same result. Maybe it's the Unity version? I'm using Unity v5.6.1f1 currently.


Ninja

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #3 on: August 12, 2017, 04:10:55 PM »
Sorry about the error in console, but still the same result with the added scene:

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 143
  • Posts: 268
  • TNet Alchemist
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #4 on: August 12, 2017, 05:03:08 PM »
Unity version shouldn't have anything to do with it. I'm on the same TNet version as you, too, so it has to be something else in your code. Try it with a blank scene so just the test code is running. I'm thinking maybe you're joining an additional channel somewhere in your code, and this channel join is taking a really long time (could be because of a lot of TNObjects or saved RFCs in that channel or a really cluttered scene).

You could verify that this is the case by setting a BP on TNManager.isJoiningChannel, then stepping into GameClient.isJoiningChannel and checking what's in the GameClient.mJoining list. Should put you on the right track.

Ninja

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #5 on: August 12, 2017, 06:48:23 PM »
You're right about Unity version not making any difference (tried it in 5.6.3f1).

Those results I posted are from an empty project, with only TNet imported, your provided code and a little more to connect to a server.

The mJoining list in TNGameClient shows a list Count of 1, with the value being -1.

I forgot to mention that I'm using v3.0.9 from the repository, not the Asset Store. When i reverted back to the 3.0.9 commit it works correctly, so something changed in the 5 commits after 3.0.9 was pushed. I'll test it for each commit and share my results.

Ninja

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #6 on: August 12, 2017, 06:57:03 PM »
The change from

  1. if (!mJoining.Remove(channelID))

to

  1. if (!mJoining.Remove(channelID) && channelID < 0)

in commit 2bf7e72 is the problem. Removing '&& channelID < 0' fixes the issue.

Ninja

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #7 on: August 12, 2017, 07:41:55 PM »
Apologies for the triple post, but I can't seem to find a way to edit them.

Altering the AND (&&) to OR (||) also fixes the issue, which may be what was intended in the first place?

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 143
  • Posts: 268
  • TNet Alchemist
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #8 on: August 12, 2017, 08:40:58 PM »
Shouldn't need either comparison, just need to check if the remove was successful or not. channelID at that point is the one generated by the server, so if you joined a random channel (-1 or -2) then channelID will always be >= 10001. mJoining would still contain -1 or -2 on the client, which is why it's necessary to check if the remove succeeded, and then loop through and remove any < 0 values if not.

No idea why ArenMook changed it, but glad you got everything working.
My version of TNet contains this:
  1. // mJoining can contain -2 and -1 when joining random channels
  2. if (!mJoining.Remove(channelID))
  3. {
  4.         for (int i = 0; i < mJoining.size; ++i)
  5.         {
  6.                 int id = mJoining[i];
  7.  
  8.                 if (id < 0)
  9.                 {
  10.                         mJoining.RemoveAt(i);
  11.                         break;
  12.                 }
  13.         }
  14. }
  15.  

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,137
  • Toronto, Canada
    • View Profile
Re: TNManager.isJoiningChannel always True when creating a new channel
« Reply #9 on: August 14, 2017, 01:52:50 AM »
That was a merge from something else in Sightseer. Looking at it I am not sure why the check was added to that line. That particular commit was mostly in other files on Sightseer's side (all game code). I'll change it back, thanks.

P.S. I just re-merged Sightseer's TNet into the TNet's github repo again with this fix alongside other additions.
« Last Edit: August 14, 2017, 02:00:56 AM by ArenMook »