コード例 #1
0
        public bool ShouldPullDataFromMecanim(NetworkState state)
        {
#if DEBUG
            if (
#else
            return
                (#endif
                MecanimDirection == MecanimDirection.UsingAnimatorMethods && (state.Entity.IsOwner || state.Entity.HasPredictedControl)

#if DEBUG
                )
            {
                if (state.Animators.Count > 1)
                {
                    NetLog.Warn("Property '{0}' set to 'UsingAnimatorMethods' but several animators have been specified, only the first one added will be used.");
                }

                return true;
            }

                return false);
#else
                ;
#endif
        }
コード例 #2
0
        public bool QueueInput(Command cmd)
        {
            if (canQueueCommands)
            {
                NetAssert.True(HasControl);

                if (CommandQueue.Count < Core.Config.commandQueueSize)
                {
                    cmd.ServerFrame = Core.ServerFrame;
                    cmd.Sequence    = CommandSequence = NetMath.SeqNext(CommandSequence, Command.SEQ_MASK);
                }
                else
                {
                    NetLog.Error("Input queue for {0} is full", this);
                    return(false);
                }

                CommandQueue.AddLast(cmd);
                return(true);
            }
            else
            {
                NetLog.Error("You can only queue commands to the host in the 'SimulateController' callback");
                return(false);
            }
        }
コード例 #3
0
        public void TakeControl(IMessageRider token)
        {
            if (IsOwner)
            {
                if (HasControl)
                {
                    NetLog.Warn("You already have control of {0}", this);
                }
                else
                {
                    // revoke any existing control
                    RevokeControl(token);

                    // take control locally
                    TakeControlInternal(token);


                    // de-freeze
                    Freeze(false);
                }
            }
            else
            {
                NetLog.Error("Only the owner of {0} can take control of it", this);
            }
        }
コード例 #4
0
        public void AssignControl(Connection connection, IMessageRider token)
        {
            if (IsOwner)
            {
                if (HasControl)
                {
                    ReleaseControl(token);
                }

                EntityProxy proxy;

                CommandLastExecuted = null;
                CommandSequence     = 0;
                CommandQueue.Clear();

                Controller = connection;
                Controller.controlling.Add(this);
                Controller.entityChannel.CreateOnRemote(this, out proxy);
                Controller.entityChannel.ForceSync(this);

                // set token
                proxy.ControlTokenLost   = null;
                proxy.ControlTokenGained = token;

                Freeze(false);
            }
            else
            {
                NetLog.Error("You can not assign control of {0}, you are not the owner", this);
            }
        }
コード例 #5
0
        public void RevokeControl(IMessageRider token)
        {
            if (IsOwner)
            {
                if (Controller)
                {
                    EntityProxy proxy;

                    // force a replication of this
                    Controller.controlling.Remove(this);
                    Controller.entityChannel.ForceSync(this, out proxy);
                    Controller = null;

                    // clear out everything
                    CommandLastExecuted = null;
                    CommandSequence     = 0;
                    CommandQueue.Clear();

                    // set token
                    if (proxy != null)
                    {
                        proxy.ControlTokenLost   = token;
                        proxy.ControlTokenGained = null;
                    }
                }

                Freeze(false);
            }
            else
            {
                NetLog.Error("You can not revoke control of {0}, you are not the owner", this);
                return;
            }
        }
コード例 #6
0
        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);
            }
        }
コード例 #7
0
        static void Entity_Only_Controller(Event ev)
        {
            if (ev.TargetEntity)
            {
                if (ev.TargetEntity.HasControl)
                {
                    RaiseLocal(ev);

                    // we can free this (never used after this)
                    ev.FreeStorage();
                }
                else
                {
                    if (ev.TargetEntity.IsOwner)
                    {
                        if (ev.TargetEntity.Controller != null)
                        {
                            ev.TargetEntity.Controller.eventChannel.Queue(ev);
                        }
                        else
                        {
                            NetLog.Warn("NetworkEvent sent to controller but no controller exists, event will NOT be raised");
                        }
                    }
                    else
                    {
                        ev.TargetEntity.Source.eventChannel.Queue(ev);
                    }
                }
            }
            else
            {
                NetLog.Warn("NetworkEvent with NULL target, event will NOT be forwarded or raised");
            }
        }
コード例 #8
0
        bool PackEvent(Event ev, Packet stream, uint sequence)
        {
            NetLog.Debug("sending event {0}", ev);

            stream.WriteContinueMarker();

            // type id of this event
            stream.WriteTypeId(ev.Meta.TypeId);

            // targets of this event
            stream.WriteInt(ev.Targets, 5);

            if (stream.WriteBool(ev.Reliability == ReliabilityModes.ReliableOrdered))
            {
                // write sequence number for reliable events
                stream.WriteUInt(sequence, Event.RELIABLE_SEQUENCE_BITS);
            }
            else
            {
                if (ev.IsEntityEvent)
                {
                    // write network id for entity events
                    stream.WriteEntity(ev.TargetEntity);
                }
            }

            stream.WriteByteArrayLengthPrefixed(ev.BinaryData, Core.Config.packetSize / 2);
            return(ev.Pack(connection, stream));
        }
コード例 #9
0
        public static void Enqueue(SceneLoadState scene)
        {
            NetLog.Debug("Loading {0} ({1})", scene, AscensionNetworkInternal.GetSceneName(scene.Scene.Index));

            delay = 0;
            LoadOps.AddLast(new LoadOp {
                scene = scene
            });
        }
コード例 #10
0
ファイル: Trigger.cs プロジェクト: RottenVisions/ascension
        public override void SetDynamic(NetworkObj obj, object value)
        {
            if (MecanimDirection == MecanimDirection.UsingAnimatorMethods)
            {
                NetLog.Error("Can't call SetDynamic on a trigger in 'UsingAnimatorMethods' mode");
                return;
            }

            obj.Storage.Values[obj[this]].TriggerLocal.Update(Core.Frame, true);
        }
コード例 #11
0
        bool VerifyCallbackPath(string path)
        {
            if (Meta.CallbackPaths.Contains(path))
            {
                return(true);
            }

            NetLog.Error("No callback path '{0}' available on {1}", path, this);
            return(false);
        }
コード例 #12
0
        public void SetIdle(Connection connection, bool idle)
        {
            if (idle && IsController(connection))
            {
                NetLog.Error("You can not idle {0} on {1}, as it is the controller for this entity", this, connection);
                return;
            }

            connection.entityChannel.SetIdle(this, idle);
        }
コード例 #13
0
        /// <summary>
        /// Get the state if this entity
        /// </summary>
        public TState GetState <TState>()
        {
            if (AEntity.Serializer is TState)
            {
                return((TState)(object)AEntity.Serializer);
            }

            NetLog.Error("You are trying to access the state of {0} as '{1}'", AEntity, typeof(TState));
            return(default(TState));
        }
コード例 #14
0
 public void SetParent(Entity entity)
 {
     if (IsOwner || HasPredictedControl)
     {
         SetParentInternal(entity);
     }
     else
     {
         NetLog.Error("You are not allowed to assign the parent of this entity, only the owner or a controller with local prediction can");
     }
 }
コード例 #15
0
        static object Create(UniqueId id)
        {
#if DEBUG
            if (_factoriesByKey.ContainsKey(id) == false)
            {
                NetLog.Error("Unknown {0}", id);
            }
#endif

            return(_factoriesByKey[id].Create());
        }
コード例 #16
0
        public void InvokeOnce(Command command, CommandCallback callback, int delay)
        {
            NetAssert.True(delay > 0);

            if (!canQueueCallbacks)
            {
                NetLog.Error("Can only queue callbacks when commands with 'IsFirstExecution' set to true are executing");
                return;
            }

            //CommandCallbacks.Add(new CommandCallbackItem { Command = command, Callback = callback, Start = -1, End = command.Number + delay, Mode = CommandCallbackModes.InvokeOnce });
        }
コード例 #17
0
        private static void Entity_Only_Controller_And_Owner(Event ev)
        {
            if (ev.TargetEntity)
            {
                if (ev.TargetEntity.HasControl)
                {
                    RaiseLocal(ev);

                    if (ev.TargetEntity.IsOwner)
                    {
                        // if we're also owner, free this
                        ev.FreeStorage();
                    }
                    else
                    {
                        // check so this was not received from source, and if it wasn't then send it to it
                        if (ev.SourceConnection != ev.TargetEntity.Source)
                        {
                            ev.TargetEntity.Source.eventChannel.Queue(ev);
                        }
                    }
                }
                else
                {
                    if (ev.TargetEntity.IsOwner)
                    {
                        // raise this locally for owner
                        RaiseLocal(ev);

                        if (ev.TargetEntity.Controller != null)
                        {
                            // check so we didn't receive this from owner
                            if (ev.SourceConnection != ev.TargetEntity.Controller)
                            {
                                ev.TargetEntity.Controller.eventChannel.Queue(ev);
                            }
                        }
                        else
                        {
                            NetLog.Warn("NetworkEvent sent to controller but no controller exists, event will NOT be raised");
                        }
                    }
                    else
                    {
                        ev.TargetEntity.Source.eventChannel.Queue(ev);
                    }
                }
            }
            else
            {
                NetLog.Warn("NetworkEvent with NULL target, event will NOT be forwarded or raised");
            }
        }
コード例 #18
0
        public static IFactory GetFactory(UniqueId id)
        {
#if DEBUG
            if (!_factoriesByKey.ContainsKey(id))
            {
                NetLog.Error("Unknown factory {0}", id);
                return(null);
            }
#endif

            return(_factoriesByKey[id]);
        }
コード例 #19
0
        public void InvokeRepeating(Command command, CommandCallback callback, int period)
        {
            NetAssert.True(period > 0);

            if (!canQueueCallbacks)
            {
                NetLog.Error("Can only queue callbacks when commands with 'IsFirstExecution' set to true are executing");
                return;
            }

            //CommandCallbacks.Add(new CommandCallbackItem { Command = command, Callback = callback, Start = command.Number + 1, End = command.Number + period, Mode = CommandCallbackModes.InvokeRepeating });
        }
コード例 #20
0
        public void Remove(MonoBehaviour behaviour)
        {
            for (int i = 0; i < targets.Count; ++i)
            {
                if (ReferenceEquals(targets[i].Behaviour, behaviour))
                {
                    targets.RemoveAt(i);
                    return;
                }
            }

            NetLog.Warn("Behaviour not available in this dispatcher, ignoring call to Remove.");
        }
コード例 #21
0
 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);
     }
 }
コード例 #22
0
        public void SetScope(Entity entity, bool inScope)
        {
            if (Core.Config.scopeMode == ScopeMode.Automatic)
            {
                NetLog.Error("SetScope has no effect when Scope Mode is set to Automatic");
                return;
            }

            if (ReferenceEquals(entity.Source, connection))
            {
                return;
            }

            if (inScope)
            {
                if (_incommingDict.ContainsKey(entity.NetworkId))
                {
                    return;
                }

                EntityProxy proxy;

                if (_outgoingDict.TryGetValue(entity.NetworkId, out proxy))
                {
                    if (proxy.Flags & ProxyFlags.DESTROY_REQUESTED)
                    {
                        if (proxy.Flags & ProxyFlags.DESTROY_PENDING)
                        {
                            proxy.Flags |= ProxyFlags.DESTROY_IGNORE;
                        }
                        else
                        {
                            proxy.Flags &= ~ProxyFlags.DESTROY_IGNORE;
                            proxy.Flags &= ~ProxyFlags.DESTROY_REQUESTED;
                        }
                    }
                }
                else
                {
                    CreateOnRemote(entity);
                }
            }
            else
            {
                if (_outgoingDict.ContainsKey(entity.NetworkId))
                {
                    DestroyOnRemote(entity);
                }
            }
        }
コード例 #23
0
        public static void RegisterTokenClass(Type type)
        {
            if (_token2id.Count == 255)
            {
                throw new ArgumentException("Can only register 255 different token types");
            }

            byte id = (byte)(_token2id.Count + 1);

            _token2id.Add(type, id);
            _id2token.Add(id, type);

            NetLog.Debug("Registered token class {0} as id {1}", type, id);
        }
コード例 #24
0
        public void Add(MonoBehaviour behaviour)
        {
            for (int i = 0; i < targets.Count; ++i)
            {
                if (ReferenceEquals(targets[i].Behaviour, behaviour))
                {
                    NetLog.Warn("Behaviour is already registered in this dispatcher, ignoring call to Add.");
                    return;
                }
            }

            targets.Add(new EventListener {
                Behaviour = behaviour, GameObject = behaviour.gameObject, Listener = behaviour as IEventListener
            });
        }
コード例 #25
0
 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);
     }
 }
コード例 #26
0
 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);
     }
 }
コード例 #27
0
ファイル: Utils.cs プロジェクト: RottenVisions/ascension
        public static void WriteByteArraySimple(this BasePacket stream, byte[] array, int maxLength)
        {
            if (stream.WriteBool(array != null))
            {
                int length = Mathf.Min(array.Length, maxLength);

                if (length < array.Length)
                {
                    NetLog.Warn("Only sending {0}/{1} bytes from byte array", length, array.Length);
                }

                stream.WriteUShort((ushort)length);
                stream.WriteByteArray(array, 0, length);
            }
        }
コード例 #28
0
        public void WriteByteArrayLengthPrefixed(byte[] array, int maxLength)
        {
            if (WriteBool(array != null))
            {
                int length = Math.Min(array.Length, maxLength);

                if (length < array.Length)
                {
                    NetLog.Warn("Only sendig {0}/{1} bytes from byte array", length, array.Length);
                }

                WriteUShort((ushort)length);
                WriteByteArray(array, 0, length);
            }
        }
コード例 #29
0
        public override void SetDynamic(NetworkObj obj, object value)
        {
            if (MecanimDirection == MecanimDirection.UsingAnimatorMethods)
            {
                NetLog.Error("Can't call SetDynamic on a float in 'UsingAnimatorMethods' mode");
                return;
            }

            var v = (float)value;

            if (NetworkValue.Diff(obj.Storage.Values[obj[this]].Float0, v))
            {
                obj.Storage.Values[obj[this]].Float0 = v;
                obj.Storage.PropertyChanged(obj.OffsetProperties + this.OffsetProperties);
            }
        }
コード例 #30
0
        public void WriteEndPoint(IPEndPoint endpoint)
        {
            var parts = endpoint.Address.ToString().Split('.');

            if (parts.Length != 4)
            {
                NetLog.Warn(string.Format("IP address: {0} was malformed, could not write.", endpoint.Address));
                return;
            }

            WriteByte(Convert.ToByte(parts[0]));
            WriteByte(Convert.ToByte(parts[1]));
            WriteByte(Convert.ToByte(parts[2]));
            WriteByte(Convert.ToByte(parts[3]));
            WriteUShort((ushort)endpoint.Port);
        }