Author Topic: TNet Newbie Help  (Read 5020 times)

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
TNet Newbie Help
« on: August 13, 2015, 05:28:34 PM »
Hello guys I have been using the standard Unity Networking for a while but today I bought TNet.

My questions are:

1. How would I get a server browser of all people who used TNServerInstance.Start?
2. Would those people have to port forward for other players to connect to them?
3. If my game has multiple maps do I make the server do an RFC to instantiate the map into the game or do I have different scenes for each map?

Thanks for reading  :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet Newbie Help
« Reply #1 on: August 14, 2015, 11:18:21 AM »
1. TNServerInstance.Start will launch a local server. If you want to have a list of such servers, you not only need to start the local servers, but also have those servers register with a centralized lobby server that you can then retrieve this list from. You can do this by specifying an additional parameter to TNServerInstance.Start: the remote lobby TCP end point (address of your lobby server). This will only work if you launch a lobby server somewhere accessible first, such as an Amazon EC2 server instance.

2. Possibly. TNet will try to open the port for them via UPnP (note the "openPort" parameter in the TNServerInstance.Start function), but if their router has UPnP disabled or doesn't support it, it won't work.

3. The usual approach is to have 1 map = 1 channel. When you do TNManager.JoinChannel you get to specify the Unity scene to load. First player that joins the channel gets to set this scene for everyone else. Other players' scene values get ignored in favor of the first one's.

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: TNet Newbie Help
« Reply #2 on: August 14, 2015, 12:06:55 PM »
I am trying to make an FPS which I have done with the normal Unity Networking before.

I made it so when the player opens the game they automatically connect to a server.
I want players when they are connected to the server to be able to make their own channels or have a server browser showing all the channels.

The "create your own channel" part is straight-forward enough but how do I get a list of all channels?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet Newbie Help
« Reply #3 on: August 14, 2015, 12:12:03 PM »
Have a look at the TNTcpLobbyClient script. Just give it the address of your remote lobby server, and you will be able to access TNTcpLobbyClient.knownServers.

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: TNet Newbie Help
« Reply #4 on: August 14, 2015, 12:23:05 PM »
Thanks for the quick reply but I need a list of channels not servers. Will knownServers work for this?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet Newbie Help
« Reply #5 on: August 14, 2015, 02:01:16 PM »
To get a list of channels, send a RequestChannelList packet like so:
  1.         void Start()
  2.         {
  3.                 TNManager.client.packetHandlers[(byte)Packet.ResponseChannelList] = UpdateWorldData;
  4.         }
  5.  
  6.         void RequestChannelData ()
  7.         {
  8.                 TNManager.BeginSend(Packet.RequestChannelList);
  9.                 TNManager.EndSend();
  10.         }
  11.  
  12.         void UpdateWorldData (Packet response, BinaryReader reader, IPEndPoint source)
  13.         {
  14.                 int count = reader.ReadInt32();
  15.  
  16.                 for (int i = 0; i < count; ++i)
  17.                 {
  18.                         int channelID = reader.ReadInt32();
  19.                         ushort players = reader.ReadUInt16();
  20.                         ushort limit = reader.ReadUInt16();
  21.                         bool hasPass = reader.ReadBoolean();
  22.                         bool persist = reader.ReadBoolean();
  23.                         string level = reader.ReadString();
  24.                         string data = reader.ReadString();
  25.                 }
  26.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet Newbie Help
« Reply #6 on: August 15, 2015, 11:05:20 PM »
In the code above I register a packet listener for channel list response in the Start() function. When I want to retrieve the list, I call the "RequestChannelData()" function. Doing so sends a request to the server, saying "give me the channel list". When this list arrives, the callback set in Start() gets called (UpdateWorldData). I then read the data, effectively getting the full list of open channels.

Lobby server lets you get a list of servers, but you said you want a list of channels, not servers. To get a list of channels from the server, you need to write code because you need to actually do something with the channel information that you get back. Generally "doing something" involves displaying the list of channels somehow, which is game code-specific.

Doomlazy

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 1
  • Posts: 28
    • View Profile
Re: TNet Newbie Help
« Reply #7 on: January 09, 2017, 02:35:40 AM »
Hey I'm planning on switching from channels over to servers. How can I make the current map, current gamemode and max players show in the server browser?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: TNet Newbie Help
« Reply #8 on: January 13, 2017, 10:52:18 PM »
The last value, "data" is a string. You can encode whatever you want in that, including a string-serialized DataNode if you're so inclined.