Author Topic: Set channel data at channel creation ?  (Read 4975 times)

David

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Set channel data at channel creation ?
« on: November 28, 2013, 02:16:57 PM »
Is there a way to set channel data at channel creation ? I wanted to set a channel name when creating a new channel and wanted to store the name in the channelData, but didn't find a way to do it.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Set channel data at channel creation ?
« Reply #1 on: November 28, 2013, 04:09:53 PM »
No, you can't set the channel data before creating it (and thus before joining it). If you don't want this channel to show up on the list of available ones, just filter the list you get from the server by removing channels without the proper data set.

David

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Set channel data at channel creation ?
« Reply #2 on: November 28, 2013, 05:23:04 PM »
Thanks for your answer. My problem is that I have a GUI where I can either choose a channel from the list of existing ones or type a new channel name then click the create channel button.

Can't I create and join a channel without loading the  scene, set channel data from my gui input field then load the game scene? I tried to do so but it seems the channel data stays null as if I didn't joined the channel after the create channel call.

« Last Edit: November 28, 2013, 05:33:38 PM by David »

sberghici

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Set channel data at channel creation ?
« Reply #3 on: November 28, 2013, 09:46:24 PM »
Ok how then to set channel name after creating it? I want to have the game name in the data field of channel list
  1.     void OnChannelList (Packet response, BinaryReader reader, IPEndPoint source)
  2.     {
  3.         // The first integer represents the number of entries to follow
  4.         int channels = reader.ReadInt32();
  5.  
  6.         // Read all incoming channel data
  7.         for (int i = 0; i < channels; ++i)
  8.         {
  9.             int id              = reader.ReadInt32();
  10.             int players         = reader.ReadUInt16();
  11.             int limit           = reader.ReadUInt16();
  12.             bool pass           = reader.ReadBoolean();
  13.             bool persistent     = reader.ReadBoolean();
  14.             string level        = reader.ReadString();
  15.             string data         = reader.ReadString();
  16.  
  17.             // TODO: Do something with this data here
  18.         }
  19.     }
  20.  

David

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Set channel data at channel creation ?
« Reply #4 on: November 29, 2013, 05:17:12 AM »
Once your in the channel you can set your channel data by affecting a string in TNManager.channelData, but as said above it only works once you've joined the channel.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Set channel data at channel creation ?
« Reply #5 on: November 29, 2013, 10:48:05 AM »
Can't I create and join a channel without loading the  scene, set channel data from my gui input field then load the game scene? I tried to do so but it seems the channel data stays null as if I didn't joined the channel after the create channel call.
A channel cannot exist until someone joins it, which is why you can't set the channel data until after you join it. I'm not sure I understand the issue here. Why can't you have your GUI accept a name and once you click the Join button, join a brand-new channel then set its name as soon as you've joined?

David

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 10
    • View Profile
Re: Set channel data at channel creation ?
« Reply #6 on: November 29, 2013, 02:29:09 PM »
Hahaha that's just me being stubborn  ;D I wanted to avoid the creation of a persistent game object just to store this data until next scene is loaded. But if I have to, I will do it ;)
Thanks for your help.

GantZ_Yaka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: Set channel data at channel creation ?
« Reply #7 on: February 11, 2014, 08:36:53 AM »
please help me understand with TNManager.channelData
I knew how to get the list of channels and how to retrieve data from there.
But I did not get to put custom string in the channel data :(
Immediately after the start channel by TNManager.JoinChannel(channel, null, false, 4, null);
I try to assign a string: TNManager.channelData = "my string";
but it does not work: (
looks as though it will take time after I created a channel, so that he could appoint himself my string.
eventually channel is created without a name, only with ID. But this is not enough! This is insufficient to show the other players immediately started rooms to choose from. how to be?

Noi14

  • Jr. Member
  • **
  • Thank You
  • -Given: 10
  • -Receive: 0
  • Posts: 57
    • View Profile
Re: Set channel data at channel creation ?
« Reply #8 on: February 11, 2014, 08:49:10 AM »
  1. TNManager.client.BeginSend(Packet.RequestSetChannelData).Write("My data");
  2. TNManager.client.EndSend();

GantZ_Yaka

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 21
    • View Profile
Re: Set channel data at channel creation ?
« Reply #9 on: February 11, 2014, 10:07:36 PM »
thanks a lot! now everything works fine  ;D

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: Set channel data at channel creation ?
« Reply #10 on: June 13, 2016, 09:05:37 AM »
I just had a similar problem with TNManager.channelData but when I used the following code instead it was fixed. I don't get it. Whats the difference between TNManager.channelData and the following code?

  1. TNManager.client.BeginSend(Packet.RequestSetChannelData).Write(infoScript.roomName);
  2. TNManager.client.EndSend();


ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Set channel data at channel creation ?
« Reply #11 on: June 16, 2016, 04:02:59 AM »
This post is from 2014 = TNet 2.

I'm guessing you are using TNet 3, which simplifies this greatly.
  1. TNManager.SetChannelData("key", value);