Exemple #1
0
        public bool parse(Q3DemoMessage message)
        {
            clc.serverMessageSequence = message.sequence;
            Q3HuffmanReader reader = new Q3HuffmanReader(message.data);

            reader.readLong();

            while (!reader.isEOD())
            {
                var b = reader.readByte();
                switch (b)
                {
                case Q3_SVC.BAD:
                case Q3_SVC.NOP:
                    return(true);

                case Q3_SVC.EOF:
                    return(true);

                case Q3_SVC.SERVERCOMMAND:
                    this.parseServerCommand(reader);
                    break;

                case Q3_SVC.GAMESTATE:
                    this.parseGameState(reader);
                    break;

                case Q3_SVC.SNAPSHOT:
                    this.parseSnapshot(reader);
                    // snapshots couldn't be mixed with game-state command in a single message
                    break;

                default:
                    // unknown command / corrupted stream
                    return(true);
                }
            }
            return(true);
        }
Exemple #2
0
        private void parsePacketEntities(Q3HuffmanReader decoder, CLSnapshot oldframe, CLSnapshot newframe)
        {
            newframe.parseEntitiesNum = client.parseEntitiesNum;
            newframe.numEntities      = 0;
            int         newnum   = 0;
            int         oldindex = 0;
            int         oldnum   = 0;
            EntityState oldstate = null;

            if (oldframe == null)
            {
                oldnum = 99999;
            }
            else
            {
                if (oldindex >= oldframe.numEntities)
                {
                    oldnum = 99999;
                }
                else
                {
                    oldstate = Ext2 <int, EntityState> .GetOrCreate(client.parseEntities, (oldframe.parseEntitiesNum + oldindex)& (Q3Const.MAX_PARSE_ENTITIES - 1));

                    oldnum = oldstate.number;
                }
            }

            while (true)
            {
                newnum = (int)decoder.readNumBits(Q3Const.GENTITYNUM_BITS);

                if (newnum == (Q3Const.MAX_GENTITIES - 1))
                {
                    break;
                }

                if (decoder.isEOD())
                {
                    Q3Utils.PrintDebug(clc.errors, "ERR_DROP, CL_ParsePacketEntities: end of message");
                    return;
                }

                while (oldnum < newnum)
                {
                    // one or more entities from the old packet are unchanged
                    CL_DeltaEntity(decoder, newframe, oldnum, oldstate, true);

                    oldindex++;

                    if (oldindex >= oldframe.numEntities)
                    {
                        oldnum = 99999;
                    }
                    else
                    {
                        oldstate = Ext2 <int, EntityState> .GetOrCreate(client.parseEntities,
                                                                        (oldframe.parseEntitiesNum + oldindex)& (Q3Const.MAX_PARSE_ENTITIES - 1));

                        oldnum = oldstate.number;
                    }
                }

                if (oldnum == newnum)
                {
                    // delta from previous state
                    CL_DeltaEntity(decoder, newframe, newnum, oldstate, false);

                    oldindex++;

                    if (oldindex >= oldframe.numEntities)
                    {
                        oldnum = 99999;
                    }
                    else
                    {
                        oldstate = Ext2 <int, EntityState> .GetOrCreate(client.parseEntities,
                                                                        (oldframe.parseEntitiesNum + oldindex)& (Q3Const.MAX_PARSE_ENTITIES - 1));

                        oldnum = oldstate.number;
                    }
                    continue;
                }

                if (oldnum > newnum)
                {
                    // delta from baseline
                    EntityState es = Ext2 <int, EntityState> .GetOrCreate(client.entityBaselines, newnum);

                    CL_DeltaEntity(decoder, newframe, newnum, es, false);
                    continue;
                }
            }

            // any remaining entities in the old frame are copied over
            while (oldnum != 99999)
            {
                // one or more entities from the old packet are unchanged
                CL_DeltaEntity(decoder, newframe, oldnum, oldstate, true);

                oldindex++;

                if (oldindex >= oldframe.numEntities)
                {
                    oldnum = 99999;
                }
                else
                {
                    oldstate = Ext2 <int, EntityState> .GetOrCreate(client.parseEntities,
                                                                    (oldframe.parseEntitiesNum + oldindex)& (Q3Const.MAX_PARSE_ENTITIES - 1));

                    oldnum = oldstate.number;
                }
            }
        }