Author Topic: Next Available Channel Id  (Read 2856 times)

dcparker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Next Available Channel Id
« on: April 12, 2013, 12:21:12 PM »
Hey Now

I am looking to find the next available Channel Id, that is not being used.  The idea someone creates a game, I call a function that returns a Channel Id, then I have the user connect to the lobby.

Not sure if TNLobbyClient.knownServers.list can be used to figure out.

Maybe something like...
TNManager.JoinChannel(FindChannelID(), firstLevel);

Each newly created game would get their own Channel Id.

dcparker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Next Available Channel Id
« Reply #1 on: April 12, 2013, 01:49:05 PM »
This is what I came up with, not the purdest, but it works.

Does anyone have something better?

  1.     private int FindChannelId(string extIp, string intIp)
  2.     {
  3.         List<ServerList.Entry> list = TNLobbyClient.knownServers.list;
  4.         int channelid = 0;
  5.         for (int i = 0; i < list.size; ++i)
  6.         {
  7.             ServerList.Entry ent = list[i];
  8.  
  9.             if (intIp != ent.internalAddress.ToString() || extIp != ent.externalAddress.ToString()) continue;
  10.  
  11.             channelid = i;
  12.             break;
  13.         }
  14.         Debug.Log(channelid + 1);
  15.         return channelid + 1;
  16.     }
  17.     private int NextChannelId()
  18.     {
  19.         int channelid = 0;
  20.  
  21.         // List of discovered servers
  22.         List<ServerList.Entry> list = TNLobbyClient.knownServers.list;
  23.  
  24.         for (int i = 0; i < 32; ++i)
  25.         {
  26.             try
  27.             {
  28.                 if (string.IsNullOrEmpty(list[i].internalAddress.ToString())) continue;
  29.             }
  30.             catch (Exception)
  31.             {
  32.                 channelid = i;
  33.                 break;
  34.             }
  35.  
  36.         }
  37.         Debug.Log(channelid + 1);
  38.         return channelid + 1;
  39.     }
  40.  
« Last Edit: April 12, 2013, 02:02:49 PM by dcparker »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Next Available Channel Id
« Reply #2 on: April 12, 2013, 06:05:11 PM »
Why do this? Why do you care what the ID is? TNManager.JoinChannel with -1 for the channel ID will create a new random channel.

dcparker

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 5
    • View Profile
Re: Next Available Channel Id
« Reply #3 on: April 12, 2013, 07:36:26 PM »
Not sure if I understand things...

1) player1 creates game1 (channel id set to 1)

2) player2 joins game1 (channel id set to 1)

3) player3 creates game2 (channel id set to 2)

4) player4 creates game3 (channel id set to 3)

5) player3 Quits game2

6) Player3 creates game4 (channel id set to 2)

-there will be no lobby.
-when game is created/joined, players go right into game.
-all games are separate.
-Players can send messages to each other. (in their game)

« Last Edit: April 12, 2013, 08:21:09 PM by dcparker »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Next Available Channel Id
« Reply #4 on: April 12, 2013, 08:24:01 PM »
And how do you know which channel to join?

If the first player joins a random channel with -1 channel ID flag, he can then check what the channel ID is after joining (TNManager.channelID), which is the number you can pass to the 2nd client.