public void OnRequestOwnership(P2PNetworkMessage netMsg) { GameObject gameObject = netMsg.m_Reader.ReadGameObject(); if (gameObject) { ReplicationComponent replComponentForGameObject = this.GetReplComponentForGameObject(gameObject, true); if (P2PLogFilter.logPedantic) { Debug.Log(string.Format("OnRequestOwnership called for {0} guid: {1}", replComponentForGameObject.name, replComponentForGameObject.GetGuidComponent.GetGuid()), gameObject); } ReplicationComponent.s_DeserializedComponent = replComponentForGameObject; P2PPeer peerById = ReplTools.GetPeerById(netMsg.m_Reader.ReadInt16()); replComponentForGameObject.ReplOnChangedOwner(peerById); ReplicationComponent.s_DeserializedComponent = null; } }
public void OnGiveOwnership(P2PNetworkMessage netMsg) { byte[] array; GameObject gameObject = netMsg.m_Reader.ReadGameObjectAndGuid(out array); if (gameObject) { ReplicationComponent replComponentForGameObject = this.GetReplComponentForGameObject(gameObject, true); if (P2PLogFilter.logPedantic) { Debug.Log(string.Format("OnGiveOwnership called for {0} guid: {1}", replComponentForGameObject.name, replComponentForGameObject.GetGuidComponent.GetGuid()), gameObject); } ReplicationComponent.s_DeserializedComponent = replComponentForGameObject; P2PPeer peerById = ReplTools.GetPeerById(netMsg.m_Reader.ReadInt16()); if (peerById == ReplTools.GetLocalPeer()) { replComponentForGameObject.ReplRequestOwnership(); } else { replComponentForGameObject.ReplOnChangedOwner(peerById); } ReplicationComponent.s_DeserializedComponent = null; return; } P2PNetworkWriter p2PNetworkWriter = new P2PNetworkWriter(); p2PNetworkWriter.StartMessage(8); p2PNetworkWriter.Write(array, GuidComponent.GUID_BYTES_CNT); p2PNetworkWriter.FinishMessage(); if (P2PLogFilter.logWarn) { Debug.LogWarning("Did not find target for give ownership message for " + new Guid(array)); } P2PSession.Instance.SendWriterTo(netMsg.m_Connection.m_Peer, p2PNetworkWriter, 0); }
public void ReplicationReceive(P2PNetworkReader reader, bool initial_state) { if (P2PLogFilter.logPedantic) { Debug.Log(string.Format("ReplicationReceive called for {0} with guid {1}", base.name, this.GetGuidComponent.GetGuid()), this); } int num = reader.ReadInt32(); if (num <= this.m_Revision && !initial_state) { return; } ReplicationComponent.s_DeserializedComponent = this; this.m_Revision = num; this.m_LastReplicationTime = Time.time; this.m_LastReplicationTimeReal = Time.realtimeSinceStartup; short num2 = reader.ReadInt16(); if (this.m_OwnerPeer.GetHostId() != num2) { this.ReplOnChangedOwner(ReplTools.GetPeerById(num2)); if (this.m_OwnerPeer == ReplTools.GetLocalPeer()) { this.ReplRequestOwnership(); } } this.ReplBlockChangeOwnership(!reader.ReadBoolean()); for (int i = 0; i < this.GetReplBehaviours.Length; i++) { IReplicatedBehaviour replicatedBehaviour = this.GetReplBehaviours[i]; if (replicatedBehaviour as UnityEngine.Object == null) { if (reader.ReadBoolean()) { ReplicationComponent.s_DeserializedComponent = null; return; } this.m_ReplBehavioursFlag[i] = false; } else if (reader.ReadBoolean()) { int uniqueIdForType = replicatedBehaviour.GetUniqueIdForType(); int num3 = reader.ReadInt32(); if (uniqueIdForType != num3) { ReplicationComponent.s_DeserializedComponent = null; return; } replicatedBehaviour.OnReplicationDeserialize(reader, initial_state); this.CallReplicationDeserialize_Gen(replicatedBehaviour, reader, initial_state); this.m_ReplBehavioursFlag[i] = true; } else { this.m_ReplBehavioursFlag[i] = false; } } for (int j = 0; j < this.GetReplBehaviours.Length; j++) { if (this.m_ReplBehavioursFlag[j]) { IReplicatedBehaviour replicatedBehaviour2 = this.GetReplBehaviours[j]; replicatedBehaviour2.OnReplicationResolve(); this.CallReplicationResolve_Gen(replicatedBehaviour2); } } if (P2PConnection.s_Size > reader.Position && !initial_state) { Debug.LogError(string.Format("Didn't read whole buffer! (number of bytes unread: {0})", P2PConnection.s_Size - reader.Position), this); } ReplicationComponent.s_DeserializedComponent = null; }