Esempio n. 1
0
 private void Update()
 {
     while (Client.IsConnected)
     {
         lock (SendBlockQueue)
         {
             IBlockEvent blockEvent;
             if (SendBlockQueue.TryDequeue(out blockEvent))
             {
                 var serializer = BitStream.Create();
                 blockEvent.Serialize(serializer);
                 var block         = serializer.GetRawBuffer();
                 var newBlockEvent = new DataBlockEvent((uint)block.Length, (uint)blockEvent.BlockEventId); //first we send info about a new block
                 Client.SendEvent(newBlockEvent);                                                           //this doesnt send yet, it queues the event
                 foreach (var chunk in block.GetChunks(63))
                 {
                     var sendBlockEvent = new DataBlockEvent(chunk, (uint)chunk.Length);
                     Client.SendEvent(sendBlockEvent); //queue the chunks
                 }
                 Client.Send();                        //send the block data
             }
         }
         Thread.Sleep(500);
     }
 }
        public IGameEvent ReadGameEvent(IBitStream stream, bool useOld = false)
        {
            uint eventId = 0;
            int  v3      = 127;//adjust value depending on game, 127 is for bf2 and bf2142
            int  v4      = 0;

            do
            {
                ++v4;
            }while (v3 > (1 << v4) - 1);//if the event amount defined above is 127 then the result will be 7, meaning we read 7 bits and those 7 bits are the event id
            eventId = stream.ReadBits((uint)v4);
            IGameEvent eventInstance;

            if (!useOld)
            {
                eventInstance = Config.EventRegistry.Trigger(eventId, stream);//dont use in development
            }
            else
            #region old
            {
                if (eventId == 1)
                {
                    eventInstance = new ChallengeEvent().DeSerialize(stream);
                }
                else if (eventId == 2)
                {
                    eventInstance = new ChallengeResponseEvent().DeSerialize(stream);
                }
                else if (eventId == 3)
                {
                    eventInstance = new ConnectionTypeEvent().DeSerialize(stream);
                }
                else if (eventId == 4)
                {
                    eventInstance = new DataBlockEvent().DeSerialize(stream);
                }
                else if (eventId == 5)
                {
                    eventInstance = new CreatePlayerEvent().DeSerialize(stream);
                }
                else if (eventId == 6)
                {
                    eventInstance = new CreateObjectEvent().DeSerialize(stream);
                }
                else if (eventId == 8)
                {
                    eventInstance = new DestroyObjectEvent().DeSerialize(stream);
                }
                else if (eventId == 11)
                {
                    eventInstance = new PostRemoteEvent().DeSerialize(stream);
                }
                else if (eventId == 16)
                {
                    eventInstance = new StringBlockEvent().DeSerialize(stream);
                }
                else if (eventId == 31)
                {
                    eventInstance = new CreateKitEvent().DeSerialize(stream);
                }
                else if (eventId == 35) //voip event
                {
                    stream.ReadBits(9); //just read so we can skip
                    eventInstance = null;
                }
                else if (eventId == 39)
                {
                    eventInstance = new VoteEvent().DeSerialize(stream);
                }
                else if (eventId == 42)
                {
                    eventInstance = new UnlockEvent().DeSerialize(stream);
                }
                else if (eventId == 46)
                {
                    eventInstance = new ContentCheckEvent().DeSerialize(stream);
                }
                else if (eventId == 50)
                {
                    eventInstance = null;
                }
                else if (eventId == 54)    //voip event, we dont care
                {
                    stream.ReadBits(0x10); //just read so we can skip
                    eventInstance = null;
                }
                else if (eventId == 56)
                {
                    eventInstance = new BeginRoundEvent().DeSerialize(stream);
                }
                else if (eventId == 57)
                {
                    eventInstance = new CreateSpawnGroupEvent().DeSerialize(stream);
                }
                else
                {
                    eventInstance = null;
                }
            }
            #endregion
            return(eventInstance);
        }