示例#1
0
        /// <summary>
        /// Removes any acked or expired outgoing events.
        /// </summary>
        private void CleanOutgoingEvents(
            SequenceId ackedEventId)
        {
            if (ackedEventId.IsValid == false)
            {
                return;
            }

            while (this.outgoingEvents.Count > 0)
            {
                RailEvent top = this.outgoingEvents.Peek();

                // Stop if we hit an un-acked reliable event
                if (top.IsReliable)
                {
                    if (top.EventId > ackedEventId)
                    {
                        break;
                    }
                }
                // Stop if we hit an unreliable event with remaining attempts
                else
                {
                    if (top.Attempts > 0)
                    {
                        break;
                    }
                }

                RailPool.Free(this.outgoingEvents.Dequeue());
            }
        }
示例#2
0
 /// <summary>
 /// Queues an event to broadcast to all clients.
 /// Use a RailEvent.SEND_RELIABLE (-1) for the number of attempts
 /// to send the event reliable-ordered (infinite retries).
 /// </summary>
 public void QueueEventBroadcast(RailEvent evnt, int attempts = 3)
 {
     foreach (RailServerPeer clientPeer in this.clients.Values)
     {
         clientPeer.QueueEvent(evnt, attempts);
     }
 }
示例#3
0
 /// <summary>
 /// Handles the execution of an incoming event.
 /// </summary>
 private void ProcessEvent(RailEvent evnt)
 {
     if (this.EventReceived != null)
     {
         this.EventReceived.Invoke(evnt, this);
     }
     this.processedEventHistory =
         this.processedEventHistory.Store(evnt.EventId);
 }
示例#4
0
        private void DecodeEvents(
            RailBitBuffer buffer)
        {
            IEnumerable <RailEvent> decoded =
                buffer.UnpackAll(
                    () => RailEvent.Decode(buffer, this.SenderTick));

            foreach (RailEvent evnt in decoded)
            {
                this.events.Add(evnt);
            }
        }
示例#5
0
        /// <summary>
        /// Queues an event to send directly to this peer.
        /// </summary>
        public void QueueEvent(RailEvent evnt, int attempts)
        {
            // TODO: Event scoping

            // All global events are sent reliably
            RailEvent clone = evnt.Clone();

            clone.EventId  = this.lastQueuedEventId;
            clone.Attempts = attempts;

            this.outgoingEvents.Enqueue(clone);
            this.lastQueuedEventId = this.lastQueuedEventId.Next;
        }
示例#6
0
        internal void OnEventReceived(RailEvent evnt, RailPeer sender)
        {
            if (evnt.EntityId.IsValid)
            {
                RailEntity entity = null;
                this.Room.TryGet(evnt.EntityId, out entity);

#if SERVER
                // Entity events can only be executed on controlled entities
                bool safeToExecute = (entity != null) && (entity.Controller == sender);
#elif CLIENT
                bool safeToExecute = (entity != null);
#endif

                if (safeToExecute)
                {
                    evnt.Invoke(this.room, sender, entity);
                }
            }
            else
            {
                evnt.Invoke(this.room, sender);
            }
        }
示例#7
0
 /// <summary>
 /// Queues an event to broadcast to all clients.
 /// Use a RailEvent.SEND_RELIABLE (-1) for the number of attempts
 /// to send the event reliable-ordered (infinite retries).
 /// </summary>
 public void QueueEvent(RailEvent evnt, int attempts = 3)
 {
     this.serverPeer.QueueEvent(evnt, attempts);
 }
示例#8
0
 internal bool EvaluateEvent(
     RailEvent evnt)
 {
     return(this.Evaluator.Evaluate(evnt));
 }