baltica 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client/client.d.ts
CHANGED
package/dist/client/client.js
CHANGED
|
@@ -36,12 +36,15 @@ class Client extends utils_1.Emitter {
|
|
|
36
36
|
await this.authenticate();
|
|
37
37
|
await this.raknet.connect();
|
|
38
38
|
this.requestNetworkSettings();
|
|
39
|
-
return new Promise((resolve) => {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
40
|
this.on("SetLocalPlayerAsInitializedPacket", () => {
|
|
41
41
|
resolve();
|
|
42
42
|
this.emit("spawn");
|
|
43
43
|
this.emit("connect");
|
|
44
44
|
});
|
|
45
|
+
this.on("disconnect", (reason) => {
|
|
46
|
+
reject(new Error(`Disconnected during login: ${reason}`));
|
|
47
|
+
});
|
|
45
48
|
});
|
|
46
49
|
}
|
|
47
50
|
registerHandshakeHandlers() {
|
|
@@ -126,9 +129,19 @@ class Client extends utils_1.Emitter {
|
|
|
126
129
|
utils_2.Logger.error("PacketViolation:", JSON.stringify(pkt, null, 2));
|
|
127
130
|
});
|
|
128
131
|
this.on("DisconnectPacket", (pkt) => {
|
|
129
|
-
|
|
132
|
+
const reason = pkt?.message?.message ?? pkt?.message ?? "Unknown reason";
|
|
133
|
+
utils_2.Logger.info(`Disconnected by server: ${reason}`);
|
|
134
|
+
this.close();
|
|
135
|
+
this.emit("disconnect", String(reason));
|
|
130
136
|
});
|
|
131
137
|
}
|
|
138
|
+
close() {
|
|
139
|
+
try {
|
|
140
|
+
this.raknet.close();
|
|
141
|
+
}
|
|
142
|
+
catch { }
|
|
143
|
+
this.removeAllListeners();
|
|
144
|
+
}
|
|
132
145
|
async authenticate() {
|
|
133
146
|
if (this.options.offline) {
|
|
134
147
|
return this.authenticateOffline();
|
|
@@ -154,16 +167,26 @@ class Client extends utils_1.Emitter {
|
|
|
154
167
|
};
|
|
155
168
|
this.loginData = types_1.LoginData.prepare(this.options, tempProfile);
|
|
156
169
|
const { username, tokensFolder } = this.options;
|
|
170
|
+
const flow = this.options.email && this.options.password
|
|
171
|
+
? "password"
|
|
172
|
+
: this.options.xboxToken
|
|
173
|
+
? "xboxToken"
|
|
174
|
+
: "deviceCode";
|
|
157
175
|
const auth = new auth_1.Auth({
|
|
158
|
-
|
|
176
|
+
flow,
|
|
177
|
+
username: flow === "deviceCode" ? username : undefined,
|
|
159
178
|
cacheDir: tokensFolder,
|
|
160
179
|
clientPublicKey: this.loginData.clientX509,
|
|
180
|
+
email: this.options.email,
|
|
181
|
+
password: this.options.password,
|
|
182
|
+
xboxToken: this.options.xboxToken,
|
|
161
183
|
});
|
|
162
184
|
return new Promise((resolve, reject) => {
|
|
163
185
|
auth.on("deviceCode", (r) => {
|
|
164
186
|
utils_2.Logger.info(`Please login at ${r.verificationUri}?otc=${r.userCode}`);
|
|
165
187
|
});
|
|
166
188
|
auth.on("login", async (result) => {
|
|
189
|
+
utils_2.Logger.info(`Logged in as §a${result.profile.username}§r`);
|
|
167
190
|
this.applyAuthResult(result);
|
|
168
191
|
resolve();
|
|
169
192
|
});
|
|
@@ -172,22 +195,10 @@ class Client extends utils_1.Emitter {
|
|
|
172
195
|
});
|
|
173
196
|
}
|
|
174
197
|
async applyAuthResult(result) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
try {
|
|
180
|
-
const payload = JSON.parse(Buffer.from(jwt.split(".")[1], "base64").toString());
|
|
181
|
-
if (payload?.extraData?.displayName) {
|
|
182
|
-
gamertag = payload.extraData.displayName;
|
|
183
|
-
xuid = payload.extraData.XUID ?? "";
|
|
184
|
-
uuid = payload.extraData.identity ?? types_1.LoginData.nextUUID(gamertag);
|
|
185
|
-
break;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
catch { }
|
|
189
|
-
}
|
|
190
|
-
this.profile = { name: gamertag, uuid, xuid };
|
|
198
|
+
const gamertag = result.profile.username || this.options.username;
|
|
199
|
+
const xuid = result.profile.xuid || "";
|
|
200
|
+
const uuid = result.profile.uuid || types_1.LoginData.nextUUID(gamertag);
|
|
201
|
+
this.profile = { name: result.profile.username, uuid, xuid };
|
|
191
202
|
this.loginData.payload = (0, types_1.createDefaultPayload)(this.options, this.profile);
|
|
192
203
|
if (this.options.skinData) {
|
|
193
204
|
Object.assign(this.loginData.payload, this.options.skinData);
|
|
@@ -27,6 +27,12 @@ export type ClientOptions = {
|
|
|
27
27
|
loginOptions: LoginOptions;
|
|
28
28
|
skinData?: Partial<SkinData>;
|
|
29
29
|
skinFile?: string;
|
|
30
|
+
/** Email for password auth flow */
|
|
31
|
+
email?: string;
|
|
32
|
+
/** Password for password auth flow */
|
|
33
|
+
password?: string;
|
|
34
|
+
/** XBL3.0 token for xbox token auth flow. Format: "XBL3.0 x={userHash};{token}" */
|
|
35
|
+
xboxToken?: string;
|
|
30
36
|
} & RaknetOptions;
|
|
31
37
|
export declare const defaultClientOptions: {
|
|
32
38
|
username: string;
|
package/dist/server/server.js
CHANGED