示例#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
    def __init__(self, parent, threadId, name, counter):
        threading.Thread.__init__(self)

        self.connection = False
        self.parent = parent
        self.threadId = threadId
        self.name = name
        self.counter = counter
        self.running = True
        self.connector = Connector()
示例#3
0
    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)
示例#4
0
from random import randint

from lcu_driver import Connector

connector = Connector()


async def set_random_icon(connection):
    # random number of a chinese icon
    random_number = randint(50, 78)

    # make the request to set the icon
    icon = await connection.request('put',
                                    '/lol-summoner/v1/current-summoner/icon',
                                    data={'profileIconId': random_number})

    # if HTTP status code is 201 the icon was applied successfully
    if icon.status == 201:
        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')
from lcu_driver import Connector
import colorama
import time
import os

client = Connector()
colorama.init()


async def get_name(cmd) -> bool:
    "Loldeki bağlantı kurulan hesabın adını gönderir."
    summoner = await cmd.request("GET", "/lol-summoner/v1/current-summoner")
    if summoner.status == 200:
        data: dict = await summoner.json()
        print(
            f"{colorama.Style.BRIGHT + colorama.Fore.GREEN + data['displayName'] + colorama.Style.RESET_ALL} ismiyle giriş yapıldı!"
        )
        return True

    else:
        print(colorama.Style.BRIGHT + colorama.Fore.RED +
              "[HATA] Lol Arkada Açık Değil" + colorama.Style.RESET_ALL)
        return False


async def readyCheck(cmd) -> bool:
    "return queue accept"
    req = await cmd.request("GET", "/lol-matchmaking/v1/ready-check")
    if req.status != 200:
        return False
    data: dict = await req.json()
示例#6
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()
示例#7
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))
示例#8
0
from lcu_driver import Connector
import os
import time
import json

connector = Connector()
CONFIG_PATH = os.path.join(
    os.path.join(os.environ.get("appdata"), "IconAutoChanger"), "config.json")


def parse_config():
    return [
        request
        for request in json.loads(open(CONFIG_PATH, "r").read())["requests"]
    ]


def check_config():
    if os.path.isfile(CONFIG_PATH):
        return True


async def send_request(connection, endpoint, method, body):
    response = await connection.request(
        method,
        endpoint,
        data=body,
    )
    if response.status == 201:
        print(
            f"Custom request sent:\nEndpoint: {endpoint}\nMethod: {method}\nBody: {body}\n"