Author Topic: Make the server host  (Read 3152 times)

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Make the server host
« on: October 15, 2013, 09:09:54 AM »
Is there anyway to make the server computer host for any channel that is created?
« Last Edit: October 15, 2013, 09:16:04 AM by addebooi »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Make the server host
« Reply #1 on: October 15, 2013, 02:03:11 PM »
Server is just a program responsible for sending messages. It can't be the host because it has no presence in the channel. That's like asking if the house can be its own owner. It can't -- only a person can own the house.

Masaaki

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 23
    • View Profile
Re: Make the server host
« Reply #2 on: October 17, 2013, 03:35:48 PM »
If you want a dedicated server, you could always go the uLink route (not buying uLink, but taking some ideas and applying them to TNet) - make a dedicated build of your game specifically for servers, and run it with the -batchmode parameter. Requires Pro, but then so does uLink's dedicated server (because basically it's the same thing). I'd probably make an editor script for compiling server builds if you go that route - would set up appropriate build options (like compiler directives) and call BuildPlayer with a subset of the game scenes required by the server.

pyscho2day

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 74
    • View Profile
Re: Make the server host
« Reply #3 on: October 18, 2013, 08:50:03 PM »
I do this in the game i am working on.  What i did is when i start a server locally (only using the server exe as a lobby) i set a bool property to true.  I then have a player object that has a property for isHost.  at some point i will will check to see if my server property is set to true and if it is i set the isHost to true in the player object.  Then say on a level/scene load who ever loads it first gets host but when the next person loads they send a rfc saying hey I'm here now and the clients that connected prior will check if they are host. If they are a host then check to see if their player object's isHost is true. If it is not true i check if the person that just connect is supposed to be the host. if they are then i make them the host with TNManager.SetHost(TNManager.players[int]);

code to check and set
  1.         //Checks if i am the host. If i am check if i should be and if not set host
  2.         //if the player that triggered the check should be the host.
  3.         public static void CheckHost(int id)
  4.         {
  5.                 //check if i am the host
  6.                 if (TNManager.isHosting)
  7.                 {
  8.                         foreach (PlayerDataClass player in PlayerDatabase.PlayerList)
  9.                         {
  10.                                 //Check if if am supposed to be host
  11.                                 if (player.networkPlayerId == TNManager.playerID && player.isHost)
  12.                                 {
  13.                                         break;
  14.                                 }
  15.                                 //check if the player is supposed to be the host and thier id matches
  16.                                 //the id of the player that triggered the check
  17.                                 else if (player.isHost && player.networkPlayerId == id)
  18.                                 {
  19.                                         for (int i = 0; i < TNManager.players.size; i++)
  20.                                         {
  21.                                                 //find the TNET player object of the player
  22.                                                 if (TNManager.players[i].id == id)
  23.                                                 {
  24.                                                         //set the player as the host
  25.                                                         TNManager.SetHost(TNManager.players[i]);
  26.                                                         break;
  27.                                                 }
  28.                                         }
  29.                                 }
  30.                         }
  31.                 }
  32.         }
  33.  

I hope this helps.