Example #1
0
    def read_delta_entity(self, frm, num):
        ## Check for server order to remove a baseline
        if huffman.readbits(1) == 1:
            # Don't know how we should handle this, it does mean no
            # new data; skipping for now
            return
        ## Check for 'no delta' flag
        if huffman.readbits(1) == 0:
            ## No changes, we should make 'from' a copy of
            ## 'to'... skipping for now
            return

        last_field = huffman.readbyte()
        entity = EntityState()
        netf = EntityStateNETF(entity)

        for i in range(0, last_field):
            if huffman.readbits(1) :
                if not netf.bits[i] :
                    if huffman.readbits(1) != 0:
                        if huffman.readbits(1) == 0:
                            netf.fields[i] = huffman.readbits(FLOAT_INT_BITS)
                        else :
                            netf.fields[i] = huffman.readfloat()
                else:
                    if huffman.readbits(1) != 0:
                        netf.fields[i] = huffman.readbits(netf.bits[i])

        netf.update()
        return entity
Example #2
0
 def parse_gamestate(self):
     ack=huffman.readlong()
     while True:
         cmd = huffman.readbyte()
         if cmd == SVC_EOF:
             break
         elif cmd == SVC_CONFIGSTRING: 
             self.parse_configstring()
         elif cmd == SVC_BASELINE:
             self.parse_baseline()
     self.gamestate.clientNum = huffman.readlong()
     self.gamestate.checksumFeed = huffman.readlong()
     return self.gamestate
Example #3
0
    def parse_playerstate(self):
        last_field=huffman.readbyte()
        player=PlayerState()
        netf=PlayerStateNETF(player)

        playerStateFieldsNum  = len( netf.bits )

        if last_field > playerStateFieldsNum :
            return None

        for i in range( 0, last_field) :
            if huffman.readbits( 1 ) :
                if netf.bits[ i ] == 0 :
                    if huffman.readbits( 1 ) == 0 :
                        netf.fields[ i ] = huffman.readbits( FLOAT_INT_BITS ) - FLOAT_INT_BIAS
                    else :
                        netf.fields[ i ] = huffman.readfloat()
                else :
                    bits = netf.bits[ i ]
                    netf.fields[ i ] = huffman.readbits( bits )
        netf.update()

        if huffman.readbits( 1 ) :
            if huffman.readbits( 1 ) :
                c = huffman.readshort()
                for i in range( MAX_STATS ) :
                    if c & ( 1 << i ) :
                        player.stats[ i ] = huffman.readshort()

            if huffman.readbits( 1 ) :
                c = huffman.readshort()
                for i in range( MAX_PERSISTANT ) :
                    if c & ( 1 << i ) :
                        player.persistant[ i ] = huffman.readshort()

            if huffman.readbits( 1 ) :
                c = huffman.readshort()
                for i in range( MAX_WEAPONS ) :
                    if c & ( 1 << i ) :
                        player.ammo[ i ] = huffman.readshort()

            if huffman.readbits( 1 ) :
                c = huffman.readshort()
                for i in range( MAX_POWERUPS ) :
                    if c & ( 1 << i ) :
                        player.powerups[ i ] = huffman.readlong()

        return player
Example #4
0
 def __iter__(self):
     while True:
         seq=huffman.readrawlong()
         length=huffman.readrawlong()
         if seq == -1 or length == -1:
             break
         huffman.fill(length)
         ack = huffman.readlong()
         cmd = huffman.readbyte()
         r = None
         if cmd == SVC_GAMESTATE: 
             r = self.parse_gamestate()
         elif cmd == SVC_SERVERCOMMAND: 
             r = self.parse_servercommand()
         elif cmd == SVC_SNAPSHOT:
             r = self.parse_snapshot()
             if len(self.snapshots) and r.serverTime == self.snapshots[-1].serverTime:
                 raise StopIteration
             self.snapshots.append(r)
         self.packets.append(r)
         if r: yield r