diff --git a/src/aimedb/index.ts b/src/aimedb/index.ts index 38946af..1e8f531 100644 --- a/src/aimedb/index.ts +++ b/src/aimedb/index.ts @@ -36,7 +36,7 @@ export default async function aimedb(socket) { // We get sent here if lookup does not return an aimeId console.log("Aimedb: Mifare register", req.luid); - output.write({ type: req.type, status: 1, aimeId: 12345678 }); + output.write({ type: req.type, status: 1, aimeId: 0x55667788 }); break; diff --git a/src/idz/decoder.ts b/src/idz/decoder.ts index b9ac043..8db9391 100644 --- a/src/idz/decoder.ts +++ b/src/idz/decoder.ts @@ -13,6 +13,15 @@ function readHeader(buf: Buffer) { }; } +readers.set(MSG.ACCOUNT_LOCK_REQ, buf => { + return { + type: "account_lock_req", + aimeId: buf.readInt32LE(0x0004), + pcbId: buf.slice(0x0008, buf.indexOf("\0", 0x0008)).toString("ascii"), + field_0018: buf.readInt16LE(0x0018), + }; +}); + readers.set(MSG.GET_CONFIG_DATA_REQ, () => { return { type: "get_config_data_req" }; }); @@ -68,9 +77,8 @@ export class Decoder extends Transform { const msgCode = this.state.readUInt16LE(0x30); const msgLen = MSG_LEN.get(msgCode); - const reader = readers.get(msgCode); - if (msgLen === undefined || reader === undefined) { + if (msgLen === undefined) { return callback( new Error( `Unknown command code ${msgCode.toString(16)}, cannot continue` @@ -82,12 +90,23 @@ export class Decoder extends Transform { return callback(null); } - const reqBuf = this.state.slice(0x30, 0x30 + msgLen); - const payload = reader(reqBuf); + const reqBuf = this.state.slice(0, 0x30 + msgLen); + const payloadBuf = reqBuf.slice(0x30); - console.log("Idz: RAW:", reqBuf.toString("hex")); - console.log("Idz: Header:", header); - console.log("Idz: Payload:", payload); + console.log("Idz: Req: Raw:", reqBuf.toString("hex")); + console.log("Idz: Req: Header:", header); + + const reader = readers.get(msgCode); + + if (reader === undefined) { + return callback( + new Error(`No reader for command code ${msgCode.toString(16)}`) + ); + } + + const payload = reader(payloadBuf); + + console.log("Idz: Req: Payload:", payload); return callback(null, payload); } diff --git a/src/idz/defs.ts b/src/idz/defs.ts index 0bea8a9..9dc1226 100644 --- a/src/idz/defs.ts +++ b/src/idz/defs.ts @@ -3,8 +3,9 @@ export const MSG = { GET_CONFIG_DATA_RES: 0x0005, GET_SERVER_LIST_REQ: 0x0006, GET_SERVER_LIST_RES: 0x0007, - ACT_LOCK_REQ: 0x0069, - ACT_LOCK_RES: 0x006a, + ACCOUNT_LOCK_REQ: 0x0069, + ACCOUNT_LOCK_RES: 0x006a, + UPDATE_STORY_CLEAR_NUM: 0x007f, GET_CONFIG_DATA_2_REQ: 0x00ab, GET_CONFIG_DATA_2_RES: 0x00ac, }; @@ -13,5 +14,6 @@ export const MSG_LEN = new Map(); MSG_LEN.set(MSG.GET_CONFIG_DATA_REQ, 0x0050); MSG_LEN.set(MSG.GET_CONFIG_DATA_2_REQ, 0x0010); -MSG_LEN.set(MSG.ACT_LOCK_REQ, 0x001c); +MSG_LEN.set(MSG.ACCOUNT_LOCK_REQ, 0x0020); +MSG_LEN.set(MSG.UPDATE_STORY_CLEAR_NUM, 0x0020); MSG_LEN.set(MSG.GET_SERVER_LIST_REQ, 0x0020); diff --git a/src/idz/encoder.ts b/src/idz/encoder.ts index b949ad2..c735b3f 100644 --- a/src/idz/encoder.ts +++ b/src/idz/encoder.ts @@ -12,11 +12,20 @@ export class Encoder extends Transform { } _transform(obj: Response, encoding, callback) { - console.log("Idz: Response:", obj); + console.log("Idz: Res: Object:", obj); let buf: Buffer; switch (obj.type) { + case "account_lock_res": + buf = Buffer.alloc(0x0020); + buf.writeUInt16LE(MSG.ACCOUNT_LOCK_RES, 0x0000); + buf.writeInt8(obj.field_0018, 0x0018); + buf.writeInt16LE(obj.field_001A, 0x001a); + buf.writeUInt32LE(obj.field_001C.getTime() / 1000, 0x001c); + + break; + case "get_config_data_res": buf = Buffer.alloc(0x01a0); buf.writeUInt16LE(MSG.GET_CONFIG_DATA_RES, 0x0000); @@ -63,6 +72,12 @@ export class Encoder extends Transform { return callback(new Error(`No writer fn for ${obj["type"]}`)); } + console.log("Idz: Res: Encoded:", buf.toString("hex")); + + if (buf.readInt16LE(0) === 0) { + throw new Error("MESSAGE TYPE CODE YOU FUCKING IDIOT"); + } + return callback(null, buf); } } diff --git a/src/idz/index.ts b/src/idz/index.ts index 5fa49a7..fee4276 100644 --- a/src/idz/index.ts +++ b/src/idz/index.ts @@ -1,8 +1,9 @@ +import { Socket } from "net"; import { hostname } from "os"; import setup from "./setup"; -export default async function idz(socket) { +export default async function idz(socket: Socket) { const { input, output } = setup(socket); console.log("Idz: Connection opened"); @@ -10,6 +11,16 @@ export default async function idz(socket) { try { for await (const msg of input) { switch (msg.type) { + case "account_lock_req": + output.write({ + type: "account_lock_res", + field_0018: 1, + field_001A: -1, + field_001C: new Date(Date.now() + 3600000), + }); + + break; + case "get_server_list_req": const myHost = hostname(); diff --git a/src/idz/request.ts b/src/idz/request.ts index 33c57dc..53b7b21 100644 --- a/src/idz/request.ts +++ b/src/idz/request.ts @@ -1,8 +1,7 @@ export interface AccountLockRequest { type: "account_lock_req"; - field_0002: number; - field_0004: number; - field_0008: Buffer; + aimeId: number; + pcbId: string; field_0018: number; } diff --git a/src/idz/response.ts b/src/idz/response.ts index ec97704..702bf9f 100644 --- a/src/idz/response.ts +++ b/src/idz/response.ts @@ -1,3 +1,10 @@ +export interface AccountLockResponse { + type: "account_lock_res"; + field_0018: number; + field_001A: number; + field_001C: Date; +} + export interface GetConfigDataResponse { type: "get_config_data_res"; status: number; @@ -49,6 +56,7 @@ export interface GetServerListResponse { } export type Response = + | AccountLockResponse | GetConfigDataResponse | GetConfigDataResponse2 | GetServerListResponse;