Skip to content

Commit 0b36645

Browse files
committed
Fixing -203 error on CHECKIN
* Breaking changes in internal api. Require user id information to pass through Checkin server. It was optional before.
1 parent dd7ceab commit 0b36645

File tree

10 files changed

+22
-17
lines changed

10 files changed

+22
-17
lines changed

src/api/auth-api-client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface LoginData extends OAuthCredential {
2121
/**
2222
* User id
2323
*/
24-
userId: number | Long;
24+
userId: Long;
2525

2626
/**
2727
* Country iso

src/api/oauth-api-client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export class OAuthApiClient {
5959
result: {
6060
type: res['token_type'] as string,
6161
credential: {
62+
userId: credential.userId,
6263
deviceUUID: credential.deviceUUID,
6364
accessToken: res['access_token'] as string,
6465
refreshToken: res['refresh_token'] as string

src/api/struct/login.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export interface AccessDataStruct {
4242

4343
export function structToLoginData(struct: AccessDataStruct, deviceUUID: string): LoginData {
4444
return {
45-
userId: struct.userId,
45+
userId: Long.fromValue(struct.userId),
4646

4747
countryIso: struct.countryIso,
4848
countryCode: struct.countryCode,

src/hook/session-factory-hook.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) storycraft. Licensed under the MIT Licence.
55
*/
66

7+
import { Long } from 'bson';
78
import { SessionConfig } from '../config';
89
import { ConnectionSession, PacketResData, SessionFactory } from '../network/request-session';
910
import { DefaultReq, AsyncCommandResult, DefaultRes } from '../request';
@@ -36,8 +37,8 @@ export class HookedSessionFactory implements SessionFactory {
3637

3738
}
3839

39-
async connect(config: SessionConfig): AsyncCommandResult<ConnectionSession> {
40-
const sessionRes = await this._factory.connect(config);
40+
async connect(userId: Long, config: SessionConfig): AsyncCommandResult<ConnectionSession> {
41+
const sessionRes = await this._factory.connect(userId, config);
4142
if (!sessionRes.success) return sessionRes;
4243

4344
return { status: sessionRes.status, success: true, result: new InspectSession(sessionRes.result, this._hook) };

src/network/request-session.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { BsonDataCodec } from '../packet';
1010
import { PacketAssembler } from './packet-assembler';
1111
import { BiStream } from '../stream';
1212
import { LocoPacketCodec } from './loco-packet-codec';
13+
import { Long } from 'bson';
1314

1415
export interface CommandSession {
1516

@@ -51,7 +52,7 @@ export interface PacketResData {
5152
*/
5253
export interface SessionFactory {
5354

54-
connect(config: SessionConfig): AsyncCommandResult<ConnectionSession>;
55+
connect(userId: Long, config: SessionConfig): AsyncCommandResult<ConnectionSession>;
5556

5657
}
5758

src/network/util/loco-entrance.ts

+2-5
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export async function getBookingData(stream: BiStream, config: BookingConfig): A
4646
export async function getCheckinData(
4747
stream: BiStream,
4848
config: CheckinConfig,
49-
userId?: Long,
49+
userId: Long,
5050
): AsyncCommandResult<CheckinRes> {
5151
const checkinSession = new LocoSession(stream);
5252

@@ -58,12 +58,9 @@ export async function getCheckinData(
5858
'ntype': config.netType,
5959
'useSub': config.subDevice,
6060
'os': config.agent,
61+
userId
6162
};
6263

63-
if (userId) {
64-
req['userId'] = userId;
65-
}
66-
6764
const res = await checkinSession.request<CheckinRes>('CHECKIN', req);
6865
checkinSession.stream.close();
6966

src/oauth/index.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
* Copyright (c) storycraft. Licensed under the MIT Licence.
55
*/
66

7+
import { Long } from "bson";
8+
79
export interface OAuthCredential {
810

11+
readonly userId: Long;
12+
913
readonly deviceUUID: string;
1014

1115
readonly accessToken: string;

src/talk/client/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class TalkClient
116116
if (this.logon) this.close();
117117

118118
// Create session stream
119-
const sessionRes = await this._sessionFactory.connect(this.configuration);
119+
const sessionRes = await this._sessionFactory.connect(credential.userId, this.configuration);
120120
if (!sessionRes.success) return sessionRes;
121121
this._session = sessionRes.result;
122122

src/talk/network/index.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { AsyncCommandResult, KnownDataStatusCode } from '../../request';
1818
import * as NetSocket from '../../network/socket';
1919
import { GetConfRes } from '../../packet/booking';
2020
import { CheckinRes } from '../../packet/checkin';
21+
import { Long } from 'bson';
2122

2223
/**
2324
* Create loco stream by performing booking and checkin.
@@ -33,7 +34,7 @@ export class TalkSessionFactory implements SessionFactory {
3334
return getBookingData(bookingStream, config);
3435
}
3536

36-
async getCheckin(config: CheckinConfig): AsyncCommandResult<CheckinRes> {
37+
async getCheckin(userId: Long, config: CheckinConfig): AsyncCommandResult<CheckinRes> {
3738
let checkinStream;
3839
const checkinCrypto = await newCryptoStore(config.locoPEMPublicKey);
3940
try {
@@ -56,11 +57,11 @@ export class TalkSessionFactory implements SessionFactory {
5657
}), checkinCrypto);
5758
}
5859

59-
return getCheckinData(checkinStream, config);
60+
return getCheckinData(checkinStream, config, userId);
6061
}
6162

62-
async connect(config: SessionConfig): AsyncCommandResult<ConnectionSession> {
63-
const checkinRes = await this.getCheckin(config);
63+
async connect(userId: Long, config: SessionConfig): AsyncCommandResult<ConnectionSession> {
64+
const checkinRes = await this.getCheckin(userId, config);
6465
if (!checkinRes.success) return checkinRes;
6566

6667
const locoStream = new LocoSecureLayer(await NetSocket.createTCPSocket({

tests/network.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
* Copyright (c) storycraft. Licensed under the MIT Licence.
55
*/
66

7-
import { DefaultConfiguration } from '../src';
7+
import { DefaultConfiguration, Long } from '../src';
88
import { TalkSessionFactory } from '../src/talk';
99

1010
describe('Network', () => {
1111
it('Create loco session', async () => {
1212
const factory = new TalkSessionFactory();
1313

14-
const res = await factory.connect(DefaultConfiguration);
14+
const res = await factory.connect(Long.fromValue(Math.floor(Math.random() * 9999999)), DefaultConfiguration);
1515
if (!res.success) throw new Error(`Session creation failed with status: ${res.status}`);
1616
res.result.stream.close();
1717
});

0 commit comments

Comments
 (0)