forked from noxious/server
Compare commits
41 Commits
feature/#1
...
feature/#1
Author | SHA1 | Date | |
---|---|---|---|
4e1e7d95ac | |||
d29420cbf3 | |||
acc04daa27 | |||
8abf5acef3 | |||
780cac9644 | |||
44481e19a8 | |||
9075bfaad5 | |||
bfd941c091 | |||
bb9f62a9c8 | |||
049b9de2b3 | |||
2008646a3f | |||
075592702c | |||
d271efc1ec | |||
297d4742a4 | |||
ab649b9fa1 | |||
4f643269eb | |||
ce1708a55e | |||
4cbd62cbb0 | |||
7b3c4b92a5 | |||
da8ef9fa65 | |||
4f9a1bc879 | |||
3638e2a793 | |||
6ac827630a | |||
3ec4bc2557 | |||
6a286590b4 | |||
34ed2ba7cb | |||
72159cdc17 | |||
70d8c43350 | |||
3a83f2c1ff | |||
ddeee356b4 | |||
e9fb277d63 | |||
e8aee51248 | |||
46fdb3edb6 | |||
dec6b36699 | |||
21a75f6cbe | |||
10a231b54c | |||
cc9eada654 | |||
6f057639c0 | |||
251a72aa97 | |||
0d7ed18b03 | |||
4a9b7987dc |
5
.gitignore
vendored
5
.gitignore
vendored
@ -309,7 +309,4 @@ $RECYCLE.BIN/
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
# End of https://www.toptal.com/developers/gitignore/api/node,jetbrains+all,visualstudiocode,macos,windows
|
||||
|
||||
prisma/dev.db
|
||||
prisma/dev.db-journal
|
||||
# End of https://www.toptal.com/developers/gitignore/api/node,jetbrains+all,visualstudiocode,macos,windows
|
10
Dockerfile
10
Dockerfile
@ -1,8 +1,8 @@
|
||||
# Use the official Node.js 22.4.1 image
|
||||
FROM node:22.4.1-alpine
|
||||
|
||||
# Install Redis
|
||||
RUN apk add --no-cache redis
|
||||
# Install Redis and tmux
|
||||
RUN apk add --no-cache redis tmux
|
||||
|
||||
# Set the working directory in the container
|
||||
WORKDIR /usr/src/
|
||||
@ -28,11 +28,13 @@ RUN npm run build
|
||||
# Expose the ports your Node.js application and Redis will listen on
|
||||
EXPOSE 80 6379
|
||||
|
||||
# Create a shell script to run Redis, run migrations, and start the application
|
||||
# Create a shell script to run Redis, run migrations, and start the application in a tmux session
|
||||
RUN echo '#!/bin/sh' > /usr/src/start.sh && \
|
||||
echo 'redis-server --daemonize yes' >> /usr/src/start.sh && \
|
||||
echo 'npx prisma migrate deploy' >> /usr/src/start.sh && \
|
||||
echo 'node dist/server.js' >> /usr/src/start.sh && \
|
||||
echo 'tmux new-session -d -s nodeapp "node dist/server.js"' >> /usr/src/start.sh && \
|
||||
echo 'echo "App is running in tmux session. Attach with: tmux attach-session -t nodeapp"' >> /usr/src/start.sh && \
|
||||
echo 'tail -f /dev/null' >> /usr/src/start.sh && \
|
||||
chmod +x /usr/src/start.sh
|
||||
|
||||
# Use the shell script as the entry point
|
||||
|
279
package-lock.json
generated
279
package-lock.json
generated
@ -44,9 +44,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@emnapi/runtime": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz",
|
||||
"integrity": "sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==",
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.3.1.tgz",
|
||||
"integrity": "sha512-kEBmG8KyqtxJZv+ygbEim+KCGtIq1fC22Ms3S4ziXmYKm8uyoLX0MHONVKwp+9opg390VaKRNt4a7A9NwmpNhw==",
|
||||
"license": "MIT",
|
||||
"optional": true,
|
||||
"dependencies": {
|
||||
@ -524,9 +524,9 @@
|
||||
]
|
||||
},
|
||||
"node_modules/@prisma/client": {
|
||||
"version": "5.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.19.1.tgz",
|
||||
"integrity": "sha512-x30GFguInsgt+4z5I4WbkZP2CGpotJMUXy+Gl/aaUjHn2o1DnLYNTA+q9XdYmAQZM8fIIkvUiA2NpgosM3fneg==",
|
||||
"version": "5.21.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/client/-/client-5.21.1.tgz",
|
||||
"integrity": "sha512-3n+GgbAZYjaS/k0M03yQsQfR1APbr411r74foknnsGpmhNKBG49VuUkxIU6jORgvJPChoD4WC4PqoHImN1FP0w==",
|
||||
"hasInstallScript": true,
|
||||
"license": "Apache-2.0",
|
||||
"engines": {
|
||||
@ -542,48 +542,48 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/debug": {
|
||||
"version": "5.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.19.1.tgz",
|
||||
"integrity": "sha512-lAG6A6QnG2AskAukIEucYJZxxcSqKsMK74ZFVfCTOM/7UiyJQi48v6TQ47d6qKG3LbMslqOvnTX25dj/qvclGg==",
|
||||
"version": "5.21.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/debug/-/debug-5.21.1.tgz",
|
||||
"integrity": "sha512-uY8SAhcnORhvgtOrNdvWS98Aq/nkQ9QDUxrWAgW8XrCZaI3j2X7zb7Xe6GQSh6xSesKffFbFlkw0c2luHQviZA==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@prisma/engines": {
|
||||
"version": "5.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.19.1.tgz",
|
||||
"integrity": "sha512-kR/PoxZDrfUmbbXqqb8SlBBgCjvGaJYMCOe189PEYzq9rKqitQ2fvT/VJ8PDSe8tTNxhc2KzsCfCAL+Iwm/7Cg==",
|
||||
"version": "5.21.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-5.21.1.tgz",
|
||||
"integrity": "sha512-hGVTldUkIkTwoV8//hmnAAiAchi4oMEKD3aW5H2RrnI50tTdwza7VQbTTAyN3OIHWlK5DVg6xV7X8N/9dtOydA==",
|
||||
"hasInstallScript": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@prisma/debug": "5.19.1",
|
||||
"@prisma/engines-version": "5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3",
|
||||
"@prisma/fetch-engine": "5.19.1",
|
||||
"@prisma/get-platform": "5.19.1"
|
||||
"@prisma/debug": "5.21.1",
|
||||
"@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36",
|
||||
"@prisma/fetch-engine": "5.21.1",
|
||||
"@prisma/get-platform": "5.21.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/engines-version": {
|
||||
"version": "5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3.tgz",
|
||||
"integrity": "sha512-xR6rt+z5LnNqTP5BBc+8+ySgf4WNMimOKXRn6xfNRDSpHvbOEmd7+qAOmzCrddEc4Cp8nFC0txU14dstjH7FXA==",
|
||||
"version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36.tgz",
|
||||
"integrity": "sha512-qvnEflL0//lh44S/T9NcvTMxfyowNeUxTunPcDfKPjyJNrCNf2F1zQLcUv5UHAruECpX+zz21CzsC7V2xAeM7Q==",
|
||||
"license": "Apache-2.0"
|
||||
},
|
||||
"node_modules/@prisma/fetch-engine": {
|
||||
"version": "5.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.19.1.tgz",
|
||||
"integrity": "sha512-pCq74rtlOVJfn4pLmdJj+eI4P7w2dugOnnTXpRilP/6n5b2aZiA4ulJlE0ddCbTPkfHmOL9BfaRgA8o+1rfdHw==",
|
||||
"version": "5.21.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/fetch-engine/-/fetch-engine-5.21.1.tgz",
|
||||
"integrity": "sha512-70S31vgpCGcp9J+mh/wHtLCkVezLUqe/fGWk3J3JWZIN7prdYSlr1C0niaWUyNK2VflLXYi8kMjAmSxUVq6WGQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@prisma/debug": "5.19.1",
|
||||
"@prisma/engines-version": "5.19.1-2.69d742ee20b815d88e17e54db4a2a7a3b30324e3",
|
||||
"@prisma/get-platform": "5.19.1"
|
||||
"@prisma/debug": "5.21.1",
|
||||
"@prisma/engines-version": "5.21.1-1.bf0e5e8a04cada8225617067eaa03d041e2bba36",
|
||||
"@prisma/get-platform": "5.21.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@prisma/get-platform": {
|
||||
"version": "5.19.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.19.1.tgz",
|
||||
"integrity": "sha512-sCeoJ+7yt0UjnR+AXZL7vXlg5eNxaFOwC23h0KvW1YIXUoa7+W2ZcAUhoEQBmJTW4GrFqCuZ8YSP0mkDa4k3Zg==",
|
||||
"version": "5.21.1",
|
||||
"resolved": "https://registry.npmjs.org/@prisma/get-platform/-/get-platform-5.21.1.tgz",
|
||||
"integrity": "sha512-sRxjL3Igst3ct+e8ya/x//cDXmpLbZQ5vfps2N4tWl4VGKQAmym77C/IG/psSMsQKszc8uFC/q1dgmKFLUgXZQ==",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@prisma/debug": "5.19.1"
|
||||
"@prisma/debug": "5.21.1"
|
||||
}
|
||||
},
|
||||
"node_modules/@socket.io/component-emitter": {
|
||||
@ -673,9 +673,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@types/express-serve-static-core": {
|
||||
"version": "4.19.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.5.tgz",
|
||||
"integrity": "sha512-y6W03tvrACO72aijJ5uF02FRq5cgDR9lUxddQ8vyF+GvmjJQqbzDcJngEjURc+ZsG31VI3hODNZJ2URj86pzmg==",
|
||||
"version": "4.19.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/express-serve-static-core/-/express-serve-static-core-4.19.6.tgz",
|
||||
"integrity": "sha512-N4LZ2xG7DatVqhCZzOGb1Yi5lMbXSZcmdLDe9EzSndPV2HpWYWzRbaerl2n27irrm94EPpprqa8KpskPT085+A==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@ -719,9 +719,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "20.16.5",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.5.tgz",
|
||||
"integrity": "sha512-VwYCweNo3ERajwy0IUlqqcyZ8/A7Zwa9ZP3MnENWcB11AejO+tLy3pu850goUW2FC/IJMdZUfKpX/yxL1gymCA==",
|
||||
"version": "20.16.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.12.tgz",
|
||||
"integrity": "sha512-LfPFB0zOeCeCNQV3i+67rcoVvoN5n0NVuR2vLG0O5ySQMgchuZlC4lgz546ZOJyDtj5KIgOxy+lacOimfqZAIA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"undici-types": "~6.19.2"
|
||||
@ -764,18 +764,6 @@
|
||||
"@types/send": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/abort-controller": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||
"integrity": "sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"event-target-shim": "^5.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.5"
|
||||
}
|
||||
},
|
||||
"node_modules/accepts": {
|
||||
"version": "1.3.8",
|
||||
"resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz",
|
||||
@ -790,9 +778,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "8.12.1",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz",
|
||||
"integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==",
|
||||
"version": "8.13.0",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.13.0.tgz",
|
||||
"integrity": "sha512-8zSiw54Oxrdym50NlZ9sUusyO1Z1ZchgRLWRaK6c86XJFClyCgFKetdowBg5bKxyp/u+CDBJG4Mpp0m3HLZl9w==",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
@ -855,26 +843,6 @@
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/base64-js": {
|
||||
"version": "1.5.1",
|
||||
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
|
||||
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/base64id": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/base64id/-/base64id-2.0.0.tgz",
|
||||
@ -951,30 +919,6 @@
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz",
|
||||
"integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"base64-js": "^1.3.1",
|
||||
"ieee754": "^1.2.1"
|
||||
}
|
||||
},
|
||||
"node_modules/buffer-equal-constant-time": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
|
||||
@ -982,9 +926,9 @@
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/bullmq": {
|
||||
"version": "5.13.2",
|
||||
"resolved": "https://registry.npmjs.org/bullmq/-/bullmq-5.13.2.tgz",
|
||||
"integrity": "sha512-McGE8k3mrCvdUHdU0sHkTKDS1xr4pff+hbEKBY51wk5S6Za0gkuejYA620VQTo3Zz37E/NVWMgumwiXPQ3yZcA==",
|
||||
"version": "5.21.1",
|
||||
"resolved": "https://registry.npmjs.org/bullmq/-/bullmq-5.21.1.tgz",
|
||||
"integrity": "sha512-+yvsd5LkbWkTW2K5C/1s8h1+gGK4F9wVfKM6AJUBSWGsbfWHXnni0Se7xHj1dieVkx6XEsfCzFtO6kZnD+mtHQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"cron-parser": "^4.6.0",
|
||||
@ -1128,9 +1072,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/cookie": {
|
||||
"version": "0.6.0",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
|
||||
"integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz",
|
||||
"integrity": "sha512-6DnInpx7SJ2AK3+CTUE/ZM0vWTUboZCegxhC2xiIydHR9jNuTAASBrfEpHhiGOZw/nX51bHt6YQl8jsGo4y/0w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
@ -1282,9 +1226,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io": {
|
||||
"version": "6.6.1",
|
||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.1.tgz",
|
||||
"integrity": "sha512-NEpDCw9hrvBW+hVEOK4T7v0jFJ++KgtPl4jKFwsZVfG1XhS0dCrSb3VMb9gPAd7VAdW52VT1EnaNiU2vM8C0og==",
|
||||
"version": "6.6.2",
|
||||
"resolved": "https://registry.npmjs.org/engine.io/-/engine.io-6.6.2.tgz",
|
||||
"integrity": "sha512-gmNvsYi9C8iErnZdVcJnvCpSKbWTt1E8+JZo8b+daLninywUWi5NQ5STSHZ9rFjFO7imNcvb8Pc5pe/wMR5xEw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/cookie": "^0.4.1",
|
||||
@ -1292,7 +1236,7 @@
|
||||
"@types/node": ">=10.0.0",
|
||||
"accepts": "~1.3.4",
|
||||
"base64id": "2.0.0",
|
||||
"cookie": "~0.4.1",
|
||||
"cookie": "~0.7.2",
|
||||
"cors": "~2.8.5",
|
||||
"debug": "~4.3.1",
|
||||
"engine.io-parser": "~5.2.1",
|
||||
@ -1312,9 +1256,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/engine.io/node_modules/cookie": {
|
||||
"version": "0.4.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA==",
|
||||
"version": "0.7.2",
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz",
|
||||
"integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
@ -1379,28 +1323,10 @@
|
||||
"node": ">= 0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/event-target-shim": {
|
||||
"version": "5.0.1",
|
||||
"resolved": "https://registry.npmjs.org/event-target-shim/-/event-target-shim-5.0.1.tgz",
|
||||
"integrity": "sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/events": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/events/-/events-3.3.0.tgz",
|
||||
"integrity": "sha512-mQw+2fkQbALzQ7V0MY0IqdnXNOeTtP4r0lN9z7AAawCXgqea7bDii20AYrIBrFd/Hx0M2Ocz6S111CaFkUcb0Q==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">=0.8.x"
|
||||
}
|
||||
},
|
||||
"node_modules/express": {
|
||||
"version": "4.21.0",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-4.21.0.tgz",
|
||||
"integrity": "sha512-VqcNGcj/Id5ZT1LZ/cfihi3ttTn+NJmkli2eZADigjq29qTlWi/hAQ43t/VLPq8+UX06FCEx3ByOYet6ZFblng==",
|
||||
"version": "4.21.1",
|
||||
"resolved": "https://registry.npmjs.org/express/-/express-4.21.1.tgz",
|
||||
"integrity": "sha512-YSFlK1Ee0/GC8QaO91tHcDxJiE/X4FbpAyQWkxAvG6AXCuR65YzK8ua6D9hvi/TzUfZMpc+BwuM1IPw8fmQBiQ==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"accepts": "~1.3.8",
|
||||
@ -1408,7 +1334,7 @@
|
||||
"body-parser": "1.20.3",
|
||||
"content-disposition": "0.5.4",
|
||||
"content-type": "~1.0.4",
|
||||
"cookie": "0.6.0",
|
||||
"cookie": "0.7.1",
|
||||
"cookie-signature": "1.0.6",
|
||||
"debug": "2.6.9",
|
||||
"depd": "2.0.0",
|
||||
@ -1650,26 +1576,6 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/ieee754": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/feross"
|
||||
},
|
||||
{
|
||||
"type": "patreon",
|
||||
"url": "https://www.patreon.com/feross"
|
||||
},
|
||||
{
|
||||
"type": "consulting",
|
||||
"url": "https://feross.org/support"
|
||||
}
|
||||
],
|
||||
"license": "BSD-3-Clause"
|
||||
},
|
||||
"node_modules/ignore-by-default": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz",
|
||||
@ -2184,15 +2090,15 @@
|
||||
}
|
||||
},
|
||||
"node_modules/pino": {
|
||||
"version": "9.4.0",
|
||||
"resolved": "https://registry.npmjs.org/pino/-/pino-9.4.0.tgz",
|
||||
"integrity": "sha512-nbkQb5+9YPhQRz/BeQmrWpEknAaqjpAqRK8NwJpmrX/JHu7JuZC5G1CeAwJDJfGes4h+YihC6in3Q2nGb+Y09w==",
|
||||
"version": "9.5.0",
|
||||
"resolved": "https://registry.npmjs.org/pino/-/pino-9.5.0.tgz",
|
||||
"integrity": "sha512-xSEmD4pLnV54t0NOUN16yCl7RIB1c5UUOse5HSyEXtBp+FgFQyPeDutc+Q2ZO7/22vImV7VfEjH/1zV2QuqvYw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"atomic-sleep": "^1.0.0",
|
||||
"fast-redact": "^3.1.1",
|
||||
"on-exit-leak-free": "^2.1.0",
|
||||
"pino-abstract-transport": "^1.2.0",
|
||||
"pino-abstract-transport": "^2.0.0",
|
||||
"pino-std-serializers": "^7.0.0",
|
||||
"process-warning": "^4.0.0",
|
||||
"quick-format-unescaped": "^4.0.3",
|
||||
@ -2206,12 +2112,11 @@
|
||||
}
|
||||
},
|
||||
"node_modules/pino-abstract-transport": {
|
||||
"version": "1.2.0",
|
||||
"resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-1.2.0.tgz",
|
||||
"integrity": "sha512-Guhh8EZfPCfH+PMXAb6rKOjGQEoy0xlAIn+irODG5kgfYV+BQ0rGYYWTIel3P5mmyXqkYkPmdIkywsn6QKUR1Q==",
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/pino-abstract-transport/-/pino-abstract-transport-2.0.0.tgz",
|
||||
"integrity": "sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"readable-stream": "^4.0.0",
|
||||
"split2": "^4.0.0"
|
||||
}
|
||||
},
|
||||
@ -2238,13 +2143,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/prisma": {
|
||||
"version": "5.19.1",
|
||||
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.19.1.tgz",
|
||||
"integrity": "sha512-c5K9MiDaa+VAAyh1OiYk76PXOme9s3E992D7kvvIOhCrNsBQfy2mP2QAQtX0WNj140IgG++12kwZpYB9iIydNQ==",
|
||||
"version": "5.21.1",
|
||||
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.21.1.tgz",
|
||||
"integrity": "sha512-PB+Iqzld/uQBPaaw2UVIk84kb0ITsLajzsxzsadxxl54eaU5Gyl2/L02ysivHxK89t7YrfQJm+Ggk37uvM70oQ==",
|
||||
"hasInstallScript": true,
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@prisma/engines": "5.19.1"
|
||||
"@prisma/engines": "5.21.1"
|
||||
},
|
||||
"bin": {
|
||||
"prisma": "build/index.js"
|
||||
@ -2256,15 +2161,6 @@
|
||||
"fsevents": "2.3.3"
|
||||
}
|
||||
},
|
||||
"node_modules/process": {
|
||||
"version": "0.11.10",
|
||||
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
|
||||
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
|
||||
"license": "MIT",
|
||||
"engines": {
|
||||
"node": ">= 0.6.0"
|
||||
}
|
||||
},
|
||||
"node_modules/process-warning": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/process-warning/-/process-warning-4.0.0.tgz",
|
||||
@ -2336,22 +2232,6 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/readable-stream": {
|
||||
"version": "4.5.2",
|
||||
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-4.5.2.tgz",
|
||||
"integrity": "sha512-yjavECdqeZ3GLXNgRXgeQEdz9fvDDkNKyHnbHRFtOr7/LcfgBcmct7t/ET+HaCTqfh06OzoAxrkN/IfjJBVe+g==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"abort-controller": "^3.0.0",
|
||||
"buffer": "^6.0.3",
|
||||
"events": "^3.3.0",
|
||||
"process": "^0.11.10",
|
||||
"string_decoder": "^1.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/readdirp": {
|
||||
"version": "3.6.0",
|
||||
"resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz",
|
||||
@ -2709,9 +2589,9 @@
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/sonic-boom": {
|
||||
"version": "4.1.0",
|
||||
"resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.1.0.tgz",
|
||||
"integrity": "sha512-NGipjjRicyJJ03rPiZCJYjwlsuP2d1/5QUviozRXC7S3WdVWNK5e3Ojieb9CCyfhq2UC+3+SRd9nG3I2lPRvUw==",
|
||||
"version": "4.2.0",
|
||||
"resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-4.2.0.tgz",
|
||||
"integrity": "sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"atomic-sleep": "^1.0.0"
|
||||
@ -2741,15 +2621,6 @@
|
||||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/string_decoder": {
|
||||
"version": "1.3.0",
|
||||
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz",
|
||||
"integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"safe-buffer": "~5.2.0"
|
||||
}
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||
@ -2848,9 +2719,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/tslib": {
|
||||
"version": "2.7.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
|
||||
"integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==",
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.0.tgz",
|
||||
"integrity": "sha512-jWVzBLplnCmoaTr13V9dYbiQ99wvZRd0vNWaDRg+aVYRcjDF3nDksxFDE/+fkXnKhpnUUkmx5pK/v8mCtLVqZA==",
|
||||
"license": "0BSD"
|
||||
},
|
||||
"node_modules/type-is": {
|
||||
@ -2867,9 +2738,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/typescript": {
|
||||
"version": "5.6.2",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.2.tgz",
|
||||
"integrity": "sha512-NW8ByodCSNCwZeghjN3o+JX5OFH0Ojg6sadjEKY4huZ52TqbJTJnDo5+Tw98lSy63NZvi4n+ez5m2u5d4PkZyw==",
|
||||
"version": "5.6.3",
|
||||
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.6.3.tgz",
|
||||
"integrity": "sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw==",
|
||||
"license": "Apache-2.0",
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"scripts": {
|
||||
"start": "npx prisma migrate deploy && node dist/server.js",
|
||||
"dev": "nodemon --exec ts-node src/server.ts",
|
||||
"dev": "nodemon --ignore 'data/*' --exec ts-node src/server.ts",
|
||||
"build": "tsc",
|
||||
"format": "prettier --write src/"
|
||||
},
|
||||
|
0
prisma/.gitignore
vendored
Normal file
0
prisma/.gitignore
vendored
Normal file
@ -53,7 +53,7 @@ CREATE TABLE `CharacterType` (
|
||||
`name` VARCHAR(191) NOT NULL,
|
||||
`gender` ENUM('MALE', 'FEMALE') NOT NULL,
|
||||
`race` ENUM('HUMAN', 'ELF', 'DWARF', 'ORC', 'GOBLIN') NOT NULL,
|
||||
`spriteId` VARCHAR(191) NOT NULL,
|
||||
`spriteId` VARCHAR(191) NULL,
|
||||
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
`updatedAt` DATETIME(3) NOT NULL,
|
||||
|
||||
@ -146,12 +146,23 @@ CREATE TABLE `Zone` (
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `ZoneEffect` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`zoneId` INTEGER NOT NULL,
|
||||
`effect` VARCHAR(191) NOT NULL,
|
||||
`strength` INTEGER NOT NULL,
|
||||
|
||||
PRIMARY KEY (`id`)
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE `ZoneObject` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`zoneId` INTEGER NOT NULL,
|
||||
`objectId` VARCHAR(191) NOT NULL,
|
||||
`depth` INTEGER NOT NULL DEFAULT 0,
|
||||
`isRotated` BOOLEAN NOT NULL DEFAULT false,
|
||||
`positionX` INTEGER NOT NULL DEFAULT 0,
|
||||
`positionY` INTEGER NOT NULL DEFAULT 0,
|
||||
|
||||
@ -174,6 +185,7 @@ CREATE TABLE `ZoneEventTileTeleport` (
|
||||
`id` VARCHAR(191) NOT NULL,
|
||||
`zoneEventTileId` VARCHAR(191) NOT NULL,
|
||||
`toZoneId` INTEGER NOT NULL,
|
||||
`toRotation` INTEGER NOT NULL,
|
||||
`toPositionX` INTEGER NOT NULL,
|
||||
`toPositionY` INTEGER NOT NULL,
|
||||
|
||||
@ -208,6 +220,9 @@ ALTER TABLE `CharacterItem` ADD CONSTRAINT `CharacterItem_characterId_fkey` FORE
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `CharacterItem` ADD CONSTRAINT `CharacterItem_itemId_fkey` FOREIGN KEY (`itemId`) REFERENCES `Item`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `ZoneEffect` ADD CONSTRAINT `ZoneEffect_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE `ZoneObject` ADD CONSTRAINT `ZoneObject_zoneId_fkey` FOREIGN KEY (`zoneId`) REFERENCES `Zone`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
|
||||
|
@ -25,8 +25,8 @@ model CharacterType {
|
||||
gender CharacterGender
|
||||
race CharacterRace
|
||||
characters Character[]
|
||||
spriteId String
|
||||
sprite Sprite @relation(fields: [spriteId], references: [id], onDelete: Cascade)
|
||||
spriteId String?
|
||||
sprite Sprite? @relation(fields: [spriteId], references: [id], onDelete: Cascade)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ model Zone {
|
||||
height Int @default(10)
|
||||
tiles Json?
|
||||
pvp Boolean @default(false)
|
||||
zoneEffects ZoneEffect[]
|
||||
zoneEventTiles ZoneEventTile[]
|
||||
zoneEventTileTeleports ZoneEventTileTeleport[]
|
||||
zoneObjects ZoneObject[]
|
||||
@ -47,15 +48,24 @@ model Zone {
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model ZoneEffect {
|
||||
id String @id @default(uuid())
|
||||
zoneId Int
|
||||
zone Zone @relation(fields: [zoneId], references: [id], onDelete: Cascade)
|
||||
effect String
|
||||
strength Int
|
||||
}
|
||||
|
||||
model ZoneObject {
|
||||
id String @id @default(uuid())
|
||||
id String @id @default(uuid())
|
||||
zoneId Int
|
||||
zone Zone @relation(fields: [zoneId], references: [id], onDelete: Cascade)
|
||||
zone Zone @relation(fields: [zoneId], references: [id], onDelete: Cascade)
|
||||
objectId String
|
||||
object Object @relation(fields: [objectId], references: [id], onDelete: Cascade)
|
||||
depth Int @default(0)
|
||||
positionX Int @default(0)
|
||||
positionY Int @default(0)
|
||||
object Object @relation(fields: [objectId], references: [id], onDelete: Cascade)
|
||||
depth Int @default(0)
|
||||
isRotated Boolean @default(false)
|
||||
positionX Int @default(0)
|
||||
positionY Int @default(0)
|
||||
}
|
||||
|
||||
enum ZoneEventTileType {
|
||||
@ -81,6 +91,7 @@ model ZoneEventTileTeleport {
|
||||
zoneEventTile ZoneEventTile @relation(fields: [zoneEventTileId], references: [id], onDelete: Cascade)
|
||||
toZoneId Int
|
||||
toZone Zone @relation(fields: [toZoneId], references: [id], onDelete: Cascade)
|
||||
toRotation Int
|
||||
toPositionX Int
|
||||
toPositionY Int
|
||||
}
|
||||
|
@ -2,8 +2,12 @@ import { Server } from 'socket.io'
|
||||
|
||||
type CommandInput = string[]
|
||||
|
||||
export default function (input: CommandInput, io: Server) {
|
||||
const message: string = input.join(' ') ?? null
|
||||
if (!message) return console.log('message is required')
|
||||
io.emit('notification', { message: message })
|
||||
export default class AlertCommand {
|
||||
constructor(private readonly io: Server) {}
|
||||
|
||||
public execute(input: CommandInput): void {
|
||||
const message: string = input.join(' ') ?? null
|
||||
if (!message) return console.log('message is required')
|
||||
this.io.emit('notification', { message: message })
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,10 @@ import ZoneManager from '../managers/zoneManager'
|
||||
|
||||
type CommandInput = string[]
|
||||
|
||||
export default function (input: CommandInput, io: Server) {
|
||||
console.log(ZoneManager.getLoadedZones())
|
||||
export default class ListZonesCommand {
|
||||
constructor(private readonly io: Server) {}
|
||||
|
||||
public execute(input: CommandInput): void {
|
||||
console.log(ZoneManager.getLoadedZones())
|
||||
}
|
||||
}
|
||||
|
58
src/commands/tiles.ts
Normal file
58
src/commands/tiles.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import fs from 'fs'
|
||||
import sharp from 'sharp'
|
||||
import { commandLogger } from '../utilities/logger'
|
||||
import { Server } from 'socket.io'
|
||||
import { getPublicPath } from '../utilities/storage'
|
||||
import path from 'path'
|
||||
|
||||
export default class TilesCommand {
|
||||
constructor(private readonly io: Server) {}
|
||||
|
||||
public async execute(): Promise<void> {
|
||||
// Get all tiles
|
||||
const tilesDir = getPublicPath('tiles')
|
||||
const tiles = fs.readdirSync(tilesDir).filter((file) => file.endsWith('.png'))
|
||||
|
||||
// Create output directory if it doesn't exist
|
||||
if (!fs.existsSync(tilesDir)) {
|
||||
fs.mkdirSync(tilesDir, { recursive: true })
|
||||
}
|
||||
|
||||
for (const tile of tiles) {
|
||||
// Check if tile is already 66x34
|
||||
const metadata = await sharp(getPublicPath('tiles', tile)).metadata()
|
||||
if (metadata.width === 66 && metadata.height === 34) {
|
||||
commandLogger.info(`Tile ${tile} already processed`)
|
||||
continue
|
||||
}
|
||||
|
||||
const inputPath = getPublicPath('tiles', tile)
|
||||
const tempPath = getPublicPath('tiles', `temp_${tile}`)
|
||||
|
||||
try {
|
||||
await sharp(inputPath)
|
||||
.resize({
|
||||
width: 66,
|
||||
height: 34,
|
||||
fit: 'fill',
|
||||
kernel: 'nearest'
|
||||
})
|
||||
.toFile(tempPath)
|
||||
|
||||
// Replace original file with processed file
|
||||
fs.unlinkSync(inputPath)
|
||||
fs.renameSync(tempPath, inputPath)
|
||||
|
||||
commandLogger.info(`Processed and replaced: ${tile}`)
|
||||
} catch (error) {
|
||||
console.error(`Error processing ${tile}:`, error)
|
||||
// Clean up temp file if it exists
|
||||
if (fs.existsSync(tempPath)) {
|
||||
fs.unlinkSync(tempPath)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
commandLogger.info('Tile processing completed.')
|
||||
}
|
||||
}
|
@ -2,9 +2,11 @@ import * as readline from 'readline'
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { Server } from 'socket.io'
|
||||
import { commandLogger } from '../utilities/logger'
|
||||
import { getAppPath } from '../utilities/storage'
|
||||
|
||||
class CommandManager {
|
||||
private commands: Map<string, Function> = new Map()
|
||||
private commands: Map<string, any> = new Map()
|
||||
private rl: readline.Interface
|
||||
private io: Server | null = null
|
||||
private rlClosed: boolean = false
|
||||
@ -23,7 +25,7 @@ class CommandManager {
|
||||
public async boot(io: Server) {
|
||||
this.io = io
|
||||
await this.loadCommands()
|
||||
console.log('[✅] Command manager loaded')
|
||||
commandLogger.info('Command manager loaded')
|
||||
this.startPrompt()
|
||||
}
|
||||
|
||||
@ -39,7 +41,9 @@ class CommandManager {
|
||||
private async processCommand(command: string): Promise<void> {
|
||||
const [cmd, ...args] = command.trim().split(' ')
|
||||
if (this.commands.has(cmd)) {
|
||||
this.commands.get(cmd)?.(args, this.io as Server)
|
||||
const CommandClass = this.commands.get(cmd)
|
||||
const commandInstance = new CommandClass(this.io as Server)
|
||||
await commandInstance.execute(args)
|
||||
} else {
|
||||
this.handleUnknownCommand(cmd)
|
||||
}
|
||||
@ -48,7 +52,6 @@ class CommandManager {
|
||||
private handleUnknownCommand(command: string) {
|
||||
switch (command) {
|
||||
case 'exit':
|
||||
console.log('Goodbye!')
|
||||
this.rl.close()
|
||||
break
|
||||
default:
|
||||
@ -58,37 +61,43 @@ class CommandManager {
|
||||
}
|
||||
|
||||
private async loadCommands() {
|
||||
const commandsDir = path.resolve(__dirname, 'commands')
|
||||
const directory = getAppPath('commands')
|
||||
commandLogger.info(`Loading commands from: ${directory}`)
|
||||
|
||||
try {
|
||||
const files: string[] = await fs.promises.readdir(commandsDir)
|
||||
const files = await fs.promises.readdir(directory, { withFileTypes: true })
|
||||
|
||||
for (const file of files) {
|
||||
await this.loadCommand(commandsDir, file)
|
||||
if (!file.isFile() || (!file.name.endsWith('.ts') && !file.name.endsWith('.js'))) {
|
||||
continue
|
||||
}
|
||||
|
||||
const fullPath = getAppPath('commands', file.name)
|
||||
const commandName = path.basename(file.name, path.extname(file.name))
|
||||
|
||||
try {
|
||||
const module = await import(fullPath)
|
||||
if (typeof module.default !== 'function') {
|
||||
commandLogger.warn(`Unrecognized export in ${file.name}`)
|
||||
continue
|
||||
}
|
||||
|
||||
this.registerCommand(commandName, module.default)
|
||||
} catch (error) {
|
||||
commandLogger.error(`Error loading command ${file.name}: ${error instanceof Error ? error.message : String(error)}`)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('[❌] Failed to read commands directory:', error)
|
||||
commandLogger.error(`Failed to read commands directory: ${error instanceof Error ? error.message : String(error)}`)
|
||||
}
|
||||
}
|
||||
|
||||
private async loadCommand(commandsDir: string, file: string) {
|
||||
try {
|
||||
const ext = path.extname(file)
|
||||
const commandName = path.basename(file, ext)
|
||||
const commandPath = path.join(commandsDir, file)
|
||||
const module = await import(commandPath)
|
||||
|
||||
this.registerCommand(commandName, module.default)
|
||||
} catch (error) {
|
||||
console.error('[❌] Failed to load command:', file, error)
|
||||
}
|
||||
}
|
||||
|
||||
private registerCommand(name: string, command: (args: string[], io: Server) => void) {
|
||||
private registerCommand(name: string, CommandClass: any) {
|
||||
if (this.commands.has(name)) {
|
||||
console.warn(`Command '${name}' is already registered. Overwriting...`)
|
||||
commandLogger.warn(`Command '${name}' is already registered. Overwriting...`)
|
||||
}
|
||||
this.commands.set(name, command)
|
||||
console.log(`Registered command: ${name}`)
|
||||
this.commands.set(name, CommandClass)
|
||||
commandLogger.info(`Registered command: ${name}`)
|
||||
}
|
||||
}
|
||||
|
||||
|
68
src/managers/dateManager.ts
Normal file
68
src/managers/dateManager.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { appLogger } from '../utilities/logger'
|
||||
import { getRootPath } from '../utilities/storage'
|
||||
import { readJsonValue, setJsonValue } from '../utilities/json'
|
||||
|
||||
class DateManager {
|
||||
private static readonly GAME_SPEED = 8 // 24 game hours / 3 real hours
|
||||
private static readonly UPDATE_INTERVAL = 1000 // 1 second
|
||||
|
||||
private io: Server | null = null
|
||||
private intervalId: NodeJS.Timeout | null = null
|
||||
private currentDate: Date = new Date()
|
||||
|
||||
public async boot(io: Server): Promise<void> {
|
||||
this.io = io
|
||||
await this.loadDate()
|
||||
this.startDateLoop()
|
||||
appLogger.info('Date manager loaded')
|
||||
}
|
||||
|
||||
public stop(): void {
|
||||
if (this.intervalId) {
|
||||
clearInterval(this.intervalId)
|
||||
this.intervalId = null
|
||||
}
|
||||
}
|
||||
|
||||
private async loadDate(): Promise<void> {
|
||||
try {
|
||||
const dateString = await readJsonValue<string>(this.getWorldFilePath(), 'date')
|
||||
this.currentDate = new Date(dateString)
|
||||
} catch (error) {
|
||||
appLogger.error(`Failed to load date: ${error instanceof Error ? error.message : String(error)}`)
|
||||
this.currentDate = new Date() // Use current date as fallback
|
||||
}
|
||||
}
|
||||
|
||||
private startDateLoop(): void {
|
||||
this.intervalId = setInterval(() => {
|
||||
this.advanceGameTime()
|
||||
this.emitDate()
|
||||
this.saveDate()
|
||||
}, DateManager.UPDATE_INTERVAL)
|
||||
}
|
||||
|
||||
private advanceGameTime(): void {
|
||||
const advanceMilliseconds = DateManager.GAME_SPEED * DateManager.UPDATE_INTERVAL
|
||||
this.currentDate = new Date(this.currentDate.getTime() + advanceMilliseconds)
|
||||
}
|
||||
|
||||
private emitDate(): void {
|
||||
this.io?.emit('date', this.currentDate)
|
||||
}
|
||||
|
||||
private async saveDate(): Promise<void> {
|
||||
try {
|
||||
await setJsonValue(this.getWorldFilePath(), 'date', this.currentDate)
|
||||
} catch (error) {
|
||||
appLogger.error(`Failed to save date: ${error instanceof Error ? error.message : String(error)}`)
|
||||
}
|
||||
}
|
||||
|
||||
private getWorldFilePath(): string {
|
||||
return getRootPath('data', 'world.json')
|
||||
}
|
||||
}
|
||||
|
||||
export default new DateManager()
|
@ -5,7 +5,7 @@ import { Server as SocketServer } from 'socket.io'
|
||||
import { TSocket } from '../utilities/types'
|
||||
import { queueLogger } from '../utilities/logger'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { getAppPath } from '../utilities/storage'
|
||||
|
||||
class QueueManager {
|
||||
private connection!: IORedis
|
||||
@ -52,9 +52,9 @@ class QueueManager {
|
||||
const { jobName, params, socketId } = job.data
|
||||
|
||||
try {
|
||||
const jobsDir = path.join(process.cwd(), 'src', 'jobs')
|
||||
const jobsDir = getAppPath('jobs')
|
||||
const extension = config.ENV === 'development' ? '.ts' : '.js'
|
||||
const jobPath = path.join(jobsDir, `${jobName}${extension}`)
|
||||
const jobPath = getAppPath('jobs', `${jobName}${extension}`)
|
||||
|
||||
if (!fs.existsSync(jobPath)) {
|
||||
queueLogger.warn(`Job file not found: ${jobPath}`)
|
||||
|
0
src/managers/weatherManager.ts
Normal file
0
src/managers/weatherManager.ts
Normal file
@ -1,7 +1,5 @@
|
||||
import { Zone } from '@prisma/client'
|
||||
import zoneRepository from '../repositories/zoneRepository'
|
||||
import characterManager from '../managers/characterManager'
|
||||
import { ExtendedCharacter } from '../utilities/types'
|
||||
|
||||
class LoadedZone {
|
||||
private readonly zone: Zone
|
||||
|
10
src/repositories/characterTypeRepository.ts
Normal file
10
src/repositories/characterTypeRepository.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import prisma from '../utilities/prisma' // Import the global Prisma instance
|
||||
import { CharacterType } from '@prisma/client'
|
||||
|
||||
class CharacterTypeRepository {
|
||||
async getAll(): Promise<CharacterType[]> {
|
||||
return prisma.characterType.findMany()
|
||||
}
|
||||
}
|
||||
|
||||
export default new CharacterTypeRepository()
|
@ -1,5 +1,5 @@
|
||||
import prisma from '../utilities/prisma' // Import the global Prisma instance
|
||||
import { Sprite, SpriteAction } from '@prisma/client'
|
||||
import { SpriteAction } from '@prisma/client'
|
||||
|
||||
class SpriteRepository {
|
||||
async getById(id: string) {
|
||||
|
@ -39,7 +39,8 @@ class ZoneRepository {
|
||||
include: {
|
||||
object: true
|
||||
}
|
||||
}
|
||||
},
|
||||
zoneEffects: true
|
||||
}
|
||||
})
|
||||
} catch (error: any) {
|
||||
|
@ -1,21 +1,21 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import express, { Application } from 'express'
|
||||
import config from './utilities/config'
|
||||
import { getAppPath } from './utilities/storage'
|
||||
import { createServer as httpServer, Server as HTTPServer } from 'http'
|
||||
import { addHttpRoutes } from './utilities/http'
|
||||
import cors from 'cors'
|
||||
import { Server as SocketServer } from 'socket.io'
|
||||
import { Authentication } from './middleware/authentication'
|
||||
import { TSocket } from './utilities/types'
|
||||
import config from './utilities/config'
|
||||
import prisma from './utilities/prisma'
|
||||
import { appLogger, watchLogs } from './utilities/logger'
|
||||
import ZoneManager from './managers/zoneManager'
|
||||
import UserManager from './managers/userManager'
|
||||
import { Authentication } from './middleware/authentication'
|
||||
// import CommandManager from './managers/CommandManager'
|
||||
import { Dirent } from 'node:fs'
|
||||
import { appLogger, watchLogs } from './utilities/logger'
|
||||
import CommandManager from './managers/commandManager'
|
||||
import CharacterManager from './managers/characterManager'
|
||||
import QueueManager from './managers/queueManager'
|
||||
import DateManager from './managers/dateManager'
|
||||
|
||||
export class Server {
|
||||
private readonly app: Application
|
||||
@ -58,23 +58,26 @@ export class Server {
|
||||
appLogger.error(`Socket.IO failed to start: ${error.message}`)
|
||||
}
|
||||
|
||||
// Load queue manager
|
||||
await QueueManager.boot(this.io)
|
||||
|
||||
// Add http API routes
|
||||
await addHttpRoutes(this.app)
|
||||
|
||||
// Load queue manager
|
||||
await QueueManager.boot(this.io)
|
||||
|
||||
// Load user manager
|
||||
await UserManager.boot()
|
||||
|
||||
// Load date manager
|
||||
await DateManager.boot(this.io)
|
||||
|
||||
// Load zoneEditor manager
|
||||
await ZoneManager.boot()
|
||||
|
||||
// Load character manager
|
||||
await CharacterManager.boot()
|
||||
|
||||
// Load command manager - Disabled for now
|
||||
// await CommandManager.boot(this.io);
|
||||
// Load command manager
|
||||
await CommandManager.boot(this.io)
|
||||
|
||||
// Listen for socket connections
|
||||
this.io.on('connection', this.handleConnection.bind(this))
|
||||
@ -86,42 +89,46 @@ export class Server {
|
||||
* @private
|
||||
*/
|
||||
private async handleConnection(socket: TSocket) {
|
||||
const eventsPath = path.join(__dirname, 'socketEvents')
|
||||
try {
|
||||
await this.loadEventHandlers(eventsPath, socket)
|
||||
await this.loadEventHandlers('socketEvents', '', socket)
|
||||
} catch (error: any) {
|
||||
appLogger.error(`Failed to load event handlers: ${error.message}`)
|
||||
}
|
||||
}
|
||||
|
||||
private async loadEventHandlers(dir: string, socket: TSocket) {
|
||||
const files: Dirent[] = await fs.promises.readdir(dir, { withFileTypes: true })
|
||||
private async loadEventHandlers(baseDir: string, subDir: string, socket: TSocket) {
|
||||
try {
|
||||
const fullDir = getAppPath(baseDir, subDir)
|
||||
const files = await fs.promises.readdir(fullDir, { withFileTypes: true })
|
||||
|
||||
for (const file of files) {
|
||||
const fullPath = path.join(dir, file.name)
|
||||
for (const file of files) {
|
||||
const filePath = getAppPath(baseDir, subDir, file.name)
|
||||
|
||||
if (file.isDirectory()) {
|
||||
await this.loadEventHandlers(baseDir, `${subDir}/${file.name}`, socket)
|
||||
continue
|
||||
}
|
||||
|
||||
if (!file.isFile() || (!file.name.endsWith('.ts') && !file.name.endsWith('.js'))) {
|
||||
continue
|
||||
}
|
||||
|
||||
if (file.isDirectory()) {
|
||||
await this.loadEventHandlers(fullPath, socket)
|
||||
} else if (file.isFile() && (file.name.endsWith('.ts') || file.name.endsWith('.js'))) {
|
||||
try {
|
||||
const module = await import(fullPath)
|
||||
if (typeof module.default === 'function') {
|
||||
if (module.default.prototype && module.default.prototype.listen) {
|
||||
// This is a class-based event
|
||||
const EventClass = module.default
|
||||
const eventInstance = new EventClass(this.io, socket)
|
||||
eventInstance.listen()
|
||||
} else {
|
||||
// This is a function-based event
|
||||
module.default(this.io, socket)
|
||||
}
|
||||
} else {
|
||||
const module = await import(filePath)
|
||||
if (typeof module.default !== 'function') {
|
||||
appLogger.warn(`Unrecognized export in ${file.name}`)
|
||||
continue
|
||||
}
|
||||
} catch (error: any) {
|
||||
appLogger.error(`Error loading event handler ${file.name}: ${error.message}`)
|
||||
|
||||
const EventClass = module.default
|
||||
const eventInstance = new EventClass(this.io, socket)
|
||||
eventInstance.listen()
|
||||
} catch (error) {
|
||||
appLogger.error(`Error loading event handler ${file.name}: ${error instanceof Error ? error.message : String(error)}`)
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
appLogger.error(`Error reading directory: ${error instanceof Error ? error.message : String(error)}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
class AssetService {}
|
||||
|
||||
export default AssetService
|
@ -1,5 +0,0 @@
|
||||
import { Character } from '@prisma/client'
|
||||
|
||||
class CharacterService {}
|
||||
|
||||
export default CharacterService
|
@ -23,14 +23,17 @@ export class ZoneEventTileService {
|
||||
data: {
|
||||
zoneId: newZoneId,
|
||||
positionX: teleport.toPositionX,
|
||||
positionY: teleport.toPositionY
|
||||
positionY: teleport.toPositionY,
|
||||
rotation: teleport.toRotation
|
||||
}
|
||||
})
|
||||
|
||||
// Update local character object
|
||||
character.zoneId = newZoneId
|
||||
character.rotation = teleport.toRotation
|
||||
character.positionX = teleport.toPositionX
|
||||
character.positionY = teleport.toPositionY
|
||||
character.isMoving = false
|
||||
|
||||
// Emit events
|
||||
io.to(oldZoneId.toString()).emit('zone:character:leave', character.id)
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket, ExtendedCharacter } from '../../utilities/types'
|
||||
import { TSocket } from '../../utilities/types'
|
||||
import CharacterRepository from '../../repositories/characterRepository'
|
||||
import CharacterManager from '../../managers/characterManager'
|
||||
|
||||
type SocketResponseT = {
|
||||
character_id: number
|
||||
@ -22,12 +21,11 @@ export default class CharacterConnectEvent {
|
||||
try {
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket?.user?.id as number, data.character_id)
|
||||
if (!character) return
|
||||
this.socket.characterId = character.id
|
||||
|
||||
CharacterManager.initCharacter(character as ExtendedCharacter)
|
||||
this.socket.characterId = character.id
|
||||
this.socket.emit('character:connect', character)
|
||||
} catch (error: any) {
|
||||
console.log('character:connect error', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +57,4 @@ export default class CharacterCreateEvent {
|
||||
return this.socket.emit('notification', { message: 'Could not create character. Please try again (later).' })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -36,4 +36,4 @@ export default class CharacterDeleteEvent {
|
||||
return this.socket.emit('notification', { message: 'Character delete failed. Please try again.' })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,4 +23,4 @@ export default class CharacterListEvent {
|
||||
console.log('character:list error', error)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,4 @@ export default class AlertCommandEvent {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../utilities/types'
|
||||
import CharacterRepository from '../../repositories/characterRepository'
|
||||
import ZoneRepository from '../../repositories/zoneRepository'
|
||||
import { isCommand } from '../../utilities/chat'
|
||||
import { gameLogger } from '../../utilities/logger'
|
||||
import CharacterManager from '../../managers/characterManager'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -26,7 +26,7 @@ export default class ChatMessageEvent {
|
||||
return
|
||||
}
|
||||
|
||||
const character = await CharacterRepository.getByUserAndId(this.socket.user?.id as number, this.socket.characterId as number)
|
||||
const character = CharacterManager.getCharacterFromSocket(this.socket)
|
||||
if (!character) {
|
||||
gameLogger.error('chat:send_message error', 'Character not found')
|
||||
callback(false)
|
||||
|
@ -29,6 +29,8 @@ export default class DisconnectEvent {
|
||||
return
|
||||
}
|
||||
|
||||
character.resetMovement = true
|
||||
|
||||
gameLogger.info('User disconnected along with their character')
|
||||
|
||||
await CharacterManager.removeCharacter(character)
|
||||
@ -39,4 +41,4 @@ export default class DisconnectEvent {
|
||||
gameLogger.error('disconnect error', error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { CharacterGender, CharacterRace } from '@prisma/client'
|
||||
|
||||
export default class CharacterTypeCreateEvent {
|
||||
constructor(
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterType:create', this.handleCharacterTypeCreate.bind(this))
|
||||
}
|
||||
|
||||
private async handleCharacterTypeCreate(data: undefined, callback: (response: boolean, characterType?: any) => void): Promise<void> {
|
||||
try {
|
||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
||||
if (!character) return callback(false)
|
||||
|
||||
if (character.role !== 'gm') {
|
||||
return callback(false)
|
||||
}
|
||||
|
||||
const newCharacterType = await prisma.characterType.create({
|
||||
data: {
|
||||
name: 'New character type',
|
||||
gender: CharacterGender.MALE,
|
||||
race: CharacterRace.HUMAN
|
||||
}
|
||||
})
|
||||
|
||||
callback(true, newCharacterType)
|
||||
} catch (error) {
|
||||
console.error('Error creating character type:', error)
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import { CharacterType } from '@prisma/client'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { gameMasterLogger } from '../../../../utilities/logger'
|
||||
import CharacterTypeRepository from '../../../../repositories/characterTypeRepository'
|
||||
|
||||
interface IPayload {}
|
||||
|
||||
export default class CharacterTypeListEvent {
|
||||
constructor(
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterType:list', this.handleCharacterTypeList.bind(this))
|
||||
}
|
||||
|
||||
private async handleCharacterTypeList(data: IPayload, callback: (response: CharacterType[]) => void): Promise<void> {
|
||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
||||
if (!character) {
|
||||
gameMasterLogger.error('gm:characterType:list error', 'Character not found')
|
||||
return callback([])
|
||||
}
|
||||
|
||||
if (character.role !== 'gm') {
|
||||
gameMasterLogger.info(`User ${character.id} tried to list character types but is not a game master.`)
|
||||
return callback([])
|
||||
}
|
||||
|
||||
// get all objects
|
||||
const items = await CharacterTypeRepository.getAll()
|
||||
callback(items)
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
import fs from 'fs'
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
interface IPayload {
|
||||
object: string
|
||||
}
|
||||
|
||||
export default class ObjectRemoveEvent {
|
||||
constructor(
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('gm:object:remove', this.handleObjectRemove.bind(this))
|
||||
}
|
||||
|
||||
private async handleObjectRemove(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
||||
if (!character) return callback(false)
|
||||
|
||||
if (character.role !== 'gm') {
|
||||
return callback(false)
|
||||
}
|
||||
|
||||
try {
|
||||
await prisma.object.delete({
|
||||
where: {
|
||||
id: data.object
|
||||
}
|
||||
})
|
||||
|
||||
// get root path
|
||||
const public_folder = getPublicPath('objects')
|
||||
|
||||
// remove the tile from the disk
|
||||
const finalFilePath = getPublicPath('objects', data.object + '.png')
|
||||
fs.unlink(finalFilePath, (err) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
callback(false)
|
||||
return
|
||||
}
|
||||
|
||||
callback(true)
|
||||
})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
|
||||
type Payload = {
|
||||
id: string
|
||||
name: string
|
||||
tags: string[]
|
||||
originX: number
|
||||
originY: number
|
||||
isAnimated: boolean
|
||||
frameSpeed: number
|
||||
frameWidth: number
|
||||
frameHeight: number
|
||||
}
|
||||
|
||||
export default class ObjectUpdateEvent {
|
||||
constructor(
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('gm:object:update', this.handleObjectUpdate.bind(this))
|
||||
}
|
||||
|
||||
private async handleObjectUpdate(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||
const character = await characterRepository.getById(this.socket.characterId as number)
|
||||
if (!character) return callback(false)
|
||||
|
||||
if (character.role !== 'gm') {
|
||||
return callback(false)
|
||||
}
|
||||
|
||||
try {
|
||||
const object = await prisma.object.update({
|
||||
where: {
|
||||
id: data.id
|
||||
},
|
||||
data: {
|
||||
name: data.name,
|
||||
tags: data.tags,
|
||||
originX: data.originX,
|
||||
originY: data.originY,
|
||||
isAnimated: data.isAnimated,
|
||||
frameSpeed: data.frameSpeed,
|
||||
frameWidth: data.frameWidth,
|
||||
frameHeight: data.frameHeight
|
||||
}
|
||||
})
|
||||
callback(true)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
@ -2,7 +2,6 @@ import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import { Object } from '@prisma/client'
|
||||
import ObjectRepository from '../../../../repositories/objectRepository'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
|
||||
interface IPayload {}
|
||||
@ -29,4 +28,4 @@ export default class ObjectListEvent {
|
||||
const objects = await ObjectRepository.getAll()
|
||||
callback(objects)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,9 @@
|
||||
import fs from 'fs'
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
interface IPayload {
|
||||
object: string
|
||||
@ -36,10 +35,10 @@ export default class ObjectRemoveEvent {
|
||||
})
|
||||
|
||||
// get root path
|
||||
const public_folder = path.join(process.cwd(), 'public', 'objects')
|
||||
const public_folder = getPublicPath('objects')
|
||||
|
||||
// remove the tile from the disk
|
||||
const finalFilePath = path.join(public_folder, data.object + '.png')
|
||||
const finalFilePath = getPublicPath('objects', data.object + '.png')
|
||||
fs.unlink(finalFilePath, (err) => {
|
||||
if (err) {
|
||||
console.log(err)
|
||||
@ -54,4 +53,4 @@ export default class ObjectRemoveEvent {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
|
||||
type Payload = {
|
||||
@ -56,4 +55,4 @@ export default class ObjectUpdateEvent {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import { writeFile } from 'node:fs/promises'
|
||||
import path from 'path'
|
||||
import fs from 'fs/promises'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import sharp from 'sharp'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { gameMasterLogger } from '../../../../utilities/logger'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
interface IObjectData {
|
||||
[key: string]: Buffer
|
||||
@ -30,7 +30,7 @@ export default class ObjectUploadEvent {
|
||||
if (character.role !== 'gm') {
|
||||
return callback(false)
|
||||
}
|
||||
const public_folder = path.join(process.cwd(), 'public', 'objects')
|
||||
const public_folder = getPublicPath('objects')
|
||||
|
||||
// Ensure the folder exists
|
||||
await fs.mkdir(public_folder, { recursive: true })
|
||||
@ -54,7 +54,7 @@ export default class ObjectUploadEvent {
|
||||
|
||||
const uuid = object.id
|
||||
const filename = `${uuid}.png`
|
||||
const finalFilePath = path.join(public_folder, filename)
|
||||
const finalFilePath = getPublicPath('objects', filename)
|
||||
await writeFile(finalFilePath, objectData)
|
||||
|
||||
gameMasterLogger.info('gm:object:upload', `Object ${key} uploaded with id ${uuid}`)
|
||||
|
@ -1,10 +1,9 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import path from 'path'
|
||||
import fs from 'fs/promises'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
export default class SpriteCreateEvent {
|
||||
constructor(
|
||||
@ -25,7 +24,7 @@ export default class SpriteCreateEvent {
|
||||
return callback(false)
|
||||
}
|
||||
|
||||
const public_folder = path.join(process.cwd(), 'public', 'sprites')
|
||||
const public_folder = getPublicPath('sprites')
|
||||
|
||||
// Ensure the folder exists
|
||||
await fs.mkdir(public_folder, { recursive: true })
|
||||
@ -38,7 +37,7 @@ export default class SpriteCreateEvent {
|
||||
const uuid = sprite.id
|
||||
|
||||
// Create folder with uuid
|
||||
const sprite_folder = path.join(public_folder, uuid)
|
||||
const sprite_folder = getPublicPath('sprites', uuid)
|
||||
await fs.mkdir(sprite_folder, { recursive: true })
|
||||
|
||||
callback(true)
|
||||
@ -47,4 +46,4 @@ export default class SpriteCreateEvent {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import { gameMasterLogger } from '../../../../utilities/logger'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
type Payload = {
|
||||
id: string
|
||||
@ -17,7 +17,7 @@ export default class GMSpriteDeleteEvent {
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {
|
||||
this.public_folder = path.join(process.cwd(), 'public', 'sprites')
|
||||
this.public_folder = getPublicPath('sprites')
|
||||
}
|
||||
|
||||
public listen(): void {
|
||||
@ -43,7 +43,7 @@ export default class GMSpriteDeleteEvent {
|
||||
}
|
||||
|
||||
private async deleteSpriteFolder(spriteId: string): Promise<void> {
|
||||
const finalFilePath = path.join(this.public_folder, spriteId)
|
||||
const finalFilePath = getPublicPath('sprites', spriteId)
|
||||
|
||||
if (fs.existsSync(finalFilePath)) {
|
||||
await fs.promises.rmdir(finalFilePath, { recursive: true })
|
||||
|
@ -2,7 +2,6 @@ import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import { Sprite } from '@prisma/client'
|
||||
import SpriteRepository from '../../../../repositories/spriteRepository'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
|
||||
interface IPayload {}
|
||||
@ -29,4 +28,4 @@ export default class SpriteListEvent {
|
||||
const sprites = await SpriteRepository.getAll()
|
||||
callback(sprites)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,10 @@ import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import type { Prisma, SpriteAction } from '@prisma/client'
|
||||
import path from 'path'
|
||||
import { writeFile, mkdir } from 'node:fs/promises'
|
||||
import sharp from 'sharp'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
type SpriteActionInput = Omit<SpriteAction, 'id' | 'spriteId' | 'frameWidth' | 'frameHeight'> & {
|
||||
sprites: string[]
|
||||
@ -73,11 +73,11 @@ export default class SpriteUpdateEvent {
|
||||
return Promise.all(
|
||||
spriteActions.map(async (spriteAction) => {
|
||||
const { action, sprites } = spriteAction
|
||||
|
||||
|
||||
if (!Array.isArray(sprites) || sprites.length === 0) {
|
||||
throw new Error(`Invalid sprites array for action: ${action}`)
|
||||
}
|
||||
|
||||
|
||||
const buffersWithDimensions = await Promise.all(
|
||||
sprites.map(async (sprite: string) => {
|
||||
const buffer = Buffer.from(sprite.split(',')[1], 'base64')
|
||||
@ -85,10 +85,10 @@ export default class SpriteUpdateEvent {
|
||||
return { buffer, width, height }
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
const frameWidth = Math.max(...buffersWithDimensions.map((b) => b.width || 0))
|
||||
const frameHeight = Math.max(...buffersWithDimensions.map((b) => b.height || 0))
|
||||
|
||||
|
||||
return {
|
||||
...spriteAction,
|
||||
frameWidth,
|
||||
@ -123,9 +123,9 @@ export default class SpriteUpdateEvent {
|
||||
}
|
||||
|
||||
async function saveSpritesToDisk(id: string, processedActions: ProcessedSpriteAction[]) {
|
||||
const publicFolder = path.join(process.cwd(), 'public', 'sprites', id)
|
||||
const publicFolder = getPublicPath('sprites', id)
|
||||
await mkdir(publicFolder, { recursive: true })
|
||||
|
||||
|
||||
await Promise.all(
|
||||
processedActions.map(async ({ action, buffersWithDimensions, frameWidth, frameHeight }) => {
|
||||
const combinedImage = await sharp({
|
||||
@ -145,11 +145,11 @@ export default class SpriteUpdateEvent {
|
||||
)
|
||||
.png()
|
||||
.toBuffer()
|
||||
|
||||
const filename = path.join(publicFolder, `${action}.png`)
|
||||
|
||||
const filename = getPublicPath('sprites', id, `${action}.png`)
|
||||
await writeFile(filename, combinedImage)
|
||||
})
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import path from 'path'
|
||||
import fs from 'fs/promises'
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { gameMasterLogger } from '../../../../utilities/logger'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
type Payload = {
|
||||
id: string
|
||||
@ -17,7 +17,7 @@ export default class GMTileDeleteEvent {
|
||||
private readonly io: Server,
|
||||
private readonly socket: TSocket
|
||||
) {
|
||||
this.public_folder = path.join(process.cwd(), 'public', 'tiles')
|
||||
this.public_folder = getPublicPath('tiles')
|
||||
}
|
||||
|
||||
public listen(): void {
|
||||
@ -54,7 +54,7 @@ export default class GMTileDeleteEvent {
|
||||
}
|
||||
|
||||
private async deleteTileFile(tileId: string): Promise<void> {
|
||||
const finalFilePath = path.join(this.public_folder, `${tileId}.png`)
|
||||
const finalFilePath = getPublicPath('tiles', `${tileId}.png`)
|
||||
try {
|
||||
await fs.unlink(finalFilePath)
|
||||
} catch (error: any) {
|
||||
|
@ -2,7 +2,6 @@ import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import { Tile } from '@prisma/client'
|
||||
import TileRepository from '../../../../repositories/tileRepository'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
|
||||
interface IPayload {}
|
||||
@ -29,4 +28,4 @@ export default class TileListEvent {
|
||||
const tiles = await TileRepository.getAll()
|
||||
callback(tiles)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import CharacterManager from '../../../../managers/characterManager'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
|
||||
type Payload = {
|
||||
@ -45,4 +44,4 @@ export default class TileUpdateEvent {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../../utilities/types'
|
||||
import { writeFile } from 'node:fs/promises'
|
||||
import path from 'path'
|
||||
import fs from 'fs/promises'
|
||||
import prisma from '../../../../utilities/prisma'
|
||||
import characterRepository from '../../../../repositories/characterRepository'
|
||||
import { gameMasterLogger } from '../../../../utilities/logger'
|
||||
import { getPublicPath } from '../../../../utilities/storage'
|
||||
|
||||
interface ITileData {
|
||||
[key: string]: Buffer
|
||||
@ -30,7 +30,7 @@ export default class TileUploadEvent {
|
||||
return
|
||||
}
|
||||
|
||||
const public_folder = path.join(process.cwd(), 'public', 'tiles')
|
||||
const public_folder = getPublicPath('tiles')
|
||||
|
||||
// Ensure the folder exists
|
||||
await fs.mkdir(public_folder, { recursive: true })
|
||||
@ -43,7 +43,7 @@ export default class TileUploadEvent {
|
||||
})
|
||||
const uuid = tile.id
|
||||
const filename = `${uuid}.png`
|
||||
const finalFilePath = path.join(public_folder, filename)
|
||||
const finalFilePath = getPublicPath('tiles', filename)
|
||||
await writeFile(finalFilePath, tileData)
|
||||
})
|
||||
|
||||
@ -55,4 +55,4 @@ export default class TileUploadEvent {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,4 +59,4 @@ export default class ZoneCreateEvent {
|
||||
callback([])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,4 +58,4 @@ export default class ZoneDeleteEvent {
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,4 +41,4 @@ export default class ZoneListEvent {
|
||||
callback([])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,4 +56,4 @@ export default class ZoneRequestEvent {
|
||||
callback(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../../utilities/types'
|
||||
import ZoneRepository from '../../../repositories/zoneRepository'
|
||||
import { Zone, ZoneEventTileType, ZoneObject } from '@prisma/client'
|
||||
import { Zone, ZoneEffect, ZoneEventTileType, ZoneObject } from '@prisma/client'
|
||||
import prisma from '../../../utilities/prisma'
|
||||
import zoneManager from '../../../managers/zoneManager'
|
||||
import CharacterRepository from '../../../repositories/characterRepository'
|
||||
@ -22,8 +22,13 @@ interface IPayload {
|
||||
toZoneId: number
|
||||
toPositionX: number
|
||||
toPositionY: number
|
||||
toRotation: number
|
||||
}
|
||||
}[]
|
||||
zoneEffects: {
|
||||
effect: string
|
||||
strength: number
|
||||
}[]
|
||||
zoneObjects: ZoneObject[]
|
||||
}
|
||||
|
||||
@ -84,14 +89,15 @@ export default class ZoneUpdateEvent {
|
||||
positionY: zoneEventTile.positionY,
|
||||
...(zoneEventTile.type === 'TELEPORT' && zoneEventTile.teleport
|
||||
? {
|
||||
teleport: {
|
||||
create: {
|
||||
toZoneId: zoneEventTile.teleport.toZoneId,
|
||||
toPositionX: zoneEventTile.teleport.toPositionX,
|
||||
toPositionY: zoneEventTile.teleport.toPositionY
|
||||
teleport: {
|
||||
create: {
|
||||
toZoneId: zoneEventTile.teleport.toZoneId,
|
||||
toPositionX: zoneEventTile.teleport.toPositionX,
|
||||
toPositionY: zoneEventTile.teleport.toPositionY,
|
||||
toRotation: zoneEventTile.teleport.toRotation
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
: {})
|
||||
}))
|
||||
},
|
||||
@ -100,10 +106,19 @@ export default class ZoneUpdateEvent {
|
||||
create: data.zoneObjects.map((zoneObject) => ({
|
||||
objectId: zoneObject.objectId,
|
||||
depth: zoneObject.depth,
|
||||
isRotated: zoneObject.isRotated,
|
||||
positionX: zoneObject.positionX,
|
||||
positionY: zoneObject.positionY
|
||||
}))
|
||||
}
|
||||
},
|
||||
zoneEffects: {
|
||||
deleteMany: { zoneId: data.zoneId },
|
||||
create: data.zoneEffects.map((zoneEffect) => ({
|
||||
effect: zoneEffect.effect,
|
||||
strength: zoneEffect.strength
|
||||
}))
|
||||
},
|
||||
updatedAt: new Date()
|
||||
}
|
||||
})
|
||||
|
||||
@ -115,6 +130,8 @@ export default class ZoneUpdateEvent {
|
||||
return
|
||||
}
|
||||
|
||||
gameMasterLogger.info(`User ${character.id} has updated zone via zone editor.`)
|
||||
|
||||
callback(zone)
|
||||
|
||||
zoneManager.unloadZone(data.zoneId)
|
||||
@ -124,4 +141,4 @@ export default class ZoneUpdateEvent {
|
||||
callback(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,4 +25,4 @@ export default class LoginEvent {
|
||||
gameLogger.error('login error', error.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../../utilities/types'
|
||||
import { ExtendedCharacter, TSocket } from '../../utilities/types'
|
||||
import ZoneRepository from '../../repositories/zoneRepository'
|
||||
import { Character, Zone } from '@prisma/client'
|
||||
import CharacterManager from '../../managers/characterManager'
|
||||
import { gameLogger } from '../../utilities/logger'
|
||||
import CharacterRepository from '../../repositories/characterRepository'
|
||||
|
||||
interface IResponse {
|
||||
zone: Zone
|
||||
@ -22,10 +23,16 @@ export default class CharacterJoinEvent {
|
||||
|
||||
private async handleCharacterJoin(callback: (response: IResponse) => void): Promise<void> {
|
||||
try {
|
||||
if (!this.socket.characterId) return
|
||||
if (!this.socket.characterId) {
|
||||
gameLogger.error('zone:character:join error', 'Zone requested but no character id set')
|
||||
return
|
||||
}
|
||||
|
||||
const character = CharacterManager.getCharacterFromSocket(this.socket)
|
||||
if (!character) return
|
||||
const character = await CharacterRepository.getById(this.socket.characterId as number)
|
||||
if (!character) {
|
||||
gameLogger.error('zone:character:join error', 'Character not found')
|
||||
return
|
||||
}
|
||||
|
||||
const zone = await ZoneRepository.getById(character.zoneId)
|
||||
if (!zone) {
|
||||
@ -33,16 +40,16 @@ export default class CharacterJoinEvent {
|
||||
return
|
||||
}
|
||||
|
||||
if (character.zoneId) {
|
||||
this.socket.leave(character.zoneId.toString())
|
||||
this.io.to(character.zoneId.toString()).emit('zone:character:leave', character)
|
||||
}
|
||||
CharacterManager.initCharacter(character as ExtendedCharacter)
|
||||
|
||||
this.socket.join(zone.id.toString())
|
||||
|
||||
// let other clients know of new character
|
||||
this.io.to(zone.id.toString()).emit('zone:character:join', character)
|
||||
|
||||
// Log
|
||||
gameLogger.info(`User ${character.id} joined zone ${zone.id}`)
|
||||
|
||||
// send over zone and characters to socket
|
||||
callback({ zone, characters: CharacterManager.getCharactersInZone(zone) })
|
||||
} catch (error: any) {
|
||||
@ -50,4 +57,4 @@ export default class CharacterJoinEvent {
|
||||
this.socket.disconnect()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
export function isCommand(message: string, command?: string) {
|
||||
if (command) {
|
||||
return message.startsWith(`:${command} `)
|
||||
return message.startsWith(`/${command} `)
|
||||
}
|
||||
return message.startsWith(':')
|
||||
return message.startsWith('/')
|
||||
}
|
||||
|
||||
export function getArgs(command: string, message: string): string[] | undefined {
|
||||
if (!isCommand(message, command)) return
|
||||
return message.split(`:${command} `)[1].split(' ')
|
||||
return message.split(`/${command} `)[1].split(' ')
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import fs from 'fs'
|
||||
import zoneRepository from '../repositories/zoneRepository'
|
||||
import zoneManager from '../managers/zoneManager'
|
||||
import { httpLogger } from './logger'
|
||||
import { getPublicPath } from './storage'
|
||||
|
||||
async function addHttpRoutes(app: Application) {
|
||||
/**
|
||||
@ -30,6 +31,7 @@ async function addHttpRoutes(app: Application) {
|
||||
key: sprite.id + '-' + spriteAction.action,
|
||||
url: '/assets/sprites/' + sprite.id + '/' + spriteAction.action + '.png',
|
||||
group: spriteAction.isAnimated ? 'sprite_animations' : 'sprites',
|
||||
frameCount: JSON.parse(JSON.stringify(spriteAction.sprites)).length,
|
||||
frameWidth: spriteAction.frameWidth,
|
||||
frameHeight: spriteAction.frameHeight
|
||||
})
|
||||
@ -116,9 +118,9 @@ async function addHttpRoutes(app: Application) {
|
||||
|
||||
let assetPath
|
||||
if (assetType === 'sprites' && spriteId) {
|
||||
assetPath = path.join(process.cwd(), 'public', assetType, spriteId, fileName)
|
||||
assetPath = getPublicPath(assetType, spriteId, fileName)
|
||||
} else {
|
||||
assetPath = path.join(process.cwd(), 'public', assetType, fileName)
|
||||
assetPath = getPublicPath(assetType, fileName)
|
||||
}
|
||||
|
||||
if (!fs.existsSync(assetPath)) {
|
||||
|
49
src/utilities/json.ts
Normal file
49
src/utilities/json.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import * as fs from 'fs/promises'
|
||||
import { appLogger } from './logger'
|
||||
|
||||
export async function readJsonFile<T>(filePath: string): Promise<T> {
|
||||
try {
|
||||
const fileContent = await fs.readFile(filePath, 'utf-8')
|
||||
return JSON.parse(fileContent) as T
|
||||
} catch (error) {
|
||||
appLogger.error(`Error reading JSON file: ${error instanceof Error ? error.message : String(error)}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function writeJsonFile<T>(filePath: string, data: T): Promise<void> {
|
||||
try {
|
||||
const jsonString = JSON.stringify(data, null, 2)
|
||||
await fs.writeFile(filePath, jsonString, 'utf-8')
|
||||
} catch (error) {
|
||||
appLogger.error(`Error writing JSON file: ${error instanceof Error ? error.message : String(error)}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function readJsonValue<T>(filePath: string, paramPath: string): Promise<T> {
|
||||
try {
|
||||
const jsonContent = await readJsonFile<any>(filePath)
|
||||
const paramValue = paramPath.split('.').reduce((obj, key) => obj && obj[key], jsonContent)
|
||||
|
||||
if (paramValue === undefined) {
|
||||
throw new Error(`Parameter ${paramPath} not found in the JSON file`)
|
||||
}
|
||||
|
||||
return paramValue as T
|
||||
} catch (error) {
|
||||
appLogger.error(`Error reading JSON parameter: ${error instanceof Error ? error.message : String(error)}`)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
export async function setJsonValue<T>(filePath: string, key: string, value: any): Promise<void> {
|
||||
try {
|
||||
const data = await readJsonFile<T>(filePath)
|
||||
const updatedData = { ...data, [key]: value }
|
||||
await writeJsonFile(filePath, updatedData)
|
||||
} catch (error) {
|
||||
appLogger.error(`Error setting JSON value: ${error instanceof Error ? error.message : String(error)}`)
|
||||
throw error
|
||||
}
|
||||
}
|
@ -1,9 +1,9 @@
|
||||
import pino from 'pino'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import { getRootPath } from './storage'
|
||||
|
||||
// Array of log types
|
||||
const LOG_TYPES = ['http', 'game', 'gameMaster', 'app', 'queue'] as const
|
||||
const LOG_TYPES = ['http', 'game', 'gameMaster', 'app', 'queue', 'command'] as const
|
||||
type LogType = (typeof LOG_TYPES)[number]
|
||||
|
||||
const createLogger = (name: LogType) =>
|
||||
@ -30,7 +30,7 @@ const loggers = Object.fromEntries(LOG_TYPES.map((type) => [type, createLogger(t
|
||||
|
||||
const watchLogs = () => {
|
||||
LOG_TYPES.forEach((type) => {
|
||||
const logFile = path.join(__dirname, '../../logs', `${type}.log`)
|
||||
const logFile = getRootPath('logs', `${type}.log`)
|
||||
|
||||
fs.watchFile(logFile, (curr, prev) => {
|
||||
if (curr.size > prev.size) {
|
||||
@ -43,6 +43,6 @@ const watchLogs = () => {
|
||||
})
|
||||
}
|
||||
|
||||
export const { http: httpLogger, game: gameLogger, gameMaster: gameMasterLogger, app: appLogger, queue: queueLogger } = loggers
|
||||
export const { http: httpLogger, game: gameLogger, gameMaster: gameMasterLogger, app: appLogger, queue: queueLogger, command: commandLogger } = loggers
|
||||
|
||||
export { watchLogs }
|
||||
|
33
src/utilities/storage.ts
Normal file
33
src/utilities/storage.ts
Normal file
@ -0,0 +1,33 @@
|
||||
import config from './config'
|
||||
import path from 'path'
|
||||
import fs from 'fs'
|
||||
|
||||
export function getRootPath(folder: string, ...additionalSegments: string[]) {
|
||||
return path.join(process.cwd(), folder, ...additionalSegments)
|
||||
}
|
||||
|
||||
export function getAppPath(folder: string, ...additionalSegments: string[]) {
|
||||
const baseDir = config.ENV === 'development' ? 'src' : 'dist'
|
||||
return path.join(process.cwd(), baseDir, folder, ...additionalSegments)
|
||||
}
|
||||
|
||||
export function getPublicPath(folder: string, ...additionalSegments: string[]) {
|
||||
return path.join(process.cwd(), 'public', folder, ...additionalSegments)
|
||||
}
|
||||
|
||||
export function doesPathExist(path: string) {
|
||||
try {
|
||||
fs.accessSync(path, fs.constants.F_OK)
|
||||
return true
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export function createDir(path: string) {
|
||||
try {
|
||||
fs.mkdirSync(path, { recursive: true })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
}
|
@ -25,10 +25,18 @@ export type TAsset = {
|
||||
key: string
|
||||
url: string
|
||||
group: 'tiles' | 'objects' | 'sprites' | 'sprite_animations' | 'sound' | 'music' | 'ui' | 'font' | 'other'
|
||||
frameCount?: number
|
||||
frameWidth?: number
|
||||
frameHeight?: number
|
||||
}
|
||||
|
||||
export type WorldSettings = {
|
||||
date: Date
|
||||
isRainEnabled: boolean
|
||||
isFogEnabled: boolean
|
||||
fogDensity: number
|
||||
}
|
||||
|
||||
// export type TCharacter = Socket & {
|
||||
// user?: User
|
||||
// character?: Character
|
||||
|
Reference in New Issue
Block a user