Author Topic: Creating Lan-Only Server  (Read 5882 times)

Sarper

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 21
    • View Profile
Creating Lan-Only Server
« on: November 21, 2014, 11:01:14 PM »
In my game I want the player to be able to start a server either lan-only or on the internet. I see that TNServerInstance.Start has an overloaded version which accepts an enum parameter named "Type" which happens to contain "Lan, Udp, Tcp". This overloaded version of the method also forces me to indicate a lobby port and a filename to save the server to :(.

So I have some questions regarding the above.

1) I consider if I set the server type to Type.Lan, it will only use the local ip address and won't be connectable through the external address. Am I correct about this assumption?
2) When it comes to choosing the server type between Udp and Tcp what is the determinant factor? What are the main differences and is it possible for one of them to be incompatible with the user's connection setup?
3) Since it's possible for a server to be either Udp or Tcp what is the best way to setup the TN Lobby Client components/scripts. I read that I shouldn't keep both Udp and Tcp lobby client active at the same time. Should I keep them both on my network manager gameobject and toggle them based on the type of the started server?

Any and all answers are much appreciated!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating Lan-Only Server
« Reply #1 on: November 22, 2014, 01:48:16 PM »
No, that enum is for the type of the lobby server you are expected to connect to. TNet doesn't offer a way to limit traffic only to your LAN. The most obvious method of limiting it is to not distribute your IP, and/or not opening the port via UPnP. Only if you tell someone your IP, and open the port via UPnP (or manually) will the actually be able to connect to you from outside of your LAN.

3. Yes, that's perfectly valid. I do that myself in Starlink.

Sarper

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Creating Lan-Only Server
« Reply #2 on: November 22, 2014, 02:28:31 PM »
No, that enum is for the type of the lobby server you are expected to connect to. TNet doesn't offer a way to limit traffic only to your LAN. The most obvious method of limiting it is to not distribute your IP, and/or not opening the port via UPnP. Only if you tell someone your IP, and open the port via UPnP (or manually) will the actually be able to connect to you from outside of your LAN.

3. Yes, that's perfectly valid. I do that myself in Starlink.

Great, thanks for the answer!

How about question #2? Is it possible for a server to not support UDP connection? If that is the case, should I check "TNManager.canUseUDP" everytime I send a tno.SendQuickly and if it's not supported do a Send instead? Is it guaranteed a TCP-only action game would have lagging movement sync & other problems?

Sarper

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Creating Lan-Only Server
« Reply #3 on: November 22, 2014, 03:14:46 PM »
I guess it will be best if I buy starlink and study it's code.

EDIT: So I bought it. Imported in a clean project. Imported the Tnet Integration package on it. Set up the layers. Checked the "run in background". And the game is not working as it's supposed to. Attached are the screenshots of the problems.

- It's not playable at all, stuck on the screen shown in the ss3.jpg.
- As soon as the stats are loaded, a strange background glitch appears as shown in ss1.jpg.
- Internet is greyed out as shown in ss2.jpg.
« Last Edit: November 22, 2014, 03:58:52 PM by Sarper »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating Lan-Only Server
« Reply #4 on: November 22, 2014, 04:51:26 PM »
Internet is grayed out because in the real Starlink game I have it hard-coded to connect to my lobby server. I don't want Starlink UI to connect to that lobby server, which is why it's grayed out.

Not sure what you mean by it not being playable... did you expect the game code? It's just the UI for it, game code isn't there, there is nothing to be playable.

The only valid glitch I see is the background on the summary list... I'll fix it now. Happens because the UI kit uses some stuff that was removed from NGUI.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating Lan-Only Server
« Reply #5 on: November 22, 2014, 05:01:50 PM »
Quote
How about question #2? Is it possible for a server to not support UDP connection? If that is the case, should I check "TNManager.canUseUDP" everytime I send a tno.SendQuickly and if it's not supported do a Send instead? Is it guaranteed a TCP-only action game would have lagging movement sync & other problems?
Yes. Starting the server, specify '0' for the UDP port and it won't be used. TNServerInstance.Start(TcpPort) automatically ignores UDP.

tno.SendQuickly automatically uses TCP if UDP is not available. You don't need to check anything.

Sarper

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Creating Lan-Only Server
« Reply #6 on: November 22, 2014, 05:49:08 PM »
Not sure what you mean by it not being playable... did you expect the game code? It's just the UI for it, game code isn't there, there is nothing to be playable.

Oh, I actually bought it to study a tnet integrated game code. Should check the product description and name before buying I guess...

Edit: Upon reading the product description it says here http://www.tasharen.com/forum/index.php?topic=4506;

Optional TNet Networking integration adds:
Server, channel and player lists
Internet/LAN/Direct Connect
Multiplayer chat
Other stuff™


But there is no internet right?
« Last Edit: November 22, 2014, 05:57:31 PM by Sarper »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating Lan-Only Server
« Reply #7 on: November 22, 2014, 06:09:53 PM »
As I mentioned, just specify your own internet lobby server. You can't use Starlink's lobby as it's for the game, not the UI kit.

Sarper

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Creating Lan-Only Server
« Reply #8 on: November 22, 2014, 10:10:55 PM »
Okay last questions.

1) I see that in Starlink udp is used for the LAN lobby and tcp for the internet. Is there a specific reason reason for that? Is it better to use the udp lobby for the LAN and the tcp for the internet?

2) Can I register a udp enabled game server on a tcp lobby server and vice-versa?

3) What data is saved in the file given to the "fileName" parameter upon starting a server and why?
« Last Edit: November 22, 2014, 11:04:30 PM by Sarper »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Creating Lan-Only Server
« Reply #9 on: November 25, 2014, 01:51:59 AM »
Quite a few reasons.

1. UDP packets can be lost in transit on the internet, and this doesn't happen via LAN. UDP also doesn't require an active connection, so you don't need to specify a specific computer to connect to. LAN approach does a generic broadcast, and computers on the network can respond. You can't broadcast to the internet.

2. UDP support of the actual game server is irrelevant. It's an option, and has nothing to do with the lobby server. So yes, you can.

3. Everything persistent. So if you create a channel with its persistent flag set to 'true', then all of the persistent RFCs you send there (Target.AllSaved, Target.OthersSaved), as well as all created/destroyed objects will be recorded and saved into that file. So the next time you join this channel, you will go right back to the state you left it in.

Sarper

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 21
    • View Profile
Re: Creating Lan-Only Server
« Reply #10 on: November 25, 2014, 04:06:45 AM »
Your answers combined with reading the docs and example code and implementing Tnet made it so much clearer. Thanks a lot!