def initaccount(session, sso_key):
    url = 'https://account.garena.com/api/account/init'
    headers = {
        'accept': '*/*',
        'cookie': f'sso_key={sso_key}',
        'referer': 'https://account.garena.com/',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'
    }
    try:
        response = session.get(url, headers=headers)
        response.raise_for_status()
        data = response.json()
        ac_session = response.cookies.get('ac_session')
        logging.info("Processing")
        return ac_session
    except requests.RequestException as e:
        logging.error(f"Processing failed: {e}")
        return None
def parse_account_details(data):
    user_info = data.get('user_info', {})
    binds = []
    if user_info.get('email'):
        binds.append('Email')
    if user_info.get('mobile_no'):
        binds.append('Phone')
    return {
        'username': user_info.get('username', 'N/A'),
        'email': user_info.get('email', 'N/A'),
        'mobile': user_info.get('mobile_no', 'N/A'),
        'country': user_info.get('acc_country', 'N/A'),
        'binds': binds,
        'status': 'Clean' if not binds else 'Binded'
    }
def get_fresh_cookie(session):
    cookies = session.cookies.get_dict()
    return '; '.join([f"{name}={value}" for name, value in cookies.items()])
def processaccount(session, account, password):
    datadome = get_datadome_cookie(session)
    if not datadome:
        return f"{account}: Datadome Failed"
    session.cookies.set('datadome', datadome)
    v1, v2, new_datadome = prelogin(session, account)
    if not v1 or not v2:
        return f"{account}: Invalid (Prelogin failed)"
    if new_datadome:
        session.cookies.set('datadome', new_datadome)
    sso_key = login(session, account, password, v1, v2)
    if not sso_key:
        return f"{account}: Invalid (Login failed)"
    session.cookies.set('sso_key', sso_key)
    ac_session = initaccount(session, sso_key)
    if not ac_session:
        return f"{account}: Invalid (Initialization failed)"
    session.cookies.set('ac_session', ac_session)
    account_init_url = 'https://account.garena.com/api/account/init'
    headers = {
        'accept': '*/*',
        'referer': 'https://account.garena.com/',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36'
    }
    try:
        response = session.get(account_init_url, headers=headers)
        response.raise_for_status()
        account_data = response.json()
        if 'error' in account_data:
            if account_data.get('error') == 'error_auth':
                return f"{account}: Invalid (Authentication error)"
        return account_data
    except Exception as e:
        return f"{account}: Error fetching account data: {e}"
def image_to_ascii(image, width=50):
    try:
        image = image.convert("L")
        aspect_ratio = image.height / image.width
        new_height = int(aspect_ratio * width)
        image = image.resize((width, new_height))
        pixels = image.getdata()
        ascii_str = ""
        for pixel in pixels:
            ascii_str += '@' if pixel < 128 else ' '  # You can customize this mapping