ibm-dev-incubator / demoparser

Apache License 2.0
34 stars 10 forks source link

Few questions #6

Open T1MOXA opened 5 years ago

T1MOXA commented 5 years ago

Can I find out the nickname and steam id of the one who recorded the demo? How to know who's observing who ?

P.S. Sorry for my English ))

rmoe commented 5 years ago

The name of the client who recorded the demo is in header.

>>> from demoparser.demofile import DemoFile
>>> data = open("/path/to/demo/1.dem", "rb").read()
>>> df = DemoFile(data)
>>> df.header.client_name.decode('utf-8')
'максим хуй сосиム'

Then you can get the steam ID from the entities.players list. Here's an example:

players = {}

def player_connect(event, msg):
    for idx, key in enumerate(event['event'].keys):
        if key.name == 'userid':
            user_id = msg.keys[idx].val_short
        if key.name == 'networkid':
            steam_id = msg.keys[idx].val_string
        if key.name == 'name':
            name = msg.keys[idx].val_string

        players[user_id] = {
            'name': name,
            'steam_id': steam_id,
            'user_id': user_id

if __name__ == "__main__":
    data = open(sys.argv[1], 'rb').read()
    d = DemoFile(data)
    d.add_callback('player_connect', player_connect)
    print(d.players)

In the case of a GOTV demo the steam ID will just be 'bot'.

T1MOXA commented 5 years ago

Is it possible to get data about for whom watching the player who recorded the demo ?

T1MOXA commented 5 years ago

There is also the entprop m_hObserverTarget? Maybe you can get it ?

T1MOXA commented 5 years ago

For some reason, this code does not work...

from demoparser.demofile import DemoFile

def player_connect(event, msg):
    print('connect')

if __name__ == "__main__":
    data = open("1.dem", 'rb').read()
    d = DemoFile(data)
    d.add_callback('player_connect', player_connect)
    d.parse()