mirror of
https://github.com/asphyxia-core/core.git
synced 2026-12-05 15:35:15 -06:00
webui
This commit is contained in:
7
.gitignore
vendored
7
.gitignore
vendored
@@ -3,9 +3,12 @@ node_modules/
|
||||
dist/*
|
||||
build/*
|
||||
dev/*
|
||||
typings/*
|
||||
|
||||
build-env/package-lock.json
|
||||
build-env/index.js
|
||||
build-env/*
|
||||
!build-env/assets/
|
||||
!build-env/typescript/
|
||||
!build-env/package.json
|
||||
|
||||
.vscode
|
||||
.vs
|
||||
|
||||
1
build-env/assets/icon.b64
Normal file
1
build-env/assets/icon.b64
Normal file
File diff suppressed because one or more lines are too long
@@ -10,7 +10,10 @@
|
||||
"axphyxia": "./index.js"
|
||||
},
|
||||
"pkg": {
|
||||
"assets": "./node_modules/typescript"
|
||||
"assets": [
|
||||
"./node_modules/typescript",
|
||||
"./assets"
|
||||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"ts-node": "^8.10.1",
|
||||
|
||||
@@ -17,7 +17,7 @@ npx ncc build .\dist\AsphyxiaCore.js -o .\build-env --external uglify-js --exter
|
||||
|
||||
# Packing
|
||||
Write-Output "Packing exe"
|
||||
npx pkg .\build-env -t "node12-win-x64,node12-win-x86" -o .\build\asphyxia-core
|
||||
npx pkg .\build-env -t "node12-win-x64,node12-win-x86,node12-linux-x64" -o .\build\asphyxia-core
|
||||
|
||||
# Renaming 64bit versions
|
||||
# Move-Item -Path ".\build\asphyxia-x64.exe" -Destination ".\build\asphyxia.exe" -Force | Out-Null
|
||||
|
||||
18
build.sh
Normal file
18
build.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir -p build
|
||||
|
||||
regex='VERSION = '"'"'(.*)'"'"''
|
||||
[[ $(cat ./src/util/Consts.ts) =~ $regex ]]
|
||||
|
||||
VERSION=${BASH_REMATCH[1]}
|
||||
|
||||
npx tsc
|
||||
|
||||
npx ncc build ./dist/AsphyxiaCore.js -o ./build-env --external uglify-js --external ts-node
|
||||
|
||||
npx pkg ./build-env -t node10.15.3-linux-armv7 -o ./build/asphyxia-core
|
||||
|
||||
rm -f build/asphyxia-$VERSION-armv7.zip
|
||||
cd build
|
||||
zip asphyxia-$VERSION-armv7.zip asphyxia-core
|
||||
273
package-lock.json
generated
273
package-lock.json
generated
@@ -69,6 +69,15 @@
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/cli-progress": {
|
||||
"version": "3.7.0",
|
||||
"resolved": "https://registry.npmjs.org/@types/cli-progress/-/cli-progress-3.7.0.tgz",
|
||||
"integrity": "sha512-h/f9+pomRHSodXOPgBjlLEESWhv2Z34pP5djmruylvEZ7MzTd1pljOmdsBpVh3uCGjTVOzb2ux8ZaXYqyPFgpQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/color-name": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||
@@ -227,6 +236,11 @@
|
||||
"repeat-string": "^1.5.2"
|
||||
}
|
||||
},
|
||||
"ansi-regex": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||
"integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg=="
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
|
||||
@@ -438,6 +452,15 @@
|
||||
"source-map": "~0.6.0"
|
||||
}
|
||||
},
|
||||
"cli-progress": {
|
||||
"version": "3.8.2",
|
||||
"resolved": "https://registry.npmjs.org/cli-progress/-/cli-progress-3.8.2.tgz",
|
||||
"integrity": "sha512-qRwBxLldMSfxB+YGFgNRaj5vyyHe1yMpVeDL79c+7puGujdKJHQHydgqXDcrkvQgJ5U/d3lpf6vffSoVVUftVQ==",
|
||||
"requires": {
|
||||
"colors": "^1.1.2",
|
||||
"string-width": "^4.2.0"
|
||||
}
|
||||
},
|
||||
"cliui": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/cliui/-/cliui-2.1.0.tgz",
|
||||
@@ -521,6 +544,13 @@
|
||||
"delayed-stream": "~1.0.0"
|
||||
}
|
||||
},
|
||||
"commander": {
|
||||
"version": "2.20.3",
|
||||
"resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz",
|
||||
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
|
||||
"dev": true,
|
||||
"optional": true
|
||||
},
|
||||
"concat-map": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||
@@ -661,6 +691,11 @@
|
||||
"jake": "^10.6.1"
|
||||
}
|
||||
},
|
||||
"emoji-regex": {
|
||||
"version": "8.0.0",
|
||||
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
|
||||
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A=="
|
||||
},
|
||||
"enabled": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/enabled/-/enabled-1.0.2.tgz",
|
||||
@@ -927,6 +962,12 @@
|
||||
"universalify": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"fs.realpath": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
|
||||
"integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=",
|
||||
"dev": true
|
||||
},
|
||||
"function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
@@ -945,6 +986,20 @@
|
||||
"assert-plus": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"glob": {
|
||||
"version": "7.1.6",
|
||||
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
|
||||
"integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs.realpath": "^1.0.0",
|
||||
"inflight": "^1.0.4",
|
||||
"inherits": "2",
|
||||
"minimatch": "^3.0.4",
|
||||
"once": "^1.3.0",
|
||||
"path-is-absolute": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"glob-parent": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.1.tgz",
|
||||
@@ -971,6 +1026,37 @@
|
||||
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.4.tgz",
|
||||
"integrity": "sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw=="
|
||||
},
|
||||
"handlebars": {
|
||||
"version": "4.7.6",
|
||||
"resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.6.tgz",
|
||||
"integrity": "sha512-1f2BACcBfiwAfStCKZNrUCgqNZkGsAT7UM3kkYtXuLo0KnaVfjKOyf7PRzB6++aK9STyT1Pd2ZCPe3EGOXleXA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"minimist": "^1.2.5",
|
||||
"neo-async": "^2.6.0",
|
||||
"source-map": "^0.6.1",
|
||||
"uglify-js": "^3.1.4",
|
||||
"wordwrap": "^1.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"uglify-js": {
|
||||
"version": "3.9.2",
|
||||
"resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.9.2.tgz",
|
||||
"integrity": "sha512-zGVwKslUAD/EeqOrD1nQaBmXIHl1Vw371we8cvS8I6mYK9rmgX5tv8AAeJdfsQ3Kk5mGax2SVV/AizxdNGhl7Q==",
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"requires": {
|
||||
"commander": "~2.20.3"
|
||||
}
|
||||
},
|
||||
"wordwrap": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz",
|
||||
"integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=",
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"har-schema": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
||||
@@ -998,6 +1084,12 @@
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
|
||||
},
|
||||
"highlight.js": {
|
||||
"version": "10.0.2",
|
||||
"resolved": "https://registry.npmjs.org/highlight.js/-/highlight.js-10.0.2.tgz",
|
||||
"integrity": "sha512-2gMT2MHU6/2OjAlnaOE2LFdr9dwviDN3Q2lSw7Ois3/5uTtahbgYTkr4EPoY828ps+2eQWiixPTF8+phU6Ofkg==",
|
||||
"dev": true
|
||||
},
|
||||
"http-errors": {
|
||||
"version": "1.7.2",
|
||||
"resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.2.tgz",
|
||||
@@ -1033,11 +1125,27 @@
|
||||
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.1.4.tgz",
|
||||
"integrity": "sha512-MzbUSahkTW1u7JpKKjY7LCARd1fU5W2rLdxlM4kdkayuCwZImjkpluF9CM1aLewYJguPDqewLam18Y6AU69A8A=="
|
||||
},
|
||||
"inflight": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
|
||||
"integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"once": "^1.3.0",
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"inherits": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
||||
"integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4="
|
||||
},
|
||||
"interpret": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/interpret/-/interpret-1.2.0.tgz",
|
||||
"integrity": "sha512-mT34yGKMNceBQUoVn7iCDKDntA7SC6gycMAWzGx1z/CMCTV7b2AAtXlo3nRyHZ1FelRkQbQjprHSYGwzLtkVbw==",
|
||||
"dev": true
|
||||
},
|
||||
"into-stream": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/into-stream/-/into-stream-5.1.1.tgz",
|
||||
@@ -1062,6 +1170,11 @@
|
||||
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-1.1.6.tgz",
|
||||
"integrity": "sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w=="
|
||||
},
|
||||
"is-docker": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.0.0.tgz",
|
||||
"integrity": "sha512-pJEdRugimx4fBMra5z2/5iRdZ63OhYV0vr0Dwm5+xtW4D1FvRkB8hamMIhnWfyJeDdyr/aa7BDyNbtG38VxgoQ=="
|
||||
},
|
||||
"is-expression": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-expression/-/is-expression-3.0.0.tgz",
|
||||
@@ -1083,6 +1196,11 @@
|
||||
"resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz",
|
||||
"integrity": "sha1-qIwCU1eR8C7TfHahueqXc8gz+MI="
|
||||
},
|
||||
"is-fullwidth-code-point": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
|
||||
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg=="
|
||||
},
|
||||
"is-glob": {
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.1.tgz",
|
||||
@@ -1119,6 +1237,14 @@
|
||||
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
|
||||
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
|
||||
},
|
||||
"is-wsl": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",
|
||||
"integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",
|
||||
"requires": {
|
||||
"is-docker": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"isarray": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
@@ -1303,11 +1429,23 @@
|
||||
"resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz",
|
||||
"integrity": "sha1-MKCy2jj3N3DoKUoNIuZiXtd9AJc="
|
||||
},
|
||||
"lunr": {
|
||||
"version": "2.3.8",
|
||||
"resolved": "https://registry.npmjs.org/lunr/-/lunr-2.3.8.tgz",
|
||||
"integrity": "sha512-oxMeX/Y35PNFuZoHp+jUj5OSEmLCaIH4KTFJh7a93cHBoFmpw2IoPs22VIz7vyO2YUnx2Tn9dzIwO2P/4quIRg==",
|
||||
"dev": true
|
||||
},
|
||||
"make-error": {
|
||||
"version": "1.3.6",
|
||||
"resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz",
|
||||
"integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw=="
|
||||
},
|
||||
"marked": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/marked/-/marked-1.0.0.tgz",
|
||||
"integrity": "sha512-Wo+L1pWTVibfrSr+TTtMuiMfNzmZWiOPeO7rZsQUY5bgsxpHesBEcIWJloWVTFnrMXnf/TL30eTFSGJddmQAng==",
|
||||
"dev": true
|
||||
},
|
||||
"media-typer": {
|
||||
"version": "0.3.0",
|
||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||
@@ -1419,6 +1557,12 @@
|
||||
"resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz",
|
||||
"integrity": "sha512-hZXc7K2e+PgeI1eDBe/10Ard4ekbfrrqG8Ep+8Jmf4JID2bNg7NvCPOZN+kfF574pFQI7mum2AUqDidoKqcTOw=="
|
||||
},
|
||||
"neo-async": {
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.1.tgz",
|
||||
"integrity": "sha512-iyam8fBuCUpWeKPGpaNMetEocMt364qkCsfL9JuhjXX6dRnguRVOfk2GZaDpPjcOKiiXCPINZC1GczQ7iTq3Zw==",
|
||||
"dev": true
|
||||
},
|
||||
"oauth-sign": {
|
||||
"version": "0.9.0",
|
||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
||||
@@ -1437,11 +1581,29 @@
|
||||
"ee-first": "1.1.1"
|
||||
}
|
||||
},
|
||||
"once": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
|
||||
"integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"wrappy": "1"
|
||||
}
|
||||
},
|
||||
"one-time": {
|
||||
"version": "0.0.4",
|
||||
"resolved": "https://registry.npmjs.org/one-time/-/one-time-0.0.4.tgz",
|
||||
"integrity": "sha1-+M33eISCb+Tf+T46nMN7HkSAdC4="
|
||||
},
|
||||
"open": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/open/-/open-7.0.3.tgz",
|
||||
"integrity": "sha512-sP2ru2v0P290WFfv49Ap8MF6PkzGNnGlAwHweB4WR4mr5d2d0woiCluUeJ218w7/+PmoBy9JmYgD5A4mLcWOFA==",
|
||||
"requires": {
|
||||
"is-docker": "^2.0.0",
|
||||
"is-wsl": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"optionator": {
|
||||
"version": "0.8.3",
|
||||
"resolved": "https://registry.npmjs.org/optionator/-/optionator-0.8.3.tgz",
|
||||
@@ -1470,6 +1632,12 @@
|
||||
"resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
|
||||
"integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ=="
|
||||
},
|
||||
"path-is-absolute": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
|
||||
"integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
|
||||
"dev": true
|
||||
},
|
||||
"path-parse": {
|
||||
"version": "1.0.6",
|
||||
"resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz",
|
||||
@@ -1748,6 +1916,15 @@
|
||||
"util-deprecate": "^1.0.1"
|
||||
}
|
||||
},
|
||||
"rechoir": {
|
||||
"version": "0.6.2",
|
||||
"resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz",
|
||||
"integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"resolve": "^1.1.6"
|
||||
}
|
||||
},
|
||||
"regenerator-runtime": {
|
||||
"version": "0.13.5",
|
||||
"resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.5.tgz",
|
||||
@@ -1884,6 +2061,17 @@
|
||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.1.tgz",
|
||||
"integrity": "sha512-JvdAWfbXeIGaZ9cILp38HntZSFSo3mWg6xGcJJsd+d4aRMOqauag1C63dJfDw7OaMYwEbHMOxEZ1lqVRYP2OAw=="
|
||||
},
|
||||
"shelljs": {
|
||||
"version": "0.8.4",
|
||||
"resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz",
|
||||
"integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"glob": "^7.0.0",
|
||||
"interpret": "^1.0.0",
|
||||
"rechoir": "^0.6.2"
|
||||
}
|
||||
},
|
||||
"simple-swizzle": {
|
||||
"version": "0.2.2",
|
||||
"resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz",
|
||||
@@ -1974,6 +2162,16 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"string-width": {
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.0.tgz",
|
||||
"integrity": "sha512-zUz5JD+tgqtuDjMhwIg5uFVV3dtqZ9yQJlZVfq4I01/K5Paj5UHj7VyrQOJvzawSVlKpObApbfD0Ed6yJc+1eg==",
|
||||
"requires": {
|
||||
"emoji-regex": "^8.0.0",
|
||||
"is-fullwidth-code-point": "^3.0.0",
|
||||
"strip-ansi": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
@@ -1989,6 +2187,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"strip-ansi": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.0.tgz",
|
||||
"integrity": "sha512-AuvKTrTfQNYNIctbR1K/YGTR1756GycPsg7b9bdV9Duqur4gv6aKqHXah67Z8ImS7WEz5QVcOtlfW2rZEugt6w==",
|
||||
"requires": {
|
||||
"ansi-regex": "^5.0.0"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "7.1.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz",
|
||||
@@ -1997,6 +2203,40 @@
|
||||
"has-flag": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"systray": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmjs.org/systray/-/systray-1.0.5.tgz",
|
||||
"integrity": "sha512-qLsl5lk8lUuqCTaREJ0nR6NgF2y2Ni01vBjUs0cVWf54ZeV4pr3TFLMcUT+od1Twb1qQMq/SKyj+BKd2vg6+Fg==",
|
||||
"requires": {
|
||||
"debug": "^3.0.1",
|
||||
"fs-extra": "^4.0.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "3.2.6",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.2.6.tgz",
|
||||
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
|
||||
"requires": {
|
||||
"ms": "^2.1.1"
|
||||
}
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-4.0.3.tgz",
|
||||
"integrity": "sha512-q6rbdDd1o2mAnQreO7YADIxf/Whx4AHBiRf6d+/cVT8h44ss+lHgxf1FemcqDnQt9X3ct4McHr+JMGlYSsK7Cg==",
|
||||
"requires": {
|
||||
"graceful-fs": "^4.1.2",
|
||||
"jsonfile": "^4.0.0",
|
||||
"universalify": "^0.1.0"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "2.1.2",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
|
||||
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"text-hex": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/text-hex/-/text-hex-1.0.0.tgz",
|
||||
@@ -2086,6 +2326,33 @@
|
||||
"mime-types": "~2.1.24"
|
||||
}
|
||||
},
|
||||
"typedoc": {
|
||||
"version": "0.17.6",
|
||||
"resolved": "https://registry.npmjs.org/typedoc/-/typedoc-0.17.6.tgz",
|
||||
"integrity": "sha512-pQiYnhG3yJk7939cv2n8uFoTsSgy5Hfiw0dgOQYa9nT9Ya1013dMctQdAXMj8JbNu7KhcauQyq9Zql9D/TziLw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"fs-extra": "^8.1.0",
|
||||
"handlebars": "^4.7.6",
|
||||
"highlight.js": "^10.0.0",
|
||||
"lodash": "^4.17.15",
|
||||
"lunr": "^2.3.8",
|
||||
"marked": "1.0.0",
|
||||
"minimatch": "^3.0.0",
|
||||
"progress": "^2.0.3",
|
||||
"shelljs": "^0.8.4",
|
||||
"typedoc-default-themes": "^0.10.1"
|
||||
}
|
||||
},
|
||||
"typedoc-default-themes": {
|
||||
"version": "0.10.1",
|
||||
"resolved": "https://registry.npmjs.org/typedoc-default-themes/-/typedoc-default-themes-0.10.1.tgz",
|
||||
"integrity": "sha512-SuqAQI0CkwhqSJ2kaVTgl37cWs733uy9UGUqwtcds8pkFK8oRF4rZmCq+FXTGIb9hIUOu40rf5Kojg0Ha6akeg==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"lunr": "^2.3.8"
|
||||
}
|
||||
},
|
||||
"typescript": {
|
||||
"version": "3.8.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz",
|
||||
@@ -2256,6 +2523,12 @@
|
||||
"resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-0.0.2.tgz",
|
||||
"integrity": "sha1-t5Zpu0LstAn4PVg8rVLKF+qhZD8="
|
||||
},
|
||||
"wrappy": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
|
||||
"dev": true
|
||||
},
|
||||
"yargs": {
|
||||
"version": "3.10.0",
|
||||
"resolved": "https://registry.npmjs.org/yargs/-/yargs-3.10.0.tgz",
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
"main": "./build/index.js",
|
||||
"devDependencies": {
|
||||
"@types/argparse": "^1.0.38",
|
||||
"@types/cli-progress": "^3.7.0",
|
||||
"@types/ejs": "^3.0.3",
|
||||
"@types/encoding-japanese": "^1.0.15",
|
||||
"@types/express": "^4.17.6",
|
||||
@@ -13,20 +14,24 @@
|
||||
"@types/node": "^13.13.4",
|
||||
"@types/pug": "^2.0.4",
|
||||
"prettier": "^2.0.5",
|
||||
"typedoc": "^0.17.6",
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@zeit/ncc": "^0.22.1",
|
||||
"argparse": "^1.0.10",
|
||||
"chalk": "^4.0.0",
|
||||
"cli-progress": "^3.8.2",
|
||||
"ejs": "^3.1.2",
|
||||
"encoding-japanese": "^1.0.30",
|
||||
"express": "^4.17.1",
|
||||
"fast-xml-parser": "^3.16.0",
|
||||
"get-caller-file": "^2.0.5",
|
||||
"lodash": "^4.17.15",
|
||||
"open": "^7.0.3",
|
||||
"pkg": "^4.4.8",
|
||||
"pug": "^2.0.4",
|
||||
"systray": "^1.0.5",
|
||||
"ts-node": "^8.10.1",
|
||||
"winston": "^3.2.1"
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import { pad } from 'lodash';
|
||||
import express from 'express';
|
||||
import chalk from 'chalk';
|
||||
import { LoadExternalModules } from './eamuse/ExternalModuleLoader';
|
||||
import { CreateTray } from './utils/Systray';
|
||||
|
||||
process.title = `Asphyxia CORE ${VERSION}`;
|
||||
CreateTray();
|
||||
|
||||
Logger.info(' _ _ ');
|
||||
Logger.info(' /\\ | | (_) ');
|
||||
@@ -27,10 +29,14 @@ Logger.info(pad(`If you bought this software, request refund immediately.`, 60))
|
||||
Logger.info(` `);
|
||||
|
||||
const EAMUSE = express();
|
||||
const WEBUI = express();
|
||||
|
||||
EAMUSE.disable('etag');
|
||||
EAMUSE.disable('x-powered-by');
|
||||
|
||||
if (ARGS.dev) {
|
||||
Logger.info(` [Console Output Enabled]`);
|
||||
}
|
||||
const external = LoadExternalModules();
|
||||
process.title = `Asphyxia CORE ${VERSION} | Modules: ${external.modules.length}`;
|
||||
if (external.modules.length <= 0) {
|
||||
@@ -38,13 +44,41 @@ if (external.modules.length <= 0) {
|
||||
Logger.info('');
|
||||
}
|
||||
|
||||
// ========== EAMUSE ============
|
||||
EAMUSE.use('*', services(`http://${ARGS.bind}:${ARGS.port}`, external.router));
|
||||
|
||||
// ========== WEB_UI ============
|
||||
WEBUI.get('/', async (req, res) => {
|
||||
res.send('hi');
|
||||
});
|
||||
|
||||
// ========== LISTEN ============
|
||||
const server = EAMUSE.listen(ARGS.port, ARGS.bind, () => {
|
||||
const serverInfo = `http://${ARGS.bind}:${ARGS.port}`;
|
||||
Logger.info(` +==========================================+`);
|
||||
Logger.info(` |${pad(serverInfo, 42)}|`);
|
||||
Logger.info(` +==========================================+`);
|
||||
const uiServer = WEBUI.listen(ARGS.ui_port, ARGS.ui_bind, () => {
|
||||
Logger.info(` [core] Server started:`);
|
||||
const serverInfo = `http://${ARGS.bind}:${ARGS.port}`;
|
||||
Logger.info(` +================== EAMUSE ================+`);
|
||||
Logger.info(` |${pad(serverInfo, 42)}|`);
|
||||
Logger.info(` +==========================================+`);
|
||||
Logger.info('');
|
||||
const webuiInfo = `http://${ARGS.ui_bind}:${ARGS.ui_port}`;
|
||||
Logger.info(` +================== WEB_UI ================+`);
|
||||
Logger.info(` |${pad(webuiInfo, 42)}|`);
|
||||
Logger.info(` +==========================================+`);
|
||||
});
|
||||
|
||||
uiServer.on('error', (err: any) => {
|
||||
if (err && err.code == 'EADDRINUSE') {
|
||||
Logger.info('WebUI failed to start: port might be in use.');
|
||||
Logger.info('Use -uip argument to change port.');
|
||||
}
|
||||
Logger.info(' ');
|
||||
Logger.error(` ${err.message}`);
|
||||
Logger.info(' ');
|
||||
Logger.info('Press any key to exit.');
|
||||
process.stdin.resume();
|
||||
process.stdin.on('data', process.exit.bind(process, 0));
|
||||
});
|
||||
});
|
||||
|
||||
server.on('error', (err: any) => {
|
||||
|
||||
@@ -7,6 +7,10 @@ const ProfileCheck: {
|
||||
[key: string]: () => boolean;
|
||||
} = {};
|
||||
|
||||
export function AddProfileCheck(gameCode: string, handler: () => boolean) {
|
||||
if (!ProfileCheck[gameCode]) ProfileCheck[gameCode] = handler;
|
||||
}
|
||||
|
||||
cardmng.add('*', 'cardmng.inquire', async (info, data, send) => {
|
||||
const model: string = info.model;
|
||||
const modelCode = model.split(':')[0] || 'NUL';
|
||||
@@ -35,6 +39,5 @@ cardmng.add('*', 'cardmng.authpass', async (info, data, send) => {
|
||||
});
|
||||
|
||||
cardmng.add('*', 'cardmng.bindmodel', async (info, data, send) => {
|
||||
const dataID: string = getAttr(data, 'refid', 'DEADC0DEFEEDBEEF');
|
||||
await send.object({ '@attr': { dataid: dataID } });
|
||||
await send.object({ '@attr': { dataid: 'DEADC0DEFEEDBEEF' } });
|
||||
});
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
import { isNil } from 'lodash';
|
||||
|
||||
import { KBinEncoding } from '../utils/KBinJSON';
|
||||
import { KBinEncoding, KAttrMap } from '../utils/KBinJSON';
|
||||
import { EamuseInfo } from '../middlewares/EamuseMiddleware';
|
||||
import { GetCallerModule } from '../utils/EamuseIO';
|
||||
import { Logger } from '../utils/Logger';
|
||||
|
||||
export interface EamuseSendOption {
|
||||
status?: number;
|
||||
encoding?: KBinEncoding;
|
||||
rootName?: string;
|
||||
attr?: any;
|
||||
attr?: KAttrMap;
|
||||
}
|
||||
|
||||
export interface EamuseSend {
|
||||
sent: boolean;
|
||||
success: (options?: EamuseSendOption) => Promise<void>;
|
||||
deny: (options?: EamuseSendOption) => Promise<void>;
|
||||
status: (code: number, options?: EamuseSendOption) => Promise<void>;
|
||||
@@ -21,15 +24,20 @@ export interface EamuseSend {
|
||||
pugFile: (file: string, data?: any, options?: EamuseSendOption) => Promise<void>;
|
||||
}
|
||||
|
||||
export type EamuseModuleRoute = (req: EamuseInfo, data: any, send: EamuseSend) => Promise<any>;
|
||||
export type EamuseModuleRoute = (info: EamuseInfo, data: any, send: EamuseSend) => Promise<any>;
|
||||
|
||||
export class EamuseModuleContainer {
|
||||
private modules: {
|
||||
[key: string]: boolean | EamuseModuleRoute;
|
||||
};
|
||||
|
||||
private fallback: {
|
||||
[key: string]: EamuseModuleRoute;
|
||||
};
|
||||
|
||||
constructor() {
|
||||
this.modules = {};
|
||||
this.fallback = {};
|
||||
}
|
||||
|
||||
public add(gameCode: string, method: string): void;
|
||||
@@ -54,6 +62,19 @@ export class EamuseModuleContainer {
|
||||
|
||||
if (gameCode instanceof EamuseModuleContainer) {
|
||||
this.modules = { ...this.modules, ...gameCode.modules };
|
||||
this.fallback = { ...this.fallback, ...gameCode.fallback };
|
||||
}
|
||||
}
|
||||
|
||||
public unhandled(gameCode: string, handler?: EamuseModuleRoute) {
|
||||
const mod = GetCallerModule();
|
||||
if (typeof handler === 'function') {
|
||||
this.fallback[gameCode] = handler;
|
||||
} else {
|
||||
this.fallback[gameCode] = async (info, data, send) => {
|
||||
Logger.warn(`unhandled method ${info.module}.${info.method}`, { module: mod.name });
|
||||
send.deny();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,18 +89,22 @@ export class EamuseModuleContainer {
|
||||
let handler = this.modules[`${moduleName}.${method}`];
|
||||
if (isNil(handler)) handler = this.modules[`${gameCode}:${moduleName}.${method}`];
|
||||
if (isNil(handler)) {
|
||||
return await send.deny();
|
||||
if (this.fallback[gameCode]) {
|
||||
return this.fallback[gameCode](info, data, send);
|
||||
} else {
|
||||
return send.deny();
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof handler === 'boolean') {
|
||||
if (handler) {
|
||||
return await send.success();
|
||||
return send.success();
|
||||
} else {
|
||||
return await send.deny();
|
||||
return send.deny();
|
||||
}
|
||||
}
|
||||
|
||||
await handler(info, data, send);
|
||||
handler(info, data, send);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
12
src/eamuse/EamuseSend.ts
Normal file
12
src/eamuse/EamuseSend.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { EamuseSendOption } from './EamuseModuleContainer';
|
||||
|
||||
export class EamuseSend {
|
||||
success: (options?: EamuseSendOption) => Promise<void>;
|
||||
deny: (options?: EamuseSendOption) => Promise<void>;
|
||||
status: (code: number, options?: EamuseSendOption) => Promise<void>;
|
||||
object: (res: any, options?: EamuseSendOption) => Promise<void>;
|
||||
xml: (res: string, data?: any, options?: EamuseSendOption) => Promise<void>;
|
||||
pug: (res: string, data?: any, options?: EamuseSendOption) => Promise<void>;
|
||||
xmlFile: (file: string, data?: any, options?: EamuseSendOption) => Promise<void>;
|
||||
pugFile: (file: string, data?: any, options?: EamuseSendOption) => Promise<void>;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { EamuseModuleContainer, EamuseModuleRoute } from './EamuseModuleContainer';
|
||||
import { kitem, karray, kattr } from '../utils/KBinJSON';
|
||||
import { kitem, karray, kattr, dataToXML } from '../utils/KBinJSON';
|
||||
import path from 'path';
|
||||
import {
|
||||
getAttr,
|
||||
@@ -10,54 +10,61 @@ import {
|
||||
getContent,
|
||||
getElement,
|
||||
getElements,
|
||||
getFirst,
|
||||
getNumber,
|
||||
getNumbers,
|
||||
getStr,
|
||||
} from '../utils/KBinJSON';
|
||||
import fs from 'fs';
|
||||
import { Logger } from '../utils/Logger';
|
||||
import { ARGS } from '../utils/ArgParser';
|
||||
|
||||
var localPath = process.cwd();
|
||||
if ((process as any).pkg) {
|
||||
localPath = path.dirname(process.argv0);
|
||||
}
|
||||
import { KDataReader } from '../utils/KDataReader';
|
||||
import { ReadSave, MODULE_PATH, WriteSave, WriteFile, GetCallerModule } from '../utils/EamuseIO';
|
||||
import { readdirSync, existsSync } from 'fs';
|
||||
import { AddProfileCheck } from './Core/CardManager';
|
||||
|
||||
/* Exposing API */
|
||||
const $: any = global;
|
||||
const MODULE_ROUTER = new EamuseModuleContainer();
|
||||
$.MODULE_PATH = path.join(localPath, 'modules');
|
||||
|
||||
const tsconfig = path.join($.MODULE_PATH, 'tsconfig.json');
|
||||
const tsconfig = path.join(MODULE_PATH, 'tsconfig.json');
|
||||
/* ncc/pkg hack */
|
||||
// require('typescript');
|
||||
const ts_node = require('ts-node');
|
||||
if (fs.existsSync(tsconfig)) {
|
||||
if (existsSync(tsconfig)) {
|
||||
/* Inject ts-node */
|
||||
ts_node.register({ project: tsconfig });
|
||||
} else {
|
||||
ts_node.register();
|
||||
}
|
||||
|
||||
$.RegisterRoute = (gameCode: string, method: string, handler: EamuseModuleRoute | boolean) => {
|
||||
if (gameCode === '*') return;
|
||||
MODULE_ROUTER.add(gameCode, method, handler);
|
||||
$.R = {
|
||||
Route: (gameCode: string, method: string, handler: EamuseModuleRoute | boolean) => {
|
||||
if (gameCode === '*') return;
|
||||
MODULE_ROUTER.add(gameCode, method, handler);
|
||||
},
|
||||
Unhandled: (gameCode: string, handler?: EamuseModuleRoute) => {
|
||||
if (gameCode === '*') return;
|
||||
MODULE_ROUTER.unhandled(gameCode, handler);
|
||||
},
|
||||
ProfileCheck: (gameCode: string, handler: () => boolean) => {
|
||||
if (gameCode === '*') return;
|
||||
AddProfileCheck(gameCode, handler);
|
||||
},
|
||||
};
|
||||
$.$ = {
|
||||
ATTR: getAttr,
|
||||
BIGINT: getBigInt,
|
||||
BIGINTS: getBigInts,
|
||||
BOOL: getBool,
|
||||
BUFFER: getBuffer,
|
||||
CONTENT: getContent,
|
||||
ELEMENT: getElement,
|
||||
ELEMENTS: getElements,
|
||||
FIRST: getFirst,
|
||||
NUMBER: getNumber,
|
||||
NUMBERS: getNumbers,
|
||||
STR: getStr,
|
||||
$.$ = (data: any) => {
|
||||
return new KDataReader(data);
|
||||
};
|
||||
$.$.ATTR = getAttr;
|
||||
$.$.BIGINT = getBigInt;
|
||||
$.$.BIGINTS = getBigInts;
|
||||
$.$.BOOL = getBool;
|
||||
$.$.BUFFER = getBuffer;
|
||||
$.$.CONTENT = getContent;
|
||||
$.$.ELEMENT = getElement;
|
||||
$.$.ELEMENTS = getElements;
|
||||
$.$.NUMBER = getNumber;
|
||||
$.$.NUMBERS = getNumbers;
|
||||
$.$.STR = getStr;
|
||||
$.$.toXML = dataToXML;
|
||||
|
||||
$.K = {
|
||||
ATTR: kattr,
|
||||
@@ -65,44 +72,94 @@ $.K = {
|
||||
ARRAY: karray,
|
||||
};
|
||||
|
||||
$.IO = {
|
||||
ReadSave,
|
||||
WriteSave,
|
||||
WriteFile,
|
||||
};
|
||||
|
||||
if (!ARGS.dev) {
|
||||
$.console.log = () => {};
|
||||
$.console.warn = () => {};
|
||||
$.console.error = () => {};
|
||||
$.console.debug = () => {};
|
||||
$.console.info = () => {};
|
||||
} else {
|
||||
$.console.log = (...msgs: any[]) => {
|
||||
const mod = GetCallerModule();
|
||||
if (mod) {
|
||||
Logger.info(msgs.join(' '), { module: mod.name });
|
||||
} else {
|
||||
Logger.info(msgs.join(' '));
|
||||
}
|
||||
};
|
||||
$.console.debug = $.console.log;
|
||||
$.console.info = $.console.log;
|
||||
$.console.warn = (...msgs: any[]) => {
|
||||
const mod = GetCallerModule();
|
||||
if (mod) {
|
||||
Logger.warn(msgs.join(' '), { module: mod.name });
|
||||
} else {
|
||||
Logger.warn(msgs.join(' '));
|
||||
}
|
||||
};
|
||||
$.console.error = (...msgs: any[]) => {
|
||||
const mod = GetCallerModule();
|
||||
if (mod) {
|
||||
Logger.error(msgs.join(' '), { module: mod.name });
|
||||
} else {
|
||||
Logger.error(msgs.join(' '));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function LoadExternalModules() {
|
||||
const loadedModules = [];
|
||||
try {
|
||||
const modules = fs.readdirSync($.MODULE_PATH);
|
||||
const modules = readdirSync(MODULE_PATH);
|
||||
for (const mod of modules) {
|
||||
const modulePath = path.join(localPath, 'modules', mod);
|
||||
const modulePath = path.resolve(MODULE_PATH, mod);
|
||||
const moduleExt = path.extname(modulePath);
|
||||
|
||||
if (
|
||||
modulePath.endsWith('.d.ts') ||
|
||||
mod.startsWith('_') ||
|
||||
mod.startsWith('core') ||
|
||||
mod == 'node_modules' ||
|
||||
(moduleExt !== '' && moduleExt !== '.ts' && moduleExt !== '.js')
|
||||
)
|
||||
continue;
|
||||
|
||||
try {
|
||||
this.instance = require(modulePath);
|
||||
if (this.instance && this.instance.default != null) {
|
||||
this.instance = this.instance.default;
|
||||
let instance = require(modulePath);
|
||||
if (instance && instance.default != null) {
|
||||
instance = instance.default;
|
||||
}
|
||||
|
||||
this.instance.register();
|
||||
loadedModules.push(path.basename(mod));
|
||||
loadedModules.push({ name: path.basename(mod), instance });
|
||||
} catch (err) {
|
||||
Logger.error(`failed to load module "${mod}"`);
|
||||
Logger.error(`failed to load`, { module: mod });
|
||||
Logger.error(err);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
||||
for (const loaded of loadedModules) {
|
||||
try {
|
||||
loaded.instance.register();
|
||||
} catch (err) {
|
||||
Logger.error(`${err}`, { module: loaded.name });
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
Logger.warn(`can not find "modules" directory.`);
|
||||
Logger.warn(`make sure your modules are installed under: ${path.join(localPath, 'modules')}`);
|
||||
Logger.warn(`make sure your modules are installed under: ${MODULE_PATH}`);
|
||||
}
|
||||
|
||||
/* Disable route registering after external module has been loaded */
|
||||
for (const prop in $.R) {
|
||||
$.R[prop] = () => {};
|
||||
}
|
||||
|
||||
return {
|
||||
modules: loadedModules,
|
||||
router: MODULE_ROUTER,
|
||||
|
||||
@@ -30,7 +30,7 @@ export const services = (url: string, modules: EamuseModuleContainer) => {
|
||||
];
|
||||
|
||||
/* General Information */
|
||||
routeEamuse.use(EamuseMiddleware).all('/', EamuseRoute(rootEA));
|
||||
routeEamuse.use(EamuseMiddleware).all('*', EamuseRoute(rootEA));
|
||||
|
||||
/* - Service */
|
||||
rootEA.add('*', 'services.get', async (info, data, send) => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import path from 'path';
|
||||
import { render as ejs, renderFile as ejsFile } from 'ejs';
|
||||
import { render as pug, renderFile as pugFile } from 'pug';
|
||||
import getCallerFile from 'get-caller-file';
|
||||
|
||||
import { RequestHandler } from 'express';
|
||||
import { findKey, get, has, defaultTo, set } from 'lodash';
|
||||
@@ -11,8 +10,11 @@ import { KonmaiEncrypt } from '../utils/KonmaiEncrypt';
|
||||
import LzKN from '../utils/LzKN';
|
||||
import { Logger } from '../utils/Logger';
|
||||
import { EamuseSendOption, EamuseModuleContainer } from '../eamuse/EamuseModuleContainer';
|
||||
import { GetCallerModule, MODULE_PATH } from '../utils/EamuseIO';
|
||||
import { ARGS } from '../utils/ArgParser';
|
||||
import { toHiraganaCase } from 'encoding-japanese';
|
||||
|
||||
const ACCEPT_AGENTS = ['EAMUSE.XRPC/1.0', 'EAMUSE.Httpac/1.0'];
|
||||
// const ACCEPT_AGENTS = ['EAMUSE.XRPC/1.0', 'EAMUSE.Httpac/1.0'];
|
||||
|
||||
export interface EABody {
|
||||
data: object;
|
||||
@@ -34,12 +36,19 @@ export const EamuseMiddleware: RequestHandler = async (req, res, next) => {
|
||||
res.set('X-Powered-By', 'Asphyxia');
|
||||
|
||||
const agent = req.headers['user-agent'];
|
||||
if (ACCEPT_AGENTS.indexOf(agent) < 0) {
|
||||
Logger.debug(`EAM: Unsupported agent: ${agent}`);
|
||||
res.sendStatus(404);
|
||||
|
||||
if (agent.indexOf('Mozilla') >= 0) {
|
||||
// Skip browser
|
||||
res.redirect(`http://${ARGS.ui_bind}:${ARGS.ui_port}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// if (ACCEPT_AGENTS.indexOf(agent) < 0) {
|
||||
// Logger.debug(`EAM: Unsupported agent: ${agent}`);
|
||||
// res.sendStatus(404);
|
||||
// return;
|
||||
// }
|
||||
|
||||
const eamuseInfo = req.headers['x-eamuse-info'];
|
||||
|
||||
let compress = req.headers['x-compress'];
|
||||
@@ -55,7 +64,7 @@ export const EamuseMiddleware: RequestHandler = async (req, res, next) => {
|
||||
});
|
||||
|
||||
req.on('end', () => {
|
||||
Logger.debug(req.url);
|
||||
// Logger.debug(req.url);
|
||||
const data = Buffer.concat(chunks);
|
||||
if (!data) {
|
||||
Logger.debug(`EAM: No Data`);
|
||||
@@ -119,6 +128,11 @@ export const EamuseRoute = (container: EamuseModuleContainer): RequestHandler =>
|
||||
const body = req.body as EABody;
|
||||
|
||||
const sendObject = async (content: any = {}, options: EamuseSendOption = {}) => {
|
||||
if ((this as any).sent) {
|
||||
return;
|
||||
} else {
|
||||
(this as any).sent = true;
|
||||
}
|
||||
const encoding = defaultTo(options.encoding, 'SHIFT_JIS');
|
||||
const attr = defaultTo(options.attr, {});
|
||||
const status = defaultTo(options.status, 0);
|
||||
@@ -157,36 +171,80 @@ export const EamuseRoute = (container: EamuseModuleContainer): RequestHandler =>
|
||||
};
|
||||
|
||||
const sendXml = async (template: string, data?: any, options?: EamuseSendOption) => {
|
||||
return sendObject(xmlToData(ejs(template, data)), options);
|
||||
const mod = GetCallerModule();
|
||||
if (!mod) {
|
||||
Logger.error(`unexpected error: unknown module`);
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = xmlToData(ejs(template, data));
|
||||
return sendObject(result, options);
|
||||
} catch (err) {
|
||||
Logger.error(err, { module: mod.name });
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
};
|
||||
|
||||
const sendPug = async (template: string, data?: any, options?: EamuseSendOption) => {
|
||||
return sendObject(xmlToData(pug(template, data)), options);
|
||||
const mod = GetCallerModule();
|
||||
if (!mod) {
|
||||
Logger.error(`unexpected error: unknown module`);
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = xmlToData(pug(template, data));
|
||||
return sendObject(result, options);
|
||||
} catch (err) {
|
||||
Logger.error(err, { module: mod.name });
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
};
|
||||
|
||||
const sendXmlFile = async (template: string, data?: any, options?: EamuseSendOption) => {
|
||||
const caller = getCallerFile();
|
||||
const callerPath = path.dirname(caller);
|
||||
const callerFile = path.basename(caller);
|
||||
if (callerPath.endsWith('modules')) {
|
||||
Logger.error(`[${callerFile}] Cannot render file templates from single-file modules`);
|
||||
const mod = GetCallerModule();
|
||||
if (!mod) {
|
||||
Logger.error(`unexpected error: unknown module`);
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
|
||||
if (mod.single) {
|
||||
Logger.error(`cannot render file templates from single-file modules`, { module: mod.name });
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
|
||||
try {
|
||||
const xml = await ejsFile(path.join(MODULE_PATH, mod.name, template), data, {});
|
||||
const result = xmlToData(xml);
|
||||
return sendObject(result, options);
|
||||
} catch (err) {
|
||||
Logger.error(err, { module: mod.name });
|
||||
return sendObject({}, { status: 1 });
|
||||
} else {
|
||||
return sendObject(xmlToData(ejsFile(path.join(callerPath, template), data)), options);
|
||||
}
|
||||
};
|
||||
|
||||
const sendPugFile = async (template: string, data?: any, options?: EamuseSendOption) => {
|
||||
const caller = getCallerFile();
|
||||
const callerPath = path.dirname(caller);
|
||||
const callerFile = path.basename(caller);
|
||||
if (callerPath.endsWith('modules')) {
|
||||
Logger.error(`[${callerFile}] Cannot render file templates from single-file modules`);
|
||||
const mod = GetCallerModule();
|
||||
if (!mod) {
|
||||
Logger.error(`unexpected error: unknown module`);
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
|
||||
if (mod.single) {
|
||||
Logger.error(`cannot render file templates from single-file modules`, { module: mod.name });
|
||||
return sendObject({}, { status: 1 });
|
||||
}
|
||||
|
||||
try {
|
||||
const result = xmlToData(pugFile(path.join(MODULE_PATH, mod.name, template), data));
|
||||
return sendObject(result, options);
|
||||
} catch (err) {
|
||||
Logger.error(err, { module: mod.name });
|
||||
return sendObject({}, { status: 1 });
|
||||
} else {
|
||||
return sendObject(xmlToData(pugFile(path.join(callerPath, template), data)), options);
|
||||
}
|
||||
};
|
||||
|
||||
const gameCode = body.model.split(':')[0];
|
||||
try {
|
||||
await container.run(
|
||||
@@ -196,6 +254,7 @@ export const EamuseRoute = (container: EamuseModuleContainer): RequestHandler =>
|
||||
{ module: body.module, method: body.method, model: body.model },
|
||||
get(body.data, `call.${body.module}`),
|
||||
{
|
||||
sent: false,
|
||||
success: options => sendObject(options),
|
||||
deny: options => sendObject({}, { ...options, status: 1 }),
|
||||
status: (status, options) => sendObject({}, { ...options, status }),
|
||||
@@ -207,9 +266,7 @@ export const EamuseRoute = (container: EamuseModuleContainer): RequestHandler =>
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
if ((process as any).pkg == null) {
|
||||
throw err;
|
||||
}
|
||||
Logger.error(err);
|
||||
await sendObject({}, { status: 1 });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,12 +13,29 @@ parser.addArgument(['-p', '--port'], {
|
||||
defaultValue: 8083,
|
||||
type: 'int',
|
||||
metavar: 'PORT',
|
||||
dest: 'port',
|
||||
});
|
||||
|
||||
parser.addArgument(['-b', '--bind'], {
|
||||
help: 'Hostname binding. In case you need to access it through LAN. (default: "localhost")',
|
||||
defaultValue: 'localhost',
|
||||
metavar: 'HOST',
|
||||
dest: 'bind',
|
||||
});
|
||||
|
||||
parser.addArgument(['-uip', '--webui-port'], {
|
||||
help: 'Set WebUI port. (default: 8084)',
|
||||
defaultValue: 8084,
|
||||
type: 'int',
|
||||
metavar: 'PORT',
|
||||
dest: 'ui_port',
|
||||
});
|
||||
|
||||
parser.addArgument(['-uib', '--webui-bind'], {
|
||||
help: 'WebUI Hostname binding. (default: "localhost")',
|
||||
defaultValue: 'localhost',
|
||||
metavar: 'HOST',
|
||||
dest: 'ui_bind',
|
||||
});
|
||||
|
||||
parser.addArgument(['-m', '--matching-port'], {
|
||||
@@ -29,6 +46,12 @@ parser.addArgument(['-m', '--matching-port'], {
|
||||
metavar: 'PORT',
|
||||
});
|
||||
|
||||
parser.addArgument(['-s', '--save-path'], {
|
||||
help: 'Set custom savedata directory',
|
||||
dest: 'save_path',
|
||||
metavar: 'PATH',
|
||||
});
|
||||
|
||||
parser.addArgument(['--console'], {
|
||||
help: 'Enable console for modules.',
|
||||
defaultValue: false,
|
||||
|
||||
@@ -1 +1 @@
|
||||
export const VERSION = 'v1.0 beta';
|
||||
export const VERSION = 'v1.02 beta';
|
||||
|
||||
@@ -1,7 +1,46 @@
|
||||
import { readFileSync, writeFileSync, existsSync } from 'fs';
|
||||
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
|
||||
|
||||
import { Logger } from './Logger';
|
||||
import { xmlToData, dataToXML } from './KBinJSON';
|
||||
import getCallerFile from 'get-caller-file';
|
||||
import path from 'path';
|
||||
import { ARGS } from './ArgParser';
|
||||
|
||||
export const EXEC_PATH = (process as any).pkg ? path.dirname(process.argv0) : process.cwd();
|
||||
export const MODULE_PATH = path.join(EXEC_PATH, 'modules');
|
||||
export const SAVE_PATH = ARGS.save_path || path.join(EXEC_PATH, 'savedata');
|
||||
|
||||
export function GetCallerModule(): { name: string; single: boolean } {
|
||||
const oldPrepareStackTrace = Error.prepareStackTrace;
|
||||
Error.prepareStackTrace = (_, stack) => stack;
|
||||
const stack = new Error().stack as any;
|
||||
Error.prepareStackTrace = oldPrepareStackTrace;
|
||||
if (stack !== null && typeof stack === 'object') {
|
||||
let inModule = false;
|
||||
let entryFile = null;
|
||||
for (const file of stack) {
|
||||
const filename: string = file.getFileName();
|
||||
if (filename.startsWith(MODULE_PATH)) {
|
||||
entryFile = path.relative(MODULE_PATH, filename);
|
||||
inModule = true;
|
||||
} else {
|
||||
if (inModule) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entryFile !== null) {
|
||||
const mod = entryFile.split(path.sep)[0];
|
||||
if (mod.endsWith('.js') || mod.endsWith('.ts')) {
|
||||
return { name: mod.substr(0, mod.length - 3), single: true };
|
||||
} else {
|
||||
return { name: mod, single: false };
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function ExistsFile(file: string): boolean {
|
||||
try {
|
||||
@@ -11,33 +50,59 @@ export function ExistsFile(file: string): boolean {
|
||||
}
|
||||
}
|
||||
|
||||
export function ReadFile(file: string): any {
|
||||
export function PrepareSaveDirectory(mod: string): string {
|
||||
const dir = path.join(SAVE_PATH, mod);
|
||||
|
||||
if (!existsSync(dir)) {
|
||||
mkdirSync(dir, { recursive: true });
|
||||
}
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
export function ReadSave(file: string): any {
|
||||
const mod = GetCallerModule();
|
||||
if (!mod) {
|
||||
Logger.error(`unknown module:`);
|
||||
Logger.error(new Error().stack);
|
||||
}
|
||||
|
||||
const dir = PrepareSaveDirectory(mod.name);
|
||||
const fullFile = path.join(dir, `${file}.json`);
|
||||
try {
|
||||
if (!existsSync(`${file}.json`)) {
|
||||
if (!existsSync(fullFile)) {
|
||||
return null;
|
||||
}
|
||||
const data = JSON.parse(
|
||||
readFileSync(`${file}.json`, {
|
||||
readFileSync(fullFile, {
|
||||
encoding: 'UTF-8',
|
||||
})
|
||||
);
|
||||
return data;
|
||||
} catch (err) {
|
||||
Logger.error(err);
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function WriteFile(file: string, data: any, formated = false) {
|
||||
export function WriteSave(file: string, data: any, formated = false) {
|
||||
const mod = GetCallerModule();
|
||||
if (!mod) {
|
||||
Logger.error(`unknown module:`);
|
||||
Logger.error(new Error().stack);
|
||||
}
|
||||
|
||||
const dir = PrepareSaveDirectory(mod.name);
|
||||
const fullFile = path.join(dir, `${file}.json`);
|
||||
try {
|
||||
if (formated) {
|
||||
writeFileSync(`${file}.json`, JSON.stringify(data, null, 4));
|
||||
writeFileSync(fullFile, JSON.stringify(data, null, 4));
|
||||
} else {
|
||||
writeFileSync(`${file}.json`, JSON.stringify(data));
|
||||
writeFileSync(fullFile, JSON.stringify(data));
|
||||
}
|
||||
Logger.info(`${file}.json Saved`);
|
||||
Logger.info(`${file}.json saved`, { module: mod.name });
|
||||
} catch (err) {
|
||||
Logger.error(err);
|
||||
Logger.error(`file writing failed: ${err}`, { module: mod.name });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,32 +124,58 @@ export function WriteFile(file: string, data: any, formated = false) {
|
||||
// }
|
||||
// }
|
||||
|
||||
export function ReadXML(file: string): any {
|
||||
// export function ReadXML(file: string): any {
|
||||
// try {
|
||||
// if (!existsSync(`${file}.xml`)) {
|
||||
// return null;
|
||||
// }
|
||||
// const data = xmlToData(readFileSync(`${file}.xml`));
|
||||
// return data;
|
||||
// } catch (err) {
|
||||
// Logger.error(err);
|
||||
// return false;
|
||||
// }
|
||||
// }
|
||||
|
||||
export function WriteFile(file: string, data: string) {
|
||||
const mod = GetCallerModule();
|
||||
if (!mod) return;
|
||||
|
||||
let target = file;
|
||||
if (!path.isAbsolute(file)) {
|
||||
target = path.resolve(MODULE_PATH, mod.name, file);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!existsSync(`${file}.xml`)) {
|
||||
writeFileSync(target, data);
|
||||
} catch (err) {
|
||||
Logger.error(`file writing failed: ${err}`, { module: mod });
|
||||
}
|
||||
}
|
||||
|
||||
// export function PrintXML(data: any) {
|
||||
// try {
|
||||
// Logger.info(dataToXML(data));
|
||||
// } catch (err) {
|
||||
// Logger.error(err);
|
||||
// }
|
||||
// }
|
||||
|
||||
export function ReadAssets(file: string): any {
|
||||
let fullFile = path.join(__dirname, 'assets', `${file}`);
|
||||
if (!(process as any).pkg) {
|
||||
fullFile = path.join('../../build-env/assets', `${file}`);
|
||||
}
|
||||
|
||||
try {
|
||||
if (!existsSync(fullFile)) {
|
||||
return null;
|
||||
}
|
||||
const data = xmlToData(readFileSync(`${file}.xml`));
|
||||
const data = readFileSync(fullFile, {
|
||||
encoding: 'UTF-8',
|
||||
});
|
||||
return data;
|
||||
} catch (err) {
|
||||
Logger.error(err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export function WriteXML(file: string, data: any) {
|
||||
try {
|
||||
writeFileSync(`${file}.xml`, dataToXML(data));
|
||||
Logger.info(`${file}.xml Saved`);
|
||||
} catch (err) {
|
||||
Logger.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
export function PrintXML(data: any) {
|
||||
try {
|
||||
Logger.info(dataToXML(data));
|
||||
} catch (err) {
|
||||
Logger.error(err);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import json2xml = xml2json.j2xParser;
|
||||
|
||||
import { BinaryLengthType, ReadBuffer, WriteBuffer } from './AutoBuffer';
|
||||
|
||||
export type KBinAttrMap = { [key: string]: number | string };
|
||||
export type KBinNumberType =
|
||||
export type KAttrMap = { [key: string]: string };
|
||||
export type KNumberType =
|
||||
| 's8'
|
||||
| 'u8'
|
||||
| 's16'
|
||||
@@ -18,8 +18,8 @@ export type KBinNumberType =
|
||||
| 'float'
|
||||
| 'double'
|
||||
| 'bool';
|
||||
export type KBinBigIntType = 's64' | 'u64';
|
||||
export type KBinNumberGroupType =
|
||||
export type KBigIntType = 's64' | 'u64';
|
||||
export type KNumberGroupType =
|
||||
| '2s8'
|
||||
| '2u8'
|
||||
| '2s16'
|
||||
@@ -48,7 +48,7 @@ export type KBinNumberGroupType =
|
||||
| '3b'
|
||||
| '4b'
|
||||
| 'vb';
|
||||
export type KBinBigIntGroupType =
|
||||
export type KBigIntGroupType =
|
||||
| '2s64'
|
||||
| '2u64'
|
||||
| '3s64'
|
||||
@@ -65,18 +65,18 @@ export type KBinControlIdentifier = 'invalid' | 'attr' | 'array' | 'void';
|
||||
export type KBinWriteableType =
|
||||
| 'bin'
|
||||
| 'str'
|
||||
| KBinNumberType
|
||||
| KBinNumberGroupType
|
||||
| KBinBigIntType
|
||||
| KBinBigIntGroupType;
|
||||
| KNumberType
|
||||
| KNumberGroupType
|
||||
| KBigIntType
|
||||
| KBigIntGroupType;
|
||||
|
||||
export type KBinAllType =
|
||||
| 'bin'
|
||||
| 'str'
|
||||
| KBinNumberType
|
||||
| KBinNumberGroupType
|
||||
| KBinBigIntType
|
||||
| KBinBigIntGroupType
|
||||
| KNumberType
|
||||
| KNumberGroupType
|
||||
| KBigIntType
|
||||
| KBigIntGroupType
|
||||
| KBinControlIdentifier;
|
||||
|
||||
(BigInt.prototype as any).toJSON = function (this: bigint): string {
|
||||
@@ -166,18 +166,13 @@ function dataSizeOf(str: string): number {
|
||||
return 1;
|
||||
}
|
||||
|
||||
const XML_TYPES: { [key: string]: number } = {
|
||||
'void': 1,
|
||||
const NUMBER_TYPES: { [key: string]: number } = {
|
||||
's8': 2,
|
||||
'u8': 3,
|
||||
's16': 4,
|
||||
'u16': 5,
|
||||
's32': 6,
|
||||
'u32': 7,
|
||||
's64': 8,
|
||||
'u64': 9,
|
||||
'bin': 10,
|
||||
'str': 11,
|
||||
'ip4': 12,
|
||||
'time': 13,
|
||||
'float': 14,
|
||||
@@ -188,8 +183,6 @@ const XML_TYPES: { [key: string]: number } = {
|
||||
'2u16': 19,
|
||||
'2s32': 20,
|
||||
'2u32': 21,
|
||||
'2s64': 22,
|
||||
'2u64': 23,
|
||||
'2f': 24,
|
||||
'2d': 25,
|
||||
'3s8': 26,
|
||||
@@ -198,8 +191,6 @@ const XML_TYPES: { [key: string]: number } = {
|
||||
'3u16': 29,
|
||||
'3s32': 30,
|
||||
'3u32': 31,
|
||||
'3s64': 32,
|
||||
'3u64': 33,
|
||||
'3f': 34,
|
||||
'3d': 35,
|
||||
'4s8': 36,
|
||||
@@ -208,12 +199,8 @@ const XML_TYPES: { [key: string]: number } = {
|
||||
'4u16': 39,
|
||||
'4s32': 40,
|
||||
'4u32': 41,
|
||||
'4s64': 42,
|
||||
'4u64': 43,
|
||||
'4f': 44,
|
||||
'4d': 45,
|
||||
'attr': 46,
|
||||
'array': 47,
|
||||
'vs8': 48,
|
||||
'vu8': 49,
|
||||
'vs16': 50,
|
||||
@@ -223,19 +210,40 @@ const XML_TYPES: { [key: string]: number } = {
|
||||
'3b': 54,
|
||||
'4b': 55,
|
||||
'vb': 56,
|
||||
'binary': 10,
|
||||
'string': 11,
|
||||
'f': 14,
|
||||
'd': 15,
|
||||
'vs64': 22,
|
||||
'vu64': 23,
|
||||
'vs32': 40,
|
||||
'vu32': 41,
|
||||
'vf': 44,
|
||||
'b': 52,
|
||||
'nodeEnd': 190,
|
||||
'endSection': 191,
|
||||
'nodeStart': 1,
|
||||
};
|
||||
|
||||
const BIGINT_TYPES: { [key: string]: number } = {
|
||||
's64': 8,
|
||||
'u64': 9,
|
||||
'2s64': 22,
|
||||
'2u64': 23,
|
||||
'3s64': 32,
|
||||
'3u64': 33,
|
||||
'4s64': 42,
|
||||
'4u64': 43,
|
||||
'vs64': 22,
|
||||
'vu64': 23,
|
||||
};
|
||||
|
||||
const XML_TYPES: { [key: string]: number } = {
|
||||
...NUMBER_TYPES,
|
||||
...BIGINT_TYPES,
|
||||
void: 1,
|
||||
bin: 10,
|
||||
str: 11,
|
||||
attr: 46,
|
||||
array: 47,
|
||||
binary: 10,
|
||||
string: 11,
|
||||
nodeEnd: 190,
|
||||
endSection: 191,
|
||||
nodeStart: 1,
|
||||
};
|
||||
|
||||
const BIN_ENCODING = 'SHIFT_JIS';
|
||||
@@ -410,7 +418,14 @@ function bufferToString(data: Buffer, encoding: string): string {
|
||||
return '';
|
||||
}
|
||||
const str = codeToString(convert(data, JOBJ_ENCODING, ENC_JP_MAP[encoding]));
|
||||
return str.substr(0, str.length - 1);
|
||||
const result = str.substr(0, str.length - 1);
|
||||
if (result.length == 16) {
|
||||
const hex_checker = /^[0-9a-fA-F]+$/;
|
||||
if (hex_checker.test(result)) {
|
||||
return 'DEADC0DEFEEDBEEF';
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function nodeToBinary(
|
||||
@@ -827,17 +842,18 @@ export function xmlToData(xml: string | Buffer): any {
|
||||
return data;
|
||||
}
|
||||
|
||||
export function kitem(type: 'str', content: string, attr?: KBinAttrMap): any;
|
||||
export function kitem(type: 'bin', content: Buffer, attr?: KBinAttrMap): any;
|
||||
export function kitem(type: 'ip4', content: string, attr?: KBinAttrMap): any;
|
||||
export function kitem(type: KBinNumberType, content: number, attr?: KBinAttrMap): any;
|
||||
export function kitem(type: KBinBigIntType, content: bigint, attr?: KBinAttrMap): any;
|
||||
export function kitem(type: KBinNumberGroupType, content: number[], attr?: KBinAttrMap): any;
|
||||
export function kitem(type: KBinBigIntGroupType, content: bigint[], attr?: KBinAttrMap): any;
|
||||
export function kitem(type: 'str', content: string, attr?: KAttrMap): any;
|
||||
export function kitem(type: 'bin', content: Buffer, attr?: KAttrMap): any;
|
||||
export function kitem(type: 'ip4', content: string, attr?: KAttrMap): any;
|
||||
export function kitem(type: 'bool', content: boolean, attr?: KAttrMap): any;
|
||||
export function kitem(type: KNumberType, content: number, attr?: KAttrMap): any;
|
||||
export function kitem(type: KBigIntType, content: bigint, attr?: KAttrMap): any;
|
||||
export function kitem(type: KNumberGroupType, content: number[], attr?: KAttrMap): any;
|
||||
export function kitem(type: KBigIntGroupType, content: bigint[], attr?: KAttrMap): any;
|
||||
export function kitem(
|
||||
type: KBinWriteableType,
|
||||
content: string | number | bigint | object,
|
||||
attr?: KBinAttrMap
|
||||
content: string | boolean | number | bigint | object,
|
||||
attr?: KAttrMap
|
||||
): any {
|
||||
if (!attr) {
|
||||
attr = {};
|
||||
@@ -853,6 +869,10 @@ export function kitem(
|
||||
contentObj = [contentObj];
|
||||
}
|
||||
|
||||
if (typeof contentObj === 'boolean') {
|
||||
contentObj = [contentObj ? 1 : 0];
|
||||
}
|
||||
|
||||
const attrObj = {
|
||||
__type: type,
|
||||
...attr,
|
||||
@@ -864,19 +884,20 @@ export function kitem(
|
||||
};
|
||||
}
|
||||
|
||||
export function kattr(attr: KBinAttrMap) {
|
||||
export function kattr(attr: KAttrMap, inner?: any) {
|
||||
return {
|
||||
...inner,
|
||||
'@attr': attr,
|
||||
};
|
||||
}
|
||||
|
||||
export function karray(type: 'u8' | 's8', content: Buffer, attr?: KBinAttrMap): any;
|
||||
export function karray(type: KBinNumberType, content: number[], attr?: KBinAttrMap): any;
|
||||
export function karray(type: KBinBigIntType, content: bigint[], attr?: KBinAttrMap): any;
|
||||
export function karray(type: 'u8' | 's8', content: Buffer, attr?: KAttrMap): any;
|
||||
export function karray(type: KNumberType, content: number[], attr?: KAttrMap): any;
|
||||
export function karray(type: KBigIntType, content: bigint[], attr?: KAttrMap): any;
|
||||
export function karray(
|
||||
type: KBinNumberType | KBinBigIntType,
|
||||
type: KNumberType | KBigIntType,
|
||||
content: number[] | bigint[] | Buffer,
|
||||
attr?: KBinAttrMap
|
||||
attr?: KAttrMap
|
||||
): any {
|
||||
let value = content as any;
|
||||
if (typeof value == 'bigint' || typeof value == 'number') {
|
||||
@@ -899,58 +920,83 @@ export function karray(
|
||||
return item;
|
||||
}
|
||||
|
||||
export function simplify(data: any) {}
|
||||
// export function simplify(data: any) {}
|
||||
|
||||
export const getFirst = (data: any, path: string, def?: any): any => {
|
||||
return get(data, `${path}.@content.0`, def);
|
||||
};
|
||||
|
||||
export const getNumber = (data: any, path: string, def?: number): number => {
|
||||
let value = get(data, `${path}.@content`);
|
||||
export const getNumber = (data: any, path?: string, def?: number): number => {
|
||||
let value = get(data, path ? `${path}.@content` : '@content');
|
||||
let result = NaN;
|
||||
if (typeof value == 'string') {
|
||||
result = Number(value);
|
||||
} else {
|
||||
result = Number(get(data, `${path}.@content.0`, def));
|
||||
result = Number(get(data, path ? `${path}.@content.0` : `@content.0`, def));
|
||||
}
|
||||
|
||||
if (result == NaN) {
|
||||
if (isNaN(result)) {
|
||||
return def;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
export const getBool = (data: any, path: string): boolean => {
|
||||
return getNumber(data, `${path}.@content.0`, 0) > 0;
|
||||
export const getBool = (data: any, path?: string): boolean => {
|
||||
return getNumber(data, path, 0) > 0;
|
||||
};
|
||||
|
||||
export const getBigInt = (data: any, path: string, def?: bigint): bigint => {
|
||||
let value = get(data, `${path}.@content`, def);
|
||||
export const getBigInt = (data: any, path?: string, def?: bigint): bigint => {
|
||||
let value = get(data, path ? `${path}.@content` : '@content', def);
|
||||
try {
|
||||
if (typeof value == 'string') {
|
||||
return BigInt(value);
|
||||
}
|
||||
return BigInt(get(data, `${path}.@content.0`, def));
|
||||
return BigInt(get(data, path ? `${path}.@content.0` : `@content.0`, def));
|
||||
} catch (_) {
|
||||
return def;
|
||||
}
|
||||
};
|
||||
|
||||
export const getContent = (data: any, path: string, def?: any): any => {
|
||||
return get(data, `${path}.@content`, def);
|
||||
export const getContent = (data: any, path?: string, def?: any): any => {
|
||||
return get(data, path ? `${path}.@content` : `@content`, def);
|
||||
};
|
||||
|
||||
export const getNumbers: (data: any, path: string, def?: number[]) => number[] = getContent;
|
||||
export const getBigInts: (data: any, path: string, def?: bigint[]) => bigint[] = getContent;
|
||||
export const getStr: (data: any, path: string, def?: string) => string = getContent;
|
||||
export const getBuffer: (data: any, path: string, def?: Buffer) => Buffer = getContent;
|
||||
|
||||
export const getAttr = (data: any, field: string, def?: string | number): string => {
|
||||
return toString(get(data, `@attr.${field}`, def));
|
||||
export const getNumbers = (data: any, path?: string, def?: number[]): number[] => {
|
||||
const type = get(data, path ? `${path}.@attr.__type` : `@attr.__type`, 'void');
|
||||
if (!NUMBER_TYPES[type]) {
|
||||
return def;
|
||||
}
|
||||
return getContent(data, path, def);
|
||||
};
|
||||
export const getBigInts = (data: any, path?: string, def?: bigint[]): bigint[] => {
|
||||
const type = get(data, path ? `${path}.@attr.__type` : `@attr.__type`, 'void');
|
||||
if (!BIGINT_TYPES[type]) {
|
||||
return def;
|
||||
}
|
||||
return getContent(data, path, def);
|
||||
};
|
||||
export const getStr = (data: any, path?: string, def?: string): string => {
|
||||
const type = get(data, path ? `${path}.@attr.__type` : `@attr.__type`, 'void');
|
||||
if (type !== 'string' && type !== 'str') {
|
||||
return def;
|
||||
}
|
||||
return getContent(data, path, def);
|
||||
};
|
||||
|
||||
export const getElement = (data: any, path: string): any[] => {
|
||||
const item: any = get(data, `${path}`, {});
|
||||
export const getBuffer = (data: any, path?: string, def?: Buffer): Buffer => {
|
||||
const type = get(data, path ? `${path}.@attr.__type` : `@attr.__type`, 'void');
|
||||
if (type !== 'bin' && type !== 'binary') {
|
||||
return def;
|
||||
}
|
||||
return getContent(data, path, def);
|
||||
};
|
||||
|
||||
export const getAttr = (data: any, path?: string): { [key: string]: string } => {
|
||||
if (!path) {
|
||||
return get(data, `@attr`, {});
|
||||
}
|
||||
return get(data, `${path}.@attr`, {});
|
||||
};
|
||||
|
||||
export const getElement = (data: any, path: string): any => {
|
||||
const item: any = get(data, `${path}`);
|
||||
if (isNil(item)) return item;
|
||||
if (isArray(item)) {
|
||||
return item[0];
|
||||
}
|
||||
@@ -958,11 +1004,11 @@ export const getElement = (data: any, path: string): any[] => {
|
||||
};
|
||||
|
||||
export const getElements = (data: any, path: string): any[] => {
|
||||
const item: any = get(data, `${path}`, []);
|
||||
const item: any = get(data, `${path}`);
|
||||
if (isNil(item)) return item;
|
||||
if (isEmpty(item)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (isArray(item)) {
|
||||
return item;
|
||||
} else {
|
||||
|
||||
69
src/utils/KDataReader.ts
Normal file
69
src/utils/KDataReader.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { isNil } from 'lodash';
|
||||
import {
|
||||
getAttr,
|
||||
getBigInt,
|
||||
getBigInts,
|
||||
getBool,
|
||||
getBuffer,
|
||||
getContent,
|
||||
getElement,
|
||||
getElements,
|
||||
getNumber,
|
||||
getNumbers,
|
||||
getStr,
|
||||
} from './KBinJSON';
|
||||
|
||||
export class KDataReader {
|
||||
public obj: any = null;
|
||||
constructor(obj: any) {
|
||||
this.obj = obj;
|
||||
}
|
||||
|
||||
attr(path?: string) {
|
||||
return getAttr(this.obj, path);
|
||||
}
|
||||
|
||||
bigint(path: string, def?: bigint): bigint {
|
||||
return getBigInt(this.obj, path, def);
|
||||
}
|
||||
|
||||
bigints(path: string, def?: bigint[]): bigint[] {
|
||||
return getBigInts(this.obj, path, def);
|
||||
}
|
||||
|
||||
bool(path: string): boolean {
|
||||
return getBool(this.obj, path);
|
||||
}
|
||||
|
||||
buffer(path: string, def?: Buffer): Buffer {
|
||||
return getBuffer(this.obj, path, def);
|
||||
}
|
||||
|
||||
content(path: string, def?: any): any {
|
||||
return getContent(this.obj, path, def);
|
||||
}
|
||||
|
||||
element(path: string): KDataReader {
|
||||
const ele = getElement(this.obj, path);
|
||||
if (isNil(ele)) return null;
|
||||
return new KDataReader(ele);
|
||||
}
|
||||
|
||||
elements(path: string): KDataReader[] {
|
||||
const ele = getElements(this.obj, path);
|
||||
if (isNil(ele)) return null;
|
||||
return ele.map(e => new KDataReader(e));
|
||||
}
|
||||
|
||||
number(path: string, def?: number): number {
|
||||
return getNumber(this.obj, path, def);
|
||||
}
|
||||
|
||||
numbers(path: string, def?: number[]): number[] {
|
||||
return getNumbers(this.obj, path, def);
|
||||
}
|
||||
|
||||
str(path: string, def?: string): string {
|
||||
return getStr(this.obj, path, def);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,25 @@
|
||||
import winston from 'winston';
|
||||
import chalk from 'chalk';
|
||||
|
||||
const isDebug = (process as any).pkg == null;
|
||||
|
||||
export const Logger = winston.createLogger({
|
||||
level: isDebug ? 'debug' : 'info',
|
||||
format: winston.format.printf(info => {
|
||||
if (info.level !== 'info') {
|
||||
return `${info.level}: ${info.message}`;
|
||||
} else {
|
||||
return `${info.message}`;
|
||||
}
|
||||
}),
|
||||
defaultMeta: { service: 'eamuse' },
|
||||
format: winston.format.combine(
|
||||
winston.format.colorize(),
|
||||
winston.format.printf(info => {
|
||||
const module =
|
||||
info.module == 'core' ? chalk.cyanBright('core') : chalk.yellowBright(info.module);
|
||||
if (info.level.indexOf('info') < 0) {
|
||||
return ` [${module}] ${info.level}: ${info.message}`;
|
||||
} else {
|
||||
if (info.module == 'core') {
|
||||
return `${info.message}`;
|
||||
}
|
||||
return ` [${module}] ${info.message}`;
|
||||
}
|
||||
})
|
||||
),
|
||||
defaultMeta: { module: 'core' },
|
||||
transports: [
|
||||
new winston.transports.Console({
|
||||
stderrLevels: ['error'],
|
||||
|
||||
42
src/utils/Systray.ts
Normal file
42
src/utils/Systray.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import SysTray from 'systray';
|
||||
import { ReadAssets } from './EamuseIO';
|
||||
import opn from 'open';
|
||||
import { VERSION } from './Consts';
|
||||
|
||||
export function CreateTray() {
|
||||
if (process.platform === 'win32') {
|
||||
const systray = new SysTray({
|
||||
menu: {
|
||||
// you should using .png icon in macOS/Linux, but .ico format in windows
|
||||
icon: ReadAssets('icon.b64'),
|
||||
title: 'Asphyxia CORE',
|
||||
tooltip: `Asphyxia CORE ${VERSION}`,
|
||||
items: [
|
||||
{
|
||||
title: 'Config',
|
||||
tooltip: 'Open WebUI',
|
||||
checked: false,
|
||||
enabled: true,
|
||||
},
|
||||
{
|
||||
title: 'Exit',
|
||||
tooltip: 'Exit CORE',
|
||||
checked: false,
|
||||
enabled: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
debug: false,
|
||||
copyDir: true,
|
||||
});
|
||||
|
||||
systray.onClick(action => {
|
||||
if (action.seq_id === 0) {
|
||||
opn('http://localhost:8083');
|
||||
} else if (action.seq_id === 1) {
|
||||
systray.kill();
|
||||
systray.writeLine;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"declaration": true,
|
||||
"declarationDir": "typings",
|
||||
"outDir": "dist"
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
|
||||
Reference in New Issue
Block a user