forked from kinnay/NintendoClients
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_createroom.py
101 lines (80 loc) · 3.01 KB
/
example_createroom.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
from nintendo.nex import backend, authentication, friends, matchmaking, common
from nintendo.account import AccountAPI
from nintendo.games import MK8, Friends
import struct
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
#This function logs in on a game server
def backend_login(title, use_auth_info, use_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 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
api = AccountAPI()
api.set_device(DEVICE_ID, SERIAL_NUMBER, SYSTEM_VERSION, REGION, COUNTRY)
api.login(USERNAME, PASSWORD)
#Connect to both the Mario Kart 8 server and the Wii U friends server
friends_backend = backend_login(
Friends, False, True, "friends.cfg"
)
game_backend = backend_login(MK8, True, False)
pid = game_backend.get_pid()
friends_client = friends.FriendsClient(friends_backend.secure_client)
matchmaker = matchmaking.MatchmakeExtensionClient(game_backend.secure_client)
#Create a matchmake session
matchmake_session = matchmaking.MatchmakeSession()
matchmake_session.player_min = 2
matchmake_session.player_max = 12
matchmake_session.participation_policy = 98
matchmake_session.game_mode = 3
matchmake_session.attribs[4] = 0x403 #DLCs enabled
matchmake_session.matchmake_system = matchmaking.MatchmakeSystem.FRIENDS
session_id = matchmaker.create_matchmake_session(
matchmake_session, "", 1
).gid
#Tell friends we're playing MK8 and have created a room
application_data = b"\0\0\x20\x03\0\0\0\0\0\0\0\0\x18" + struct.pack("<I", pid) + b"\0\0\0"
presence = friends.NintendoPresenceV2()
presence.flags = 0x1EE
presence.is_online = True
presence.game_key.title_id = MK8.TITLE_ID_EUR
presence.game_key.title_version = MK8.LATEST_VERSION
presence.message = "I'm a Python client"
presence.unk2 = 2
presence.unk3 = 2
presence.game_server_id = MK8.GAME_SERVER_ID
presence.unk4 = 3
presence.pid = pid
presence.gathering_id = session_id
presence.application_data = application_data
friends_client.update_presence(presence)
input("Press enter to disconnect and exit\n")
#Tell friends we've gone offline
presence = friends.NintendoPresenceV2()
friends_client.update_presence(presence)
#Disconnect from servers
game_backend.close()
friends_backend.close()