Skip to content

Commit

Permalink
Begin to prepare support for passcode auth
Browse files Browse the repository at this point in the history
  • Loading branch information
dhleong committed Mar 29, 2021
1 parent 871308f commit e0dcf59
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/remoteplay/packets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum RemotePlayCommand {
}

export enum RemotePlayResponseType {
PASSCODE = 0x4,
LOGIN = 0x05,
}

Expand Down
13 changes: 13 additions & 0 deletions src/remoteplay/packets/passcode-request.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { IncomingPacket, IResultPacket } from "../../socket/packets/base";
import { RemotePlayResponseType } from "../packets";

/**
* Sent by the server in response to a LOGIN request when the account
* is protected by a passcode
*/
export class RemotePlayPasscodeRequestPacket
extends IncomingPacket
implements IResultPacket {
public readonly type: number = RemotePlayResponseType.PASSCODE;
public result = 0;
}
20 changes: 17 additions & 3 deletions src/remoteplay/proc/login.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { IConnectionConfig } from "../../device/model";
import { performRpc } from "../../socket/helpers";
import { performRpc, RpcError } from "../../socket/helpers";
import { IDeviceProc, IDeviceSocket } from "../../socket/model";
import { LoginResultError } from "../../socket/packets/incoming/login-result";
import { RemotePlayCommand, RemotePlayOutgoingPacket, RemotePlayResponseType } from "../packets";
import { RemotePlayLoginResultPacket } from "../packets/login-result";
import { RemotePlayPasscodeRequestPacket } from "../packets/passcode-request";

type Result = RemotePlayLoginResultPacket | RemotePlayPasscodeRequestPacket;

export class RemotePlayLoginProc implements IDeviceProc {
constructor(
public config: IConnectionConfig,
) {}

public async perform(socket: IDeviceSocket) {
// TODO send passcode, if provided
await performRpc<RemotePlayLoginResultPacket>(
const response = await performRpc<Result>(
socket,
new RemotePlayOutgoingPacket(RemotePlayCommand.LOGIN),
RemotePlayResponseType.LOGIN,
);

if (response.type === RemotePlayResponseType.PASSCODE) {
if (!this.config.login?.passCode) {
throw new RpcError(
1,
LoginResultError.PASSCODE_IS_NEEDED,
);
}

// TODO send passcode
}
}
}

0 comments on commit e0dcf59

Please sign in to comment.