Author Topic: Auth Server with Multiple rooms  (Read 7286 times)

sunriser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Auth Server with Multiple rooms
« on: February 12, 2013, 12:43:44 PM »
If I have a auth server app running like what is mentioned here: http://www.tasharen.com/forum/index.php?topic=2996.0

The implementation I'd like to have is each channel with a host running server logic for clients just in that room.  Each "room" would be an instance of my "game server" with it's own game logic and memory variables in the same scene. This would appear to necessitate in instance of TNManager for each "room".

Is it possible to do this instancing of TNManager with the current version of TNet (with a small example of how to in code)?

BTW, I'm still loving this framework. The Event handling of Network, room, Channel Lists, etc. is just superb :)

krissebesta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #1 on: February 12, 2013, 08:38:54 PM »
Hey sunriser!  What you have described is EXACTLY what I am trying to implement for my own game!  Maybe we can exchange ideas and code samples to help each other get it working.  Or perhaps post code here for everyone to benefit from.

From what I've read and understand TNManager "handles" all loaded channels/rooms.  So if you are loading the same scene in different channels I believe the single instance of TNManager can appropriately route the packets to the different channels/rooms.

Did you see my other thread with a question on stripping out the assets (graphics, sounds, and animations) from the server's version of each scene in order to keep memory demands lower on the server?

http://www.tasharen.com/forum/index.php?topic=3044.0

I am also very interested in ArenMook's reply on this topic.  Cheers! - Kris

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #2 on: February 13, 2013, 01:24:26 PM »
Easiest approach: run your server, and a headless client (Unity using TNet client). The idea is to have the headless client join the channel first -- thus becoming the host.

I generally don't advise this approach though as it's very resource-intensive (you need a new local Unity+TNet client for each channel). Having the clients handle physics is still by far the cheapest solution.

krissebesta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #3 on: February 13, 2013, 03:54:59 PM »
ArenMook: Interesting idea but I'd rather do what sunriser is considering (previous post).

Quote
Is it possible to do this instancing of TNManager with the current version of TNet (with a small example of how to in code)?

So is it possible to create multiple instances of TNManager?

Thanks, Kris

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #4 on: February 13, 2013, 10:14:54 PM »
TNManager is just a wrapper that uses TNet.GameClient and keeps a list of known players. You can just as easily create a new MonoBehaviour with a new TNet.GameClient inside.

krissebesta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #5 on: February 14, 2013, 04:07:41 PM »
@ArenMook: Sounds good.  I'll create a new MonoBehavour class, maybe say "TNGameManager", and basically copy the contents of TNManager and remove the single instance code which will allow me to create multiple (a List) of the new "TNGameManager" class. This will allow me to create to add a new TNGameManager object for each game the auth. server creates/hosts.

You know, this may be something a lot of other developers out there will want to use (hint, hint  ;)).  Is this something you may want to consider adding to the TNet library?

Cheers! - Kris

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #6 on: February 14, 2013, 09:14:29 PM »
I am too busy for the time being. The next update to TNet will already be pretty big with UPnP and a re-designed discovery / lobby system.

krissebesta

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 20
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #7 on: February 14, 2013, 09:57:19 PM »
@ArenMook:  No worries.  I'm planning on implementing these changes in the next week for my own project.  How about I send you my code when I've got it working, you can review it and possibly add it into the TNet library?

Cheers! - Kris

sunriser

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 17
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #8 on: March 01, 2013, 11:33:35 PM »
Easiest approach: run your server, and a headless client (Unity using TNet client). The idea is to have the headless client join the channel first -- thus becoming the host.

I generally don't advise this approach though as it's very resource-intensive (you need a new local Unity+TNet client for each channel). Having the clients handle physics is still by far the cheapest solution.

OK so in my server code, I create a static Headless Client as you suggested:

  1. static TNet.GameClient HeadlessClientHost = new TNet.GameClient();

I then do a connect to my localhost by:

  1. IPEndPoint ip = TNet.Tools.ResolveEndPoint("127.0.0.1", 19101);
  2.  
  3.                 if (ip == null)
  4.                 {
  5.                     Debug.LogError("Unable to resolve 127.0.0.1");                    
  6.                 }
  7.                 else
  8.                 {
  9.                     HeadlessClientHost.playerName = "RoomServerAdmin";                    
  10.                     NGUIDebug.Log("Connect to Server");                    
  11.                     HeadlessClientHost.Connect(ip, null);
  12.                    
  13.                 }
  14.  

At this point I believe my client connects successfully, but now it's a matter of the event triggers that were used in TNManager. When this client connects I have:

  1. void OnNetworkConnect(bool success, string message)
  2.     {
  3.         NGUIDebug.Log("Connected to Server");
  4.         HeadlessClientHost.JoinChannel(ServerChannelNumber, "", false, 7, "");
  5.         HeadlessClientHost.playerName = "ServerAdmin";
  6.        
  7.     }
  8.  

which is probably not right because the OnNetworkConnect is only used on TNManager which I'm not using.

What do I need to do to allow the TNet.GameClient to have proper OnNetworkConnect,OnNetworkJoinChannel,OnNetworkPlayerJoin,OnNetwrokPlayerLeave, etc. notifications?

Update:

I add an Awake method with this:

  1. void Awake()
  2.         {
  3.            HeadlessClientHost.onConnect = OnNetworkConnect;
  4.         }

I still do not seem to be able to get that method to fire on connect.

Thank you!
« Last Edit: March 02, 2013, 10:40:57 AM by sunriser »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Auth Server with Multiple rooms
« Reply #9 on: March 02, 2013, 12:00:59 PM »
OnNetworkConnect is only sent when you connect to the server. In your case you should use OnNetworkPlayerJoin / OnNetworkPlayerLeave notifications. But again, they require a TNManager. If you don't use the TNManager, you need to register your own set of delegates. Check what I do in TNManager.Awake().