예제 #1
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);

                    //
                    if (disposed)
                    {
                        return;
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        public void Tick()
        {
            if (!IsReadyForNextFrame)
            {
                throw new InvalidOperationException();
            }

            Connection.Send(NetFrameNumber + FramesAhead, localOrders.Select(o => o.Serialize()).ToList());
            localOrders.Clear();


            foreach (var order in frameData.OrdersForFrame(World, NetFrameNumber))
            {
                UnitOrders.ProcessOrder(this, World, order.Client, order.Order);
            }

            Connection.SendSync(NetFrameNumber, OrderIO.SerializeSync(World.SyncHash()));
            NetFrameNumber++;
        }