ValvePython / dota2

🐸 Python package for interacting with Dota 2 Game Coordinator
http://dota2.readthedocs.io
205 stars 32 forks source link

Event not triggering on party invite event #6

Closed m-bo-one closed 8 years ago

m-bo-one commented 8 years ago

Hello! On your examples I made functionality for parties but have some troubles for event triggering. (Part of party code. Need for explanation)

# dota2/features/party.py
from dota2.enums import EGCBaseMsg, EDOTAGCMsg

class Party(object):

    def __init__(self):
        super(Party, self).__init__()
        self.party = None

    ....

    def invite_to_party(self, steam_id=None):
        """
        Invites a player to a party. This will create a new party
        if you aren't in one.

        :param steam_id: steam_id
        :return: job event id
        :rtype: str

        Response event: ``invite_to_party``

        :param steam_id: steam_id for response
        :type steam_id: :class:`int`

        :param match: `CMsgInviteToParty <https://github.com/ValvePython/dota2/blob/master/protobufs/base_gcmessages.proto#L80>`_ proto message
        """
        if not steam_id:
            if self.verbose_debug:
                self._LOG.debug("Steam ID required to create a party invite.")
            return False

        if self.verbose_debug:
            self._LOG.debug("Inviting %s to a party." % steam_id)

        jobid = self.send_job(EGCBaseMsg.EMsgGCInviteToParty, {
            "steam_id": steam_id,
            "as_coach": True
        })

        def wrap_invite_to_party(message):
            self.emit('invite_to_party', message)

        self.once(jobid, wrap_invite_to_party)

        return jobid

    ....

This code works, It send job to GC dota 2 and I get notification: screenshot from 2016-09-06 17-44-35 But I can't handle it, when player accept/decline party by this code:

@dota2.on('ready')
def do_some_in_dota():
    steamId64 = 76561198022766961
    jobid = dota2.invite_to_party(steamId64)
    resp = dota2.wait_event(jobid, timeout=10)

    if resp:
        import ipdb; ipdb.set_trace()

Because resp is always None( And don't understant why, same by logic code but in another style also did not trigger:

@dota2.on('ready')
def do_some_in_dota():
    steamId64 = 76561198022766961
    dota2.invite_to_party(steamId64)

@dota2.on('invite_to_party')
def on_party_invited():
    import ipdb; ipdb.set_trace()

Full code of Party you can find here https://github.com/DeV1doR/dota2/tree/party (detailed https://github.com/DeV1doR/dota2/blob/party/dota2/features/party.py) and added in to FeatureBase.

For quick problem reproducing I paste gist with loader script: https://gist.github.com/DeV1doR/4e9e1ee414ca247cd15e3d0dcc3787f6

rossengeorgiev commented 8 years ago

Because resp is always None

The timeout expires after 10s and the method returns None. http://steam.readthedocs.io/en/latest/api/steam.client.html#steam.client.SteamClient.wait_event

Are you sure EMsgGCInviteToParty is a job? A debug log would be nice to see what happens around the time the invite is sent.

m-bo-one commented 8 years ago

log - https://gist.github.com/DeV1doR/62d235c6b68fc7a60cf252e7b7b7a8c1 I think InviteToParty must have the response handle, but can't find when it must be occur. I found in node-dota2 this: https://github.com/DeV1doR/node-dota2/blob/staging/handlers/parties.js#L5, and implement same here: https://github.com/DeV1doR/dota2/blob/party/dota2/features/party.py#L10, but when it must emit, have not find yet.

The timeout expires after 10s and the method returns None. http://steam.readthedocs.io/en/latest/api/steam.client.html#steam.client.SteamClient.wait_event

Yes I understand this, and it's return None when I already clicked on accept or decline.

UPD: I think I need to try something like:

    self.on(EGCBaseMsg.EMsgGCPartyInviteResponse,
        self.__handle_party_response)

    def __handle_party_response(self, message):
        self.emit('response_party_invite', message)

because in this message must be info about that user accepted or declined party.

m-bo-one commented 8 years ago

Tried code above, this event not triggered and did not find in logs. When I accept or decline party invite, only triggering 5453 proto - EMsg.ClientFromGC(

rossengeorgiev commented 8 years ago

@DeV1doR enable verbose_debug on the dota2client instance, rather than on the steam client.

This is probably the response, but you need verbose_debug to log the message contents.

Incoming: <EGCBaseMsg.EMsgGCInvitationCreated: 4502>

The actual party is a SO object, which gets updated when anything changes (e.g. someone leaving, etc). The cleanest and simplest way to approach implementing any functionality is to use NetHook and record what messages get sent when you are doing stuff in the real client.

m-bo-one commented 8 years ago

@rossengeorgiev , dota2 verbose_debug = True logs (with accept party) https://gist.github.com/DeV1doR/e4c758941fe282d3eb64986e4a7f9438

m-bo-one commented 8 years ago

@rossengeorgiev, thank you) I think I understand, CMsgInviteToParty triggering when Player invite bot to party and when Player accept/decline in used CMsgInvitationCreated (need to test, just thoughts)

m-bo-one commented 8 years ago

I was wrong, this

[2016-09-07 12:36:39,843] DEBUG Dota2Client: Incoming: <EGCBaseMsg.EMsgGCInvitationCreated: 4502>
msg: 4502
headerLength: 0
---------
group_id: 24716324451114646
steam_id: 76561198022766961
user_offline: false

just show invitation response after sending invite, it don't have data about if user accept or declined party( ok will try NetHook