From de8b654f9c50b21833476fc44cc2ee7aa70c07f5 Mon Sep 17 00:00:00 2001 From: Tau Date: Fri, 29 Mar 2019 20:28:46 -0400 Subject: [PATCH] wip --- package.json | 1 + src/idz/decoder.ts | 19 ++++++++++++++----- src/idz/defs.ts | 24 +++++++++++++++--------- src/idz/encoder.ts | 16 +++++++++++++--- src/idz/index.ts | 16 ++++++++++++---- src/idz/request.ts | 20 ++++++++++++++------ src/idz/response.ts | 18 ++++++++++++------ yarn.lock | 2 +- 8 files changed, 82 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 38cdd1c..56915ac 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "dependencies": { "compression": "^1.7.3", "express": "^4.16.4", + "iconv-lite": "^0.4.24", "morgan": "^1.9.1", "multiparty": "^4.2.1", "raw-body": "^2.3.3" diff --git a/src/idz/decoder.ts b/src/idz/decoder.ts index 8db9391..2c79563 100644 --- a/src/idz/decoder.ts +++ b/src/idz/decoder.ts @@ -1,6 +1,6 @@ import { Transform } from "stream"; -import { MSG, MSG_LEN } from "./defs"; +import { MSG, REQ_LEN } from "./defs"; import { Request } from "./request"; type ReaderFn = (buf: Buffer) => Request; @@ -22,12 +22,21 @@ readers.set(MSG.ACCOUNT_LOCK_REQ, buf => { }; }); -readers.set(MSG.GET_CONFIG_DATA_REQ, () => { - return { type: "get_config_data_req" }; +readers.set(MSG.CREATE_TEAM_REQ, buf => { + return { + type: "create_team_req", + field_0004: buf.readInt32LE(0x0004), + field_0008: buf.readInt32LE(0x0008), + field_000C: buf.readInt8(0x000c), + }; +}); + +readers.set(MSG.GET_CONFIG_REQ, () => { + return { type: "get_config_req" }; }); readers.set(MSG.GET_CONFIG_DATA_2_REQ, () => { - return { type: "get_config_data_2_req" }; + return { type: "get_config_2_req" }; }); readers.set(MSG.GET_SERVER_LIST_REQ, () => { @@ -76,7 +85,7 @@ export class Decoder extends Transform { } const msgCode = this.state.readUInt16LE(0x30); - const msgLen = MSG_LEN.get(msgCode); + const msgLen = REQ_LEN.get(msgCode); if (msgLen === undefined) { return callback( diff --git a/src/idz/defs.ts b/src/idz/defs.ts index 9dc1226..3a6297d 100644 --- a/src/idz/defs.ts +++ b/src/idz/defs.ts @@ -1,19 +1,25 @@ export const MSG = { - GET_CONFIG_DATA_REQ: 0x0004, - GET_CONFIG_DATA_RES: 0x0005, + CREATE_RECORD_REQ: 0x0066, + CREATE_RECORD_RES: 0x0001, // doesn't follow the pattern! + CREATE_TEAM_REQ: 0x007b, + CREATE_TEAM_RES: 0x007c, + GET_CONFIG_REQ: 0x0004, + GET_CONFIG_RES: 0x0005, GET_SERVER_LIST_REQ: 0x0006, GET_SERVER_LIST_RES: 0x0007, ACCOUNT_LOCK_REQ: 0x0069, ACCOUNT_LOCK_RES: 0x006a, - UPDATE_STORY_CLEAR_NUM: 0x007f, + UPDATE_STORY_CLEAR_REQ: 0x007f, GET_CONFIG_DATA_2_REQ: 0x00ab, GET_CONFIG_DATA_2_RES: 0x00ac, }; -export const MSG_LEN = new Map(); +export const REQ_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.ACCOUNT_LOCK_REQ, 0x0020); -MSG_LEN.set(MSG.UPDATE_STORY_CLEAR_NUM, 0x0020); -MSG_LEN.set(MSG.GET_SERVER_LIST_REQ, 0x0020); +REQ_LEN.set(MSG.CREATE_RECORD_REQ, 0x00c0); +REQ_LEN.set(MSG.CREATE_TEAM_REQ, 0x0010); +REQ_LEN.set(MSG.GET_CONFIG_REQ, 0x0050); +REQ_LEN.set(MSG.GET_CONFIG_DATA_2_REQ, 0x0010); +REQ_LEN.set(MSG.ACCOUNT_LOCK_REQ, 0x0020); +REQ_LEN.set(MSG.UPDATE_STORY_CLEAR_REQ, 0x0020); +REQ_LEN.set(MSG.GET_SERVER_LIST_REQ, 0x0020); diff --git a/src/idz/encoder.ts b/src/idz/encoder.ts index c735b3f..b9dedd3 100644 --- a/src/idz/encoder.ts +++ b/src/idz/encoder.ts @@ -1,8 +1,11 @@ +import iconv = require("iconv-lite"); import { Transform } from "stream"; import { MSG } from "./defs"; import { Response } from "./response"; +const sjis = "shift_jis"; + export class Encoder extends Transform { constructor() { super({ @@ -26,14 +29,21 @@ export class Encoder extends Transform { break; - case "get_config_data_res": + case "create_team_res": + buf = Buffer.alloc(0x0ca0); + buf.writeUInt16LE(MSG.CREATE_TEAM_RES, 0x0000); + iconv.encode(obj.name, sjis).copy(buf, 0x0024); + + break; + + case "get_config_res": buf = Buffer.alloc(0x01a0); - buf.writeUInt16LE(MSG.GET_CONFIG_DATA_RES, 0x0000); + buf.writeUInt16LE(MSG.GET_CONFIG_RES, 0x0000); buf.writeUInt16LE(obj.status, 0x0002); break; - case "get_config_data_2_res": + case "get_config_2_res": buf = Buffer.alloc(0x230); buf.writeUInt16LE(MSG.GET_CONFIG_DATA_2_RES, 0x0000); buf.writeUInt16LE(obj.status, 0x0002); diff --git a/src/idz/index.ts b/src/idz/index.ts index fee4276..a35542d 100644 --- a/src/idz/index.ts +++ b/src/idz/index.ts @@ -21,6 +21,14 @@ export default async function idz(socket: Socket) { break; + case "create_team_req": + output.write({ + type: "create_team_res", + name: "ASS GENTLEMEN", + }); + + break; + case "get_server_list_req": const myHost = hostname(); @@ -66,17 +74,17 @@ export default async function idz(socket: Socket) { break; - case "get_config_data_req": + case "get_config_req": output.write({ - type: "get_config_data_res", + type: "get_config_res", status: 1, }); break; - case "get_config_data_2_req": + case "get_config_2_req": output.write({ - type: "get_config_data_2_res", + type: "get_config_2_res", status: 1, }); diff --git a/src/idz/request.ts b/src/idz/request.ts index 53b7b21..f5180fd 100644 --- a/src/idz/request.ts +++ b/src/idz/request.ts @@ -5,12 +5,19 @@ export interface AccountLockRequest { field_0018: number; } -export interface GetConfigDataRequest { - type: "get_config_data_req"; +export interface CreateTeamRequest { + type: "create_team_req"; + field_0004: number; + field_0008: number; + field_000C: number; } -export interface GetConfigDataRequest2 { - type: "get_config_data_2_req"; +export interface GetConfigRequest { + type: "get_config_req"; +} + +export interface GetConfigRequest2 { + type: "get_config_2_req"; } export interface GetServerListRequest { @@ -19,6 +26,7 @@ export interface GetServerListRequest { export type Request = | AccountLockRequest - | GetConfigDataRequest - | GetConfigDataRequest2 + | CreateTeamRequest + | GetConfigRequest + | GetConfigRequest2 | GetServerListRequest; diff --git a/src/idz/response.ts b/src/idz/response.ts index 702bf9f..0e029fe 100644 --- a/src/idz/response.ts +++ b/src/idz/response.ts @@ -5,13 +5,18 @@ export interface AccountLockResponse { field_001C: Date; } -export interface GetConfigDataResponse { - type: "get_config_data_res"; +export interface CreateTeamResponse { + type: "create_team_res"; + name: string; +} + +export interface GetConfigResponse { + type: "get_config_res"; status: number; } -export interface GetConfigDataResponse2 { - type: "get_config_data_2_res"; +export interface GetConfigResponse2 { + type: "get_config_2_res"; status: number; } @@ -57,6 +62,7 @@ export interface GetServerListResponse { export type Response = | AccountLockResponse - | GetConfigDataResponse - | GetConfigDataResponse2 + | CreateTeamResponse + | GetConfigResponse + | GetConfigResponse2 | GetServerListResponse; diff --git a/yarn.lock b/yarn.lock index 452a8a2..0b03f5f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1602,7 +1602,7 @@ iconv-lite@0.4.23: dependencies: safer-buffer ">= 2.1.2 < 3" -iconv-lite@0.4.24: +iconv-lite@0.4.24, iconv-lite@^0.4.24: version "0.4.24" resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b" integrity sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==