internal void ReceiveNotify(NotifyPacket notifyPacket, NetworkReader networkReader, int channelId) { int sequenceDistance = (int)sequencer.Distance(notifyPacket.Sequence, receiveSequence); // sequence is so far out of bounds we can't save, just kick him (or her!) if (Math.Abs(sequenceDistance) > WINDOW_SIZE) { connection?.Disconnect(); return; } // this message is old, we already received // a newer or duplicate packet. Discard it if (sequenceDistance <= 0) { return; } receiveSequence = notifyPacket.Sequence; if (sequenceDistance >= ACK_MASK_BITS) { receiveMask = 1; } else { receiveMask = (receiveMask << sequenceDistance) | 1; } AckPackets(notifyPacket.ReceiveSequence, notifyPacket.AckMask); int msgType = MessagePacker.UnpackId(networkReader); InvokeHandler(msgType, networkReader, channelId); if (Time.unscaledTime - lastNotifySentTime > NOTIFY_ACK_TIMEOUT) { SendNotify(new NotifyAck(), null, channelId); } }
public void TestWrappingDistance() { var sequencer = new Sequencer(8); Assert.That(sequencer.Distance(254, 4), Is.EqualTo(-6)); }
public void TestNegativeDistance() { var sequencer = new Sequencer(8); Assert.That(sequencer.Distance(8, 0), Is.EqualTo(8)); }
public void TestDistanceAtBegining() { var sequencer = new Sequencer(8); Assert.That(sequencer.Distance(0, 8), Is.EqualTo(-8)); }
public void ValuesAfterWrappingConsideredToBeGreater() { var sequencer = new Sequencer(8); Assert.That(sequencer.Distance(254, 4), Is.EqualTo(-6)); }
public void ShouldReturnPositiveDistanceIfSecondIdComesBefore() { var sequencer = new Sequencer(8); Assert.That(sequencer.Distance(8, 0), Is.EqualTo(8)); }
public void ShouldReturnNegativeDistanceIfSecondIdComesAfter() { var sequencer = new Sequencer(8); Assert.That(sequencer.Distance(0, 8), Is.EqualTo(-8)); }