Author Topic: Tutorial suggestion : working with servers and channels  (Read 4946 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Tutorial suggestion : working with servers and channels
« on: June 30, 2016, 08:34:43 AM »
My experience with TNet to date has been simple peer-to-peer networking for which the tutorials are fine. Now I'm looking at supporting multiple servers with multiple channels on the same network, and trying to figure out protocols for finding and joining games, it's actually a poorly documented field leaving me with a lot of guesswork. Considering the same situation is going to be faced by everyone using TNet to do wider server games, I think it makes sense to have a tutorial covering this, talking about discoverability, order to join, which callbacks to use, etc.

Importantly, I'm approaching this not from the viewpoint of PC gamers used to server settings, but mobile gamers who want as few buttons and options to worry about as possible. So on my end, I only want to show stuff like password entry when required. At home, it should be as easy as pressing a button to start or join multiplayer, while on a public network, getting servers, game lists, attempting to join, responding approriately, etc.

Would have posted this in the Tutorials thread but it seems to be locked.

Bill.Smock

  • Newbie
  • *
  • Thank You
  • -Given: 6
  • -Receive: 2
  • Posts: 19
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #1 on: June 30, 2016, 01:28:02 PM »
Hate to be that guy - but this is all included in the Starlink package.  I'm not saying "oh to get that information you have to pay $45", but it is pretty much already built for you.  Tutorials for it would be nice, though!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #2 on: July 02, 2016, 12:16:30 AM »
You don't need the Starlink package for it. The most simple example of this is the Main Menu that comes with TNet. It detects LAN servers and lists them for the user to select.

Retrieving a list of channels with data such as whether it's password-protected or not is a simple matter of calling the TNManager.GetChannelList, example of which I've answered a couple times in the past. For example here: http://www.tasharen.com/forum/index.php?topic=14198.0

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #3 on: July 05, 2016, 05:20:41 AM »
Hate to be that guy - but this is all included in the Starlink package.  I'm not saying "oh to get that information you have to pay $45", but it is pretty much already built for you.  Tutorials for it would be nice, though!
From the sounds of it, it's a traditional PC-esque front end. I don't want server lists when there's only one open server present. And the effort of learning and reworking Starlink to my needs will likely be as much as learning how to do this from scratch, given past experience of reworking things.

The creation of a robust network frontend is actually a significant undertaking beyond the scope of the current tutorials that keep everything as simple as possible. I actually set about changing my network interface to just match the example as then it 'should be easy'. However, the more I work on this, the more caveats and scenarios I find that need dealing with to support the target user experience, and I'm having to root through code and internet searches to understand what's going on, and then rewrite my code where my initial understanding was wrong. eg. The password exists on the channel, not the server, so you need to join a server and then test the channels. So how do I hide a server from the list of servers if it has a full channel with two players?

It's proven (and continues to be) a significant undertaking. Seeing as networking on mobile has to be a major use of TNet nowadays with multiple devices' servers on the same network a possibility and needing filtering and selection and per-server responses, it seems a tutorial covering everything that goes on is warranted. Even just a diagram would be hugely helpful! We aren't all networking experts - the big draw of Unity is making development a possiblity for the less experienced/would be developer - and when there are bugs in the library messing us about as well, learning how it all works is all the harder (is it not working because I'm doing something wrong, or the library is?). :p

Point being, one day of someone's time creating a tutorial can save many man-weeks of time for users, which is why tutorials are made in the first place (to make it easier) and I think the whole network server setup and management requires that as much as every other facet of TNet already covered in the tutorials.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #4 on: July 05, 2016, 08:01:13 PM »
Hide a server using TNServerInstance.isListening = false. Re-add it by setting it to 'true' later. Although note that you can always just set the TNServerInstance.serverName with something meaningful -- for example a string you can Split() with data inside that contains not just the server name, but number of players, channels, games, or whatever else you need to be there.

The Main Menu example explains how the LAN server discovery works. If you don't want to display the server list if there is only 1 server, you obviously don't have to. That's user code and has nothing to do with networking.

Channel discovery is the same thing, just available while connected via TNManager.GetChannelList(), which is trivial and I've already linked that example in the previous reply.

Maybe if I understood whatever you believe is challenging here I could better comprehend what you want placed in a tutorial?

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #5 on: July 14, 2016, 05:28:13 PM »
I've been over two weeks working on this now across two games. Every step is thwarting me and I'm making zero progress, unable to work on any other aspects of the games until this networking is solved.

I had no idea how to work with passwords until explained on the forum because the tutorials don't cover it (where's the tutorial on "adding a password to your server"?). I had no idea I needed to join 127.0.0.1 to join a local server until explained here. I had no idea the 'server.dat' file would keep the password between servers being started on the same device. I have no idea how to manage that file in Android or deal with it using 'world.dat' by default when no file is specified. Currently even basic RFCs aren't working for me any more. I create a server and join it. TNManager.isInChannel == true. I call a tno.send and nothing happens. Android is grumbling about world.dat being inaccessible - is that what's killing the Send call? I also have my password test work fine on Android but exactly the same code creating a server in the Unity editor means the password input box is never shown on Android devices.

I was using TNet 2 fine up to this point, just creating a server and joining it in an unsophisticated way. I had basic multiplayer working and demo'd the game and it was well received. I'm eager to finish it but trying to provide a nice setup frontend that can support multiple games on the same LAN and handling the players drop-in, drop-out coop, I'm in the complete dark due to lack of decent explanation.

Is it really too much to ask for a walk through creating a mobile-server networked game that covers all the pitfalls I'm discovering day by day? Add it to the Examples. Include password protection on channels and have it so we can build and run the example on multiple devices on the same network, starting and stopping servers, joining and leaving channels, and setting and leaving blank passwords. The user experience should be a case of creating a new game (which creates a server, with optional password, and automatically joins it), or joining from a list of games on the network with password input as required.
« Last Edit: July 14, 2016, 05:46:32 PM by Shifty Geezer »

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #6 on: July 15, 2016, 04:08:34 AM »
You have the source code to TNet. You are compiling it yourself, so it works. You have Unity which comes with: exception handling and reporting (when an exception occurs it will be printed to the output window, and usually won't crash the game), profiler, and debugger. You can literally step through every CIL instruction as your game executes. You've spent two weeks fighting TNet? I don't believe you're trying hard enough, then. If you had bothered to look through the source code you could solve your problems in no time at all. Sure, Aren could noob-ify the entire TNet library and practically spoonfeed all his customers, but then people like me that use TNet as a tool instead of a full-fledged solution become inconveniced by how much unnecessary code we'd have to dig through. Perhaps that's something Aren does want to do, and I certainly can't blame him, as there seems to be a lot more noob coders than real programmers in the Unity ecosystem.

Now, I don't have TNet3 yet, so I won't be able to provide the spoon you so desire, but I'll help with what I can:
127.0.0.1 is localhost, if you send a packet to 127.0.0.1 it will never leave your motherboard. Stays within the OS. If you're hosting a server on your PC you should always connect to localhost. This isn't specific to TNet. This is networking in general.

The server writes to a few files: server.dat (or world.dat, whatever you name it), server.config (or world.config) Config/ban.txt, and Config/admin.txt. You can see this in TNGameServer::SaveTo(string fileName). I can't see an instance where the *.dat file would be written if NONE of your channels are persistent. In fact, it should be deleted. So, check that NONE of your channels are persistent, and then read the error message and stack trace if it's still failing.

You're going to need to provide more information about your RFC issue. Error messages, stack traces, code snippets. The presence (or lack) of *.dat shouldn't effect RFCs.

I'm not sure I understand what you're saying about your password test. I think you're saying you can host and connect on Android devices, but if you host on Unity editor you can't connect on Android devices. I would test the connection. Are you forwarding the ports? I would recommend not running the server within the Unity editor. Instead you should build and run, or run the standalone server. I believe you'd have to allow Unity editor through your firewall if you wish to connect to it from other devices.

A frontend should be made by the game developer... Imagine if every game had the same frontend. How crappy would that be?

No, it isn't too much to ask for a walkthrough covering the creation of a mobile networked game. It is however too much to ask for a complete spoonfed game "example".

At some point you're going to have to take a step back and decide whether you should be blaming TNet or yourself. You literally have the full, HEAVILY COMMENTED source code... Lacking experience in programming or networking is no excuse and should only motivate you to LEARN like everyone else has.

Sorry for the harsh tone, I've spent 4 days back in the unmanaged environment. Spent 31 straight hours debugging machine code. The managed environment gives you sooo much freedom, so it's agitating to hear people complaining about simple stuff.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #7 on: July 15, 2016, 04:34:12 AM »
I've been developing for years. I know the importance of explaining clearly one's problems and Aren has been very helpful with NGUI and TNet. However, my day job is a private tutor, explaining things to people to make it easier to learn, and that's a large part of getting humanity to progress faster than everyone having to struggle with learning stuff other people already know.

I used the TNet example as a frame of reference. I basically used the same code, but the moment I add a test for a password (join channel, show password box if password protected), it stops working. I've run the example, adding a password field, and it works fine on creating and stopping a new server. And one can say, "it's your fault" but I've already encountered two bugs - one is the one Aren fixed where the server port was getting reset to 0, and the other is NGUI input labels where the delete key on PC works on the wrong input; I've sent a copy of that project to Aren to look at.

So when something goes wrong, I can't be sure if I'm doing it wrong or if there's a bug. When it's more clearly explained, it helps pinpoint where the issues are.

I've even started again from scratch. Import the example and work from there. Only I import it and it doesn't import correctly with a Binary to YAML error and the Menu Examples list being full of random numbers instead of the strings and no Examples menu is drawn.

Things aren't going well!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #8 on: July 16, 2016, 12:59:44 AM »
Wait, are you saying that you can't import TNet's examples?

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Tutorial suggestion : working with servers and channels
« Reply #9 on: July 16, 2016, 03:58:33 AM »
Yep. In that project, importing TNet fails to import the example scene correctly. At which point I switched back from my new Windows 10 install (clean install, nothing but Win 10 and Unity and Android development stuff) to my old Windows 7 install where I eventually found the connection wasn't working when the PC was serving.

So conclusion at the this point is everything's a bit screwed (being polite), next course of action is to reinstall Windows 7, go back to an earlier version of the project, and restart the whole thing.