// When acking an event, all events of the same kind and same client with lower seq id will be removed.
        // The last acked event will be stored in order to check if it has been already processed.
        public void AckEvent(Event ievent)
        {
            _eventQueue = _eventQueue.Where(ev => !(ev.ClientId == ievent.ClientId &&
                                                    ev.GetEventEnum().Equals(ievent.GetEventEnum()) &&
                                                    UnsignedCircularComparator.compareLong((ulong)ev.SeqId, (ulong)ievent.SeqId, (ulong)Connection.MAX_SEQ_ID) < 1))
                          .ToList();

            _lastAcked = _lastAcked.Where(ev => !(ev.ClientId == ievent.ClientId &&
                                                  ev.GetEventEnum().Equals(ievent.GetEventEnum()))).ToList();
            _lastAcked.Add(ievent);
        }
        // Checks whether the event has been processed already or not.
        public bool ShouldProcessEvent(Event ievent)
        {
            Event lastAckedEvent = _lastAcked.Find(ev => ev.ClientId == ievent.ClientId &&
                                                   ev.GetEventEnum().Equals(ievent.GetEventEnum()));

            return(lastAckedEvent == null ||
                   UnsignedCircularComparator.compareLong((ulong)ievent.SeqId, (ulong)lastAckedEvent.SeqId, (ulong)Connection.MAX_SEQ_ID) == 1);
        }
Example #3
0
 public EventBuilder(Event ievent)
 {
     _seqId           = ievent.SeqId;
     _clientId        = ievent.ClientId;
     _ack             = ievent.Ack;
     _eventEnum       = ievent.GetEventEnum();
     _timeoutTypeEnum = ievent.GetTimeoutType();
     _payload         = ievent.GetPayload();
 }
Example #4
0
        private void ReceiveEvent(byte[] receivedBytes, IPEndPoint remoteEndpoint)
        {
            Connection connection   = _connectionList.Find(con => con.IsThisEndpoint(remoteEndpoint));
            int        connectionId = connection == null ? -1 : connection.Id;

            Event ievent = Event.Deserialize(receivedBytes).SetClientId(connectionId)
                           .Build();

            //Debug.Log("Receiving from: " + remoteEndpoint + "\nclient: "+ ievent.ClientId + " - seqId: " + ievent.SeqId + " - ack: " + ievent.Ack + " - timeout: " + ievent.GetTimeoutType() + " - type: " + ievent.GetEventEnum() );
            if (ievent.GetEventEnum().Equals(EventEnum.Connection))
            {
                ievent = HandleConnectionEvent(ievent, remoteEndpoint);
            }
            _eventManager.ReceiveEvent(ievent);
        }