diff --git a/src/Playground.ts b/src/Playground.ts
index 69aa074..a038f80 100644
--- a/src/Playground.ts
+++ b/src/Playground.ts
@@ -1,26 +1,16 @@
-import { xmlToData, dataToXML, kencode, kitem } from './utils/KBinJSON';
-import ejs from 'ejs';
-import pug from 'pug';
+import { xmlToData, dataToXML, kencode, kitem, kdecode } from './utils/KBinJSON';
+import { KonmaiEncrypt } from './utils/KonmaiEncrypt';
+import iconv from 'iconv-lite';
+import { writeFileSync, readFileSync, write } from 'fs';
-const data = {
- attr: 0,
- text: 'text',
-};
+// const data = readFileSync('response.bin');
+// const decode = kdecode(data);
+// console.log(dataToXML(decode));
-const xmlData = {
- root: { '@attr': { test: data.attr }, 'test': kitem('str', data.text) },
-};
-const ejsData = xmlToData(
- ejs.render('<%= text %>', data)
+const request = iconv.encode(
+ '\n\n',
+ 'utf8'
);
-const pugData = xmlToData(pug.render('root(test=attr)\n test #{text}', data));
-console.log(JSON.stringify(xmlData, null, 4));
-console.log(JSON.stringify(ejsData, null, 4));
-console.log(JSON.stringify(pugData, null, 4));
-
-console.log(kencode(xmlData).compare(kencode(ejsData)));
-console.log(kencode(xmlData).compare(kencode(pugData)));
-console.log(kencode(xmlData));
-console.log(kencode(ejsData));
-console.log(kencode(pugData));
+const key = new KonmaiEncrypt('1-5ebc47ba-9868');
+writeFileSync(`${key.getPublicKey()}.bin`, key.encrypt(request));
diff --git a/src/eamuse/Core/index.ts b/src/eamuse/Core/index.ts
index b45396c..2749b4f 100644
--- a/src/eamuse/Core/index.ts
+++ b/src/eamuse/Core/index.ts
@@ -4,6 +4,7 @@ import { facility } from './Facility';
import { pcbtracker } from './PCBTracker';
import { kitem } from '../../utils/KBinJSON';
import { EamuseModuleContainer } from '../EamuseModuleContainer';
+import { Logger } from '../../utils/Logger';
export const core = new EamuseModuleContainer();
@@ -29,6 +30,19 @@ core.add('*', 'tax.get_phase', async (info, data, send) => {
});
});
+core.add('*', 'dlstatus.progress', async (info, data, send) => {
+ await send.success();
+});
+
+core.add('*', 'posevent.income.sales.sale', async (info, data, send) => {
+ Logger.debug(JSON.stringify(data, null, 4));
+ await send.object([
+ { '@attr': { status: 0 } },
+ { '@attr': { status: 0 } },
+ { '@attr': { status: 0 } },
+ ]);
+});
+
core.add(eacoin);
core.add(facility);
core.add(cardmng);
diff --git a/src/eamuse/Services.ts b/src/eamuse/Services.ts
index 9475a37..bfc6dfd 100644
--- a/src/eamuse/Services.ts
+++ b/src/eamuse/Services.ts
@@ -3,6 +3,7 @@ import { Router } from 'express';
import { EamuseMiddleware, EamuseRoute } from '../middlewares/EamuseMiddleware';
import { core } from './Core';
import { EamuseModuleContainer } from './EamuseModuleContainer';
+import { dataToXML } from '../utils/KBinJSON';
export const services = (url: string, modules: EamuseModuleContainer) => {
const routeEamuse = Router();
@@ -27,6 +28,8 @@ export const services = (url: string, modules: EamuseModuleContainer) => {
'lobby2',
'dlstatus',
'netlog',
+ 'sidmgr',
+ 'globby',
];
/* General Information */
@@ -60,6 +63,27 @@ export const services = (url: string, modules: EamuseModuleContainer) => {
services.item.push({ '@attr': { name: moduleName, url } });
}
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ //
+ // ;
+
await send.object(services);
return;
});
diff --git a/src/middlewares/EamuseMiddleware.ts b/src/middlewares/EamuseMiddleware.ts
index 2adb4f0..ada00bf 100644
--- a/src/middlewares/EamuseMiddleware.ts
+++ b/src/middlewares/EamuseMiddleware.ts
@@ -1,5 +1,5 @@
import { RequestHandler } from 'express';
-import { findKey, get, has } from 'lodash';
+import { findKey, get, has, isArray } from 'lodash';
import {
isKBin,
@@ -14,6 +14,7 @@ import LzKN from '../utils/LzKN';
import { Logger } from '../utils/Logger';
import { EamuseModuleContainer } from '../eamuse/EamuseModuleContainer';
import { EamuseSend } from '../eamuse/EamuseSend';
+import { dataToXML } from '../utils/KBinJSON';
// const ACCEPT_AGENTS = ['EAMUSE.XRPC/1.0', 'EAMUSE.Httpac/1.0'];
@@ -118,16 +119,26 @@ export const EamuseMiddleware: RequestHandler = async (req, res, next) => {
return;
}
- const eaModule = findKey(get(xml, 'call'), x => has(x, '@attr.method'));
- const eaMethod = get(xml, `call.${eaModule}.@attr.method`);
- const model = get(xml, 'call.@attr.model');
+ const eaModule = findKey(
+ get(xml, 'call'),
+ x => has(x, '@attr.method') || has(x, '0.@attr.method')
+ );
- if (!eaModule || !eaMethod) {
+ if (!eaModule) {
res.sendStatus(404);
return;
}
- Logger.debug(`${eaModule}.${eaMethod}`);
+ let moduleObj: any[] = get(xml, `call.${eaModule}`, null);
+ if (!isArray(moduleObj)) moduleObj = [moduleObj];
+
+ const eaMethods: string[] = moduleObj.map(x => get(x, `@attr.method`));
+ const eaMethod = eaMethods.join('.');
+ const model = get(xml, 'call.@attr.model');
+
+ if (!(process as any).pkg) {
+ Logger.debug(`${eaModule}.${eaMethod}\n${dataToXML(xml, false)}`);
+ }
req.body = {
data: xml,
diff --git a/src/utils/Consts.ts b/src/utils/Consts.ts
index b8c8582..e128da4 100644
--- a/src/utils/Consts.ts
+++ b/src/utils/Consts.ts
@@ -1,2 +1,2 @@
-export const VERSION = 'v1.03 beta';
+export const VERSION = 'v1.04 beta';
export const SAFEHEX = 'ADEBEEFA';
diff --git a/src/utils/KBinJSON.ts b/src/utils/KBinJSON.ts
index 1efcc01..5686d17 100644
--- a/src/utils/KBinJSON.ts
+++ b/src/utils/KBinJSON.ts
@@ -436,15 +436,18 @@ function bufferToString(data: Buffer, encoding: KBinEncoding): string {
}
const str = iconv.decode(data, encoding);
const result = str.substr(0, str.length - 1);
- if (result.startsWith(SAFEHEX)) return result;
- if (result.length == 16) {
- const hex_checker = /^[0-9a-fA-F]+$/;
- if (hex_checker.test(result)) {
- return 'DEADC0DEFEEDBEEF';
- }
- }
+ // if (result.startsWith(SAFEHEX)) return result;
+
+ // if (result.length == 16) {
+ // const hex_checker = /^[0-9a-fA-F]+$/;
+ // if (hex_checker.test(result)) {
+ // return 'DEADC0DEFEEDBEEF';
+ // }
+ // }
+
return result;
+ // replace(/(^|\s*)[0|E][A-F|a-f|0-9]{15}($|\s+)/g, '$1DEADC0DEFEEDBEEF$2');
}
function nodeToBinary(
@@ -764,9 +767,40 @@ export function ip2int(ip: string): number {
);
}
+function escape(data: string | number): string {
+ return data
+ .toString()
+ .replace(/&/g, '&')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''')
+ .replace(//g, '>');
+}
+
+function unescape(data: string | number): string {
+ return data
+ .toString()
+ .replace(/&/g, '&')
+ .replace(/"/g, '"')
+ .replace(/'/g, "'")
+ .replace(/</g, '<')
+ .replace(/>/g, '>');
+}
+
function transformJObj(obj: any, toStr = true): void {
if (obj !== null && obj !== undefined) {
const data = obj['@content'];
+
+ if (obj['@attr']) {
+ for (const attr in obj['@attr']) {
+ if (toStr) {
+ obj['@attr'][attr] = escape(obj['@attr'][attr]);
+ } else {
+ obj['@attr'][attr] = unescape(obj['@attr'][attr]);
+ }
+ }
+ }
+
if (data !== undefined) {
let vType = 'void';
if (obj['@attr'] && obj['@attr'].__type) {
@@ -776,7 +810,9 @@ function transformJObj(obj: any, toStr = true): void {
obj['@attr'].__count = toSafeInteger(obj['@attr'].__count);
}
if (toStr) {
- if (typeof data !== 'object') {
+ if (typeof data == 'string') {
+ obj['@content'] = escape(data);
+ } else if (typeof data !== 'object') {
obj['@content'] = data.toString();
} else {
if (Buffer.isBuffer(data)) {
@@ -796,13 +832,15 @@ function transformJObj(obj: any, toStr = true): void {
} else if (vType === 'ip4') {
const parts = data.split(' ');
obj['@content'] = parts.map(ip2int);
- } else if (vType !== 'str') {
+ } else if (vType !== 'str' && vType !== 'void') {
const parts = data.split(' ');
if (vType.endsWith('64')) {
obj['@content'] = parts.map(v => BigInt(v));
} else {
obj['@content'] = parts.map(v => parseFloat(v));
}
+ } else {
+ obj['@content'] = unescape(data);
}
}
}
@@ -827,7 +865,7 @@ function transformJObj(obj: any, toStr = true): void {
}
}
-export function dataToXML(data: any): string | Buffer {
+export function dataToXML(data: any, header: boolean = true): string {
const options = {
attributeNamePrefix: '',
attrNodeName: '@attr',
@@ -848,7 +886,8 @@ export function dataToXML(data: any): string | Buffer {
transformJObj(data, false);
- return '\n' + xml;
+ if (header) return "\n" + xml;
+ else return xml;
}
export function dataToXMLBuffer(data: any, encoding: KBinEncoding): Buffer {
@@ -877,7 +916,7 @@ export function dataToXMLBuffer(data: any, encoding: KBinEncoding): Buffer {
export function detectXMLEncoding(xml: Buffer): KBinEncoding {
const header = iconv.decode(xml.subarray(0, Math.min(128, xml.length)), 'ascii');
const match = header.match(/<\?xml.*encoding=['|"](.*)['|"].*?>/);
- if (match.length < 2) {
+ if (!match || match.length < 2) {
return 'utf8';
}
const encoding = XML2ICONV[match[1].toLowerCase()];