Rewrite in typescrypt #327

Merged
Sirherobrine23 merged 13 commits from re_Typescript into main 2022-03-28 21:43:14 +00:00
9 changed files with 691 additions and 24 deletions
Showing only changes of commit 0e0218f8b6 - Show all commits

448
package-lock.json generated
View File

@ -19,14 +19,17 @@
"axios": "^0.26.1", "axios": "^0.26.1",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.17.3", "express": "^4.17.3",
"typescript": "^4.6.2" "typescript": "^4.6.2",
"yargs": "^17.4.0"
}, },
"bin": { "bin": {
"bds_maneger": "bin/BdsManeger.js" "bds_maneger": "bin/BdsManeger.js"
}, },
"devDependencies": { "devDependencies": {
"@types/adm-zip": "^0.4.34", "@types/adm-zip": "^0.4.34",
"@types/express": "^4.17.13",
"@types/node": "^17.0.22", "@types/node": "^17.0.22",
"@types/yargs": "^17.0.10",
"npm-run-all": "^4.1.5" "npm-run-all": "^4.1.5"
}, },
"engines": { "engines": {
@ -42,12 +45,97 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"node_modules/@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
"integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==",
"dev": true,
"dependencies": {
"@types/connect": "*",
"@types/node": "*"
}
},
"node_modules/@types/connect": {
"version": "3.4.35",
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz",
"integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/express": {
"version": "4.17.13",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz",
"integrity": "sha512-6bSZTPaTIACxn48l50SR+axgrqm6qXFIxrdAKaG6PaJk3+zuUr35hBlgT7vOmJcum+OEaIBLtHV/qloEAFITeA==",
"dev": true,
"dependencies": {
"@types/body-parser": "*",
"@types/express-serve-static-core": "^4.17.18",
"@types/qs": "*",
"@types/serve-static": "*"
}
},
"node_modules/@types/express-serve-static-core": {
"version": "4.17.28",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz",
"integrity": "sha512-P1BJAEAW3E2DJUlkgq4tOL3RyMunoWXqbSCygWo5ZIWTjUgN1YnaXWW4VWl/oc8vs/XoYibEGBKP0uZyF4AHig==",
"dev": true,
"dependencies": {
"@types/node": "*",
"@types/qs": "*",
"@types/range-parser": "*"
}
},
"node_modules/@types/mime": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz",
"integrity": "sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==",
"dev": true
},
"node_modules/@types/node": { "node_modules/@types/node": {
"version": "17.0.22", "version": "17.0.22",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.22.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.22.tgz",
"integrity": "sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw==", "integrity": "sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw==",
"dev": true "dev": true
}, },
"node_modules/@types/qs": {
"version": "6.9.7",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz",
"integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==",
"dev": true
},
"node_modules/@types/range-parser": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz",
"integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==",
"dev": true
},
"node_modules/@types/serve-static": {
"version": "1.13.10",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.10.tgz",
"integrity": "sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ==",
"dev": true,
"dependencies": {
"@types/mime": "^1",
"@types/node": "*"
}
},
"node_modules/@types/yargs": {
"version": "17.0.10",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.10.tgz",
"integrity": "sha512-gmEaFwpj/7f/ROdtIlci1R1VYU1J4j95m8T+Tj3iBgiBFKg1foE/PSl93bBd5T9LDXNPo8UlNN6W0qwD8O5OaA==",
"dev": true,
"dependencies": {
"@types/yargs-parser": "*"
}
},
"node_modules/@types/yargs-parser": {
"version": "21.0.0",
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz",
"integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==",
"dev": true
},
"node_modules/accepts": { "node_modules/accepts": {
"version": "1.3.8", "version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
@ -68,6 +156,14 @@
"node": ">=6.0" "node": ">=6.0"
} }
}, },
"node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"engines": {
"node": ">=8"
}
},
"node_modules/ansi-styles": { "node_modules/ansi-styles": {
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
@ -164,6 +260,16 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/cliui": {
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
"integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==",
"dependencies": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.0",
"wrap-ansi": "^7.0.0"
}
},
"node_modules/color-convert": { "node_modules/color-convert": {
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
@ -283,6 +389,11 @@
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
}, },
"node_modules/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=="
},
"node_modules/encodeurl": { "node_modules/encodeurl": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
@ -351,6 +462,14 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==",
"engines": {
"node": ">=6"
}
},
"node_modules/escape-html": { "node_modules/escape-html": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
@ -471,6 +590,14 @@
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true "dev": true
}, },
"node_modules/get-caller-file": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==",
"engines": {
"node": "6.* || 8.* || >= 10.*"
}
},
"node_modules/get-intrinsic": { "node_modules/get-intrinsic": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
@ -696,6 +823,14 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/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==",
"engines": {
"node": ">=8"
}
},
"node_modules/is-negative-zero": { "node_modules/is-negative-zero": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz",
@ -1133,6 +1268,14 @@
"node": ">=4" "node": ">=4"
} }
}, },
"node_modules/require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=",
"engines": {
"node": ">=0.10.0"
}
},
"node_modules/resolve": { "node_modules/resolve": {
"version": "1.22.0", "version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
@ -1311,6 +1454,19 @@
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/string.prototype.padend": { "node_modules/string.prototype.padend": {
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/string.prototype.padend/-/string.prototype.padend-3.1.3.tgz", "resolved": "https://registry.npmjs.org/string.prototype.padend/-/string.prototype.padend-3.1.3.tgz",
@ -1354,6 +1510,17 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-bom": { "node_modules/strip-bom": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
@ -1495,6 +1662,85 @@
"funding": { "funding": {
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
},
"node_modules/wrap-ansi": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
}
},
"node_modules/wrap-ansi/node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"dependencies": {
"color-convert": "^2.0.1"
},
"engines": {
"node": ">=8"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/wrap-ansi/node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"dependencies": {
"color-name": "~1.1.4"
},
"engines": {
"node": ">=7.0.0"
}
},
"node_modules/wrap-ansi/node_modules/color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
},
"node_modules/y18n": {
"version": "5.0.8",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA==",
"engines": {
"node": ">=10"
}
},
"node_modules/yargs": {
"version": "17.4.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.4.0.tgz",
"integrity": "sha512-WJudfrk81yWFSOkZYpAZx4Nt7V4xp7S/uJkX0CnxovMCt1wCE8LNftPpNuF9X/u9gN5nsD7ycYtRcDf2pL3UiA==",
"dependencies": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",
"get-caller-file": "^2.0.5",
"require-directory": "^2.1.1",
"string-width": "^4.2.3",
"y18n": "^5.0.5",
"yargs-parser": "^21.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/yargs-parser": {
"version": "21.0.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.0.1.tgz",
"integrity": "sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg==",
"engines": {
"node": ">=12"
}
} }
}, },
"dependencies": { "dependencies": {
@ -1507,12 +1753,97 @@
"@types/node": "*" "@types/node": "*"
} }
}, },
"@types/body-parser": {
"version": "1.19.2",
"resolved": "https://registry.npmjs.org/@types/body-parser/-/body-parser-1.19.2.tgz",
"integrity": "sha512-ALYone6pm6QmwZoAgeyNksccT9Q4AWZQ6PvfwR37GT6r6FWUPguq6sUmNGSMV2Wr761oQoBxwGGa6DR5o1DC9g==",
"dev": true,
"requires": {
"@types/connect": "*",
"@types/node": "*"
}
},
"@types/connect": {
"version": "3.4.35",
"resolved": "https://registry.npmjs.org/@types/connect/-/connect-3.4.35.tgz",
"integrity": "sha512-cdeYyv4KWoEgpBISTxWvqYsVy444DOqehiF3fM3ne10AmJ62RSyNkUnxMJXHQWRQQX2eR94m5y1IZyDwBjV9FQ==",
"dev": true,
"requires": {
"@types/node": "*"
}
},
"@types/express": {
"version": "4.17.13",
"resolved": "https://registry.npmjs.org/@types/express/-/express-4.17.13.tgz",
"integrity": "sha512-6bSZTPaTIACxn48l50SR+axgrqm6qXFIxrdAKaG6PaJk3+zuUr35hBlgT7vOmJcum+OEaIBLtHV/qloEAFITeA==",
"dev": true,
"requires": {
"@types/body-parser": "*",
"@types/express-serve-static-core": "^4.17.18",
"@types/qs": "*",
"@types/serve-static": "*"
}
},
"@types/express-serve-static-core": {
"version": "4.17.28",
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.17.28.tgz",
"integrity": "sha512-P1BJAEAW3E2DJUlkgq4tOL3RyMunoWXqbSCygWo5ZIWTjUgN1YnaXWW4VWl/oc8vs/XoYibEGBKP0uZyF4AHig==",
"dev": true,
"requires": {
"@types/node": "*",
"@types/qs": "*",
"@types/range-parser": "*"
}
},
"@types/mime": {
"version": "1.3.2",
"resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.2.tgz",
"integrity": "sha512-YATxVxgRqNH6nHEIsvg6k2Boc1JHI9ZbH5iWFFv/MTkchz3b1ieGDa5T0a9RznNdI0KhVbdbWSN+KWWrQZRxTw==",
"dev": true
},
"@types/node": { "@types/node": {
"version": "17.0.22", "version": "17.0.22",
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.22.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.22.tgz",
"integrity": "sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw==", "integrity": "sha512-8FwbVoG4fy+ykY86XCAclKZDORttqE5/s7dyWZKLXTdv3vRy5HozBEinG5IqhvPXXzIZEcTVbuHlQEI6iuwcmw==",
"dev": true "dev": true
}, },
"@types/qs": {
"version": "6.9.7",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz",
"integrity": "sha512-FGa1F62FT09qcrueBA6qYTrJPVDzah9a+493+o2PCXsesWHIn27G98TsSMs3WPNbZIEj4+VJf6saSFpvD+3Zsw==",
"dev": true
},
"@types/range-parser": {
"version": "1.2.4",
"resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz",
"integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==",
"dev": true
},
"@types/serve-static": {
"version": "1.13.10",
"resolved": "https://registry.npmjs.org/@types/serve-static/-/serve-static-1.13.10.tgz",
"integrity": "sha512-nCkHGI4w7ZgAdNkrEu0bv+4xNV/XDqW+DydknebMOQwkpDGx8G+HTlj7R7ABI8i8nKxVw0wtKPi1D+lPOkh4YQ==",
"dev": true,
"requires": {
"@types/mime": "^1",
"@types/node": "*"
}
},
"@types/yargs": {
"version": "17.0.10",
"resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-17.0.10.tgz",
"integrity": "sha512-gmEaFwpj/7f/ROdtIlci1R1VYU1J4j95m8T+Tj3iBgiBFKg1foE/PSl93bBd5T9LDXNPo8UlNN6W0qwD8O5OaA==",
"dev": true,
"requires": {
"@types/yargs-parser": "*"
}
},
"@types/yargs-parser": {
"version": "21.0.0",
"resolved": "https://registry.npmjs.org/@types/yargs-parser/-/yargs-parser-21.0.0.tgz",
"integrity": "sha512-iO9ZQHkZxHn4mSakYV0vFHAVDyEOIJQrV2uZ06HxEPcx+mt8swXoZHIbaaJ2crJYFfErySgktuTZ3BeLz+XmFA==",
"dev": true
},
"accepts": { "accepts": {
"version": "1.3.8", "version": "1.3.8",
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
@ -1527,6 +1858,11 @@
"resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.9.tgz", "resolved": "https://registry.npmjs.org/adm-zip/-/adm-zip-0.5.9.tgz",
"integrity": "sha512-s+3fXLkeeLjZ2kLjCBwQufpI5fuN+kIGBxu6530nVQZGVol0d7Y/M88/xw9HGGUcJjKf8LutN3VPRUBq6N7Ajg==" "integrity": "sha512-s+3fXLkeeLjZ2kLjCBwQufpI5fuN+kIGBxu6530nVQZGVol0d7Y/M88/xw9HGGUcJjKf8LutN3VPRUBq6N7Ajg=="
}, },
"ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ=="
},
"ansi-styles": { "ansi-styles": {
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
@ -1608,6 +1944,16 @@
"supports-color": "^5.3.0" "supports-color": "^5.3.0"
} }
}, },
"cliui": {
"version": "7.0.4",
"resolved": "https://registry.npmjs.org/cliui/-/cliui-7.0.4.tgz",
"integrity": "sha512-OcRE68cOsVMXp1Yvonl/fzkQOyjLSu/8bhPDfQt0e0/Eb283TKP20Fs2MqoPsr9SwA595rRCA+QMzYc9nBP+JQ==",
"requires": {
"string-width": "^4.2.0",
"strip-ansi": "^6.0.0",
"wrap-ansi": "^7.0.0"
}
},
"color-convert": { "color-convert": {
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
@ -1706,6 +2052,11 @@
"resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz",
"integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0="
}, },
"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=="
},
"encodeurl": { "encodeurl": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
@ -1759,6 +2110,11 @@
"is-symbol": "^1.0.2" "is-symbol": "^1.0.2"
} }
}, },
"escalade": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz",
"integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw=="
},
"escape-html": { "escape-html": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz",
@ -1847,6 +2203,11 @@
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true "dev": true
}, },
"get-caller-file": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz",
"integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg=="
},
"get-intrinsic": { "get-intrinsic": {
"version": "1.1.1", "version": "1.1.1",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.1.1.tgz",
@ -2006,6 +2367,11 @@
"has-tostringtag": "^1.0.0" "has-tostringtag": "^1.0.0"
} }
}, },
"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-negative-zero": { "is-negative-zero": {
"version": "2.0.2", "version": "2.0.2",
"resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz", "resolved": "https://registry.npmjs.org/is-negative-zero/-/is-negative-zero-2.0.2.tgz",
@ -2312,6 +2678,11 @@
"path-type": "^3.0.0" "path-type": "^3.0.0"
} }
}, },
"require-directory": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz",
"integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I="
},
"resolve": { "resolve": {
"version": "1.22.0", "version": "1.22.0",
"resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz", "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.0.tgz",
@ -2451,6 +2822,16 @@
"resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.5.0.tgz",
"integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow=" "integrity": "sha1-Fhx9rBd2Wf2YEfQ3cfqZOBR4Yow="
}, },
"string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"requires": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
}
},
"string.prototype.padend": { "string.prototype.padend": {
"version": "3.1.3", "version": "3.1.3",
"resolved": "https://registry.npmjs.org/string.prototype.padend/-/string.prototype.padend-3.1.3.tgz", "resolved": "https://registry.npmjs.org/string.prototype.padend/-/string.prototype.padend-3.1.3.tgz",
@ -2482,6 +2863,14 @@
"define-properties": "^1.1.3" "define-properties": "^1.1.3"
} }
}, },
"strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"requires": {
"ansi-regex": "^5.0.1"
}
},
"strip-bom": { "strip-bom": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz", "resolved": "https://registry.npmjs.org/strip-bom/-/strip-bom-3.0.0.tgz",
@ -2580,6 +2969,63 @@
"is-string": "^1.0.5", "is-string": "^1.0.5",
"is-symbol": "^1.0.3" "is-symbol": "^1.0.3"
} }
},
"wrap-ansi": {
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
"requires": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"dependencies": {
"ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
"requires": {
"color-convert": "^2.0.1"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
"requires": {
"color-name": "~1.1.4"
}
},
"color-name": {
"version": "1.1.4",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
}
}
},
"y18n": {
"version": "5.0.8",
"resolved": "https://registry.npmjs.org/y18n/-/y18n-5.0.8.tgz",
"integrity": "sha512-0pfFzegeDWJHJIAmTLRP2DwHjdF5s7jo9tuztdQxAhINCdvS+3nGINqPd00AphqJR/0LhANUS6/+7SCb98YOfA=="
},
"yargs": {
"version": "17.4.0",
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.4.0.tgz",
"integrity": "sha512-WJudfrk81yWFSOkZYpAZx4Nt7V4xp7S/uJkX0CnxovMCt1wCE8LNftPpNuF9X/u9gN5nsD7ycYtRcDf2pL3UiA==",
"requires": {
"cliui": "^7.0.2",
"escalade": "^3.1.1",
"get-caller-file": "^2.0.5",
"require-directory": "^2.1.1",
"string-width": "^4.2.3",
"y18n": "^5.0.5",
"yargs-parser": "^21.0.0"
}
},
"yargs-parser": {
"version": "21.0.1",
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.0.1.tgz",
"integrity": "sha512-9BK1jFpLzJROCI5TzwZL/TU4gqjK5xiHV/RfWLOahrjAko/e4DJkRDZQXfvqAsiZzzYhgAzbgz6lg48jcm4GLg=="
} }
} }
} }

View File

@ -67,11 +67,14 @@
"axios": "^0.26.1", "axios": "^0.26.1",
"cors": "^2.8.5", "cors": "^2.8.5",
"express": "^4.17.3", "express": "^4.17.3",
"typescript": "^4.6.2" "typescript": "^4.6.2",
"yargs": "^17.4.0"
}, },
"devDependencies": { "devDependencies": {
"@types/adm-zip": "^0.4.34", "@types/adm-zip": "^0.4.34",
"@types/express": "^4.17.13",
"@types/node": "^17.0.22", "@types/node": "^17.0.22",
"@types/yargs": "^17.0.10",
"npm-run-all": "^4.1.5" "npm-run-all": "^4.1.5"
} }
} }

68
src/api.ts Normal file
View File

@ -0,0 +1,68 @@
import express from "express";
import cors from "cors";
import * as ServerManeger from "./server";
import { isDate } from "util/types";
const app = express();
app.use(cors());
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.use((req, res, next) => {
res.json = (body) => {
if (!res.get("Content-Type")) {
res.set("Content-Type", "application/json");
}
res.send(JSON.stringify(body, (key, value) => {
if (typeof value === "bigint") value = value.toString();
else if (isDate(value)) value = value.toString();
return value;
}, 2));
return res;
}
return next();
});
export function listen(port: number|string) {app.listen(port, () => console.log("API Listening on port %s", port));}
// Get Sessions
app.all("/", ({res}) => res.json((() => {
const sessions = ServerManeger.getSessions();
const data = {};
Object.keys(sessions).map(key => data[key] = {
players: sessions[key].getPlayer(),
ports: sessions[key].ports()
});
return data;
})()));
// Get Players
app.get("/:SessionID/player", (req, res) => {
const SessionID: string = req.params.SessionID;
const Sessions = ServerManeger.getSessions();
if (!Sessions[SessionID]) return res.status(404).send({message: "Session not found"});
return res.json(Sessions[SessionID].getPlayer());
});
// Get Player Info
app.get("/:SessionID/player/:Player", (req, res) => {
const { SessionID, Player } = req.params;
const Sessions = ServerManeger.getSessions();
if (!Sessions[SessionID]) return res.status(404).send({message: "Session not found"});
return res.json(Sessions[SessionID].getPlayer()[Player]);
});
// Player Action
app.post("/:SessionID/player/:Player/:Action", (req, res) => {
const { SessionID, Player, Action } = req.params;
const Sessions = ServerManeger.getSessions();
if (!Sessions[SessionID]) return res.status(404).send({message: "Session not found"});
const player = Sessions[SessionID].getPlayer()[Player];
if (!player) return res.status(404).send({message: "Player not found"});
if (Action !== "connect") return res.status(400).send({message: "Player no connected to server"});
if (Action.toLowerCase() === "tp") {
const { x, y, z } = req.body;
if (!x || !y || !z) return res.status(400).send({message: "Missing x, y or z"});
Sessions[SessionID].commands.tpPlayer(Player, parseInt(x), parseInt(y), parseInt(z));
return res.status(200).send({message: "Player teleported"});
}
return res.status(400).send({message: "Action not found"});
});

23
src/backup.ts Normal file
View File

@ -0,0 +1,23 @@
import os from "os";
import path from "path";
import fs from "fs";
import AdmZip from "adm-zip";
export default CreateBackup;
export async function CreateBackup(Platform: "bedrock"|"java"|"pocketmine"|"spigot"|"dragonfly") {
const ServerPath = path.resolve(process.env.SERVERPATH||path.join(os.homedir(), "bds_core/servers"), Platform);
const BackupPath = path.resolve(process.env.BACKUPPATH||path.join(os.homedir(), "bds_core/backups"));
if (!(fs.existsSync(ServerPath))) throw new Error("Server no Installed or path not found");
if (!(fs.existsSync(BackupPath))) fs.mkdirSync(BackupPath, {recursive: true});
const BackupFile = path.resolve(BackupPath, `${Platform}_${new Date().toISOString().replace(/:/g, "-")}.zip`);
const Backup = new AdmZip();
if (Platform === "bedrock") {
if (fs.existsSync(path.join(ServerPath, "worlds"))) Backup.addLocalFolder(path.join(ServerPath, "worlds"));
if (fs.existsSync(path.join(ServerPath, "server.properties"))) Backup.addLocalFile(path.join(ServerPath, "server.properties"));
if (fs.existsSync(path.join(ServerPath, "permissions.json"))) Backup.addLocalFile(path.join(ServerPath, "permissions.json"));
}
const zipBuffer = Backup.toBuffer();
fs.writeFileSync(BackupFile, zipBuffer);
return zipBuffer;
}

51
src/bin/index.ts Normal file
View File

@ -0,0 +1,51 @@
import yargs from "yargs";
import readline from "readline"
import * as BdsCore from "../index";
import * as bdsTypes from "../globalType";
const Yargs = yargs(process.argv.slice(2)).command("download", "Download and Install server", yargs => {
const options = yargs.option("platform", {
alias: "p",
describe: "Bds Core Platform",
choices: ["bedrock", "java", "pocketmine", "spigot", "dragonfly"],
default: "bedrock"
}).option("version", {
alias: "v",
describe: "Server Version",
demandOption: true,
type: "string"
}).parseSync();
const Platform = options.platform as bdsTypes.Platform;
console.log("Starting Download...");
BdsCore.DownloadServer.DownloadServer(Platform, options.version === "latest"?true:options.version).then(res => {
console.log("Sucess to download server");
console.info("Release date: %s", `${res.Date.getDate()}/${res.Date.getMonth()+1}/${res.Date.getFullYear()}`);
});
}).command("start", "Start Server", yargs => {
const options = yargs.option("platform", {
alias: "p",
describe: "Bds Core Platform",
choices: ["bedrock", "java", "pocketmine", "spigot", "dragonfly"],
default: "bedrock"
}).option("api", {
alias: "a",
describe: "Bds Core API port listen",
default: "3000",
type: "number"
}).parseSync();
const Platform = options.platform as bdsTypes.Platform;
BdsCore.API.listen(options.api);
const Server = BdsCore.Server.Start(Platform);
console.log("Session ID: %s", Server.id);
Server.on("all", data => process.stdout.write(data));
const Input = readline.createInterface({input: process.stdin,output: process.stdout})
Input.on("line", line => Server.commands.execCommand(line));
Server.exit(Input.close);
Input.on("close", () => Server.commands.execCommand("stop"));
}).command({
command: "*",
handler: () => {
Yargs.showHelp();
}
}).help().version(false);
Yargs.parseSync();

View File

@ -3,13 +3,14 @@ import fs from "fs";
import os from "os"; import os from "os";
import adm_zip from "adm-zip"; import adm_zip from "adm-zip";
import { getBuffer, getGithubRelease } from "./HttpRequests"; import { getBuffer, getGithubRelease } from "./HttpRequests";
import * as bdsTypes from "./globalType";
type getVersionsType = { type getVersionsType = {
latest: { latest: {
[d: string]: string|undefined [d: string]: string|undefined
}; };
platform: Array<{ platform: Array<{
name: "pocketmine"|"java"|"bedrock"|"dragonfly"|"spigot"; name: bdsTypes.Platform;
version: string; version: string;
Date: string; Date: string;
data: string | {[platform: string]: {[arch: string]: string;};}; data: string | {[platform: string]: {[arch: string]: string;};};
@ -29,30 +30,30 @@ async function InstallPHP(PathToInstall: string) {
return Release; return Release;
} }
export async function DownloadServer(Platform: "bedrock"|"java"|"pocketmine"|"spigot"|"dragonfly", Version: string|boolean) { export async function DownloadServer(Platform: bdsTypes.Platform, Version: string|boolean) {
const ServerPath = path.resolve(process.env.SERVERPATH||path.join(os.homedir(), "bds_core")); const ServerPath = path.resolve(process.env.SERVERPATH||path.join(os.homedir(), "bds_core/servers"), Platform);
const versions = await getVersions() const versions = await getVersions()
const info = versions.platform.filter(v => v.name === Platform).find(v => v.version === (typeof Version === "boolean"?versions.latest[Platform]:Version)); const info = versions.platform.filter(v => v.name === Platform).find(v => v.version === (typeof Version === "boolean"?versions.latest[Platform]:Version));
if (Platform === "bedrock") { if (Platform === "bedrock") {
const BedrockPath = path.resolve(ServerPath, "bedrock"); const BedrockPath = path.resolve(ServerPath);
if (!(await fs.existsSync(BedrockPath))) fs.mkdirSync(BedrockPath, {recursive: true}); if (!(await fs.existsSync(BedrockPath))) fs.mkdirSync(BedrockPath, {recursive: true});
const BedrockZip = new adm_zip(await getBuffer(info.data[process.platform][process.arch])); const BedrockZip = new adm_zip(await getBuffer(info.data[process.platform][process.arch]));
BedrockZip.extractAllTo(BedrockPath, true); BedrockZip.extractAllTo(BedrockPath, true);
} else if (Platform === "java") { } else if (Platform === "java") {
const JavaPath = path.resolve(ServerPath, "java"); const JavaPath = path.resolve(ServerPath);
if (!(await fs.existsSync(JavaPath))) fs.mkdirSync(JavaPath, {recursive: true}); if (!(await fs.existsSync(JavaPath))) fs.mkdirSync(JavaPath, {recursive: true});
await fs.promises.writeFile(path.resolve(JavaPath, "Server.jar"), await getBuffer(String(info.data))); await fs.promises.writeFile(path.resolve(JavaPath, "Server.jar"), await getBuffer(String(info.data)));
} else if (Platform === "spigot") { } else if (Platform === "spigot") {
const SpigotPath = path.resolve(ServerPath, "spigot"); const SpigotPath = path.resolve(ServerPath);
if (!(await fs.existsSync(SpigotPath))) fs.mkdirSync(SpigotPath, {recursive: true}); if (!(await fs.existsSync(SpigotPath))) fs.mkdirSync(SpigotPath, {recursive: true});
await fs.promises.writeFile(path.resolve(SpigotPath, "Spigot.jar"), await getBuffer(String(info.data))); await fs.promises.writeFile(path.resolve(SpigotPath, "Spigot.jar"), await getBuffer(String(info.data)));
} else if (Platform === "pocketmine") { } else if (Platform === "pocketmine") {
const PocketminePath = path.resolve(ServerPath, "pocketmine"); const PocketminePath = path.resolve(ServerPath);
if (!(await fs.existsSync(PocketminePath))) fs.mkdirSync(PocketminePath, {recursive: true}); if (!(await fs.existsSync(PocketminePath))) fs.mkdirSync(PocketminePath, {recursive: true});
await InstallPHP(PocketminePath); await InstallPHP(PocketminePath);
await fs.promises.writeFile(path.resolve(PocketminePath, "PocketMine.phar"), await getBuffer(String(info.data))); await fs.promises.writeFile(path.resolve(PocketminePath, "PocketMine.phar"), await getBuffer(String(info.data)));
} else if (Platform === "dragonfly") { } else if (Platform === "dragonfly") {
const DragonflyPath = path.resolve(ServerPath, "dragonfly"); const DragonflyPath = path.resolve(ServerPath);
if (!(await fs.existsSync(DragonflyPath))) fs.mkdirSync(DragonflyPath, {recursive: true}); if (!(await fs.existsSync(DragonflyPath))) fs.mkdirSync(DragonflyPath, {recursive: true});
await fs.promises.writeFile(path.resolve(DragonflyPath, "Dragonfly"+(process.platform === "win32"?".exe":"")), await getBuffer(String(info.data))); await fs.promises.writeFile(path.resolve(DragonflyPath, "Dragonfly"+(process.platform === "win32"?".exe":"")), await getBuffer(String(info.data)));
} }

1
src/globalType.ts Normal file
View File

@ -0,0 +1 @@
export type Platform = "bedrock"|"java"|"pocketmine"|"spigot"|"dragonfly";

7
src/index.ts Normal file
View File

@ -0,0 +1,7 @@
import * as Server from "./server";
import * as Backup from "./backup";
import * as DownloadServer from "./download_server";
import * as API from "./api";
export default {Server, Backup, DownloadServer, API};
export {Server, Backup, DownloadServer, API};

View File

@ -1,23 +1,31 @@
import path from "path"; import path from "path";
import fs from "fs";
import os from "os"; import os from "os";
import crypto from "crypto"; import crypto from "crypto";
import child_process from "child_process"; import child_process from "child_process";
import * as bdsTypes from "./globalType";
type Session = { type BdsSession = {
id: string;
startDate: Date; startDate: Date;
on: (from: "stdout"|"stderr", callback: (data: string) => void) => void; on: (from: "all"|"stdout"|"stderr", callback: (data: string) => void) => void;
exit: (callback: (code: number, signal: string) => void) => void; exit: (callback: (code: number, signal: string) => void) => void;
getPlayer: () => {[player: string]: {action: "connect"|"disconnect"|"unknown"; date: Date; history: Array<{action: "connect"|"disconnect"|"unknown"; date: Date}>}};
ports: () => Array<{port: number; protocol: "TCP"|"UDP"; version?: "IPv4"|"IPv6"}>;
commands: { commands: {
tpPlayer: (username: string, x: number, y: number, z: number) => void; tpPlayer: (username: string, x: number, y: number, z: number) => void;
execCommand: (command: string) => void; execCommand: (command: string) => void;
} }
}; };
const Sessions: {[Session: string]: Session} = {}; // Server Sessions
export async function getSessions() {return Sessions;} const Sessions: {[Session: string]: BdsSession} = {};
export function getSessions() {return Sessions;}
export function Start(Platform: "bedrock"|"java"|"pocketmine"|"spigot"|"dragonfly"): Session { // Start Server
const ServerPath = path.resolve(process.env.SERVERPATH||path.join(os.homedir(), "bds_core")); export function Start(Platform: bdsTypes.Platform): BdsSession {
const ServerPath = path.resolve(process.env.SERVERPATH||path.join(os.homedir(), "bds_core/servers"), Platform);
if (!(fs.existsSync(ServerPath))) fs.mkdirSync(ServerPath, {recursive: true});
const Process: {command: string; args: Array<string>; env: {[env: string]: string}; cwd: string;} = { const Process: {command: string; args: Array<string>; env: {[env: string]: string}; cwd: string;} = {
command: "", command: "",
args: [], args: [],
@ -26,7 +34,7 @@ export function Start(Platform: "bedrock"|"java"|"pocketmine"|"spigot"|"dragonfl
}; };
if (Platform === "bedrock") { if (Platform === "bedrock") {
if (process.platform === "darwin") throw new Error("Run Docker image"); if (process.platform === "darwin") throw new Error("Run Docker image");
Process.command = path.resolve(ServerPath, "bedrock/bedrock"+(process.platform === "win32"?".exe":"")); Process.command = path.resolve(ServerPath, "bedrock_server"+(process.platform === "win32"?".exe":""));
if (process.platform !== "win32") { if (process.platform !== "win32") {
child_process.execFileSync("chmod", ["a+x", Process.command]); child_process.execFileSync("chmod", ["a+x", Process.command]);
Process.env.LD_LIBRARY_PATH = path.resolve(ServerPath, "bedrock"); Process.env.LD_LIBRARY_PATH = path.resolve(ServerPath, "bedrock");
@ -39,24 +47,77 @@ export function Start(Platform: "bedrock"|"java"|"pocketmine"|"spigot"|"dragonfl
} else if (Platform === "java"||Platform === "spigot") { } else if (Platform === "java"||Platform === "spigot") {
Process.command = "java"; Process.command = "java";
Process.args.push("-jar"); Process.args.push("-jar");
if (Platform === "java") Process.args.push(path.resolve(ServerPath, "java/Server.jar")); if (Platform === "java") Process.args.push(path.resolve(ServerPath, "Server.jar"));
else Process.args.push(path.resolve(ServerPath, "spigot/Spigot.jar")); else Process.args.push(path.resolve(ServerPath, "Spigot.jar"));
} else if (Platform === "pocketmine") { } else if (Platform === "pocketmine") {
if (process.platform === "win32") Process.command = path.resolve(ServerPath, "pocketmine/bins/php/php"); if (process.platform === "win32") Process.command = path.resolve(ServerPath, "php/php");
else Process.command = path.resolve(ServerPath, "pocketmine/bins/php7/bin/php"); else Process.command = path.resolve(ServerPath, "php7/bin/php");
Process.args.push(path.resolve(ServerPath, "pocketmine/PocketMine-MP.phar")); Process.args.push(path.resolve(ServerPath, "PocketMine-MP.phar"));
} }
// Start Server // Start Server
console.log(Process.command, ...Process.args);
const ServerProcess = child_process.execFile(Process.command, Process.args, {env: Process.env, cwd: Process.cwd, maxBuffer: Infinity}); const ServerProcess = child_process.execFile(Process.command, Process.args, {env: Process.env, cwd: Process.cwd, maxBuffer: Infinity});
const StartDate = new Date(); const StartDate = new Date();
// Log callback // Log callback
const onLog = (from: "stdout"|"stderr", callback: (data: string) => void) => { const onLog = (from: "all"|"stdout"|"stderr", callback: (data: string) => void) => {
ServerProcess[from].on("data", callback); if (from === "all") {
ServerProcess.stdout.on("data", callback);
ServerProcess.stderr.on("data", callback);
} else if (from === "stderr") ServerProcess.stderr.on("data", callback);
else if (from === "stdout") ServerProcess.stdout.on("data", callback);
else throw new Error("Unknown log from");
return; return;
} }
const playersConnections: {[player: string]: {action: "connect"|"disconnect"|"unknown"; date: Date; history: Array<{action: "connect"|"disconnect"|"unknown"; date: Date}>}} = {};
const ports: Array<{port: number; protocol: "TCP"|"UDP"; version?: "IPv4"|"IPv6"}> = [];
onLog("all", data => {
if (Platform === "bedrock") {
(() => {
const portParse = data.match(/(IPv[46])\s+.*,\s+port:\s+(.*)/);
if (portParse) ports.push({
port: parseInt(portParse[2]),
protocol: "UDP",
version: portParse[1] as "IPv4"|"IPv6"
});
const portParse2 = data.match(/port:\s+(.*)/);
if (portParse2) {
if (!ports.find(p => p.port === parseInt(portParse2[1]))) ports.push({
port: parseInt(portParse2[1]),
protocol: "UDP",
});
}
})()
const playerBedrock = (() => {
const [action, player, xuid] = (data.match(/r\s+(.*)\:\s+(.*)\,\s+xuid\:\s+(.*)/)||[]).slice(1, 4);
const __PlayerAction: {player: string, xuid: string|undefined, action: "connect"|"disconnect"|"unknown"} = {
player: player,
xuid: xuid,
action: "unknown"
};
if (action === "connected") __PlayerAction.action = "connect";
else if (action === "disconnected") __PlayerAction.action = "disconnect";
return __PlayerAction;
})();
if (playerBedrock.player && playerBedrock.action) {
const actionDate = new Date();
if (!!playersConnections[playerBedrock.player]) {
playersConnections[playerBedrock.player].action = playerBedrock.action;
playersConnections[playerBedrock.player].date = actionDate;
playersConnections[playerBedrock.player].history.push({action: playerBedrock.action, date: actionDate});
} else {
playersConnections[playerBedrock.player] = {
action: playerBedrock.action,
date: actionDate,
history: [{action: playerBedrock.action, date: actionDate}]
};
}
}
}
});
// Exit callback // Exit callback
const onExit = (callback: (code: number, signal: string) => void): void => { const onExit = (callback: (code: number, signal: string) => void): void => {
ServerProcess.on("exit", callback); ServerProcess.on("exit", callback);
@ -80,11 +141,17 @@ export function Start(Platform: "bedrock"|"java"|"pocketmine"|"spigot"|"dragonfl
startDate: StartDate, startDate: StartDate,
on: onLog, on: onLog,
exit: onExit, exit: onExit,
ports: () => ports,
getPlayer: () => playersConnections,
commands: { commands: {
execCommand: execCommand, execCommand: execCommand,
tpPlayer: tpPlayer, tpPlayer: tpPlayer,
} }
}; };
const logFile = path.resolve(ServerPath, `../log/${Seesion.id}.log`);
if(!(fs.existsSync(path.parse(logFile).dir))) fs.mkdirSync(path.parse(logFile).dir, {recursive: true});
const logStream = fs.createWriteStream(logFile, {flags: "w+"});
onLog("all", data => logStream.write(data));
Sessions[Seesion.id] = Seesion; Sessions[Seesion.id] = Seesion;
return Seesion; return Seesion;
} }