Hi everyone!
First off I want to say I'm very much a newbie to TNet and Multiplayer/Networking-development in general.
That said, I only hear great things about TNET, but as many newbies here have obviously noted in the past, documentation is somewhat lacking.
Don't get me wrong, there are a few written tutorials, an (apparently slightly outdated?) video tutorial and fairly extensive documentation for every function in the source code.
And as many have stated in the past, Aren is doing a great job of handling the forums with brief but to the point input and answers.
There does however seem to be a ton of people having a hard time getting over that first threshold (myself included), setting up a proper connection to a standalone (.exe) remote lobby server and getting things up and running with instantiating and connecting to a server + reporting instances to the remote lobby.
Even after spending two full days reading just about every forum post on the subject, going through the entire source code script by script and looking at every sticky tutorial, I still can't make heads or tails of it, and humbly ask those of you who "get it" to drop some knowledge in this post.
So, first off, what I'm trying to accomplish is the following:
- Launch a copy of the standalone TNServer.exe registered only as a lobby server.
- Inside Unity: Launch a game server (TNServerInstance.Start()), thus creating a server (or room) for other players to connect to.
- Report the new game server instance to the lobby server (with name, num of connected players and a set player limit of say 4 players), making the game server/room visible to other players as a list (to which connectivity buttons could be added)
- Connect one or more clients to the instantiated game server (and updating status in the lobby server).The idea is of course to have a lobby server, listing many instances of game servers - and allowing other players/clients to connect to one of these listed game servers.
Let's start with the TNServer.exe (Lobby Server):This needs to be set up in a publicly available space (say Amazon EC2 or simply a home computer exposed on the internet; firewalls open/ports forwarded in router, etc).
In my case, I've set it up on my home server (available within the LAN as 192.168.10.150). But it will of course be using the external IP (or connected domain name) things get off the ground. TNServer.exe is currently launched with the following args:
TNServer.exe -name "LOBBY" -tcpLobby 5129The reason I've used TCP instead of UDP is to avoid burst of keep alive transmissions and allowing for use of for example Amazon EC2, which apparently limit UDP traffic?)
The lobby server launches as expected (listing external IP, TCP Lobby Server started on port 5129, and so on). For some reason UPnP doesn't work for me even though my router supports it and it's enabled, but from what I gather, that doesn't matter any way. I've also portforwarded ports 5127-5129 for the servers external IP through the router.
Let's proceed to Unity and instantiating/creating a game server:It seems the recommended way to create a game server and connecting it to a remote lobby is the following method:
static bool TNet.TNServerInstance.Start (int tcpPort, int udpPort, string fileName, Type type, IPEndPoint remoteLobby, bool openPort = true)
// Start a local game server and connect to a remote lobby server.
(See:
http://www.tasharen.com/tnet/docs/class_t_net_1_1_t_n_server_instance.html#a2fa49c255504f3be28ca60c2f3ab880e for more info)
This could translate to a script looking something like this, right?
void Start() {
if (!TNServerInstance.isActive) {
Debug.Log("Starting server");
TNServerInstance.serverName = "Test Game Server";
TNServerInstance.Start(5127, 5128, null, TNServerInstance.Type.Tcp, Tools.ResolveEndPoint("192.168.10.150", 5129));
} else {
Debug.Log("Server already started");
}
TNManager.Connect();
}
This seems to create a Game Server called Test Game Server with one connected player (judging from the _Server game object in the hierarchy (under DontDestroyOnLoad, at runtime). From what I understand the Lobby Server should give some kind of response whenever a game server is registered, but since I'm not getting any response what so ever from the Lobby server upon running the script above, I'm assuming I'm just instantiating a game server and connecting to it - and preparing to register it with the lobby server...? I'm assuming something is missing that actually registers the instance with the lobby server? Does this make sense? Am I missing something here?
If we proceed to the part about getting a list from the Lobby Server:There's a reference to the TNTcpLobbyClient-script, in "Example 0 - Menu.pdf" (included in the examples/documentation in the Unity Asset Bundle):
A Server Lobby allows for a server list to be displayed to the user and in this example it will show up as a list of IP addresses to the right of the Connect and Start Server buttons. This example uses a UDP based lobby, which is good for searching the Local Area Network for fellow gamers, but in other types of games, such as Windward, you would want to use a TCP based lobby on a central server. TNet comes with the script TNTcpLobbyClient script to do this.
I have no idea how to use the TNTcpLobbyClient-script properly, but I've tried using some snippets of example code for listing registered servers, included in the PDF:
// List of discovered servers
List<ServerList.Entry> list = TNLobbyClient.knownServers.list;
// Server list example script automatically collects servers that have recently announced themselves
for (int i = 0; i < list.size; ++i) {
ServerList.Entry ent = list[i];
}
Debug.Log(list.size);
List.size returns 0, so again, I don't think anything has been registered with the lobby server. And this is about where I'm currently stuck.
So if you know what's missing or what I'm doing wrong, please help me fill in the blanks and get things up and running.
Thank you all - and have a great weekend!