void InvokeCallbacksForProperty(int propertyIndex) { try { NetworkPropertyInfo pi = Meta.Properties[propertyIndex]; List <PropertyCallback> callbacks; List <PropertyCallbackSimple> callbacksSimple; for (int i = 0; i < pi.Paths.Length; ++i) { if (Callbacks.TryGetValue(pi.Paths[i], out callbacks)) { for (int c = 0; c < callbacks.Count; ++c) { callbacks[c](this, pi.Paths[pi.Paths.Length - 1], new ArrayIndices(pi.Indices)); } } if (CallbacksSimple.TryGetValue(pi.Paths[i], out callbacksSimple)) { for (int c = 0; c < callbacksSimple.Count; ++c) { callbacksSimple[c](); } } } } catch (Exception exn) { NetLog.Exception(exn); } }
public override bool Write(Connection connection, NetworkObj obj, NetworkStorage storage, Packet packet) { try { packet.WriteToken(storage.Values[obj[this]].ProtocolToken); return(true); } catch (Exception exn) { NetLog.Error("User code threw exception while serializing protocol token"); NetLog.Exception(exn); return(false); } }
public void PacketLost(Packet packet) { for (int i = 0; i < channels.Length; ++i) { channels[i].Lost(packet); } try { } catch (Exception exn) { NetLog.Exception(exn); NetLog.Error("exception thrown while handling lost packet to {0}", sockConn.RemoteEndPoint); } }
public void PacketDelivered(Packet packet) { try { for (int i = 0; i < channels.Length; ++i) { channels[i].Delivered(packet); } } catch (Exception exn) { NetLog.Exception(exn); NetLog.Error("exception thrown while handling delivered packet to {0}", sockConn.RemoteEndPoint); } }
public void PacketReceived(Packet Packet) { try { using (Packet packet = Core.AllocatePacket()) { packet.Set(Packet); //This copies the values into the newly acquired packet //Read signature & frame packet.Type = packet.ReadByte(); packet.Frame = packet.ReadIntVB(); if (packet.Frame > remoteFrameActual) { remoteFrameAdjust = true; remoteFrameActual = packet.Frame; } //OLD method //bitsSecondInAcc += packet.ActualSize; bitsSecondInAcc += packet.Position; packetsReceived += 1; for (int i = 0; i < channels.Length; ++i) { channels[i].Read(packet); } //for (int i = 0; i < channels.Length; ++i) //{ // channels[i].ReadDone(); //} packetStatsIn.Enqueue(packet.Stats); NetAssert.False(Packet.Overflowing); //SocketLog.Info("Received packet of length {0}", packet.ActualSize); } } catch (Exception exn) { NetLog.Exception(exn); NetLog.Error("exception thrown while unpacking data from {0}, disconnecting", sockConn.RemoteEndPoint); Disconnect(); } }
/// <summary> /// Load a scene based on name, only possible on the Server /// </summary> /// <param name="scene">The scene to load</param> /// <param name="token">A data token from the server</param> public static void LoadScene(string scene, IMessageRider token) { VerifyIsRunning(); int sceneIndex = -1; try { sceneIndex = AscensionNetworkInternal.GetSceneIndex(scene); } catch (Exception exn) { NetLog.Error("Exception thrown while trying to find index of scene '{0}'", scene); NetLog.Exception(exn); return; } Core.LoadScene(sceneIndex, token); }
public bool Send(out Packet sentPacket) { bool sent; try { Packet packet = Core.AllocatePacket(); packet.Frame = Core.Frame; packet.Number = ++packetCounter; packet.Type = (byte)NetworkMsg.Data; packet.UserToken = packet; //Write signature & frame packet.WriteByte(packet.Type); packet.WriteIntVB(packet.Frame); for (int i = 0; i < channels.Length; ++i) { channels[i].Pack(packet); } NetAssert.False(packet.Overflowing); sockConn.Send(packet); sent = true; sentPacket = packet; sentPacket.Set(packet); //SocketLog.Info("Sending packet of length {0}", packet.ActualSize); bitsSecondOutAcc += packet.Position; packetStatsOut.Enqueue(packet.Stats); } catch (Exception exn) { NetLog.Exception(exn); throw; } return(sent); }
public void Raise(Event ev) { IEventFactory factory = Factory.GetEventFactory(ev.Meta.TypeId); List <CallbackWrapper> newCallbacks; if (callbacks.TryGetValue(ev.GetType(), out newCallbacks)) { for (int i = 0; i < callbacks.Count; ++i) { newCallbacks[i].Wrapper(ev); } } for (int i = 0; i < targets.Count; ++i) { EventListener mb = targets[i]; if (mb.Behaviour) { // dont call on disabled behaviours if (mb.Behaviour.enabled == false) { if ((mb.Listener == null) || (mb.Listener.InvokeIfDisabled == false)) { continue; } } // dont call on behaviours attached to inactive game objects if (mb.GameObject.activeInHierarchy == false) { if ((mb.Listener == null) || (mb.Listener.InvokeIfGameObjectIsInactive == false)) { continue; } } // invoke event try { factory.Dispatch(ev, mb.Behaviour); } catch (Exception exn) { NetLog.Error("User code threw exception when invoking {0}", ev); NetLog.Exception(exn); } } else { // remove callback if this behaviour is destroyed targets.RemoveAt(i); // --i; continue; } } }
public void Detach() { NetAssert.NotNull(UnityObject); NetAssert.True(IsAttached); NetAssert.True(NetworkId.Packed != 0UL); if (AutoRemoveChildEntities) { foreach (AscensionEntity child in UnityObject.GetComponentsInChildren(typeof(AscensionEntity), true)) { if (child.IsAttached && (ReferenceEquals(child.entity, this) == false)) { child.transform.parent = null; } } } if (Controller) { RevokeControl(null); } // destroy on all connections var it = Core.connections.GetIterator(); while (it.Next()) { it.val.entityChannel.DestroyOnRemote(this); } // call out to behaviours foreach (IEntityBehaviour eb in Behaviours) { try { if (eb.Invoke && ReferenceEquals(eb.entity, this.UnityObject)) { eb.Detached(); eb.entity = null; } } catch (Exception exn) { NetLog.Error("User code threw exception inside Detach callback"); NetLog.Exception(exn); } } // call out to user try { GlobalEventListenerBase.EntityDetachedInvoke(this.UnityObject); } catch (Exception exn) { NetLog.Error("User code threw exception inside Detach callback"); NetLog.Exception(exn); } // clear out attached flag Flags &= ~EntityFlags.ATTACHED; // remove from entities list if (Core.entitiesFrozen.Contains(this)) { Core.entitiesFrozen.Remove(this); } if (Core.entitiesThawed.Contains(this)) { Core.entitiesThawed.Remove(this); } // clear from unity object UnityObject.entity = null; // log NetLog.Debug("Detached {0}", this); }
public void Attach() { NetAssert.NotNull(UnityObject); NetAssert.False(IsAttached); NetAssert.True((NetworkId.Packed == 0UL) || (Source != null)); try { AttachIsRunning = true; // mark as don't destroy on load GameObject.DontDestroyOnLoad(UnityObject.gameObject); // assign network id if (Source == null) { NetworkId = NetworkIdAllocator.Allocate(); } // add to entities list Core.entitiesThawed.AddLast(this); // mark as attached Flags |= EntityFlags.ATTACHED; // call out to behaviours foreach (IEntityBehaviour eb in Behaviours) { try { if (eb.Invoke && ReferenceEquals(eb.entity, this.UnityObject)) { eb.Attached(); } } catch (Exception exn) { NetLog.Error("User code threw exception inside Attached callback"); NetLog.Exception(exn); } } // call out to user try { GlobalEventListenerBase.EntityAttachedInvoke(this.UnityObject); } catch (Exception exn) { NetLog.Error("User code threw exception inside Attached callback"); NetLog.Exception(exn); } // log NetLog.Debug("Attached {0} (Token: {1})", this, AttachToken); } finally { AttachIsRunning = false; } }