-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Begin to prepare support for passcode auth
- Loading branch information
Showing
3 changed files
with
31 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |