示例#1
0
async def main():
    nas = nnas.NNASClient()
    nas.set_device(DEVICE_ID, SERIAL_NUMBER, SYSTEM_VERSION)
    nas.set_title(Friends.TITLE_ID_EUR, Friends.LATEST_VERSION)
    nas.set_locale(REGION, COUNTRY, LANGUAGE)

    access_token = await nas.login(USERNAME, PASSWORD)
    nex_token = await nas.get_nex_token(access_token.token,
                                        Friends.GAME_SERVER_ID)

    pid = await nas.get_pid(USERNAME)
    mii = await nas.get_mii(pid)

    s = settings.load("friends")
    s.configure(Friends.ACCESS_KEY, Friends.NEX_VERSION)
    async with backend.connect(s, nex_token.host, nex_token.port) as be:
        async with be.login(str(nex_token.pid), nex_token.password) as client:
            nna_info = friends.NNAInfo()
            nna_info.principal_info.pid = pid
            nna_info.principal_info.nnid = USERNAME
            nna_info.principal_info.mii.name = mii.name
            nna_info.principal_info.mii.data = mii.data

            #NintendoPresenceV2 tells the server about your online status, which
            #game you're currently playing, etc. This will be shown to your friends
            #in their friend list (unless you disabled this feature).
            presence = friends.NintendoPresenceV2()

            friends_client = friends.FriendsClientV2(client)
            response = await friends_client.update_and_get_all_information(
                nna_info, presence, BIRTHDAY)

            if response.comment.text:
                print("Your status message: %s (last changed on %s)" %
                      (response.comment.text, response.comment.changed))
            else:
                print("You don't have a status message")

            if response.friends:
                print("Friends:")
                for friend in response.friends:
                    principal_info = friend.nna_info.principal_info
                    print("\tNNID:", principal_info.nnid)
                    print("\tName:", principal_info.mii.name)

                    presence = friend.presence
                    print("\tOnline:", ["No", "Yes"][presence.is_online])
                    if presence.game_key.title_id:
                        print("\tPlaying: %016X (v%i)" %
                              (presence.game_key.title_id,
                               presence.game_key.title_version))

                    if friend.comment.text:
                        print("\tStatus: %s (last changed on %s)" %
                              (friend.comment.text, friend.comment.changed))

                    print("\tFriend since:", friend.befriended)
                    print("\tLast online:", friend.last_online)
                    print("\t" + "-" * 40)
                print()
            else:
                print("You don't have any friends")

            if response.sent_requests:
                print("Friend requests sent:")
                print_requests(response.sent_requests)
            else:
                print("You haven't sent any friend requests")

            if response.received_requests:
                print("Friend requests received:")
                print_requests(response.received_requests)
            else:
                print("You haven't received any friend requests")

            if response.blacklist:
                print("Blacklist:")
                for item in response.blacklist:
                    principal_info = item.principal_info
                    print("\tWho: %s (%s)" %
                          (principal_info.nnid, principal_info.mii.name))
                    if item.game_key.title_id:
                        print("\tGame: %016X (%i)" %
                              (item.game_key.title_id,
                               item.game_key.title_version))
                    print("\tSince:", item.since)
                    print("\t" + "-" * 40)
            else:
                print("You haven't blacklisted any users")
                                friends.FriendsTitle.NEX_VERSION,
                                backend.Settings("friends.cfg"))
backend.connect(nex_token.host, nex_token.port)
backend.login(nex_token.username, nex_token.password, None,
              authentication.NintendoLoginData(nex_token.token))

#Even though you're sending your username and pid to the server, you can't
#requests friend information of other people. You'll always get your own data
client = friends.FriendsClient(backend)
principal_preference, comment, friends, requests_sent, requests_received, \
  blacklist, unk1, notifications, unk2 = client.get_all_information(
    friends.NNAInfo(
        friends.PrincipalBasicInfo(
   pid, USERNAME, #Pid and nnid
   #If you change mii name or data here it will also be changed on Nintendo's servers
   friends.MiiV2(mii.name, 0, 0, mii.data, common.DateTime(0)),
   2
        ),
        0x5E, 0x0B
    ),
    #NintendoPresenceV2 tells the server about your online status, which
    #game you're currently playing, etc. This will be shown to your friends
    #in their friend list (unless you disabled this feature).
    friends.NintendoPresenceV2(
        0, 0, friends.GameKey(0, 0), 0, None, 0, 0, 0, 0, 0, 0, b"", 3, 3, 3
    ),
    #Enter your birthday here
    common.DateTime.make(31, 12, 2000, 0, 0, 0)
)

#Now print everything
示例#3
0
mii = nnas.get_mii(pid)

nex_token = nnas.get_nex_token(Friends.GAME_SERVER_ID)

backend = backend.BackEndClient("friends.cfg")
backend.configure(Friends.ACCESS_KEY, Friends.NEX_VERSION)
backend.connect(nex_token.host, nex_token.port)

login_data = authentication.NintendoLoginData()
login_data.token = nex_token.token
backend.login(
	nex_token.username, nex_token.password,
	None, login_data
)

nna_info = friends.NNAInfo()
nna_info.principal_info.pid = pid
nna_info.principal_info.nnid = USERNAME
nna_info.principal_info.mii.name = mii.name
nna_info.principal_info.mii.data = mii.data.build()

#NintendoPresenceV2 tells the server about your online status, which
#game you're currently playing, etc. This will be shown to your friends
#in their friend list (unless you disabled this feature).	
presence = friends.NintendoPresenceV2()

client = friends.FriendsClient(backend.secure_client)
response = client.get_all_information(
	nna_info, presence,
	#Enter your birthday here
	common.DateTime.make(15, 11, 1999, 0, 0, 0)