public override void Deserialize(NetworkReader reader) { this.peers = new PeerInfoMessage[(int) reader.ReadUInt16()]; for (int index = 0; index < this.peers.Length; ++index) { PeerInfoMessage peerInfoMessage = new PeerInfoMessage(); peerInfoMessage.Deserialize(reader); this.peers[index] = peerInfoMessage; } }
public override void Serialize(NetworkWriter writer) { writer.Write((ushort)this.peers.Length); PeerInfoMessage[] array = this.peers; for (int i = 0; i < array.Length; i++) { PeerInfoMessage peerInfoMessage = array[i]; peerInfoMessage.Serialize(writer); } }
public override void Deserialize(NetworkReader reader) { int num = reader.ReadUInt16(); this.peers = new PeerInfoMessage[num]; for (int i = 0; i < this.peers.Length; i++) { PeerInfoMessage message = new PeerInfoMessage(); message.Deserialize(reader); this.peers[i] = message; } }
public override void Deserialize(NetworkReader reader) { int num = (int)reader.ReadUInt16(); this.peers = new PeerInfoMessage[num]; for (int i = 0; i < this.peers.Length; i++) { PeerInfoMessage peerInfoMessage = new PeerInfoMessage(); peerInfoMessage.Deserialize(reader); this.peers[i] = peerInfoMessage; } }
public override void Deserialize(NetworkReader reader) { this.oldServerConnectionId = (int) reader.ReadPackedUInt32(); int num = reader.ReadUInt16(); this.peers = new PeerInfoMessage[num]; for (int i = 0; i < this.peers.Length; i++) { PeerInfoMessage message = new PeerInfoMessage(); message.Deserialize(reader); this.peers[i] = message; } }
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; } }
public override void Deserialize(NetworkReader reader) { this.oldServerConnectionId = (int)reader.ReadPackedUInt32(); int num = (int)reader.ReadUInt16(); this.peers = new PeerInfoMessage[num]; for (int i = 0; i < this.peers.Length; i++) { PeerInfoMessage peerInfoMessage = new PeerInfoMessage(); peerInfoMessage.Deserialize(reader); this.peers[i] = peerInfoMessage; } }
// 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; if (m_Peers == null) { return(false); } foreach (var peer in m_Peers) { 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); }
public virtual bool FindNewHost(out PeerInfoMessage newHostInfo, out bool youAreNewHost) { if (this.m_Peers == null) { if (LogFilter.logError) Debug.LogError((object) "NetworkMigrationManager FindLowestHost no peers"); newHostInfo = (PeerInfoMessage) null; youAreNewHost = false; return false; } if (LogFilter.logDev) Debug.Log((object) "NetworkMigrationManager FindLowestHost"); newHostInfo = new PeerInfoMessage(); newHostInfo.connectionId = 50000; newHostInfo.address = string.Empty; newHostInfo.port = 0; int num = -1; youAreNewHost = false; if (this.m_Peers == null) return false; foreach (PeerInfoMessage peer in this.m_Peers) { if (peer.connectionId != 0 && !peer.isHost) { if (peer.isYou) num = peer.connectionId; if (peer.connectionId < newHostInfo.connectionId) newHostInfo = peer; } } if (newHostInfo.connectionId == 50000) return false; if (newHostInfo.connectionId == num) youAreNewHost = true; if (LogFilter.logDev) Debug.Log((object) ("FindNewHost new host is " + newHostInfo.address)); return true; }
/// <summary> /// <para>This sends the set of peers in the game to all the peers in the game.</para> /// </summary> public void SendPeerInfo() { if (!this.m_HostMigration) return; PeerListMessage peerListMessage = new PeerListMessage(); List<PeerInfoMessage> peerInfoMessageList = new List<PeerInfoMessage>(); for (int index = 0; index < NetworkServer.connections.Count; ++index) { NetworkConnection connection = NetworkServer.connections[index]; if (connection != null) { PeerInfoMessage peerInfoMessage = new PeerInfoMessage(); string address; int port; NetworkID network; NodeID dstNode; byte error; NetworkTransport.GetConnectionInfo(NetworkServer.serverHostId, connection.connectionId, out address, out port, out network, out dstNode, out error); peerInfoMessage.connectionId = connection.connectionId; peerInfoMessage.port = port; if (index == 0) { peerInfoMessage.port = NetworkServer.listenPort; peerInfoMessage.isHost = true; peerInfoMessage.address = "<host>"; } else { peerInfoMessage.address = address; peerInfoMessage.isHost = false; } List<PeerInfoPlayer> peerInfoPlayerList = new List<PeerInfoPlayer>(); using (List<PlayerController>.Enumerator enumerator = connection.playerControllers.GetEnumerator()) { while (enumerator.MoveNext()) { PlayerController current = enumerator.Current; if (current != null && (Object) current.unetView != (Object) null) { PeerInfoPlayer peerInfoPlayer; peerInfoPlayer.netId = current.unetView.netId; peerInfoPlayer.playerControllerId = current.unetView.playerControllerId; peerInfoPlayerList.Add(peerInfoPlayer); } } } if (connection.clientOwnedObjects != null) { using (HashSet<NetworkInstanceId>.Enumerator enumerator = connection.clientOwnedObjects.GetEnumerator()) { while (enumerator.MoveNext()) { NetworkInstanceId current = enumerator.Current; GameObject localObject = NetworkServer.FindLocalObject(current); if (!((Object) localObject == (Object) null) && (int) localObject.GetComponent<NetworkIdentity>().playerControllerId == -1) { PeerInfoPlayer peerInfoPlayer; peerInfoPlayer.netId = current; peerInfoPlayer.playerControllerId = (short) -1; peerInfoPlayerList.Add(peerInfoPlayer); } } } } if (peerInfoPlayerList.Count > 0) peerInfoMessage.playerIds = peerInfoPlayerList.ToArray(); peerInfoMessageList.Add(peerInfoMessage); } } peerListMessage.peers = peerInfoMessageList.ToArray(); for (int index = 0; index < NetworkServer.connections.Count; ++index) { NetworkConnection connection = NetworkServer.connections[index]; if (connection != null) { peerListMessage.oldServerConnectionId = connection.connectionId; connection.Send((short) 11, (MessageBase) peerListMessage); } } }
/// <summary> /// <para>Sets the Id that the ClientScene will use when reconnecting to a new host after host migration.</para> /// </summary> /// <param name="newReconnectId">The Id to use when reconnecting to a game.</param> /// <param name="peers">The set of known peers in the game. This may be null.</param> public static void SetReconnectId(int newReconnectId, PeerInfoMessage[] peers) { ClientScene.s_ReconnectId = newReconnectId; ClientScene.s_Peers = peers; if (!LogFilter.logDebug) return; Debug.Log((object) ("ClientScene::SetReconnectId: " + (object) newReconnectId)); }
/// <summary> /// /// <para> /// This sends information about all participants in the current network game to the connection. /// </para> /// /// </summary> /// <param name="targetConnection">Connection to send peer info to.</param> public void SendNetworkInfo(NetworkConnection targetConnection) { PeerListMessage peerListMessage = new PeerListMessage(); List<PeerInfoMessage> list = new List<PeerInfoMessage>(); for (int connId = 0; connId < this.m_Connections.Count; ++connId) { NetworkConnection networkConnection = this.m_Connections.Get(connId); if (networkConnection != null) { PeerInfoMessage peerInfoMessage = new PeerInfoMessage(); string address; int port; NetworkID network; NodeID dstNode; byte error; NetworkTransport.GetConnectionInfo(this.m_ServerId, networkConnection.connectionId, out address, out port, out network, out dstNode, out error); peerInfoMessage.connectionId = networkConnection.connectionId; peerInfoMessage.address = address; peerInfoMessage.port = port; peerInfoMessage.isHost = false; peerInfoMessage.isYou = networkConnection == targetConnection; list.Add(peerInfoMessage); } } if (NetworkServer.localClientActive) list.Add(new PeerInfoMessage() { address = "HOST", port = this.m_ServerPort, connectionId = 0, isHost = true, isYou = false }); peerListMessage.peers = list.ToArray(); for (int connId = 0; connId < this.m_Connections.Count; ++connId) { NetworkConnection networkConnection = this.m_Connections.Get(connId); if (networkConnection != null) networkConnection.Send((short) 11, (MessageBase) peerListMessage); } }
internal NetworkClient BecomeHostInternal(NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage[] peers) { if (s_Active) { if (LogFilter.logError) { Debug.LogError("BecomeHost already a server."); } return null; } if (!NetworkClient.active) { if (LogFilter.logError) { Debug.LogError("BecomeHost NetworkClient not active."); } return null; } Configure(hostTopology); if (matchInfo == null) { if (LogFilter.logDev) { Debug.Log("BecomeHost Listen on " + port); } if (!Listen(port)) { if (LogFilter.logError) { Debug.LogError("BecomeHost bind failed."); } return null; } } else { if (LogFilter.logDev) { Debug.Log("BecomeHost match:" + matchInfo.networkId); } ListenRelay(matchInfo.address, matchInfo.port, matchInfo.networkId, Utility.GetSourceID(), matchInfo.nodeId); } foreach (NetworkIdentity identity in ClientScene.objects.Values) { if ((identity != null) && (identity.gameObject != null)) { NetworkIdentity.AddNetworkId(identity.netId.Value); this.m_NetworkScene.SetLocalObject(identity.netId, identity.gameObject, false, false); identity.OnStartServer(true); } } if (LogFilter.logDev) { Debug.Log("NetworkServer BecomeHost done. oldConnectionId:" + oldConnectionId); } this.RegisterMessageHandlers(); if (!NetworkClient.RemoveClient(oldClient) && LogFilter.logError) { Debug.LogError("BecomeHost failed to remove client"); } if (LogFilter.logDev) { Debug.Log("BecomeHost localClient ready"); } NetworkClient client2 = ClientScene.ReconnectLocalServer(); ClientScene.Ready(client2.connection); ClientScene.SetReconnectId(oldConnectionId, peers); ClientScene.AddPlayer(ClientScene.readyConnection, 0); return client2; }
public static NetworkClient BecomeHost(NetworkClient oldClient, int port, MatchInfo matchInfo, int oldConnectionId, PeerInfoMessage[] peers) { return instance.BecomeHostInternal(oldClient, port, matchInfo, oldConnectionId, peers); }
/// <summary> /// <para>This sends the set of peers in the game to all the peers in the game.</para> /// </summary> public void SendPeerInfo() { if (this.m_HostMigration) { PeerListMessage msg = new PeerListMessage(); List<PeerInfoMessage> list = new List<PeerInfoMessage>(); for (int i = 0; i < NetworkServer.connections.Count; i++) { NetworkConnection connection = NetworkServer.connections[i]; if (connection != null) { string str; int num2; NetworkID kid; NodeID eid; byte num3; PeerInfoMessage item = new PeerInfoMessage(); NetworkTransport.GetConnectionInfo(NetworkServer.serverHostId, connection.connectionId, out str, out num2, out kid, out eid, out num3); item.connectionId = connection.connectionId; item.port = num2; if (i == 0) { item.port = NetworkServer.listenPort; item.isHost = true; item.address = "<host>"; } else { item.address = str; item.isHost = false; } List<PeerInfoPlayer> list2 = new List<PeerInfoPlayer>(); for (int k = 0; k < connection.playerControllers.Count; k++) { PlayerController controller = connection.playerControllers[k]; if ((controller != null) && (controller.unetView != null)) { PeerInfoPlayer player; player.netId = controller.unetView.netId; player.playerControllerId = controller.unetView.playerControllerId; list2.Add(player); } } if (connection.clientOwnedObjects != null) { foreach (NetworkInstanceId id in connection.clientOwnedObjects) { GameObject obj2 = NetworkServer.FindLocalObject(id); if ((obj2 != null) && (obj2.GetComponent<NetworkIdentity>().playerControllerId == -1)) { PeerInfoPlayer player2; player2.netId = id; player2.playerControllerId = -1; list2.Add(player2); } } } if (list2.Count > 0) { item.playerIds = list2.ToArray(); } list.Add(item); } } msg.peers = list.ToArray(); for (int j = 0; j < NetworkServer.connections.Count; j++) { NetworkConnection connection2 = NetworkServer.connections[j]; if (connection2 != null) { msg.oldServerConnectionId = connection2.connectionId; connection2.Send(11, msg); } } } }
public virtual bool FindNewHost(out PeerInfoMessage newHostInfo, out bool youAreNewHost) { if (this.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"); } newHostInfo = new PeerInfoMessage(); newHostInfo.connectionId = 0xc350; newHostInfo.address = ""; newHostInfo.port = 0; int connectionId = -1; youAreNewHost = false; if (this.m_Peers == null) { return false; } for (int i = 0; i < this.m_Peers.Length; i++) { PeerInfoMessage message = this.m_Peers[i]; if ((message.connectionId != 0) && !message.isHost) { if (message.isYou) { connectionId = message.connectionId; } if (message.connectionId < newHostInfo.connectionId) { newHostInfo = message; } } } if (newHostInfo.connectionId == 0xc350) { return false; } if (newHostInfo.connectionId == connectionId) { youAreNewHost = true; } if (LogFilter.logDev) { Debug.Log("FindNewHost new host is " + newHostInfo.address); } return true; }