public override void Deserialize(NetworkReader reader) { oldServerConnectionId = (int)reader.ReadPackedUInt32(); int numPeers = reader.ReadUInt16(); peers = new PeerInfoMessage[numPeers]; for (int i = 0; i < peers.Length; ++i) { var peerInfo = new PeerInfoMessage(); peerInfo.Deserialize(reader); peers[i] = peerInfo; } }
// utility function called by the default UI on client after connection to host was lost, to pick a new host. public virtual bool FindNewHost(out NetworkSystem.PeerInfoMessage newHostInfo, out bool youAreNewHost) { if (m_Peers == null) { if (LogFilter.logError) { Debug.LogError("NetworkMigrationManager FindLowestHost no peers"); } newHostInfo = null; youAreNewHost = false; return(false); } if (LogFilter.logDev) { Debug.Log("NetworkMigrationManager FindLowestHost"); } const int k_FakeConnectionId = 50000; newHostInfo = new PeerInfoMessage(); newHostInfo.connectionId = k_FakeConnectionId; newHostInfo.address = ""; newHostInfo.port = 0; int yourConnectionId = -1; youAreNewHost = false; for (int peerId = 0; peerId < m_Peers.Length; peerId++) { var peer = m_Peers[peerId]; if (peer.connectionId == 0) { continue; } if (peer.isHost) { continue; } if (peer.isYou) { yourConnectionId = peer.connectionId; } if (peer.connectionId < newHostInfo.connectionId) { newHostInfo = peer; } } if (newHostInfo.connectionId == k_FakeConnectionId) { return(false); } if (newHostInfo.connectionId == yourConnectionId) { youAreNewHost = true; } if (LogFilter.logDev) { Debug.Log("FindNewHost new host is " + newHostInfo.address); } return(true); }