This commit is contained in:
Tau 2019-03-29 20:28:46 -04:00
parent b460fa1aa0
commit de8b654f9c
8 changed files with 82 additions and 34 deletions

View File

@ -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"

View File

@ -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(

View File

@ -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<number, number>();
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);

View File

@ -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);

View File

@ -21,6 +21,14 @@ export default async function idz(socket: Socket) {
break;
case "create_team_req":
output.write({
type: "create_team_res",
name: " ",
});
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,
});

View File

@ -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;

View File

@ -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;

View File

@ -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==