コード例 #1
0
ファイル: demo.py プロジェクト: Danmer/qldemo-python
    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
コード例 #2
0
ファイル: demo.py プロジェクト: Danmer/qldemo-python
 def parse_configstring(self, data=(None, None)):
     i, string = data
     if not i:
         i = huffman.readshort()
         string = huffman.readbigstring()
     dest=self.gamestate.configstrings
     fieldname=str(i)
     output=string
     if CS_STRING_MAP.get(i, None):
         dest=self.gamestate.config
         fieldname=CS_STRING_MAP.get(i)
     if string.startswith("\\"):
         output={}
         subfields = string.split('\\')
         if not fieldname in dest:
             dest[fieldname]={}
         for x in range(1, len(subfields)-1, 2):
             output[subfields[x]]=subfields[x+1]
     if i >= CS_PLAYERS and i < CS_PLAYERS+MAX_CLIENTS:
         clientNum = i-CS_PLAYERS
         fieldname=int(clientNum)
         subfields = string.split('\\')
         output = {}
         for x in range(0, len(subfields), 2):
             output[subfields[x]]=subfields[x+1]
         if output['t'] == TEAM_SPECTATOR:
             dest=self.gamestate.spectators
         else:
             dest=self.gamestate.players
     if i >= CS_SOUNDS and i < CS_SOUNDS+MAX_SOUNDS:
         dest=self.gamestate.config
         fieldname='sound'+str(i-CS_SOUNDS)
     if i >= CS_LOCATIONS and i < CS_LOCATIONS+MAX_LOCATIONS:
         dest=self.gamestate.config
         fieldname='location{:02d}'.format(i-CS_LOCATIONS)
     dest[fieldname]=output