AddFrameOrders() публичный Метод

public AddFrameOrders ( int clientId, int frame, byte orders ) : void
clientId int
frame int
orders byte
Результат void
Пример #1
0
        public void TickImmediate()
        {
            if (localImmediateOrders.Count != 0 && GameSaveLastFrame < NetFrameNumber + FramesAhead)
            {
                Connection.SendImmediate(localImmediateOrders.Select(o => o.Serialize()));
            }
            localImmediateOrders.Clear();

            var immediatePackets = new List <(int ClientId, byte[] Packet)>();

            Connection.Receive(
                (clientId, packet) =>
            {
                var frame = BitConverter.ToInt32(packet, 0);
                if (packet.Length == 5 && packet[4] == (byte)OrderType.Disconnect)
                {
                    frameData.ClientQuit(clientId, frame);
                }
                else if (packet.Length > 4 && packet[4] == (byte)OrderType.SyncHash)
                {
                    if (packet.Length != 4 + Order.SyncHashOrderLength)
                    {
                        Log.Write("debug", "Dropped sync order with length {0}. Expected length {1}.".F(packet.Length, 4 + Order.SyncHashOrderLength));
                        return;
                    }

                    CheckSync(packet);
                }
                else if (frame == 0)
                {
                    immediatePackets.Add((clientId, packet));
                }
                else
                {
                    frameData.AddFrameOrders(clientId, frame, packet);
                }
            });

            foreach (var p in immediatePackets)
            {
                foreach (var o in p.Packet.ToOrderList(World))
                {
                    UnitOrders.ProcessOrder(this, World, p.ClientId, o);

                    // A mod switch or other event has pulled the ground from beneath us
                    if (disposed)
                    {
                        return;
                    }
                }
            }
        }
Пример #2
0
        public void TickImmediate()
        {
            var immediateOrders = localOrders.Where(o => o.IsImmediate).ToList();

            if (immediateOrders.Count != 0)
            {
                Connection.SendImmediate(immediateOrders.Select(o => o.Serialize()).ToList());
            }
            localOrders.RemoveAll(o => o.IsImmediate);

            var immediatePackets = new List <Pair <int, byte[]> >();

            Connection.Receive(
                (clientId, packet) =>
            {
                var frame = BitConverter.ToInt32(packet, 0);
                if (packet.Length == 5 && packet[4] == 0xBF)
                {
                    frameData.ClientQuit(clientId, frame);
                }
                else if (packet.Length >= 5 && packet[4] == 0x65)
                {
                    CheckSync(packet);
                }
                else if (frame == 0)
                {
                    immediatePackets.Add(Pair.New(clientId, packet));
                }
                else
                {
                    frameData.AddFrameOrders(clientId, frame, packet);
                }
            });

            foreach (var p in immediatePackets)
            {
                foreach (var o in p.Second.ToOrderList(World))
                {
                    UnitOrders.ProcessOrder(this, World, p.First, o);

                    // A mod switch or other event has pulled the ground from beneath us
                    if (disposed)
                    {
                        return;
                    }
                }
            }
        }
Пример #3
0
        public void TickImmediate()
        {
            if (localImmediateOrders.Count != 0 && GameSaveLastFrame < NetFrameNumber + FramesAhead)
            {
                Connection.SendImmediate(localImmediateOrders.Select(o => o.Serialize()));
            }
            localImmediateOrders.Clear();

            var immediatePackets = new List <Pair <int, byte[]> >();

            Connection.Receive(
                (clientId, packet) =>
            {
                var frame = BitConverter.ToInt32(packet, 0);
                if (packet.Length == 5 && packet[4] == (byte)OrderType.Disconnect)
                {
                    frameData.ClientQuit(clientId, frame);
                }
                else if (packet.Length >= 5 && packet[4] == (byte)OrderType.SyncHash)
                {
                    CheckSync(packet);
                }
                else if (frame == 0)
                {
                    immediatePackets.Add(Pair.New(clientId, packet));
                }
                else
                {
                    frameData.AddFrameOrders(clientId, frame, packet);
                }
            });

            foreach (var p in immediatePackets)
            {
                foreach (var o in p.Second.ToOrderList(World))
                {
                    UnitOrders.ProcessOrder(this, World, p.First, o);

                    // A mod switch or other event has pulled the ground from beneath us
                    if (disposed)
                    {
                        return;
                    }
                }
            }
        }
Пример #4
0
 void ReceiveAllOrdersAndCheckSync()
 {
     Connection.Receive(
         (clientId, packet) =>
     {
         var frame = BitConverter.ToInt32(packet, 0);
         if (packet.Length == 5 && packet[4] == (byte)OrderType.Disconnect)
         {
             frameData.ClientQuit(clientId, frame);
         }
         else if (packet.Length >= 5 && packet[4] == (byte)OrderType.SyncHash)
         {
             CheckSync(packet);
         }
         else if (frame == 0)
         {
             receivedImmediateOrders.Add(Pair.New(clientId, packet));
         }
         else
         {
             frameData.AddFrameOrders(clientId, frame, packet);
         }
     });
 }