def backend_login(title, auth_info, login_data, settings=None):
	api.set_title(title.TITLE_ID_EUR, title.LATEST_VERSION)
	nex_token = api.get_nex_token(title.GAME_SERVER_ID)

	auth_info = None
	login_data = None
	if auth_info:
		auth_info = authentication.AuthenticationInfo(nex_token.token, title.SERVER_VERSION)
	if login_data:
		login_data = authentication.NintendoLoginData(nex_token.token)
	
	client = backend.BackEndClient(title.ACCESS_KEY, title.NEX_VERSION, settings)
	client.connect(nex_token.host, nex_token.port)
	client.login(
		nex_token.username, nex_token.password, auth_info
	)
	return client
Exemple #2
0
def backend_login(title, use_auth_info, use_login_data, settings=None):
    nnas.set_title(title.TITLE_ID_EUR, title.LATEST_VERSION)
    nex_token = nnas.get_nex_token(title.GAME_SERVER_ID)

    auth_info = None
    login_data = None
    if use_auth_info:
        auth_info = authentication.AuthenticationInfo()
        auth_info.token = nex_token.token
        auth_info.server_version = title.SERVER_VERSION
    if use_login_data:
        login_data = authentication.NintendoLoginData()
        login_data.token = nex_token.token

    client = backend.BackEndClient(settings)
    clietn.configure(title.ACCESS_KEY, title.NEX_VERSION)
    client.connect(nex_token.host, nex_token.port)
    client.login(nex_token.username, nex_token.password, auth_info, login_data)
    return client
Exemple #3
0
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(SMM2.TITLE_ID, SMM2.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(SMM2.ACCESS_KEY, SMM2.NEX_VERSION, SMM2.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            # Search for ninji courses
            store = datastore.DataStoreClientSMM2(client)

            param = datastore.SearchCoursesEventParam()
            courses = await store.search_courses_event(param)
            print("Found %i ninji courses.\n" % len(courses))

            # Print information about the oldest ninji course
            course = courses[-1]
            print("Name:", course.name)
            print("Description:", course.description)
            print("Start time:", course.upload_time)
            print("End time:", course.end_time)
            print()

            # Request ghost info
            param = datastore.GetEventCourseGhostParam()
            param.data_id = course.data_id
            param.time = 30000  # Request ghosts with a time around 30 seconds
            param.count = 1  # Only request a single ghost

            ghost = (await store.get_event_course_ghost(param))[0]

            # Request info about the ghost player
            param = datastore.GetUsersParam()
            param.pids = [ghost.pid]

            user = (await store.get_users(param)).users[0]
            print("Player:", user.name)
            print("Time: %i.%03i" % (ghost.time // 1000, ghost.time % 1000))
            print()

            # Download replay file
            header_info = await store.get_req_get_info_headers_info(
                ghost.replay_file.data_type)
            headers = {h.key: h.value for h in header_info.headers}
            response = await http.get(ghost.replay_file.url, headers=headers)
            response.raise_if_error()

            # Decompress and save replay file
            data = zlib.decompress(response.body)
            with open("replay.bin", "wb") as f:
                f.write(data)
Exemple #4
0
# Log in on baas server
baas = BAASClient()
baas.set_system_version(SYSTEM_VERSION)
baas.authenticate(device_token)
response = baas.login(BAAS_USER_ID, BAAS_PASSWORD, app_token)

user_id = int(response["user"]["id"], 16)
id_token = response["idToken"]

# Connect to game server
backend = backend.BackEndClient("switch.cfg")
backend.configure(SMM2.ACCESS_KEY, SMM2.NEX_VERSION, SMM2.CLIENT_VERSION)
backend.connect(HOST, PORT)

# Log in on game server
auth_info = authentication.AuthenticationInfo()
auth_info.token = id_token
auth_info.ngs_version = 4  #Switch
auth_info.token_type = 2
backend.login(str(user_id), auth_info=auth_info)

# Search for ninji courses
store = datastore.DataStoreClientSMM2(backend.secure_client)

param = datastore.SearchCoursesEventParam()
courses = store.search_courses_event(param)
print("Found %i ninji courses.\n" % len(courses))

# Print information about the most recent ninji course
course = courses[0]
print("Name:", course.name)
Exemple #5
0
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(ACNH.TITLE_ID, ACNH.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(ACNH.ACCESS_KEY, ACNH.NEX_VERSION, ACNH.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            mm = matchmaking.MatchmakeExtensionClient(client)

            param = matchmaking.MatchmakeSessionSearchCriteria()
            param.attribs = ["", "", "", "", "", ""]
            param.game_mode = "2"
            param.min_participants = "1"
            param.max_participants = "1,8"
            param.matchmake_system = "1"
            param.vacant_only = False
            param.exclude_locked = True
            param.exclude_non_host_pid = True
            param.selection_method = 0
            param.vacant_participants = 1
            param.exclude_user_password = True
            param.exclude_system_password = True
            param.refer_gid = 0
            param.codeword = CODE

            sessions = await mm.browse_matchmake_session_no_holder_no_result_range(
                param)
            if not sessions:
                print("\nNo island found for '%s'\n" % CODE)
            else:
                session = sessions[0]
                data = session.application_data
                print("\nFound island:")
                print("\tId:", session.id)
                print("\tActive players:", session.participation_count)
                print("\tIsland name:",
                      data[12:32].decode("utf16").rstrip("\0"))
                print("\tHost name:", data[40:60].decode("utf16").rstrip("\0"))
                print()
api.set_device(DEVICE_ID, SERIAL_NUMBER, SYSTEM_VERSION, REGION, COUNTRY)
api.set_title(MK8.TITLE_ID_EUR, MK8.LATEST_VERSION)
api.login(USERNAME, PASSWORD)

my_pid = api.get_pid(USERNAME)
friend_pid = api.get_pid(FRIEND_NAME)

mii_name = api.get_mii(my_pid).name

# Connect to game server
nex_token = api.get_nex_token(MK8.GAME_SERVER_ID)
backend = backend.BackEndClient(MK8.ACCESS_KEY, MK8.NEX_VERSION)
backend.connect(nex_token.host, nex_token.port)
backend.login(
    nex_token.username, nex_token.password,
    authentication.AuthenticationInfo(nex_token.token, MK8.SERVER_VERSION))

matchmake_ext = matchmaking.MatchmakeExtensionClient(backend)

# Find friend room
playing_sessions = matchmake_ext.get_playing_session([friend_pid])
if not playing_sessions:
    raise RuntimeError("Couldn't find friend room for %s" % FRIEND_NAME)

gathering = playing_sessions[0].gathering

# Request session key (for p2p)
session_key = matchmake_ext.join_matchmake_session(gathering.id,
                                                   "This is NintendoClients")

# Request station urls of session host
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(GBG.TITLE_ID, GBG.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(GBG.ACCESS_KEY, GBG.NEX_VERSION, GBG.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            store = datastore.DataStoreClient(client)

            # Request meta data
            param = datastore.DataStoreGetMetaParam()
            param.data_id = code_to_data_id(GAME_CODE)

            meta = await store.get_meta(param)
            print("Data id:", meta.data_id)
            print("Owner id:", meta.owner_id)
            print("Uploaded at:", meta.create_time)
            print("Expires at:", meta.expire_time)

            # Download game file
            result = await store.get_object_infos([meta.data_id])
            result.results[0].raise_if_error()

            info = result.infos[0]
            url = "https://" + info.url
            headers = {h.key: h.value for h in info.headers}
            response = await http.get(url, headers=headers)
            response.raise_if_error()
            with open("game.bin", "wb") as f:
                f.write(response.body)
async def main():
    keys = KeySet.load(PATH_KEYS)
    info = ProdInfo(keys, PATH_PRODINFO)

    with open(PATH_TICKET, "rb") as f:
        ticket = f.read()

    cert = info.get_tls_cert()
    pkey = info.get_tls_key()

    dauth = DAuthClient(keys)
    dauth.set_certificate(cert, pkey)
    dauth.set_system_version(SYSTEM_VERSION)
    response = await dauth.device_token(dauth.BAAS)
    device_token = response["device_auth_token"]

    aauth = AAuthClient()
    aauth.set_system_version(SYSTEM_VERSION)
    response = await aauth.auth_digital(SMM2.TITLE_ID, SMM2.LATEST_VERSION,
                                        device_token, ticket)
    app_token = response["application_auth_token"]

    baas = BAASClient()
    baas.set_system_version(SYSTEM_VERSION)

    response = await baas.authenticate(device_token)
    access_token = response["accessToken"]

    response = await baas.login(BAAS_USER_ID, BAAS_PASSWORD, access_token,
                                app_token)
    user_id = int(response["user"]["id"], 16)
    id_token = response["idToken"]

    auth_info = authentication.AuthenticationInfo()
    auth_info.token = id_token
    auth_info.ngs_version = 4  #Switch
    auth_info.token_type = 2

    s = settings.load("switch")
    s.configure(SMM2.ACCESS_KEY, SMM2.NEX_VERSION, SMM2.CLIENT_VERSION)
    async with backend.connect(s, HOST, PORT) as be:
        async with be.login(str(user_id), auth_info=auth_info) as client:
            store = datastore.DataStoreClientSMM2(client)

            param = datastore.GetUserOrCourseParam()
            param.code = COURSE_ID
            param.course_option = datastore.CourseOption.ALL

            response = await store.get_user_or_course(param)
            course = response.course

            # Print information about the course
            print("Level info:")
            print("\tName:", course.name)
            print("\tDescription:", course.description)
            print("\tUploaded at:", course.upload_time)
            print("\tGame:", GameStyles[course.game_style])
            print("\tTheme:", CourseThemes[course.course_theme])
            print("\tDifficulty:", Difficulties[course.difficulty])
            print("\tFirst tag:", TagNames[course.tag1])
            print("\tSecond tag:", TagNames[course.tag2])
            print("\tWorld record:",
                  format_time(course.time_stats.world_record))
            print("\tNumber of comments:", course.comment_stats[0])

            # Request information about its uploader
            param = datastore.GetUsersParam()
            param.pids = [course.owner_id]

            response = await store.get_users(param)
            user = response.users[0]
            print("Uploader:")
            print("\tCode:", user.code)
            print("\tName:", user.name)
            print("\tCountry:", user.country)
            print("\tLast active:", user.last_active)

            # Download thumbnails
            await download_thumbnail(store, course.one_screen_thumbnail,
                                     "thumbnail_onescreen.jpg")
            await download_thumbnail(store, course.entire_thumbnail,
                                     "thumbnail_entire.jpg")

            # Download level file
            param = datastore.DataStorePrepareGetParam()
            param.data_id = course.data_id

            req_info = await store.prepare_get_object(param)
            response = await http.get(req_info.url)
            response.raise_if_error()
            with open("level.bin", "wb") as f:
                f.write(response.body)
Exemple #9
0
from nintendo import account

PRINCIPAL_ID = "..." #PrincipalID
NEX_PASSWORD = "******" #Nex Password
NASC_REQUEST = "..." #Full NASC request for login; alternatively can login using NNID(?)

nex_account_details = nasc.login(NASC_REQUEST)

backend = backend.BackEndClient(
	'd6f08b40', # ACNL Nex Access Key
	31017, # Nex Version
	# backend.Settings("dream.cfg")
)
backend.connect(nex_account_details['host'], nex_account_details['port'])

login_info = authentication.AuthenticationInfo()
login_info.token = nex_account_details['token']
login_info.ngs_version = 3
login_info.token_type = 0
login_info.server_version = 2006

backend.login(PRINCIPAL_ID, NEX_PASSWORD, auth_info=login_info)

store = datastore.DataStoreClient(backend.secure_client)

get_param = datastore.DataStorePrepareGetParam()
get_param.data_id = 1206006	#This is dream Address 5D00-0012-66F6; 00001266F6 converted to decimal is 1206006; 5D is just a client side checksum(?) and not needed for downloads
get_param.lock_id = 0
get_param.persistence_target.owner_id = 0
get_param.persistence_target.persistence_id = 65535
get_param.access_password = 0