Пример #1
0
 private void PackID(Packer packer, int id)
 {
     if (this.nextID < sbyte.MaxValue)
     {
         packer.Pack((sbyte)id);
     }
     else if (this.nextID < short.MaxValue)
     {
         packer.Pack((short)id);
     }
     else
     {
         packer.Pack(id);
     }
 }
Пример #2
0
 protected override void fixMessage(Packer packer, byte[] message)
 {
     packer.Pack((byte)Protocol.Unordered);
     packer.Pack(message);
 }
Пример #3
0
 private void sendAckMessage(int accnum)
 {
     Packer packer = new Packer(5);
     packer.Pack((byte)(((int)Protocol.Reliable) | ACK_BIT));
     packer.Pack(accnum);
     this.connection.SendInternal(packer.GetPackedData());
 }
Пример #4
0
            protected override void fixMessage(Packer packer, byte[] message)
            {
                int toSendAccNum = this.sendAccNum++;
                packer.Pack((byte)Protocol.Reliable);
                packer.Pack(toSendAccNum);
                packer.Pack(message);

                MessageResendTimer timer = new MessageResendTimer();
                timer.accnumber = toSendAccNum;
                timer.message = packer.GetPackedData();
                timer.stopWatch.Start();

                connection.reliableTimer.addResender(timer);
            }
Пример #5
0
            private byte[] buildOrderedMessages(UnPacker unPacker)
            {
                List<int> keysToRemove = new List<int>();
                Packer packer = new Packer(unPacker.remaining());
                packer.Pack(unPacker.UnpackByteArray(unPacker.remaining()));

                foreach (var item in this.outOfOrderMessages.Keys)
                {
                    if (this.lastOrderedMessage + 1 == item)
                    {
                        keysToRemove.Add(item);
                        this.lastOrderedMessage++;
                        packer.Pack(this.outOfOrderMessages[item]);
                    }
                    else
                    {
                        break;
                    }
                }

                keysToRemove.ForEach((x) => this.outOfOrderMessages.Remove(x));

                return packer.GetPackedData();
            }
Пример #6
0
 protected override void fixMessage(Packer packer, byte[] message)
 {
     packer.Pack((byte)Protocol.Ordered);
     packer.Pack(sendReciveSequenceNumber++);
     packer.Pack(message);
 }
Пример #7
0
        private UdpClient SendConnectionAck(IPEndPoint endpoint)
        {
            UdpClient client = new UdpClient(new IPEndPoint(IPAddress.Any, 0));
            client.Connect(endpoint);

            Packer packer = new Packer(4);
            packer.Pack(((IPEndPoint)client.Client.LocalEndPoint).Port);
            client.Send(packer.GetPackedData(), 4);
            return client;
        }