public void Run() { hostPlayer = null; List <PlayerPingPair> hostables = new List <PlayerPingPair>(); System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); foreach (MNPlayer player in players) { if (player.canHost) { var pair = new PlayerPingPair(player); var reply = ping.Send(MNListServer.Instance.GetProperAddress(player)); if (reply.Status == System.Net.NetworkInformation.IPStatus.Success) { pair.ping = reply.RoundtripTime; } hostables.Add(pair); } } ping.Dispose(); if (hostables.Count <= 0) { return; } PlayerPingPair best = hostables[0]; foreach (PlayerPingPair pair in hostables) { if (best.ping > pair.ping) { best = pair; } } hostPlayer = best.player; }
public override bool Equals(object obj) { if (obj == null || this.GetType() != obj.GetType()) { return(false); } MNPlayer player = (MNPlayer)obj; return(this.uuid == player.uuid); }
// Start is called before the first frame update void Start() { joiningRoomId = -1; NatUtility.DeviceFound += NatUtility_DeviceFound; NatUtility.DeviceLost += NatUtility_DeviceLost; natDevice = null; NatUtility.StartDiscovery(); database = PluginManager.GetAvailableDatabase(); database.OnRoomDataChangedEvent += Database_OnRoomDataChangedEvent; Player = new MNPlayer("Player"); }
public MNRoomData(string roomName, MNPlayer adminPlayer, int capacity) { Status = RoomStatus.WaitingPlayer; HostPlayer = null; this.AdminPlayer = adminPlayer; this.RoomName = roomName; this.Capacity = capacity; Players = new List <MNPlayer>(); Players.Add(adminPlayer); JoinRequests = new List <MNPlayer>(); }
public string GetProperAddress(MNPlayer hostPlayer) { if (hostPlayer.Equals(Player)) { return("127.0.0.1"); } else if (hostPlayer.wanAddress == Player.wanAddress) { return(hostPlayer.lanAddress); } else { return(hostPlayer.wanAddress); } }
public PlayerPingPair(MNPlayer player) { this.player = player; ping = 4000;//pingのデフォルトタイムアウト時間 }