예제 #1
0
class LCU():

    connector = None

    def __init__(self):

        self.connector = Connector()
        self.run_window()

        @self.connector.ready
        async def connect(connection):
            print('LCU API is ready to be used.')
            summoner = await connection.request(
                'get', '/lol-summoner/v1/current-summoner')
            print(await summoner.json())

        @self.connector.ws.register('/lol-summoner/')
        async def eventlist(connection, event):
            print(f'lcu event {event.data} was fired.')

        @self.connector.close
        async def disconnect(connection):
            print('The client was closed')
            await self.connector.stop()

        self.connector.start()
예제 #2
0
        print(f'Chinese icon number {random_number} was set correctly.')
    else:
        print('Unknown problem, the icon was not set.')


# fired when LCU API is ready to be used
@connector.ready
async def connect(connection):
    print('LCU API is ready to be used.')

    # check if the user is already logged into his account
    summoner = await connection.request('get',
                                        '/lol-summoner/v1/current-summoner')
    if summoner.status != 200:
        print(
            'Please login into your account to change your icon and restart the script...'
        )
    else:
        print('Setting new icon...')
        await set_random_icon(connection)


# fired when League Client is closed (or disconnected from websocket)
@connector.close
async def disconnect(_):
    print('The client have been closed!')


# starts the connector
connector.start()
예제 #3
0
    else:
        print(colorama.Fore.RED + "[-] Oyun Kabul Edilemedi!" +
              colorama.Style.RESET_ALL)


@client.ready
async def on(cmd) -> None:
    check = await get_name(cmd)
    print(colorama.Style.BRIGHT + colorama.Fore.BLUE +
          "[+] Kabul Etmek İçin Oyun Bekleniyor..." + colorama.Style.RESET_ALL)
    while True:
        x = await readyCheck(cmd)
        if x is True:
            await accept(cmd)
        time.sleep(0.1)


if __name__ == "__main__":
    os.system("@echo off")
    os.system("cls")
    print(colorama.Fore.GREEN + f"""
     ____  _____           _____ _           ____          _       ____  ___  ____  
    |  _ \|___ / _ __  ___|_   _| |__   ___ / ___|___   __| | ___ / ___|/ _ \|  _ \ 
    | |_) | |_ \| '_ \|_  / | | | '_ \ / _ \ |   / _ \ / _` |/ _ \ |  _| | | | | | |
    |  _ < ___) | | | |/ /  | | | | | |  __/ |__| (_) | (_| |  __/ |_| | |_| | |_| |
    |_| \_\____/|_| |_/___| |_| |_| |_|\___|\____\___/ \__,_|\___|\____|\___/|____/

                    {colorama.Fore.CYAN + "GitHub: https://github.com/R3nzTheCodeGOD" + colorama.Style.RESET_ALL}
    """)
    client.start()
예제 #4
0
def working():
    work_loop = asyncio.new_event_loop()
    connector = Connector(loop=work_loop)

    # to make sure the page has been loaded before running a JS script
    page_loaded = asyncio.Event(loop=work_loop)
    window.web_view.page_loaded = page_loaded

    # fired when LCU API is ready to be used
    @connector.ready
    async def connect(connection):
        logger.info('LCU API is ready to be used.')
        window.status_bar.showMessage("Connected to the League client")

        # check whether session is in place
        resp = await connection.request('get', '/lol-champ-select/v1/session')
        await page_loaded.wait()
        if resp.status == 200:
            data = await resp.json()
            logger.info("session is already in place")
            logger.info(data)

            if not window.web_view.is_pick_now():
                window.go_to_pick_now()
                await page_loaded.wait()

            champselect.reset()
            updated, dict_updated = champselect.update(data)
            logger.info(champselect)
            if updated:
                window.call_update(champselect.__repr__(), dict_updated)
        else:
            logger.info("session is not in place")

    # fired when League Client is closed (or disconnected from websocket)
    @connector.close
    async def disconnect(_):
        logger.info('The client have been closed!')
        window.status_bar.showMessage("Waiting for a connection...")
        await connector.stop()

    # subscribe to '/lol-summoner/v1/session' endpoint
    @connector.ws.register('/lol-champ-select/v1/session', event_types=('CREATE', 'UPDATE', 'DELETE',))
    async def new_event(connection, event):
        if event.type == 'Create':
            logger.info("session created")
            logger.info(json.dumps(event.data))

            window.go_to_pick_now()
            champselect.reset()
            await page_loaded.wait()

        elif event.type == 'Update':
            if not window.web_view.is_pick_now():
                window.go_to_pick_now()
                champselect.reset()

            logger.info(json.dumps(event.data))
            updated, dict_updated = champselect.update(event.data)
            await page_loaded.wait()
            if updated:
                window.call_update(champselect.__repr__(), dict_updated)

        elif event.type == 'Delete':
            logger.info("session deleted")

    connector.start()
예제 #5
0
class LCU(QRunnable):
    def __init__(self):
        super(LCU, self).__init__()

        self.signals = LCUSignals()

        self.beenInChampSelect = False

        self.champSelectLock = asyncio.Lock()

        # self.rockPaperScissorsBot = False

        self.connector = Connector()
        self.connector.open(self.lcu_ready)
        self.connector.close(self.lcu_close)
        self.connector.ws.register('/lol-gameflow/v1/gameflow-phase',
                                   event_types=('UPDATE', ))(
                                       self.gameflowChanged)

        self.connector.ws.register('/lol-champ-select/v1/session',
                                   event_types=('UPDATE', ))(
                                       self.championSelectChanged)

    @pyqtSlot()
    def run(self):
        self.connector.start()

    async def lcu_ready(self, connection):
        summoner = await connection.request(
            'get',
            '/lol-platform-config/v1/namespaces/LoginDataPacket/platformId')

        if summoner.status == 200:
            region = await summoner.json()
            if region == 'EUN1':
                lolapi.set_default_region('EUNE')
            elif region == 'EUW1':
                lolapi.set_default_region('EUW')
            else:
                print('UNSUPPORTED REGION')
                return

            self.signals.result.emit((Messages.LCU_CONNECTED, ))

            phase = await connection.request(
                'get', '/lol-gameflow/v1/gameflow-phase')

            if phase.status == 200:
                event = type("", (), dict(data=await phase.json()))()
                await self.gameflowChanged(connection, event)

    async def lcu_close(self, _):
        self.signals.result.emit((Messages.LCU_DISCONNECTED, ))

    async def gameflowChanged(self, connection, event):
        print(f"gameflow status: {event.data}")

        if event.data == "ChampSelect":
            self.signals.result.emit((Messages.CHAMPSELECT_ENTERED, ))
        else:
            if self.beenInChampSelect:
                self.beenInChampSelect = False
                self.signals.result.emit(
                    (Messages.CHAMPSELECT_SAVE, self.championSelect))

        if event.data == "InProgress":
            self.signals.result.emit((Messages.GAME_STARTED, ))
        elif event.data == "None" or event.data == "Lobby":
            self.signals.result.emit((Messages.NONE, ))

    async def fetchSummoner(self, connection, summonerId):
        summoner = await connection.request(
            'get', '/lol-summoner/v1/summoners/{}'.format(summonerId))

        if summoner.status == 200:
            json = await summoner.json()
            return json['displayName'], json['puuid']

    async def championSelectChanged(self, connection, event):
        myTeam = event.data['myTeam']
        theirTeam = event.data['theirTeam']

        async with self.champSelectLock:
            updated = False

            if not self.beenInChampSelect:
                players = {}
                for player in myTeam + theirTeam:
                    name = ''
                    puuid = ''

                    if player['summonerId'] != 0:
                        name, puuid = await self.fetchSummoner(
                            connection, player['summonerId'])

                    players[player['cellId']] = Player(
                        name, puuid, player['team'],
                        player['assignedPosition'])

                me = await connection.request(
                    'get', '/lol-summoner/v1/current-summoner')
                if me.status == 200:
                    json = await me.json()

                    self.championSelect = ChampionSelect(
                        players, json['displayName'])
                    self.beenInChampSelect = True
                    updated = True

            actions = itertools.chain(*event.data['actions'])
            for action in actions:
                if action['type'] == 'ban' and action['completed']:
                    updated = self.championSelect.setPlayerBannedChampion(
                        action['actorCellId'], action['id'],
                        action['championId'])

            champId = 0
            for player in myTeam + theirTeam:
                if player['championPickIntent'] == 0:
                    champId = player['championId']
                else:
                    champId = player['championPickIntent']

                if champId != 0:
                    changed = await self.championSelect.setPlayerChampion(
                        player['cellId'], champId)

                    if not updated and changed:
                        updated = True

            if updated:
                self.signals.result.emit(
                    (Messages.CHAMPSELECT_UPDATED, self.championSelect))