Launching a dedicated lobby server:Launch the dedicated server as you normally do, but specify the lobby port (udpLobby is valid too).
@echo off
start "TNet Test Lobby Server" "TNServer.exe" -name "TNet_TestLobbySrv" -tcpLobby 5129
Registering dedicated game servers with your lobby server:Simply launch the dedicated server using a batch file like this:
@echo off
start "TNet Test Server" "TNServer.exe" -name "TNet_TestSrv" -tcp 5127 -udp 5128 -tcpLobby "192.168.1.2" "5129"
Registering runtime-created servers with your lobby server:Launch the server as you normally do but pass in the endpoint for your lobby server.
TNServerInstance
.Start(5127,
5128,
"", Type
.TCP,
new IPEndPoint
(IPAddress
.Parse("192.168.1.2"),
5129),
true)
Connecting to the lobby server and retrieving list of registered servers:Attach a TNTcpLobbyClient component to any gameobject. Then, in your code, use TNLobbyClient to access lobby data. It just works.
And for your last question, I'm not sure. You can pass a callback to UPnP's Open function and see if UPnP was able to automatically port-forward, but UPnP failing doesn't necessarily mean the user is unable to host a server (they could have manually forwarded their ports or they aren't behind NAT). The only way I can think of is writing a super small client & server. Client takes in your gameserver's port and sends it to server. Server attempts to connect to port. If connection fails, notify client. Client notifies caller. Host the server somewhere remote. You could build this into TNet's lobby server, actually, so you wouldn't even need to write the client part.