Author Topic: Ping player & setting host  (Read 2427 times)

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Ping player & setting host
« on: October 09, 2013, 12:26:29 PM »
Hello! I was thinking a a system that when a player join so call the "OnNetworkPlayerJoin" which takes a parameter "Player". so when the player joins so will the current host check with every client currently conencted to the current channel for their Ping and if someone has a better ping so will he be the new "host".
Why i want to do that is becouse if someone with a bad ping is host for around 20 players, and the host is sending RPC and all from the AI so will the game be slower for the rest of the players.
Was checking around the unity forum and came along this: http://docs.unity3d.com/Documentation/ScriptReference/Network.GetAveragePing.html , and apparently the TNET.player and the Unitys Network player aint the same. So is their any way for checking theirs ping and or determine a new host for a channel

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ping player & setting host
« Reply #1 on: October 09, 2013, 01:53:52 PM »
Each player has a TNManager.ping of their own, and it's a local value representing the time it takes for a packet to travel from the player to the server and back. This value is only on the client-side right now, so you would have to have the host ask everyone in the channel what their current ping is, then pick the best one to be the host.

Keep in mind though, the ping can spike, and often varies greatly. Choosing a host on player join may not be the best option. Doing checks periodically and averaging out the result is a better alternative.

addebooi

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 26
    • View Profile
Re: Ping player & setting host
« Reply #2 on: October 09, 2013, 02:50:17 PM »
Havent tried this yet, but would there be something like this: like every 10 seconds the host requires the ping from all players. That would be the host sends RFC to all players in the channel, then from that RFC function it sends the players ping and which player who sent it to the host in a RFC. The host stores it in a list and then compares it. If that would work, how do i appoint leader for the host? Is it just for the host to call TNManager.SetHost(player);? and then done?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Ping player & setting host
« Reply #3 on: October 10, 2013, 07:55:32 AM »
Yup. Just SetHost on whomever you want. Just keep in mind that only the host can transfer the host status.