Update server platforms to v2 paths #465

Merged
Sirherobrine23 merged 4 commits from multi-server-installs into main 2022-09-27 23:29:33 +00:00
22 changed files with 541 additions and 582 deletions

View File

@ -8,4 +8,6 @@ updates:
- package-ecosystem: npm
directory: /
schedule:
interval: daily
interval: monthly
assignees:
- Sirherobrine23

View File

@ -20,6 +20,8 @@ jobs:
- Spigot
runs-on: ubuntu-latest
name: "${{ matrix.platform }}"
env:
BDS_HOME: "~/.bdsCore"
steps:
- uses: actions/checkout@v3
name: Code checkout
@ -50,4 +52,15 @@ jobs:
# Run test
- name: Test
run: npm run test:partial -- tests/${{ matrix.platform }}.ts
run: npm run test:partial -- tests/${{ matrix.platform }}.ts
# Upload bds root
- name: Upload BdsCore folder
uses: actions/upload-artifact@v3
with:
name: ${{ matrix.platform }}
path: |
~/.bdsCore
!~/.bdsCore/**/*.debug
!~/.bdsCore/**/bedrock_server
!~/.bdsCore/**/*_packs/

394
package-lock.json generated
View File

@ -1,19 +1,18 @@
{
"name": "@the-bds-maneger/core",
"version": "4.5.2",
"version": "4.5.3",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@the-bds-maneger/core",
"version": "4.5.2",
"version": "4.5.3",
"license": "GPL-3.0",
"dependencies": {
"@the-bds-maneger/server_versions": "^4.2.0",
"adm-zip": "^0.5.9",
"axios": "^0.27.2",
"cron": "^2.1.0",
"got": "^11.8.5",
"got": "^12.5.1",
"prismarine-nbt": "^2.2.1",
"tar": "^6.1.11"
},
@ -69,25 +68,25 @@
}
},
"node_modules/@sindresorhus/is": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
"integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw==",
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-5.3.0.tgz",
"integrity": "sha512-CX6t4SYQ37lzxicAqsBtxA3OseeoVrh9cSJ5PFYam0GksYlupRfy1A+Q4aYD3zvcfECLc0zO2u+ZnR2UYKvCrw==",
"engines": {
"node": ">=10"
"node": ">=14.16"
},
"funding": {
"url": "https://github.com/sindresorhus/is?sponsor=1"
}
},
"node_modules/@szmarczak/http-timer": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz",
"integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz",
"integrity": "sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw==",
"dependencies": {
"defer-to-connect": "^2.0.0"
"defer-to-connect": "^2.0.1"
},
"engines": {
"node": ">=10"
"node": ">=14.16"
}
},
"node_modules/@the-bds-maneger/server_versions": {
@ -148,17 +147,6 @@
"@types/node": "*"
}
},
"node_modules/@types/cacheable-request": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",
"integrity": "sha512-B3xVo+dlKM6nnKTcmm5ZtY/OL8bOAOd2Olee9M1zft65ox50OzjEHW91sDiU9j6cvW8Ejg1/Qkf4xd2kugApUA==",
"dependencies": {
"@types/http-cache-semantics": "*",
"@types/keyv": "*",
"@types/node": "*",
"@types/responselike": "*"
}
},
"node_modules/@types/cron": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/cron/-/cron-2.0.0.tgz",
@ -174,14 +162,6 @@
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz",
"integrity": "sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ=="
},
"node_modules/@types/keyv": {
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz",
"integrity": "sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/luxon": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.0.1.tgz",
@ -199,14 +179,6 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.22.tgz",
"integrity": "sha512-TsmoXYd4zrkkKjJB0URF/mTIKPl+kVcbqClB2F/ykU7vil1BfWZVndOnpEIozPv4fURD28gyPFeIkW2G+KXOvw=="
},
"node_modules/@types/responselike": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz",
"integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/tar": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/@types/tar/-/tar-6.1.2.tgz",
@ -555,28 +527,28 @@
}
},
"node_modules/cacheable-lookup": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",
"integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA==",
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-7.0.0.tgz",
"integrity": "sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w==",
"engines": {
"node": ">=10.6.0"
"node": ">=14.16"
}
},
"node_modules/cacheable-request": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.2.tgz",
"integrity": "sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew==",
"version": "10.2.1",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.1.tgz",
"integrity": "sha512-3tLJyBjGuXw1s5gpKFSG3iS4kaKT4id04dZi98wzHQp/8cqZNweBnrF9J+rrlvrf4M53OdtDGNctNHFias8BEA==",
"dependencies": {
"clone-response": "^1.0.2",
"get-stream": "^5.1.0",
"http-cache-semantics": "^4.0.0",
"keyv": "^4.0.0",
"lowercase-keys": "^2.0.0",
"normalize-url": "^6.0.1",
"responselike": "^2.0.0"
"@types/http-cache-semantics": "^4.0.1",
"get-stream": "^6.0.1",
"http-cache-semantics": "^4.1.0",
"keyv": "^4.5.0",
"mimic-response": "^4.0.0",
"normalize-url": "^7.1.0",
"responselike": "^3.0.0"
},
"engines": {
"node": ">=8"
"node": ">=14.16"
}
},
"node_modules/call-bind": {
@ -676,17 +648,6 @@
"wrap-ansi": "^7.0.0"
}
},
"node_modules/clone-response": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz",
"integrity": "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==",
"dependencies": {
"mimic-response": "^1.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@ -946,14 +907,6 @@
"node": ">= 0.8"
}
},
"node_modules/end-of-stream": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
"dependencies": {
"once": "^1.4.0"
}
},
"node_modules/entities": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.4.0.tgz",
@ -1189,6 +1142,14 @@
"node": ">= 6"
}
},
"node_modules/form-data-encoder": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-2.1.2.tgz",
"integrity": "sha512-FCaIOVTRA9E0siY6FeXid7D5yrCqpsErplUkE2a1BEiKj1BE9z6FbKB4ntDTwC4NVLie9p+4E9nX4mWwEOT05A==",
"engines": {
"node": ">= 14.17"
}
},
"node_modules/forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -1263,14 +1224,11 @@
}
},
"node_modules/get-stream": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
"integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
"dependencies": {
"pump": "^3.0.0"
},
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==",
"engines": {
"node": ">=8"
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
@ -1331,24 +1289,24 @@
}
},
"node_modules/got": {
"version": "11.8.5",
"resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz",
"integrity": "sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==",
"version": "12.5.1",
"resolved": "https://registry.npmjs.org/got/-/got-12.5.1.tgz",
"integrity": "sha512-sD16AK8cCyUoPtKr/NMvLTFFa+T3i3S+zoiuvhq0HP2YiqBZA9AtlBjAdsQBsLBK7slPuvmfE0OxhGi7N5dD4w==",
"dependencies": {
"@sindresorhus/is": "^4.0.0",
"@szmarczak/http-timer": "^4.0.5",
"@types/cacheable-request": "^6.0.1",
"@types/responselike": "^1.0.0",
"cacheable-lookup": "^5.0.3",
"cacheable-request": "^7.0.2",
"@sindresorhus/is": "^5.2.0",
"@szmarczak/http-timer": "^5.0.1",
"cacheable-lookup": "^7.0.0",
"cacheable-request": "^10.2.1",
"decompress-response": "^6.0.0",
"http2-wrapper": "^1.0.0-beta.5.2",
"lowercase-keys": "^2.0.0",
"p-cancelable": "^2.0.0",
"responselike": "^2.0.0"
"form-data-encoder": "^2.1.2",
"get-stream": "^6.0.1",
"http2-wrapper": "^2.1.10",
"lowercase-keys": "^3.0.0",
"p-cancelable": "^3.0.0",
"responselike": "^3.0.0"
},
"engines": {
"node": ">=10.19.0"
"node": ">=14.16"
},
"funding": {
"url": "https://github.com/sindresorhus/got?sponsor=1"
@ -1460,12 +1418,12 @@
"integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
},
"node_modules/http2-wrapper": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz",
"integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==",
"version": "2.1.11",
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-2.1.11.tgz",
"integrity": "sha512-aNAk5JzLturWEUiuhAN73Jcbq96R7rTitAoXV54FYMatvihnpD2+6PUgU4ce3D/m5VDbw+F5CsyKSF176ptitQ==",
"dependencies": {
"quick-lru": "^5.1.1",
"resolve-alpn": "^1.0.0"
"resolve-alpn": "^1.2.0"
},
"engines": {
"node": ">=10.19.0"
@ -1772,11 +1730,14 @@
}
},
"node_modules/lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-3.0.0.tgz",
"integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ==",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/luxon": {
@ -1851,11 +1812,14 @@
}
},
"node_modules/mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==",
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-4.0.0.tgz",
"integrity": "sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg==",
"engines": {
"node": ">=4"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/minimatch": {
@ -2119,11 +2083,11 @@
}
},
"node_modules/normalize-url": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
"integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A==",
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-7.2.0.tgz",
"integrity": "sha512-uhXOdZry0L6M2UIo9BTt7FdpBDiAGN/7oItedQwPKh8jh31ZlvC8U9Xl/EJ3aijDHaywXTW3QbZ6LuCocur1YA==",
"engines": {
"node": ">=10"
"node": ">=12.20"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
@ -2165,6 +2129,7 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"dev": true,
"dependencies": {
"wrappy": "1"
}
@ -2186,11 +2151,11 @@
}
},
"node_modules/p-cancelable": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz",
"integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-3.0.0.tgz",
"integrity": "sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw==",
"engines": {
"node": ">=8"
"node": ">=12.20"
}
},
"node_modules/p-limit": {
@ -2335,15 +2300,6 @@
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
"integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag=="
},
"node_modules/pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"dependencies": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"node_modules/punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
@ -2457,11 +2413,14 @@
"integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g=="
},
"node_modules/responselike": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz",
"integrity": "sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-3.0.0.tgz",
"integrity": "sha512-40yHxbNcl2+rzXvZuVkrYohathsSJlMTXKryG5y8uciHv1+xDLHQpgjG64JUO9nrEq2jGLH6IZ8BcZyw3wrweg==",
"dependencies": {
"lowercase-keys": "^2.0.0"
"lowercase-keys": "^3.0.0"
},
"engines": {
"node": ">=14.16"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
@ -3020,7 +2979,8 @@
"node_modules/wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"dev": true
},
"node_modules/ws": {
"version": "8.9.0",
@ -3180,16 +3140,16 @@
}
},
"@sindresorhus/is": {
"version": "4.6.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-4.6.0.tgz",
"integrity": "sha512-t09vSN3MdfsyCHoFcTRCH/iUtG7OJ0CsjzB8cjAmKc/va/kIgeDI/TxsigdncE/4be734m0cvIYwNaV4i2XqAw=="
"version": "5.3.0",
"resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-5.3.0.tgz",
"integrity": "sha512-CX6t4SYQ37lzxicAqsBtxA3OseeoVrh9cSJ5PFYam0GksYlupRfy1A+Q4aYD3zvcfECLc0zO2u+ZnR2UYKvCrw=="
},
"@szmarczak/http-timer": {
"version": "4.0.6",
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-4.0.6.tgz",
"integrity": "sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==",
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/@szmarczak/http-timer/-/http-timer-5.0.1.tgz",
"integrity": "sha512-+PmQX0PiAYPMeVYe237LJAYvOMYW1j2rH5YROyS3b4CTVJum34HfRvKvAzozHAQG0TnHNdUfY9nCeUyRAs//cw==",
"requires": {
"defer-to-connect": "^2.0.0"
"defer-to-connect": "^2.0.1"
}
},
"@the-bds-maneger/server_versions": {
@ -3244,17 +3204,6 @@
"@types/node": "*"
}
},
"@types/cacheable-request": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/@types/cacheable-request/-/cacheable-request-6.0.2.tgz",
"integrity": "sha512-B3xVo+dlKM6nnKTcmm5ZtY/OL8bOAOd2Olee9M1zft65ox50OzjEHW91sDiU9j6cvW8Ejg1/Qkf4xd2kugApUA==",
"requires": {
"@types/http-cache-semantics": "*",
"@types/keyv": "*",
"@types/node": "*",
"@types/responselike": "*"
}
},
"@types/cron": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/@types/cron/-/cron-2.0.0.tgz",
@ -3270,14 +3219,6 @@
"resolved": "https://registry.npmjs.org/@types/http-cache-semantics/-/http-cache-semantics-4.0.1.tgz",
"integrity": "sha512-SZs7ekbP8CN0txVG2xVRH6EgKmEm31BOxA07vkFaETzZz1xh+cbt8BcI0slpymvwhx5dlFnQG2rTlPVQn+iRPQ=="
},
"@types/keyv": {
"version": "3.1.4",
"resolved": "https://registry.npmjs.org/@types/keyv/-/keyv-3.1.4.tgz",
"integrity": "sha512-BQ5aZNSCpj7D6K2ksrRCTmKRLEpnPvWDiLPfoGyhZ++8YtiK9d/3DBKPJgry359X/P1PfruyYwvnvwFjuEiEIg==",
"requires": {
"@types/node": "*"
}
},
"@types/luxon": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/@types/luxon/-/luxon-3.0.1.tgz",
@ -3295,14 +3236,6 @@
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.7.22.tgz",
"integrity": "sha512-TsmoXYd4zrkkKjJB0URF/mTIKPl+kVcbqClB2F/ykU7vil1BfWZVndOnpEIozPv4fURD28gyPFeIkW2G+KXOvw=="
},
"@types/responselike": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/@types/responselike/-/responselike-1.0.0.tgz",
"integrity": "sha512-85Y2BjiufFzaMIlvJDvTTB8Fxl2xfLo4HgmHzVBz08w4wDePCTjYw66PdrolO0kzli3yam/YCgRufyo1DdQVTA==",
"requires": {
"@types/node": "*"
}
},
"@types/tar": {
"version": "6.1.2",
"resolved": "https://registry.npmjs.org/@types/tar/-/tar-6.1.2.tgz",
@ -3560,22 +3493,22 @@
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="
},
"cacheable-lookup": {
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-5.0.4.tgz",
"integrity": "sha512-2/kNscPhpcxrOigMZzbiWF7dz8ilhb/nIHU3EyZiXWXpeq/au8qJ8VhdftMkty3n7Gj6HIGalQG8oiBNB3AJgA=="
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/cacheable-lookup/-/cacheable-lookup-7.0.0.tgz",
"integrity": "sha512-+qJyx4xiKra8mZrcwhjMRMUhD5NR1R8esPkzIYxX96JiecFoxAXFuz/GpR3+ev4PE1WamHip78wV0vcmPQtp8w=="
},
"cacheable-request": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-7.0.2.tgz",
"integrity": "sha512-pouW8/FmiPQbuGpkXQ9BAPv/Mo5xDGANgSNXzTzJ8DrKGuXOssM4wIQRjfanNRh3Yu5cfYPvcorqbhg2KIJtew==",
"version": "10.2.1",
"resolved": "https://registry.npmjs.org/cacheable-request/-/cacheable-request-10.2.1.tgz",
"integrity": "sha512-3tLJyBjGuXw1s5gpKFSG3iS4kaKT4id04dZi98wzHQp/8cqZNweBnrF9J+rrlvrf4M53OdtDGNctNHFias8BEA==",
"requires": {
"clone-response": "^1.0.2",
"get-stream": "^5.1.0",
"http-cache-semantics": "^4.0.0",
"keyv": "^4.0.0",
"lowercase-keys": "^2.0.0",
"normalize-url": "^6.0.1",
"responselike": "^2.0.0"
"@types/http-cache-semantics": "^4.0.1",
"get-stream": "^6.0.1",
"http-cache-semantics": "^4.1.0",
"keyv": "^4.5.0",
"mimic-response": "^4.0.0",
"normalize-url": "^7.1.0",
"responselike": "^3.0.0"
}
},
"call-bind": {
@ -3645,14 +3578,6 @@
"wrap-ansi": "^7.0.0"
}
},
"clone-response": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz",
"integrity": "sha512-ROoL94jJH2dUVML2Y/5PEDNaSHgeOdSDicUyS7izcF63G6sTc/FTjLub4b8Il9S8S0beOfYt0TaA5qvFK+w0wA==",
"requires": {
"mimic-response": "^1.0.0"
}
},
"color-convert": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
@ -3849,14 +3774,6 @@
"resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz",
"integrity": "sha512-TPJXq8JqFaVYm2CWmPvnP2Iyo4ZSM7/QKcSmuMLDObfpH5fi7RUGmd/rTDf+rut/saiDiQEeVTNgAmJEdAOx0w=="
},
"end-of-stream": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz",
"integrity": "sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==",
"requires": {
"once": "^1.4.0"
}
},
"entities": {
"version": "4.4.0",
"resolved": "https://registry.npmjs.org/entities/-/entities-4.4.0.tgz",
@ -4017,6 +3934,11 @@
"mime-types": "^2.1.12"
}
},
"form-data-encoder": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-2.1.2.tgz",
"integrity": "sha512-FCaIOVTRA9E0siY6FeXid7D5yrCqpsErplUkE2a1BEiKj1BE9z6FbKB4ntDTwC4NVLie9p+4E9nX4mWwEOT05A=="
},
"forwarded": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -4069,12 +3991,9 @@
}
},
"get-stream": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
"integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
"requires": {
"pump": "^3.0.0"
}
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/get-stream/-/get-stream-6.0.1.tgz",
"integrity": "sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg=="
},
"glob": {
"version": "7.2.0",
@ -4121,21 +4040,21 @@
}
},
"got": {
"version": "11.8.5",
"resolved": "https://registry.npmjs.org/got/-/got-11.8.5.tgz",
"integrity": "sha512-o0Je4NvQObAuZPHLFoRSkdG2lTgtcynqymzg2Vupdx6PorhaT5MCbIyXG6d4D94kk8ZG57QeosgdiqfJWhEhlQ==",
"version": "12.5.1",
"resolved": "https://registry.npmjs.org/got/-/got-12.5.1.tgz",
"integrity": "sha512-sD16AK8cCyUoPtKr/NMvLTFFa+T3i3S+zoiuvhq0HP2YiqBZA9AtlBjAdsQBsLBK7slPuvmfE0OxhGi7N5dD4w==",
"requires": {
"@sindresorhus/is": "^4.0.0",
"@szmarczak/http-timer": "^4.0.5",
"@types/cacheable-request": "^6.0.1",
"@types/responselike": "^1.0.0",
"cacheable-lookup": "^5.0.3",
"cacheable-request": "^7.0.2",
"@sindresorhus/is": "^5.2.0",
"@szmarczak/http-timer": "^5.0.1",
"cacheable-lookup": "^7.0.0",
"cacheable-request": "^10.2.1",
"decompress-response": "^6.0.0",
"http2-wrapper": "^1.0.0-beta.5.2",
"lowercase-keys": "^2.0.0",
"p-cancelable": "^2.0.0",
"responselike": "^2.0.0"
"form-data-encoder": "^2.1.2",
"get-stream": "^6.0.1",
"http2-wrapper": "^2.1.10",
"lowercase-keys": "^3.0.0",
"p-cancelable": "^3.0.0",
"responselike": "^3.0.0"
}
},
"has": {
@ -4214,12 +4133,12 @@
}
},
"http2-wrapper": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-1.0.3.tgz",
"integrity": "sha512-V+23sDMr12Wnz7iTcDeJr3O6AIxlnvT/bmaAAAP/Xda35C90p9599p0F1eHR/N1KILWSoWVAiOMFjBBXaXSMxg==",
"version": "2.1.11",
"resolved": "https://registry.npmjs.org/http2-wrapper/-/http2-wrapper-2.1.11.tgz",
"integrity": "sha512-aNAk5JzLturWEUiuhAN73Jcbq96R7rTitAoXV54FYMatvihnpD2+6PUgU4ce3D/m5VDbw+F5CsyKSF176ptitQ==",
"requires": {
"quick-lru": "^5.1.1",
"resolve-alpn": "^1.0.0"
"resolve-alpn": "^1.2.0"
}
},
"https-proxy-agent": {
@ -4441,9 +4360,9 @@
}
},
"lowercase-keys": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-2.0.0.tgz",
"integrity": "sha512-tqNXrS78oMOE73NMxK4EMLQsQowWf8jKooH9g7xPavRT706R6bkQJ6DY2Te7QukaZsulxa30wQ7bk0pm4XiHmA=="
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/lowercase-keys/-/lowercase-keys-3.0.0.tgz",
"integrity": "sha512-ozCC6gdQ+glXOQsveKD0YsDy8DSQFjDTz4zyzEHNV5+JP5D62LmfDZ6o1cycFx9ouG940M5dE8C8CTewdj2YWQ=="
},
"luxon": {
"version": "1.28.0",
@ -4496,9 +4415,9 @@
}
},
"mimic-response": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz",
"integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ=="
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-4.0.0.tgz",
"integrity": "sha512-e5ISH9xMYU0DzrT+jl8q2ze9D6eWBto+I8CNpe+VI+K2J/F/k3PdkdTdz4wvGVH4NTpo+NRYTVIuMQEMMcsLqg=="
},
"minimatch": {
"version": "5.0.1",
@ -4694,9 +4613,9 @@
"dev": true
},
"normalize-url": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-6.1.0.tgz",
"integrity": "sha512-DlL+XwOy3NxAQ8xuC0okPgK46iuVNAK01YN7RueYBqqFeGsBjV9XmCAzAdgt+667bCl5kPh9EqKKDwnaPG1I7A=="
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-7.2.0.tgz",
"integrity": "sha512-uhXOdZry0L6M2UIo9BTt7FdpBDiAGN/7oItedQwPKh8jh31ZlvC8U9Xl/EJ3aijDHaywXTW3QbZ6LuCocur1YA=="
},
"nwsapi": {
"version": "2.2.2",
@ -4725,6 +4644,7 @@
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
"integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==",
"dev": true,
"requires": {
"wrappy": "1"
}
@ -4743,9 +4663,9 @@
}
},
"p-cancelable": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-2.1.1.tgz",
"integrity": "sha512-BZOr3nRQHOntUjTrH8+Lh54smKHoHyur8We1V8DSMVrl5A2malOOwuJRnKRDjSnkoeBh4at6BwEnb5I7Jl31wg=="
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/p-cancelable/-/p-cancelable-3.0.0.tgz",
"integrity": "sha512-mlVgR3PGuzlo0MmTdk4cXqXWlwQDLnONTAg6sm62XkMJEiRxN3GL3SffkYvqwonbkJBcrI7Uvv5Zh9yjvn2iUw=="
},
"p-limit": {
"version": "3.1.0",
@ -4847,15 +4767,6 @@
"resolved": "https://registry.npmjs.org/psl/-/psl-1.9.0.tgz",
"integrity": "sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag=="
},
"pump": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.0.tgz",
"integrity": "sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww==",
"requires": {
"end-of-stream": "^1.1.0",
"once": "^1.3.1"
}
},
"punycode": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz",
@ -4939,11 +4850,11 @@
"integrity": "sha512-0a1F4l73/ZFZOakJnQ3FvkJ2+gSTQWz/r2KE5OdDY0TxPm5h4GkqkWWfM47T7HsbnOtcJVEF4epCVy6u7Q3K+g=="
},
"responselike": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-2.0.1.tgz",
"integrity": "sha512-4gl03wn3hj1HP3yzgdI7d3lCkF95F21Pz4BPGvKHinyQzALR5CapwC8yIi0Rh58DEMQ/SguC03wFj2k0M/mHhw==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/responselike/-/responselike-3.0.0.tgz",
"integrity": "sha512-40yHxbNcl2+rzXvZuVkrYohathsSJlMTXKryG5y8uciHv1+xDLHQpgjG64JUO9nrEq2jGLH6IZ8BcZyw3wrweg==",
"requires": {
"lowercase-keys": "^2.0.0"
"lowercase-keys": "^3.0.0"
}
},
"safe-buffer": {
@ -5349,7 +5260,8 @@
"wrappy": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==",
"dev": true
},
"ws": {
"version": "8.9.0",

View File

@ -33,9 +33,8 @@
"dependencies": {
"@the-bds-maneger/server_versions": "^4.2.0",
"adm-zip": "^0.5.9",
"axios": "^0.27.2",
"cron": "^2.1.0",
"got": "^11.8.5",
"got": "^12.5.1",
"prismarine-nbt": "^2.2.1",
"tar": "^6.1.11"
},
@ -49,4 +48,4 @@
"ts-node": "^10.9.1",
"typescript": "^4.8.3"
}
}
}

View File

@ -1,15 +1,14 @@
import * as path from "node:path";
import * as fsOld from "node:fs";
import * as fs from "node:fs/promises";
import path from "node:path";
import fsOld from "node:fs";
import fs from "node:fs/promises";
import admZip from "adm-zip";
import * as Proprieties from "./Proprieties";
import { promisify } from "node:util";
import { platformManeger } from "@the-bds-maneger/server_versions";
import admZip from "adm-zip";
import { execAsync } from "./childPromisses";
import { actions, actionConfig } from "./globalPlatfroms";
import { serverRoot, logRoot } from './pathControl';
import * as Proprieties from "./Proprieties";
import { saveFile } from "./httpRequest";
export const serverPath = path.join(serverRoot, "Bedrock");
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
// RegExp
export const saveFileFolder = /^(worlds|server\.properties|config|((permissions|allowlist|valid_known_packs)\.json)|(development_.*_packs))$/;
@ -17,7 +16,8 @@ export const portListen = /\[.*\]\s+(IPv[46])\s+supported,\s+port:\s+([0-9]+)/;
export const started = /\[.*\]\s+Server\s+started\./;
export const player = /\[.*\]\s+Player\s+((dis|)connected):\s+(.*),\s+xuid:\s+([0-9]+)/;
export async function installServer(version: string|boolean) {
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath } = await pathControl("bedrock", platformOptions);
const bedrockData = await platformManeger.bedrock.find(version);
const zip = new admZip(await saveFile(bedrockData.url[process.platform]));
if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
@ -67,7 +67,8 @@ const serverConfig: actionConfig[] = [
},
];
export async function startServer() {
export async function startServer(platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath, logsPath } = await pathControl("bedrock", platformOptions);
if (!fsOld.existsSync(serverPath)) throw new Error("Install server fist");
const args: string[] = [];
let command = path.join(serverPath, "bedrock_server");
@ -83,13 +84,13 @@ export async function startServer() {
// execAsync(`echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list && sudo apt update && sudo apt install libssl1.1`, {stdio: "inherit"});
// }
const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_bedrock_${process.platform}_${process.arch}.stdout.log`);
return new actions({command, args, options: {cwd: serverPath, maxBuffer: Infinity, env: {LD_LIBRARY_PATH: process.platform === "win32"?undefined:serverPath}, logPath: {stdout: logFileOut}}}, serverConfig);
const logFileOut = path.join(logsPath, `${Date.now()}_${process.platform}_${process.arch}.log`);
return new actions({
processConfig: {command, args, options: {cwd: serverPath, maxBuffer: Infinity, env: {LD_LIBRARY_PATH: process.platform === "win32"?undefined:serverPath}, logPath: {stdout: logFileOut}}},
hooks: serverConfig
});
}
// File config
export const fileProperties = path.join(serverPath, "server.properties");
// Update file config
export type keyConfig = "serverName"|"gamemode"|"forceGamemode"|"difficulty"|"allowCheats"|"maxPlayers"|"onlineMode"|"allowList"|"serverPort"|"serverPortv6"|"viewDistance"|"tickDistance"|"playerIdleTimeout"|"maxThreads"|"levelName"|"levelSeed"|"defaultPlayerPermissionLevel"|"texturepackRequired"|"chatRestriction";
export async function updateConfig(key: "serverName", value: string): Promise<string>;
@ -111,7 +112,9 @@ export async function updateConfig(key: "levelSeed", value?: string): Promise<st
export async function updateConfig(key: "defaultPlayerPermissionLevel", value: "visitor"|"member"|"operator"): Promise<string>;
export async function updateConfig(key: "texturepackRequired", value: boolean): Promise<string>;
export async function updateConfig(key: "chatRestriction", value: "None"|"Dropped"|"Disabled"): Promise<string>;
export async function updateConfig(key: keyConfig, value: string|number|boolean): Promise<string> {
export async function updateConfig(key: keyConfig, value: string|number|boolean, platformOptions: bdsPlatformOptions = {id: "default"}): Promise<string> {
const { serverPath } = await pathControl("bedrock", platformOptions);
const fileProperties = path.join(serverPath, "server.properties");
if (!fsOld.existsSync(fileProperties)) throw new Error("Install server fist!");
let fileConfig = await fs.readFile(fileProperties, "utf8");
if (key === "serverName") fileConfig = fileConfig.replace(/server-name=.*/, `server-name=${value}`);
@ -200,7 +203,9 @@ type rawConfig = {
"emit-server-telemetry"?: boolean
}
export async function getConfig(): Promise<bedrockConfig> {
export async function getConfig(platformOptions: bdsPlatformOptions = {id: "default"}): Promise<bedrockConfig> {
const { serverPath } = await pathControl("bedrock", platformOptions);
const fileProperties = path.join(serverPath, "server.properties");
if (!fsOld.existsSync(fileProperties)) throw new Error("Install server fist");
const config = Proprieties.parse<rawConfig>(await fs.readFile(fileProperties, "utf8"));
const configBase: bedrockConfig = {};

View File

@ -1,6 +1,5 @@
import type { ObjectEncodingOptions } from "node:fs";
import * as child_process from "node:child_process";
export const execFile = child_process.execFile;
export type ExecFileOptions = ObjectEncodingOptions & child_process.ExecFileOptions & {stdio?: "ignore"|"inherit"};
export function execFileAsync(command: string): Promise<{stdout: string, stderr: string}>;
@ -15,7 +14,7 @@ export function execFileAsync(command: string, args?: ExecFileOptions|(string|nu
childOptions.maxBuffer = Infinity;
if (childOptions?.env) childOptions.env = {...process.env, ...childOptions.env};
return new Promise<{stdout: string, stderr: string}>((resolve, rejectExec) => {
const child = execFile(command, childArgs.map(String), childOptions, (err, out, err2) => {if (err) return rejectExec(err);resolve({stdout: out, stderr: err2});});
const child = child_process.execFile(command, childArgs.map(String), childOptions, (err, out, err2) => {if (err) return rejectExec(err);resolve({stdout: out, stderr: err2});});
if (options?.stdio === "inherit") {
child.stdout.on("data", data => process.stdout.write(data));
child.stderr.on("data", data => process.stderr.write(data));

View File

@ -2,22 +2,21 @@ import net from "node:net";
import crypto from "node:crypto";
import fs from "node:fs/promises";
import tar from "tar";
import { bdsRoot } from "./pathControl";
import { bdsRoot } from "./platformPathManeger";
async function exists(filePath: string) {
return fs.access(filePath).then(() => true).catch(() => false);
}
export type payload = {
httpVersion?: string,
request?: {
method: string,
path: string,
},
response?: {
code: number,
text: string
},
request?: {method: string, path: string},
response?: {code: number, text: string},
header?: {[key: string]: string|boolean|number},
second?: payload,
body?: any,
raw?: string,
socket?: net.Socket
body?: any,
};
export class payloadError extends Error {
@ -32,12 +31,16 @@ const payloadRequest = /^(GET|POST|CONNECT|HEAD|PUT|DELETE)\s+(.*)\s+HTTP\/([0-9
const payloadResponse = /HTTP\/([0-9\.]+)\s+([0-9]+)\s+([\w\S\s]+)/;
const parseHeard = /^([0-9A-Za-z\._-\s@]+):([\w\S\s]+)/;
async function parsePayload(input: string|Buffer|net.Socket): Promise<payload> {
const payloadBody: payload = {header: {}};
let data = "";
if (typeof input === "string") data = input; else {
if (Buffer.isBuffer(input)) data = input.toString("utf8");
else data = await new Promise<string>(done => input.once("data", dataInput => done(dataInput.toString("utf8"))))
else {
payloadBody.socket = input;
data = await new Promise<string>(done => input.once("data", dataInput => done(dataInput.toString("utf8"))));
}
}
const payloadBody: payload = {raw: data, header: {}};
payloadBody.raw = data;
if (/^{.*}$/.test(data.replace(/\r?\n/, ""))) {
payloadBody.body = JSON.parse(data);
return payloadBody;
@ -90,7 +93,7 @@ function stringifyPayload(socket: net.Socket, response: payload) {
let message = "";
if (response.request) message += `${response.request.method.toUpperCase()} ${response.request.path} HTTP/${response.httpVersion||"1.0"}\r\n`;
else message += `HTTP/${response.httpVersion||"1.0"} ${response.response.code} ${response.response.text}\r\n`;
if (response.header) Object.keys(response.header).forEach(key => `${key}: ${response.header[key]}\r\n`);
if (response.header) message += (Object.keys(response.header).map(key => `${key}: ${response.header[key]}`).join("\r\n"))+"\r\n";
message += "\r\n";
if (response.body !== undefined) {
if (Array.isArray(response.body)||typeof response.body === "object") message += JSON.stringify(response.body);
@ -108,7 +111,6 @@ export class exportBds {
#server = net.createServer(async (socket): Promise<any> => {
if (!this.acceptConnection) return stringifyPayload(socket, {response: {code: 400, text: "Server locked"}, body: {erro: "Server locked"}}).end();
const payload = await parsePayload(await new Promise<string>(done => socket.once("data", res => done(res.toString("utf8")))));
console.log(payload);
if (payload.header.Authorization !== this.authToken) return stringifyPayload(socket, {response: {code: 401, text: "Not allowed"}, body: {error: "Invalid token"}}).end();
else stringifyPayload(socket, {response: {code: 200, text: "Success"}, header: {Date: (new Date()).toISOString(), "Content-Type": "bdsStream/tar"}});
this.acceptConnection = false;
@ -116,8 +118,8 @@ export class exportBds {
// Compact bds root
const tarCompress = tar.create({gzip: true, cwd: bdsRoot}, await fs.readdir(bdsRoot));
tarCompress.pipe(socket);
tarCompress.on("data", ({length}) => console.log("Send to %s, size: %f", socket.localAddress+":"+socket.localPort, length));
tarCompress.on("end", () => this.#server.close());
socket.on("close", tarCompress.destroy);
});
public async listen(port = 0) {
@ -139,15 +141,14 @@ export class exportBds {
}
export async function importBds(option: {host: string, port: number, authToken: string}) {
await fs.rename(bdsRoot, bdsRoot+"_backup_"+Date.now());
const client = stringifyPayload(net.createConnection({host: option.host, port: option.port}), {request: {method: "GET", path: "/"}, header: {Authorization: option.authToken}});
await parsePayload(client);
if (await exists(bdsRoot)) await fs.rename(bdsRoot, bdsRoot+"_backup_"+Date.now());
const {socket} = await parsePayload(stringifyPayload(net.createConnection({host: option.host, port: option.port}), {request: {method: "GET", path: "/"}, header: {Authorization: option.authToken}}));
console.info("Connection sucess!");
const tar_extract = tar.extract({cwd: bdsRoot, noChmod: false, noMtime: false, preserveOwner: true});
client.pipe(tar_extract);
client.on("data", ({length}) => console.log("Recive size: %f", length));
socket.pipe(tar_extract);
return new Promise<void>((done, reject) => {
client.once("close", () => done());
client.on("error", reject);
socket.on("error", reject);
tar_extract.on("error", reject);
socket.once("close", () => tar_extract.on("finish", done));
});
}

View File

@ -2,20 +2,13 @@ import fs from "node:fs";
import readline from "node:readline";
import child_process from "node:child_process";
import { EventEmitter } from "node:events";
import type {pluginManeger as globalPluginManeger} from "./plugin/main";
import type { pluginManeger } from "./plugin/plugin";
import type { script_hook } from "./plugin/hook";
export type playerClass = {[player: string]: {action: "connect"|"disconnect"|"unknown"; date: Date; history: Array<{action: "connect"|"disconnect"|"unknown"; date: Date}>}};
export type playerBase = {playerName: string, connectTime: Date, xuid?: string, action?: string};
/**
* @deprecated Please use playerAction now
*/
export type actionsPlayer = {
name: "playerConnect"|"playerDisconnect"|"playerUnknown",
callback: (data: string, done: (player: playerBase) => void) => void
}
export type newPlayerAction = {
name: "playerAction",
callback: (data: string, playerConnect: (player: playerBase) => void, playerDisconnect: (player: playerBase) => void, playerUnknown: (player: playerBase) => void) => void
};
@ -44,7 +37,7 @@ export type actionTp = {
export type actionPlugin = {
name: "pluginManeger",
class: () => Promise<globalPluginManeger>
class: () => Promise<pluginManeger>
};
export type actionHooks = {
@ -53,15 +46,17 @@ export type actionHooks = {
}
export type actionRun = actionsServerStop|actionTp;
export type actionCallback = actionsPlayer|newPlayerAction|actionsPort|actionsServerStarted|actionsServerStarted;
export type actionCallback = actionsPlayer|actionsPort|actionsServerStarted|actionsServerStarted;
export type actionConfig = actionCallback|actionRun|actionPlugin|actionHooks;
export declare interface actions {
on(act: "error", fn: (data: any) => void): this;
on(act: "playerConnect"|"playerDisconnect"|"playerUnknown", fn: (data: playerBase) => void): this;
on(act: "portListening", fn: (data: portListen) => void): this;
on(act: "serverStarted", fn: (data: serverStarted) => void): this;
on(act: "log_stderr", fn: (data: string) => void): this;
on(act: "log_stdout", fn: (data: string) => void): this;
on(act: "log", fn: (data: string) => void): this;
on(act: "exit", fn: (data: {code: number, signal: NodeJS.Signals}) => void): this;
once(act: "playerConnect"|"playerDisconnect"|"playerUnknown", fn: (data: playerBase) => void): this;
@ -69,6 +64,7 @@ export declare interface actions {
once(act: "serverStarted", fn: (data: serverStarted) => void): this;
once(act: "log_stderr", fn: (data: string) => void): this;
once(act: "log_stdout", fn: (data: string) => void): this;
once(act: "log", fn: (data: string) => void): this;
once(act: "exit", fn: (data: {code: number, signal: NodeJS.Signals}) => void): this;
}
@ -84,7 +80,7 @@ export class actions extends EventEmitter {
return this.#childProcess?.kill(signal);
}
public plugin?: globalPluginManeger;
public plugin?: pluginManeger;
public hooks?: script_hook;
public platform?: string;
@ -114,16 +110,16 @@ export class actions extends EventEmitter {
}
public processConfig: actionCommandOption;
constructor(processConfig: actionCommandOption, config: actionConfig[]) {
constructor(platformConfig: {processConfig: actionCommandOption, hooks: actionConfig[]}) {
super({captureRejections: false});
if (!processConfig.args) processConfig.args = [];
if (!processConfig.options) processConfig.options = {};
processConfig.options.maxBuffer = Infinity;
this.processConfig = processConfig;
this.#childProcess = child_process.execFile(processConfig.command, processConfig.args, processConfig.options);
if (processConfig.options.logPath) {
this.#childProcess.stdout.pipe(fs.createWriteStream(processConfig.options.logPath.stdout));
if (processConfig.options.logPath.stderr) this.#childProcess.stderr.pipe(fs.createWriteStream(processConfig.options.logPath.stderr));
if (!platformConfig?.processConfig.args) platformConfig.processConfig.args = [];
if (!platformConfig?.processConfig.options) platformConfig.processConfig.options = {};
platformConfig.processConfig.options.maxBuffer = Infinity;
this.processConfig = platformConfig?.processConfig;
this.#childProcess = child_process.execFile(platformConfig?.processConfig.command, platformConfig?.processConfig.args, platformConfig?.processConfig.options);
if (platformConfig?.processConfig.options.logPath) {
this.#childProcess.stdout.pipe(fs.createWriteStream(platformConfig?.processConfig.options.logPath.stdout));
if (platformConfig?.processConfig.options.logPath.stderr) this.#childProcess.stderr.pipe(fs.createWriteStream(platformConfig?.processConfig.options.logPath.stderr));
}
this.#childProcess.on("error", data => this.emit("error", data));
@ -132,11 +128,11 @@ export class actions extends EventEmitter {
const readlineStderr = readline.createInterface(this.#childProcess.stderr);
readlineStdout.on("line", data => this.emit("log_stdout", data));
readlineStderr.on("line", data => this.emit("log_stderr", data));
readlineStdout.on("line", data => this.emit("data", data));
readlineStderr.on("line", data => this.emit("data", data));
readlineStdout.on("line", data => this.emit("log", data));
readlineStderr.on("line", data => this.emit("log", data));
const plug = config.find((a: actionPlugin) => a?.name === "pluginManeger") as actionPlugin;
const hooks = config.find((a: actionHooks) => a?.name === "pluginHooks") as actionHooks;
const plug = platformConfig?.hooks?.find((a: actionPlugin) => a?.name === "pluginManeger") as actionPlugin;
const hooks = platformConfig?.hooks?.find((a: actionHooks) => a?.name === "pluginHooks") as actionHooks;
if (!!hooks) Promise.resolve().then(() => hooks.class(this)).then(res => this.hooks = res);
if (!!plug) plug.class().then(res => this.plugin = res).catch(err => this.emit("error", err));
@ -177,20 +173,20 @@ export class actions extends EventEmitter {
});
// Callbacks
(config.filter((a: actionCallback) => typeof a?.callback === "function") as actionCallback[]).forEach(fn => {
(platformConfig?.hooks?.filter((a: actionCallback) => typeof a?.callback === "function") as actionCallback[]).forEach(fn => {
// Use new player actions
if (fn.name === "playerAction") {
const playerConnect = (data: playerBase) => this.emit("playerConnect", data), playerDisonnect = (data: playerBase) => this.emit("playerDisconnect", data), playerUnknown = (data: playerBase) => this.emit("playerUnknown", data);
this.on("log_stdout", data => fn.callback(data, playerConnect, playerDisonnect, playerUnknown));
this.on("log_stderr", data => fn.callback(data, playerConnect, playerDisonnect, playerUnknown));
return;
} else if (fn.name === "playerConnect"||fn.name === "playerDisconnect"||fn.name === "playerUnknown") console.warn("Migrate %s to playerAction", fn.name);
}
this.on("log_stdout", data => fn.callback(data, (...args: any[]) => this.emit(fn.name, ...args)));
this.on("log_stderr", data => fn.callback(data, (...args: any[]) => this.emit(fn.name, ...args)));
});
// Set backend run function
(config.filter((a: actionRun) => typeof a?.run === "function") as actionRun[]).forEach(action => {
(platformConfig?.hooks?.filter((a: actionRun) => typeof a?.run === "function") as actionRun[]).forEach(action => {
if (action.name === "serverStop") this.#stopServerFunction = action.run;
else if (action.name === "tp") this.#tpfunction = action.run;
});

View File

@ -1,29 +1,49 @@
import { tmpdir } from "node:os";
import fs from "node:fs";
import path from "node:path";
import axios from "axios";
import got from "got";
import tar from "tar";
import AdmZip from "adm-zip";
let got: (typeof import("got"))["default"];
const gotCjs = async () => got||(await (eval('import("got")') as Promise<typeof import("got")>)).default;
gotCjs().then(res => got = res);
export async function saveFile(url: string, options?: {filePath?: string, headers?: {[key: string]: string|number}}) {
let fileSave = path.join(tmpdir(), "bdscore_"+(Math.random()*155515151).toFixed()+"_raw_bdscore_"+path.basename(url));
const Headers = {};
let fileSave = path.join(tmpdir(), Date.now()+"_raw_bdscore_"+path.basename(url));
if (options) {
if (options.filePath && typeof options.filePath === "string") fileSave = options.filePath;
if (options.headers) Object.keys(options.headers).forEach(key => Headers[key] = String(options.headers[key]));
}
const gotStream = got.stream({url, headers: Headers, isStream: true});
gotStream.pipe(fs.createWriteStream(fileSave, {autoClose: false}));
const fsStream = fs.createWriteStream(fileSave, {autoClose: false});
const gotStream = (await gotCjs()).stream({url, headers: Headers, isStream: true});
gotStream.pipe(fsStream);
await new Promise<void>((done, reject) => {
gotStream.on("end", () => setTimeout(done, 1000));
gotStream.on("error", reject);
fsStream.on("error", reject);
gotStream.once("end", () => fsStream.once("finish", done));
});
return fileSave;
}
export async function getBuffer(url: string, options?: {method?: string,body?: any, headers?: {[key: string]: string}}): Promise<Buffer> {
const Headers = {};
let Body: any;
if (options) {
if (options.headers) Object.keys(options.headers).forEach(key => Headers[key] = options.headers[key]);
if (options.body) Body = options.body;
}
return (await gotCjs())(url, {
headers: Headers,
body: Body,
method: (options?.method||"GET").toUpperCase() as any,
responseType: "buffer"
}).then(({body}) => Buffer.from(body));
}
export async function tarExtract(url: string, options?: {folderPath?: string, headers?: {[key: string]: string|number}}) {
let fileSave = path.join(tmpdir(), "_bdscore", (Math.random()*155515151).toFixed()+"_raw_bdscore");
let fileSave = path.join(tmpdir(), "_bdscore", Date.now()+"_raw_bdscore");
const Headers = {};
if (options) {
if (options.folderPath && typeof options.folderPath === "string") fileSave = options.folderPath;
@ -31,7 +51,7 @@ export async function tarExtract(url: string, options?: {folderPath?: string, he
}
if (!fs.existsSync(fileSave)) await fs.promises.mkdir(fileSave, {recursive: true});
const gotStream = got.stream({url, headers: Headers, isStream: true});
const gotStream = (await gotCjs()).stream({url, headers: Headers, isStream: true});
const tarE = tar.extract({
cwd: fileSave,
noChmod: false,
@ -48,26 +68,28 @@ export async function tarExtract(url: string, options?: {folderPath?: string, he
});
}
export async function getBuffer(url: string, options?: {method?: string,body?: any, headers?: {[key: string]: string}}): Promise<Buffer> {
const Headers = {};
let Body: any;
if (options) {
if (options.headers) Object.keys(options.headers).forEach(key => Headers[key] = options.headers[key]);
if (options.body) Body = options.body;
const isGithubRoot = /github.com\/[\S\w]+\/[\S\w]+\/archive\//;
export async function extractZip(url: string, folderTarget: string) {
const downloadedFile = await saveFile(url);
const extract = async (targetFolder: string) => {
const zip = new AdmZip(downloadedFile);
await new Promise<void>((done, reject) => {
zip.extractAllToAsync(targetFolder, true, true, (err) => {
if (err) return done();
return reject(err);
})
});
}
// if (typeof fetch === "undefined")
return axios.get(url, {
responseEncoding: "arraybuffer",
responseType: "arraybuffer",
headers: Headers,
data: Body,
method: (options?.method||"GET").toUpperCase()
}).then(({data}) => Buffer.from(data));
// return fetch(url, {
// method: "GET",
// body: typeof Body === "object" ? JSON.stringify(Body, null, 2):Body,
// headers: Headers
// }).then(res => res.arrayBuffer()).then(res => Buffer.from(res));
if (isGithubRoot.test(url)) {
const tempFolder = await fs.promises.mkdtemp(path.join(tmpdir(), "githubRoot_"), "utf8");
await extract(tempFolder);
const files = await fs.promises.readdir(tempFolder);
if (files.length === 0) throw new Error("Invalid extract");
console.log("%s -> %s", path.join(tempFolder, files[0]), folderTarget)
await fs.promises.cp(path.join(tempFolder, files[0]), folderTarget, {recursive: true, force: true, preserveTimestamps: true, verbatimSymlinks: true});
return await fs.promises.rm(tempFolder, {recursive: true, force: true});
}
return extract(folderTarget);
}
export async function getJSON<JSONReturn = any>(url: string, options?: {method?: string, body?: any, headers?: {[key: string]: string}}): Promise<JSONReturn> {
@ -173,7 +195,7 @@ export type githubTree = {
"url": string
}[],
};
export async function githubTree(username: string, repo: string, tree: string) {
export async function githubTree(username: string, repo: string, tree: string = "main") {
const validate = /^[a-zA-Z0-9_\-]+$/;
if (!validate.test(username)) throw new Error("Invalid username");
if (!validate.test(repo)) throw new Error("Invalid repository name");

View File

@ -1,9 +1,11 @@
export { exportBds, importBds, payloadError } from "./export_import";
export { pluginManeger } from "./plugin/main";
export { importBds, exportBds, payloadError } from "./export_import";
export * as platformPathManeger from "./platformPathManeger"
export * as globalPlatfroms from "./globalPlatfroms";
export * as Bedrock from "./bedrock";
export * as pluginManeger from "./plugin/plugin";
export * as pluginHooks from "./plugin/hook";
export * as PocketmineMP from "./pocketmine";
export * as Powernukkit from "./pwnuukit";
export * as Java from "./java";
export * as PaperMC from "./paper";
export * as Bedrock from "./bedrock";
export * as Spigot from "./spigot";
export * as PaperMC from "./paper";
export * as Java from "./java";

View File

@ -3,14 +3,14 @@ import fs from "node:fs/promises";
import fsOld from "node:fs";
import os from "node:os";
import { platformManeger } from "@the-bds-maneger/server_versions";
import { serverRoot, logRoot } from "./pathControl";
import { actions, actionConfig } from "./globalPlatfroms";
import { saveFile } from "./httpRequest";
export const serverPath = path.join(serverRoot, "java");
const jarPath = path.join(serverPath, "server.jar");
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
// export const serverPath = path.join(serverRoot, "java");
export async function installServer(version: string|boolean) {
if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath } = await pathControl("java", platformOptions);
const jarPath = path.join(serverPath, "server.jar");
return platformManeger.java.find(version).then(release => saveFile(release.url, {filePath: jarPath}).then(() => release));
}
@ -58,7 +58,9 @@ const serverConfig: actionConfig[] = [
},
];
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean}) {
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean, platformOptions: bdsPlatformOptions}) {
const { serverPath, logsPath } = await pathControl("java", Config?.platformOptions||{id: "default"});
const jarPath = path.join(serverPath, "server.jar");
if (!fsOld.existsSync(jarPath)) throw new Error("Install server fist.");
const command = "java";
const args = ["-jar"];
@ -75,6 +77,9 @@ export async function startServer(Config?: {maxMemory?: number, minMemory?: numb
args.push(jarPath, "nogui");
const eula = path.join(serverPath, "eula.txt");
await fs.writeFile(eula, (await fs.readFile(eula, "utf8").catch(() => "eula=false")).replace("eula=false", "eula=true"));
const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_java_${process.platform}_${process.arch}.stdout.log`);
return new actions({command, args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}}, serverConfig);
const logFileOut = path.join(logsPath, `${Date.now()}_${process.platform}_${process.arch}.log`);
return new actions({
processConfig: {command, args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}},
hooks: serverConfig
});
}

View File

@ -2,19 +2,14 @@ import path from "node:path";
import fs from "node:fs/promises";
import fsOld from "node:fs";
import os from "node:os";
import { pluginManeger as plugin_maneger } from "./plugin/main";
import { platformManeger } from "@the-bds-maneger/server_versions";
import { serverRoot, logRoot } from "./pathControl";
import { actions, actionConfig } from "./globalPlatfroms";
import { saveFile } from "./httpRequest";
import { script_hook } from "./plugin/hook";
export const serverPath = path.join(serverRoot, "Papermc");
const jarPath = path.join(serverPath, "server.jar");
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
export const pluginManger = () => (new plugin_maneger("paper", false)).loadPlugins();
export async function installServer(version: string|boolean) {
if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
return platformManeger.paper.find(version).then(release => saveFile(release.url, {filePath: jarPath}).then(() => release));
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath } = await pathControl("paper", platformOptions);
return platformManeger.paper.find(version).then(release => saveFile(release.url, {filePath: path.join(serverPath, "paper.jar")}).then(() => release));
}
export const started = /\[.*\].*\s+Done\s+\(.*\)\!.*/;
@ -27,14 +22,6 @@ const serverConfig: actionConfig[] = [
childProcess.runCommand("stop");
},
},
{
name: "pluginManeger",
class: () => (new plugin_maneger("paper", false)).loadPlugins()
},
{
name: "pluginHooks",
class: (actions) => new script_hook("paper", actions)
},
{
name: "serverStarted",
callback(data, done) {
@ -71,8 +58,9 @@ const serverConfig: actionConfig[] = [
},
];
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean, pluginList?: string[]}) {
if (!fsOld.existsSync(jarPath)) throw new Error("Install server fist.");
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean, platformOptions?: bdsPlatformOptions}) {
const { serverPath, logsPath } = await pathControl("paper", Config?.platformOptions||{id: "default"});
if (!fsOld.existsSync(path.join(serverPath, "paper.jar"))) throw new Error("Install server fist.");
const args = [];
if (Config) {
if (Config.maxFreeMemory) {
@ -83,15 +71,14 @@ export async function startServer(Config?: {maxMemory?: number, minMemory?: numb
if (Config.minMemory) args.push(`-Xms${Config.minMemory}m`);
if (Config.maxMemory) args.push(`-Xmx${Config.maxMemory}m`);
}
if (Config.pluginList) {
const pluginManeger = await (new plugin_maneger("paper")).loadPlugins();
await Promise.all(Config.pluginList.map(pluginName => pluginManeger.installPlugin(pluginName)));
}
}
args.push("-jar", jarPath, "nogui");
args.push("-jar", path.join(serverPath, "paper.jar"), "nogui");
const eula = path.join(serverPath, "eula.txt");
await fs.writeFile(eula, (await fs.readFile(eula, "utf8").catch(() => "eula=false")).replace("eula=false", "eula=true"));
const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_spigot_${process.platform}_${process.arch}.stdout.log`);
return new actions({command: "java", args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}}, serverConfig);
const logFileOut = path.join(logsPath, `${Date.now()}_${process.platform}_${process.arch}.log`);
return new actions({
processConfig: {command: "java", args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}},
hooks: serverConfig
});
}

View File

@ -1,32 +0,0 @@
import fs from "node:fs/promises";
import fsOld from "node:fs";
import path from "node:path";
import os from "node:os";
// bds Root
export const bdsRoot = process.env.BDS_HOME||path.join(os.homedir(), ".bdsManeger");
if (!fsOld.existsSync(bdsRoot)) fs.mkdir(bdsRoot, {recursive: true}).then(() => console.log("Bds Root created"));
// Server Folder
export const serverRoot = path.join(bdsRoot, "Servers");
if (!fsOld.existsSync(serverRoot)) fs.mkdir(serverRoot, {recursive: true});
// Build Folder
export const BuildRoot = path.join(bdsRoot, "build");
if (!fsOld.existsSync(BuildRoot)) fs.mkdir(BuildRoot, {recursive: true});
// Logs Folder
export const logRoot = path.join(bdsRoot, "logFolder");
if (!fsOld.existsSync(logRoot)) fs.mkdir(logRoot, {recursive: true});
// Worlds Folder
export const worldFolder = path.join(bdsRoot, "Worlds");
if (!fsOld.existsSync(worldFolder)) fs.mkdir(serverRoot, {recursive: true});
// Plugins hooks
export const pluginHooksFolder = path.join(bdsRoot, "pluginHooks");
if (!fsOld.existsSync(pluginHooksFolder)) fs.mkdir(pluginHooksFolder, {recursive: true});
// Bds backup
export const backupFolder = path.join(bdsRoot, "Backup");
if (!fsOld.existsSync(backupFolder)) fs.mkdir(backupFolder, {recursive: true});

120
src/platformPathManeger.ts Normal file
View File

@ -0,0 +1,120 @@
import crypto from "node:crypto";
import path from "node:path";
import fs from "node:fs/promises";
import os from "node:os";
export let bdsRoot = path.join(os.homedir(), ".bdsManeger");
if (process.env.BDS_HOME) {
if (process.env.BDS_HOME.startsWith("~")) process.env.BDS_HOME = process.env.BDS_HOME.replace("~", os.homedir());
bdsRoot = process.env.BDS_HOME;
}
async function exists(filePath: string) {
return fs.access(filePath).then(() => true).catch((() => false));
}
export type bdsPlatform = "bedrock"|"java"|"pocketmine"|"spigot"|"powernukkit"|"paper";
export type bdsPlatformOptions = {
newId?: boolean,
id?: "default"|string,
withBuildFolder?: boolean
};
// This array to valida platform imput!
const platformArray: bdsPlatform[] = [
"bedrock",
"java",
"pocketmine",
"spigot",
"powernukkit",
"paper"
];
/**
* Register or get folder to Servers, this is to create and maneger folders
* @param platform - Select platform to maneger folders
* @param options - ?
*/
export async function pathControl(platform: bdsPlatform, options?: bdsPlatformOptions) {
if (!platformArray.includes(platform)) throw new Error("Invalid platform");
if (!options) options = {};
if (!await exists(path.join(bdsRoot, platform))) await fs.mkdir(path.join(bdsRoot, platform), {recursive: true});
// Create if not exists
const foldersAndLink = await fs.readdir(path.join(bdsRoot, platform));
if (foldersAndLink.length === 0) options.newId = true;
if (options.newId) {
options.id = crypto.randomBytes(12).toString("hex");
fs.mkdir(path.join(bdsRoot, platform, options.id), {recursive: true});
if (await exists(path.join(bdsRoot, platform, "default"))) await fs.unlink(path.join(bdsRoot, platform, "default"));
await fs.symlink(path.join(bdsRoot, platform, options.id), path.join(bdsRoot, platform, "default"));
}
// Get real id
if (options?.id === "default") options.id = path.basename(await fs.realpath(path.join(bdsRoot, platform, options.id)));
// Create folder if not exists
const serverRoot = path.join(bdsRoot, platform, options.id);
if (!(await exists(serverRoot))) await fs.mkdir(serverRoot, {recursive: true});
const serverPath = path.join(serverRoot, "server");
if (!(await exists(serverPath))) await fs.mkdir(serverPath, {recursive: true});
const hooksPath = path.join(serverRoot, "hooks");
if (!(await exists(hooksPath))) await fs.mkdir(hooksPath, {recursive: true});
const backupPath = path.join(serverRoot, "backup");
if (!(await exists(backupPath))) await fs.mkdir(backupPath, {recursive: true});
const logsPath = path.join(serverRoot, "logs");
if (!(await exists(logsPath))) await fs.mkdir(logsPath, {recursive: true});
let buildFolder: string;
if (options?.withBuildFolder) {
buildFolder = path.join(serverRoot, "build");
if (!(await exists(buildFolder))) await fs.mkdir(buildFolder, {recursive: true});
}
return {
id: options?.id,
serverRoot,
serverPath,
hooksPath,
backupPath,
logsPath,
buildFolder,
};
}
/**
* Change default folder to Platform
* @param platform
* @param id
* @returns
*/
export async function changeDefault(platform: bdsPlatform, id: bdsPlatformOptions["id"]) {
if (!platformArray.includes(platform)) throw new Error("Invalid platform");
const serverPlatform = path.join(bdsRoot, platform);
if (!await exists(serverPlatform)) throw new Error("Install server fist!");
const ids = (await fs.readdir(serverPlatform)).filter(folder => folder.toLowerCase() !== "default");
if (!ids.includes(id)) throw new Error("Id not exists to Platform");
const oldPath = fs.realpath(path.join(bdsRoot, platform, "default"));
if (await exists(path.join(bdsRoot, platform, "default"))) await fs.unlink(path.join(bdsRoot, platform, "default"));
await fs.symlink(path.join(bdsRoot, platform, id), path.join(bdsRoot, platform, "default"));
return {
oldPath,
newPath: path.join(bdsRoot, platform, id)
};
}
/**
* Get all ids to platform
* @param platform
* @returns
*/
export async function getIds(platform: bdsPlatform) {
if (!platformArray.includes(platform)) throw new Error("Invalid platform");
const serverPlatform = path.join(bdsRoot, platform);
if (!await exists(serverPlatform)) throw new Error("Install server fist!");
return (await fs.readdir(serverPlatform)).filter(folder => folder.toLowerCase() !== "default");
}

View File

@ -2,7 +2,6 @@ import path from "node:path";
import fs from "node:fs/promises";
import { execFileAsync } from "../childPromisses";
import { actions } from "../globalPlatfroms";
import { pluginHooksFolder } from "../pathControl";
import { saveFile } from "../httpRequest";
export type hooksPlatform = "bedrock"|"java"|"pocketmine"|"spigot"|"powernukkit"|"paper";
@ -23,7 +22,6 @@ export class script_hook {
#serverActions: actions;
#currentPlatform: hooksPlatformGeneric;
#localFolder: string;
#localGericFolder = path.join(pluginHooksFolder, "Generic");
async #registerScript(filePath: string) {
const lo_script = (await(eval(`import("${filePath}")`))) as hooksRegister|{default: hooksRegister};
@ -42,11 +40,8 @@ export class script_hook {
async #loadLocalScript() {
if (!this.#serverActions) throw new Error("Server actions (globalPlatform) is undefined");
if (!await exists(this.#localFolder)) await fs.mkdir(this.#localFolder, {recursive: true});
if (!await exists(this.#localGericFolder)) await fs.mkdir(this.#localGericFolder, {recursive: true});
const localFiles = (await fs.readdir(this.#localFolder)).map(file => path.join(this.#localFolder, file));
const genericLocalFiles = (await fs.readdir(this.#localGericFolder)).map(file => path.join(this.#localGericFolder, file));
console.log(([...localFiles, ...genericLocalFiles]));
for (const localFile of ([...localFiles, ...genericLocalFiles])) {
for (const localFile of localFiles) {
await fs.lstat(localFile).then(async stat => {
if (stat.isFile()) return this.#registerScript(localFile);
if (await exists(path.join(localFile, "package.json"))) {
@ -66,30 +61,23 @@ export class script_hook {
}
}
public async installHook(urlHost: string, fileName?: string, isGeneric?: boolean) {
public async installHook(urlHost: string, fileName?: string) {
if (!await exists(this.#localFolder)) await fs.mkdir(this.#localFolder, {recursive: true});
if (!await exists(this.#localGericFolder)) await fs.mkdir(this.#localGericFolder, {recursive: true});
if (!fileName) fileName = path.basename(urlHost);
const onSave = path.join(isGeneric?this.#localGericFolder:this.#localFolder, fileName);
const onSave = path.join(this.#localFolder, fileName);
// Git
if (gitUrlDetect.test(urlHost)) {
await execFileAsync("git", ["clone", urlHost, "--depth", 1, onSave], {cwd: pluginHooksFolder});
await execFileAsync("git", ["clone", urlHost, "--depth", 1, onSave], {cwd: this.#localFolder});
if (await exists(path.join(onSave, "package.json"))) await execFileAsync("npm", ["install", "--no-save"], {cwd: onSave, stdio: "inherit"});
} else await saveFile(urlHost, {filePath: onSave});
if (!!this.#serverActions) await this.#registerScript(onSave);
return;
}
constructor(targetPlatform: hooksPlatform, platformActions?: actions) {
constructor(hookFolder: string, targetPlatform: hooksPlatform, platformActions?: actions) {
this.#serverActions = platformActions;
this.#currentPlatform = targetPlatform;
if (targetPlatform === "spigot") this.#localFolder = path.join(pluginHooksFolder, "Spigot");
else if (targetPlatform === "paper") this.#localFolder = path.join(pluginHooksFolder, "Spigot");
else if (targetPlatform === "pocketmine") this.#localFolder = path.join(pluginHooksFolder, "PocketmineMP");
else if (targetPlatform === "powernukkit") this.#localFolder = path.join(pluginHooksFolder, "Powernukkit");
else if (targetPlatform === "bedrock") this.#localFolder = path.join(pluginHooksFolder, "Bedrock");
else if (targetPlatform === "java") this.#localFolder = path.join(pluginHooksFolder, "Java");
else throw new Error("Invalid platform");
this.#localFolder = hookFolder;
if (platformActions) this.#loadLocalScript();
}
}

View File

@ -1,85 +0,0 @@
import path from "node:path/posix";
import fs from "node:fs/promises";
import admZip from "adm-zip";
import { existsSync } from "node:fs";
import { saveFile, githubTree, getJSON } from "../httpRequest";
import { serverPath as spigotServerPath } from "../spigot";
import { serverPath as papertServerPath } from "../paper";
import { serverPath as pocketmineServerPath } from "../pocketmine";
import { serverPath as powernukkittServerPath } from "../pwnuukit";
import { actions } from "../globalPlatfroms";
import { script_hook } from "./hook";
export type pluginPlatform = "spigot"|"paper"|"pocketmine"|"powernukkit";
export type pluginFunctions = {
platforms: pluginPlatform[],
scriptName?: string,
register: (actions: actions) => void,
};
export type pluginConfig = {
name: string,
fileName?: string,
url: string,
type?: "zip"|"jar"|"raw",
platforms: pluginPlatform[],
dependes?: (string|pluginConfig)[],
scripts?: string[]
};
export class pluginManeger {
#platform: pluginPlatform;
#hook: script_hook;
pluginList: pluginConfig[] = [];
scriptList: pluginFunctions[] = [];
#mountRepoRaw(...args: string[]) {
const ufixPath = path.join("/The-Bds-Maneger/plugin_list/main", path.resolve("/", ...args));
return {
url: "https://raw.githubusercontent.com"+ufixPath,
addPluginStyle: ufixPath.replace(/\/The\-Bds\-Maneger\/plugin_list\/main\/|\.\//, "")
};
}
async #addPlugin (file?: string): Promise<pluginConfig|void> {
const config = await getJSON<pluginConfig>(this.#mountRepoRaw(file).url);
if (this.pluginList.some(plugin => plugin.name === config.name)) return config;
if (!config.platforms?.includes(this.#platform)) return;
this.pluginList.push(config);
if (config.dependes) {
config.dependes = await Promise.all(config.dependes.map((depend: string) => this.#addPlugin(this.#mountRepoRaw(path.dirname(file), depend).addPluginStyle))) as pluginConfig[];
}
};
async installPlugin(name: string) {
const plugin = this.pluginList.find(plugin => plugin.name === name);
if (!plugin) throw new Error(`${name} plugin not avaible to install`);
console.log("Installing %s plugin", plugin.name);
let pluginFolder: string;
if (this.#platform === "paper") pluginFolder = path.join(papertServerPath, "plugins");
else if (this.#platform === "spigot") pluginFolder = path.join(spigotServerPath, "plugins");
else if (this.#platform === "pocketmine") pluginFolder = path.join(pocketmineServerPath, "plugins");
else if (this.#platform === "powernukkit") pluginFolder = path.join(powernukkittServerPath, "plugins");
else throw new Error("Invalid platform");
if (!existsSync(pluginFolder)) await fs.mkdir(pluginFolder, {recursive: true});
const saveOut = path.join(pluginFolder, plugin.fileName||`${plugin.name}.${path.extname(plugin.fileName||plugin.url)}`);
await saveFile(plugin.url, {filePath: saveOut});
if (plugin.type === "zip") {
const zip = new admZip(saveOut);
zip.extractAllTo(pluginFolder, true);
await fs.rm(saveOut, {force: true});
}
if (plugin.scripts && !!this.#hook) await Promise.all(plugin.scripts.map(file => this.#hook.installHook(this.#mountRepoRaw(file).url)));
if (plugin.dependes) await Promise.all(plugin.dependes.map((depend: pluginConfig) => this.installPlugin(depend.name)));
}
async loadPlugins() {
for (const file of (await githubTree("The-Bds-Maneger", "plugin_list", "main")).tree.filter(file => file.path.endsWith(".json"))) await this.#addPlugin(file.path);
return this;
}
constructor(platform: pluginPlatform, autloadPLugins: boolean = true) {
this.#platform = platform;
this.#hook = new script_hook(platform);
if (autloadPLugins) this.loadPlugins();
}
};

36
src/plugin/plugin.ts Normal file
View File

@ -0,0 +1,36 @@
import path from "node:path";
import * as http_request from "../httpRequest";
import type { bdsPlatform } from "../platformPathManeger";
export type pluginConfig = {
name: string,
url: string,
fileName?: string,
platforms: bdsPlatform[],
dependecies?: string[],
/** @deprecated */
scripts?: string[],
};
export class pluginManeger {
#pluginFolder: string;
constructor(pluginFolder: string) {
this.#pluginFolder = pluginFolder;
}
async installPlugin(pluginName: string) {
let pluginUrl = pluginName;
if (!/^http[s]:\/\//.test(pluginName)) {
const file = (await http_request.githubTree("The-Bds-Maneger", "plugin_list")).tree.find(file => file.path.includes("plugins/") && file.path.endsWith(".json") && path.parse(file.path.toLowerCase()).name === pluginName);
if (!file) throw new Error("Cannot find plugin!");
pluginUrl = `https://raw.githubusercontent.com/The-Bds-Maneger/plugin_list/main/${file.path}`;
}
const pluginConfig: pluginConfig = await http_request.getJSON(pluginUrl);
if (!pluginConfig.fileName) pluginConfig.fileName = path.basename(pluginConfig.url);
await http_request.saveFile(pluginConfig.url, {
filePath: path.join(this.#pluginFolder, pluginConfig?.fileName)
});
await Promise.all(pluginConfig.dependecies?.map(depencie => this.installPlugin(depencie)));
if (pluginConfig.scripts) console.info("Plese migrate (%s) script to hooks", pluginConfig.fileName);
}
};

View File

@ -1,24 +1,22 @@
import path from "node:path";
import fs from "node:fs/promises";
import os from "node:os";
import { existsSync as fsExistsSync, Stats } from "node:fs";
import AdmZip from "adm-zip";
import { existsSync as fsExistsSync, Stats } from "node:fs";
import { platformManeger } from "@the-bds-maneger/server_versions";
import { execFileAsync, execAsync } from './childPromisses';
import { logRoot, serverRoot } from "./pathControl";
import { getBuffer, githubRelease, GithubRelease, saveFile, tarExtract } from "./httpRequest";
import { actionConfig, actions } from './globalPlatfroms';
import AdmZip from "adm-zip";
import { promisify } from 'node:util';
export const serverPath = path.join(serverRoot, "pocketmine");
export const serverPhar = path.join(serverPath, "pocketmine.phar");
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
async function findPhp(extraPath?: string): Promise<string> {
async function findPhp(serverPath: string, extraPath?: string): Promise<string> {
if (!extraPath) extraPath = path.join(serverPath, "bin");
const files = await Promise.all((await fs.readdir(extraPath)).map(file => fs.lstat(path.join(extraPath, file)).then(stat => ({stat, file, fullPath: path.join(extraPath, file)})).catch(() => {})));
let folderFF = "";
for (const file of (files.filter(a=>!!a) as {file: string, fullPath: string, stat: Stats}[]).sort(a => a.stat.isDirectory() ? 1:-1)) {
if (file.stat.isDirectory()) {
folderFF = await findPhp(file.fullPath).catch(() => "");
folderFF = await findPhp(serverPath, file.fullPath).catch(() => "");
if (folderFF) return folderFF;
} else if (file.file === "php"||file.file === "php.exe") return file.fullPath;
}
@ -50,7 +48,7 @@ if (!filter) filter = [/.*/];
return files;
}
async function buildPhp() {
async function buildPhp(serverPath: string) {
if (fsExistsSync(path.resolve(serverPath, "bin"))) await fs.rm(path.resolve(serverPath, "bin"), {recursive: true});
const tempFolder = path.join(os.tmpdir(), "bdsPhp_"+(Math.random()*19999901).toString(16).replace(".", "").replace(/[0-9]/g, (_, a) =>a=="1"?"a":a=="2"?"b":a=="3"?"S":"k"));
if (!fsExistsSync(tempFolder)) fs.mkdir(tempFolder, {recursive: true});
@ -70,7 +68,7 @@ async function buildPhp() {
console.log("PHP Build success!");
}
async function installPhp(): Promise<void> {
async function installPhp(serverPath: string): Promise<void> {
const releases: (githubRelease["assets"][0])[] = [];
(await GithubRelease("The-Bds-Maneger", "Build-PHP-Bins")).map(re => re.assets).forEach(res => releases.push(...res));
if (fsExistsSync(path.resolve(serverPath, "bin"))) await fs.rm(path.resolve(serverPath, "bin"), {recursive: true});
@ -100,17 +98,17 @@ async function installPhp(): Promise<void> {
}
}
// test it's works php
await execFileAsync(await findPhp(), ["-v"]).catch(err => {
await execFileAsync(await findPhp(serverPath), ["-v"]).catch(err => {
console.warn(String(err));
return buildPhp()
return buildPhp(serverPath)
});
}
export async function installServer(version: string|boolean) {
if (!fsExistsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
await installPhp();
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath } = await pathControl("pocketmine", platformOptions);
await installPhp(serverPath);
const info = await platformManeger.pocketmine.find(version);
await saveFile(info?.url, {filePath: serverPhar});
await saveFile(info?.url, {filePath: path.join(serverPath, "pocketmine.phar")});
return info;
}
@ -152,8 +150,13 @@ const serverConfig: actionConfig[] = [
},
];
export async function startServer() {
if (!fsExistsSync(serverPath)) throw new Error("Install server fist!");
const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_pocketmine_${process.platform}_${process.arch}.stdout.log`);
return new actions({command: await findPhp(), args: [serverPhar, "--no-wizard", "--enable-ansi"], options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}}, serverConfig);
export async function startServer(platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath, logsPath } = await pathControl("pocketmine", platformOptions);
const serverPhar = path.join(serverPath, "pocketmine.phar");
if (!fsExistsSync(serverPhar)) throw new Error("Install server fist!");
const logFileOut = path.join(logsPath, `${Date.now()}_${process.platform}_${process.arch}.stdout.log`);
return new actions({
processConfig: {command: await findPhp(serverPath), args: [serverPhar, "--no-wizard", "--enable-ansi"], options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}},
hooks: serverConfig
});
}

View File

@ -1,16 +1,21 @@
import * as path from "node:path";
import * as fsOld from "node:fs";
import * as fs from "node:fs/promises";
import path from "node:path";
import fsOld from "node:fs";
import fs from "node:fs/promises";
import os from "node:os";
import { serverRoot, logRoot } from './pathControl';
import { actions, actionConfig } from './globalPlatfroms';
import { actions, actionConfig } from "./globalPlatfroms";
import { platformManeger } from "@the-bds-maneger/server_versions";
import { saveFile } from "./httpRequest";
export const serverPath = path.join(serverRoot, "power_nukkit");
const jarPath = path.join(serverPath, "pwnukkit.jar");
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath } = await pathControl("powernukkit", platformOptions);
const jarPath = path.join(serverPath, "pwnukkit.jar");
if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
return platformManeger.powernukkit.find(version).then(release => saveFile(release.url, {filePath: jarPath}).then(() => release));
}
export const playerAction = /^.*\[.*\]\s([\S\w]+|"[\S\w]+")\s+(left|joined)\s+the\s+game$/;
export const portListen = /Opening\s+server\s+on\s+(([A-Za-z0-9:\.]+):([0-9]+))/;
const serverConfig: actionConfig[] = [
{
name: "serverStop",
@ -50,12 +55,9 @@ const serverConfig: actionConfig[] = [
}
];
export async function installServer(version: string|boolean) {
if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
return platformManeger.powernukkit.find(version).then(release => saveFile(release.url, {filePath: jarPath}).then(() => release));
}
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean}) {
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean, platformOptions?: bdsPlatformOptions}) {
const { serverPath, logsPath } = await pathControl("powernukkit", Config?.platformOptions||{id: "default"});
const jarPath = path.join(serverPath, "pwnukkit.jar");
if (!fsOld.existsSync(jarPath)) throw new Error("Install server fist.");
const args = [
"-XX:+UseG1GC",
@ -90,6 +92,9 @@ export async function startServer(Config?: {maxMemory?: number, minMemory?: numb
}
}
args.push("-jar", jarPath, "--language", "eng");
const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_pwnukkit_${process.platform}_${process.arch}.stdout.log`);
return new actions({command: "java", args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}}, serverConfig);
const logFileOut = path.join(logsPath, `${Date.now()}_${process.platform}_${process.arch}.log`);
return new actions({
processConfig: {command: "java", args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}},
hooks: serverConfig
});
}

View File

@ -2,15 +2,9 @@ import path from "node:path";
import fs from "node:fs/promises";
import fsOld from "node:fs";
import os from "node:os";
import {pluginManeger as plugin_maneger} from "./plugin/main";
import { serverRoot, logRoot, BuildRoot } from './pathControl';
import { actions, actionConfig } from './globalPlatfroms';
import { actions, actionConfig } from "./globalPlatfroms";
import { getBuffer, getJSON, saveFile } from "./httpRequest";
import { script_hook } from "./plugin/hook";
export const serverPath = path.join(serverRoot, "spigot");
export const serverPathBuild = path.join(BuildRoot, "spigot");
const jarPath = path.join(serverPath, "server.jar");
import { pathControl, bdsPlatformOptions } from "./platformPathManeger";
async function listVersions() {
const data = (await getBuffer("https://hub.spigotmc.org/versions/")).toString("utf8").split("\r").filter(line => /\.json/.test(line)).map(line => {const [, data] = line.match(/>(.*)<\//); return data?.replace(".json", "");}).filter(ver => /^[0-9]+\./.test(ver));
@ -25,15 +19,14 @@ async function listVersions() {
return data2.sort((b, a) => a.date.getTime() - b.date.getTime());
}
export async function installServer(version: string|boolean) {
if (!fsOld.existsSync(serverPath)) await fs.mkdir(serverPath, {recursive: true});
if (!fsOld.existsSync(serverPathBuild)) await fs.mkdir(serverPathBuild, {recursive: true});
export async function installServer(version: string|boolean, platformOptions: bdsPlatformOptions = {id: "default"}) {
const { serverPath } = await pathControl("spigot", platformOptions);
const jarPath = path.join(serverPath, "server.jar");
if (typeof version === "boolean"||version === "latest") version = (await listVersions())[0].version;
await fs.cp(await saveFile(`https://github.com/The-Bds-Maneger/SpigotBuilds/releases/download/${version}/Spigot.jar`), jarPath, {force: true});
return;
}
export const pluginManger = () => (new plugin_maneger("spigot", false)).loadPlugins();
export const started = /\[.*\].*\s+Done\s+\(.*\)\!.*/;
export const portListen = /\[.*\]:\s+Starting\s+Minecraft\s+server\s+on\s+(([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[A-Za-z0-9]+|\*):([0-9]+))/;
@ -43,14 +36,6 @@ const serverConfig: actionConfig[] = [
name: "serverStop",
run: (child) => child.runCommand("stop")
},
{
name: "pluginManeger",
class: () => (new plugin_maneger("spigot", false)).loadPlugins()
},
{
name: "pluginHooks",
class: (actions) => new script_hook("spigot", actions)
},
{
name: "serverStarted",
callback(data, done) {
@ -89,7 +74,9 @@ const serverConfig: actionConfig[] = [
},
];
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean, pluginList?: string[]}) {
export async function startServer(Config?: {maxMemory?: number, minMemory?: number, maxFreeMemory?: boolean, platformOptions?: bdsPlatformOptions}) {
const { serverPath, logsPath } = await pathControl("spigot", Config?.platformOptions||{id: "default"});
const jarPath = path.join(serverPath, "server.jar");
if (!fsOld.existsSync(jarPath)) throw new Error("Install server fist.");
const args = [];
if (Config) {
@ -101,16 +88,14 @@ export async function startServer(Config?: {maxMemory?: number, minMemory?: numb
if (Config.minMemory) args.push(`-Xms${Config.minMemory}m`);
if (Config.maxMemory) args.push(`-Xmx${Config.maxMemory}m`);
}
if (Config.pluginList) {
const pluginManeger = await (new plugin_maneger("spigot")).loadPlugins();
await Promise.all(Config.pluginList.map(pluginName => pluginManeger.installPlugin(pluginName)));
}
}
args.push("-jar", jarPath, "nogui");
const eula = path.join(serverPath, "eula.txt");
await fs.readFile(eula, "utf8").catch(() => "eula=false").then(eulaFile => fs.writeFile(eula, eulaFile.replace("eula=false", "eula=true")));
const logFileOut = path.join(logRoot, `bdsManeger_${Date.now()}_spigot_${process.platform}_${process.arch}.stdout.log`);
return new actions({command: "java", args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}}, serverConfig);
const logFileOut = path.join(logsPath, `${Date.now()}_${process.platform}_${process.arch}.log`);
return new actions({
processConfig: {command: "java", args, options: {cwd: serverPath, maxBuffer: Infinity, logPath: {stdout: logFileOut}}},
hooks: serverConfig
});
}

View File

@ -4,8 +4,6 @@ describe("PaperMC", () => {
it("Install and Start", async function(){
this.timeout(Infinity);
await paper.installServer("latest");
const plugin = await paper.pluginManger();
await plugin.installPlugin("Geyser");
const serverManeger = await paper.startServer({maxFreeMemory: true});
serverManeger.on("log_stdout", console.log);
serverManeger.on("log_stderr", console.info);

View File

@ -4,8 +4,6 @@ describe("Spigot", () => {
it("Install and Start", async function(){
this.timeout(Infinity);
await spigot.installServer("latest");
const plugin = await spigot.pluginManger();
await plugin.installPlugin("Geyser");
const serverManeger = await spigot.startServer();
serverManeger.on("log_stdout", console.log);
serverManeger.on("log_stderr", console.info);