forked from kinnay/NintendoClients
-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_friend_notifications.py
76 lines (58 loc) · 2.38 KB
/
example_friend_notifications.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from nintendo.nex import backend, authentication, notification
from nintendo.games import Friends
from nintendo import account
import logging
logging.basicConfig(level=logging.INFO)
#Device id can be retrieved with a call to MCP_GetDeviceId on the Wii U
#Serial number can be found on the back of the Wii U
DEVICE_ID = 12345678
SERIAL_NUMBER = "..."
SYSTEM_VERSION = 0x220
REGION = 4 #EUR
COUNTRY = "NL"
USERNAME = "..." #Nintendo network id
PASSWORD = "..." #Nintendo network password
class NotificationServer(notification.NintendoNotificationServer):
def __init__(self):
super().__init__()
self.name_cache = {}
def process_nintendo_notification_event(self, context, event):
pid = event.pid
if pid not in self.name_cache:
self.name_cache[pid] = api.get_nnid(pid)
name = self.name_cache[pid]
if event.type == notification.NintendoNotificationType.LOGOUT:
print("%s is now offline" %name)
elif event.type == notification.NintendoNotificationType.UNFRIENDED:
print("%s removed you from his friend list" %name)
elif event.type == notification.NintendoNotificationType.STATUS_CHANGE:
print("%s changed his status message to: %s" %(name, event.data.text))
elif event.type == notification.NintendoNotificationType.PRESENCE_CHANGE:
presence = event.data
game = "[%016X v%i]" %(presence.game_key.title_id, presence.game_key.title_version)
message = presence.message
if message:
print("%s is playing %s (message: %s)" %(name, game, message))
else:
print("%s is playing %s" %(name, game))
else:
print("Unknown notification type %i (from %s)" %(event.type, name))
def process_presence_change_event(self, context, event):
self.process_nintendo_notification_event(context, event)
api = account.AccountAPI()
api.set_device(DEVICE_ID, SERIAL_NUMBER, SYSTEM_VERSION, REGION, COUNTRY)
api.set_title(Friends.TITLE_ID_EUR, Friends.LATEST_VERSION)
api.login(USERNAME, PASSWORD)
nex_token = api.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
)
backend.secure_client.register_server(NotificationServer())
input("Press enter to disconnect and exit\n")
backend.close()