(feat): initialize for v3
This commit is contained in:
parent
4c68e8f4f4
commit
14db43c67c
163
package-lock.json
generated
163
package-lock.json
generated
@ -1,27 +1,20 @@
|
|||||||
{
|
{
|
||||||
"name": "simrail-logs",
|
"name": "simrail-logs",
|
||||||
"version": "1.0.0",
|
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "simrail-logs",
|
"name": "simrail-logs",
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"dependencies": {
|
"workspaces": [
|
||||||
"@simrail/types": "^0.0.4",
|
"packages/backend",
|
||||||
"@types/mongoose": "^5.11.97",
|
"packages/frontend"
|
||||||
"dayjs": "^1.11.12",
|
],
|
||||||
"ejs": "^3.1.10",
|
|
||||||
"express": "^4.19.2",
|
|
||||||
"mongoose": "^8.5.1",
|
|
||||||
"redis": "^4.6.15",
|
|
||||||
"uuid": "^10.0.0",
|
|
||||||
"wildcard-match": "^5.1.3"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/node": "^22.0.0",
|
"@types/node": "^22.0.0",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
|
"concurrently": "^9.0.1",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "^2.4.1",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.5.4"
|
||||||
}
|
}
|
||||||
@ -262,6 +255,10 @@
|
|||||||
"resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz",
|
"resolved": "https://registry.npmjs.org/async/-/async-3.2.5.tgz",
|
||||||
"integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg=="
|
"integrity": "sha512-baNZyqaaLhyLVKm/DlvdW051MSgO6b8eVfIezl9E5PqWxFgzLm/wQntEW4zOytVburDEr0JlALEpdOFwvErLsg=="
|
||||||
},
|
},
|
||||||
|
"node_modules/backend": {
|
||||||
|
"resolved": "packages/backend",
|
||||||
|
"link": true
|
||||||
|
},
|
||||||
"node_modules/balanced-match": {
|
"node_modules/balanced-match": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
|
||||||
@ -388,6 +385,87 @@
|
|||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg=="
|
||||||
},
|
},
|
||||||
|
"node_modules/concurrently": {
|
||||||
|
"version": "9.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/concurrently/-/concurrently-9.0.1.tgz",
|
||||||
|
"integrity": "sha512-wYKvCd/f54sTXJMSfV6Ln/B8UrfLBKOYa+lzc6CHay3Qek+LorVSBdMVfyewFhRbH0Rbabsk4D+3PL/VjQ5gzg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"chalk": "^4.1.2",
|
||||||
|
"lodash": "^4.17.21",
|
||||||
|
"rxjs": "^7.8.1",
|
||||||
|
"shell-quote": "^1.8.1",
|
||||||
|
"supports-color": "^8.1.1",
|
||||||
|
"tree-kill": "^1.2.2",
|
||||||
|
"yargs": "^17.7.2"
|
||||||
|
},
|
||||||
|
"bin": {
|
||||||
|
"conc": "dist/bin/concurrently.js",
|
||||||
|
"concurrently": "dist/bin/concurrently.js"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=18"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/open-cli-tools/concurrently?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/cliui": {
|
||||||
|
"version": "8.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/cliui/-/cliui-8.0.1.tgz",
|
||||||
|
"integrity": "sha512-BSeNnyus75C4//NQ9gQt1/csTXyo/8Sb+afLAkzAptFuMsod9HFokGNudZpi/oQV73hnVK+sR+5PVRMd+Dr7YQ==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"string-width": "^4.2.0",
|
||||||
|
"strip-ansi": "^6.0.1",
|
||||||
|
"wrap-ansi": "^7.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/supports-color": {
|
||||||
|
"version": "8.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-8.1.1.tgz",
|
||||||
|
"integrity": "sha512-MpUEN2OodtUzxvKQl72cUF7RQ5EiHsGvSsVG0ia9c5RbWGL2CI4C7EpPS8UTBIplnlzZiNuV56w+FuNxy3ty2Q==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"has-flag": "^4.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/chalk/supports-color?sponsor=1"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/yargs": {
|
||||||
|
"version": "17.7.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/yargs/-/yargs-17.7.2.tgz",
|
||||||
|
"integrity": "sha512-7dSzzRQ++CKnNI/krKnYRV7JKKPUXMEh61soaHKg9mrWEhzFWhFnxPxGl+69cD1Ou63C13NUPCnmIcrvqCuM6w==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"cliui": "^8.0.1",
|
||||||
|
"escalade": "^3.1.1",
|
||||||
|
"get-caller-file": "^2.0.5",
|
||||||
|
"require-directory": "^2.1.1",
|
||||||
|
"string-width": "^4.2.3",
|
||||||
|
"y18n": "^5.0.5",
|
||||||
|
"yargs-parser": "^21.1.1"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/concurrently/node_modules/yargs-parser": {
|
||||||
|
"version": "21.1.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-21.1.1.tgz",
|
||||||
|
"integrity": "sha512-tVpsJW7DdjecAiFpbIB1e3qxIQsE6NoPc5/eTdrbbIC4h0LVsWhnoa3g+m2HclBIujHzsxZ4VJVA+GUuc2/LBw==",
|
||||||
|
"dev": true,
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/content-disposition": {
|
"node_modules/content-disposition": {
|
||||||
"version": "0.5.4",
|
"version": "0.5.4",
|
||||||
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
"resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.4.tgz",
|
||||||
@ -889,6 +967,12 @@
|
|||||||
"node": ">=12.0.0"
|
"node": ">=12.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/lodash": {
|
||||||
|
"version": "4.17.21",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
|
||||||
|
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/media-typer": {
|
"node_modules/media-typer": {
|
||||||
"version": "0.3.0",
|
"version": "0.3.0",
|
||||||
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
|
||||||
@ -1263,6 +1347,15 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/rxjs": {
|
||||||
|
"version": "7.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-7.8.1.tgz",
|
||||||
|
"integrity": "sha512-AA3TVj+0A2iuIoQkWEK/tqFjBq2j+6PO6Y0zJcvzLAFhEFIO3HL0vls9hWLncZbAAbK0mar7oZ4V079I/qPMxg==",
|
||||||
|
"dev": true,
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.1.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/safe-buffer": {
|
"node_modules/safe-buffer": {
|
||||||
"version": "5.2.1",
|
"version": "5.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
|
||||||
@ -1350,6 +1443,15 @@
|
|||||||
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz",
|
||||||
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
|
"integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw=="
|
||||||
},
|
},
|
||||||
|
"node_modules/shell-quote": {
|
||||||
|
"version": "1.8.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/shell-quote/-/shell-quote-1.8.1.tgz",
|
||||||
|
"integrity": "sha512-6j1W9l1iAs/4xYBI1SYOVZyFcCis9b4KCLQ8fgAGG07QvzaRLVVRQvAy85yNmmZSjYjg4MWh4gNvlPujU/5LpA==",
|
||||||
|
"dev": true,
|
||||||
|
"funding": {
|
||||||
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/side-channel": {
|
"node_modules/side-channel": {
|
||||||
"version": "1.0.6",
|
"version": "1.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz",
|
||||||
@ -1496,6 +1598,21 @@
|
|||||||
"node": ">=14"
|
"node": ">=14"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/tree-kill": {
|
||||||
|
"version": "1.2.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/tree-kill/-/tree-kill-1.2.2.tgz",
|
||||||
|
"integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==",
|
||||||
|
"dev": true,
|
||||||
|
"bin": {
|
||||||
|
"tree-kill": "cli.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/tslib": {
|
||||||
|
"version": "2.7.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz",
|
||||||
|
"integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
"node_modules/type-is": {
|
"node_modules/type-is": {
|
||||||
"version": "1.6.18",
|
"version": "1.6.18",
|
||||||
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
"resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.18.tgz",
|
||||||
@ -1675,6 +1792,28 @@
|
|||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"packages/backend": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"license": "AGPL-3.0-only",
|
||||||
|
"dependencies": {
|
||||||
|
"@simrail/types": "^0.0.4",
|
||||||
|
"@types/mongoose": "^5.11.97",
|
||||||
|
"dayjs": "^1.11.12",
|
||||||
|
"ejs": "^3.1.10",
|
||||||
|
"express": "^4.19.2",
|
||||||
|
"mongoose": "^8.5.1",
|
||||||
|
"redis": "^4.6.15",
|
||||||
|
"uuid": "^10.0.0",
|
||||||
|
"wildcard-match": "^5.1.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/express": "^4.17.21",
|
||||||
|
"@types/node": "^22.0.0",
|
||||||
|
"@types/uuid": "^10.0.0",
|
||||||
|
"copyfiles": "^2.4.1",
|
||||||
|
"typescript": "^5.5.4"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
package.json
27
package.json
@ -1,33 +1,24 @@
|
|||||||
{
|
{
|
||||||
"name": "simrail-logs",
|
"name": "simrail-logs",
|
||||||
|
"private": true,
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"build": "yarn workspace backend build && yarn workspace frontend build",
|
||||||
"postbuild": "copyfiles --error --up 1 src/http/views/**/* src/http/views/* dist",
|
"start": "concurrently --kill-others-on-fail \"yarn workspace backend start\" \"yarn workspace frontend start\""
|
||||||
"dev": "npm run build && doppler run node dist",
|
|
||||||
"scripts:clear-redis": "doppler run node scripts/clear-redis.js",
|
|
||||||
"scripts:mongo-migration": "doppler run node scripts/mongo-migration.js"
|
|
||||||
},
|
},
|
||||||
|
"workspaces": [
|
||||||
|
"packages/backend",
|
||||||
|
"packages/frontend"
|
||||||
|
],
|
||||||
"author": "Aleksander <alekswilc> Wilczyński",
|
"author": "Aleksander <alekswilc> Wilczyński",
|
||||||
"license": "AGPL-3.0-only",
|
"license": "AGPL-3.0-only",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/express": "^4.17.21",
|
"@types/express": "^4.17.21",
|
||||||
"@types/node": "^22.0.0",
|
"@types/node": "^22.0.0",
|
||||||
"@types/uuid": "^10.0.0",
|
"@types/uuid": "^10.0.0",
|
||||||
|
"concurrently": "^9.0.1",
|
||||||
"copyfiles": "^2.4.1",
|
"copyfiles": "^2.4.1",
|
||||||
"typescript": "^5.5.4"
|
"typescript": "^5.5.4"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module"
|
||||||
"dependencies": {
|
|
||||||
"@simrail/types": "^0.0.4",
|
|
||||||
"@types/mongoose": "^5.11.97",
|
|
||||||
"dayjs": "^1.11.12",
|
|
||||||
"ejs": "^3.1.10",
|
|
||||||
"express": "^4.19.2",
|
|
||||||
"mongoose": "^8.5.1",
|
|
||||||
"redis": "^4.6.15",
|
|
||||||
"uuid": "^10.0.0",
|
|
||||||
"wildcard-match": "^5.1.3"
|
|
||||||
},
|
|
||||||
"typings": "types/typings.d.ts"
|
|
||||||
}
|
}
|
||||||
|
1680
packages/backend/package-lock.json
generated
Normal file
1680
packages/backend/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
33
packages/backend/package.json
Normal file
33
packages/backend/package.json
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"name": "backend",
|
||||||
|
"private": true,
|
||||||
|
"main": "../../dist/backend/index.js",
|
||||||
|
"version": "3.0.0",
|
||||||
|
"scripts": {
|
||||||
|
"build": "tsc",
|
||||||
|
"postbuild": "copyfiles --error --up 1 src/http/views/**/* src/http/views/* ../../dist/backend/",
|
||||||
|
"start": "yarn build && doppler run node ../../dist/backend/index.js"
|
||||||
|
},
|
||||||
|
"author": "Aleksander <alekswilc> Wilczyński",
|
||||||
|
"license": "AGPL-3.0-only",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/express": "^4.17.21",
|
||||||
|
"@types/node": "^22.0.0",
|
||||||
|
"@types/uuid": "^10.0.0",
|
||||||
|
"copyfiles": "^2.4.1",
|
||||||
|
"typescript": "^5.5.4"
|
||||||
|
},
|
||||||
|
"type": "module",
|
||||||
|
"dependencies": {
|
||||||
|
"@simrail/types": "^0.0.4",
|
||||||
|
"@types/mongoose": "^5.11.97",
|
||||||
|
"dayjs": "^1.11.12",
|
||||||
|
"ejs": "^3.1.10",
|
||||||
|
"express": "^4.19.2",
|
||||||
|
"mongoose": "^8.5.1",
|
||||||
|
"redis": "^4.6.15",
|
||||||
|
"uuid": "^10.0.0",
|
||||||
|
"wildcard-match": "^5.1.3"
|
||||||
|
},
|
||||||
|
"typings": "types/typings.d.ts"
|
||||||
|
}
|
@ -1,56 +1,56 @@
|
|||||||
import { createClient, RedisClientType } from 'redis';
|
import { createClient, RedisClientType } from 'redis';
|
||||||
import './util/time.js';
|
import './util/time.js';
|
||||||
import { SimrailClient, SimrailClientEvents } from './util/SimrailClient.js';
|
import { SimrailClient, SimrailClientEvents } from './util/SimrailClient.js';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
import { StationsModule } from './modules/stations.js';
|
import { StationsModule } from './modules/stations.js';
|
||||||
import { ApiModule } from './http/server.js';
|
import { ApiModule } from './http/server.js';
|
||||||
import mongoose from 'mongoose';
|
import mongoose from 'mongoose';
|
||||||
import { IPlayer } from './types/player.js';
|
import { IPlayer } from './types/player.js';
|
||||||
import { Station, Server, Train } from '@simrail/types';
|
import { Station, Server, Train } from '@simrail/types';
|
||||||
import { TrainsModule } from './modules/trains.js';
|
import { TrainsModule } from './modules/trains.js';
|
||||||
|
|
||||||
|
|
||||||
; (async () => {
|
; (async () => {
|
||||||
global.redis = await createClient({
|
global.redis = await createClient({
|
||||||
url: process.env.REDIS_URI!
|
url: process.env.REDIS_URI!
|
||||||
})
|
})
|
||||||
.on('error', err => console.log('Redis Client Error', err))
|
.on('error', err => console.log('Redis Client Error', err))
|
||||||
.connect() as RedisClientType;
|
.connect() as RedisClientType;
|
||||||
console.log('Redis connected');
|
console.log('Redis connected');
|
||||||
|
|
||||||
await mongoose.connect(process.env.MONGO_URI!);
|
await mongoose.connect(process.env.MONGO_URI!);
|
||||||
|
|
||||||
console.log('MongoDB connected');
|
console.log('MongoDB connected');
|
||||||
global.client = new SimrailClient();
|
global.client = new SimrailClient();
|
||||||
|
|
||||||
client.on(SimrailClientEvents.StationJoined, (server: Server, station: Station, player: IPlayer) => {
|
client.on(SimrailClientEvents.StationJoined, (server: Server, station: Station, player: IPlayer) => {
|
||||||
console.log(`${server.ServerCode} | ${station.Name} | ${player.personaname} joined`);
|
console.log(`${server.ServerCode} | ${station.Name} | ${player.personaname} joined`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(SimrailClientEvents.StationLeft, (server: Server, station: Station, player: IPlayer, joinedAt: number) => {
|
client.on(SimrailClientEvents.StationLeft, (server: Server, station: Station, player: IPlayer, joinedAt: number) => {
|
||||||
console.log(`${server.ServerCode} | ${station.Name} | ${player.personaname} left. | ${joinedAt ? dayjs(joinedAt).fromNow() : 'no time data.'}`);
|
console.log(`${server.ServerCode} | ${station.Name} | ${player.personaname} left. | ${joinedAt ? dayjs(joinedAt).fromNow() : 'no time data.'}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(SimrailClientEvents.TrainLeft, (server: Server, train: Train, player: IPlayer, joinedAt: number, leftAt: number, points: number, distance: number, vehicle: string) => {
|
client.on(SimrailClientEvents.TrainLeft, (server: Server, train: Train, player: IPlayer, joinedAt: number, leftAt: number, points: number, distance: number, vehicle: string) => {
|
||||||
console.log(`${server.ServerCode} | ${train.TrainName} | ${player.personaname} left. | ${joinedAt ? dayjs(joinedAt).fromNow() : 'no time data.'} |
|
console.log(`${server.ServerCode} | ${train.TrainName} | ${player.personaname} left. | ${joinedAt ? dayjs(joinedAt).fromNow() : 'no time data.'} |
|
||||||
${vehicle} | ${distance / 1000} | ${points}`);
|
${vehicle} | ${distance / 1000} | ${points}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on(SimrailClientEvents.TrainJoined, (server: Server, train: Train, player: IPlayer, start: number) => {
|
client.on(SimrailClientEvents.TrainJoined, (server: Server, train: Train, player: IPlayer, start: number) => {
|
||||||
console.log(`${server.ServerCode} | ${train.TrainName} | ${player.personaname} joined | ${start}`);
|
console.log(`${server.ServerCode} | ${train.TrainName} | ${player.personaname} joined | ${start}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
StationsModule.load();
|
StationsModule.load();
|
||||||
TrainsModule.load();
|
TrainsModule.load();
|
||||||
ApiModule.load();
|
ApiModule.load();
|
||||||
|
|
||||||
|
|
||||||
// process.on('unhandledRejection', (reason, promise) => {
|
// process.on('unhandledRejection', (reason, promise) => {
|
||||||
// console.error(reason);
|
// console.error(reason);
|
||||||
// console.error(promise);
|
// console.error(promise);
|
||||||
// })
|
// })
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,51 +1,51 @@
|
|||||||
import { Server, Station } from '@simrail/types';
|
import { Server, Station } from '@simrail/types';
|
||||||
import { MLog } from '../mongo/logs.js';
|
import { MLog } from '../mongo/logs.js';
|
||||||
import { IPlayer } from '../types/player.js';
|
import { IPlayer } from '../types/player.js';
|
||||||
import { SimrailClientEvents } from '../util/SimrailClient.js';
|
import { SimrailClientEvents } from '../util/SimrailClient.js';
|
||||||
import { v4 } from 'uuid';
|
import { v4 } from 'uuid';
|
||||||
import { MProfile } from '../mongo/profile.js';
|
import { MProfile } from '../mongo/profile.js';
|
||||||
import { SteamUtil } from '../util/SteamUtil.js';
|
import { SteamUtil } from '../util/SteamUtil.js';
|
||||||
|
|
||||||
export class StationsModule {
|
export class StationsModule {
|
||||||
public static load() {
|
public static load() {
|
||||||
|
|
||||||
client.on(SimrailClientEvents.StationLeft, async (server: Server, station: Station, player: IPlayer, joinedAt: number) => {
|
client.on(SimrailClientEvents.StationLeft, async (server: Server, station: Station, player: IPlayer, joinedAt: number) => {
|
||||||
const stats = await SteamUtil.getPlayerStats(player.steamid);
|
const stats = await SteamUtil.getPlayerStats(player.steamid);
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
if (stats) {
|
if (stats) {
|
||||||
const time = (date.getTime() - joinedAt) ?? 0;
|
const time = (date.getTime() - joinedAt) || 0;
|
||||||
|
|
||||||
const userProfile = await MProfile.findOne({ steam: player.steamid }) ?? await MProfile.create({ steam: player.steamid, id: v4(), steamName: player.personaname });
|
const userProfile = await MProfile.findOne({ steam: player.steamid }) ?? await MProfile.create({ steam: player.steamid, id: v4(), steamName: player.personaname });
|
||||||
if (!userProfile.dispatcherStats) userProfile.dispatcherStats = {};
|
if (!userProfile.dispatcherStats) userProfile.dispatcherStats = {};
|
||||||
|
|
||||||
if (userProfile.dispatcherStats[station.Name]) {
|
if (userProfile.dispatcherStats[station.Name]) {
|
||||||
userProfile.dispatcherStats[station.Name].time = userProfile.dispatcherStats[station.Name].time + time;
|
userProfile.dispatcherStats[station.Name].time = userProfile.dispatcherStats[station.Name].time + time;
|
||||||
} else {
|
} else {
|
||||||
userProfile.dispatcherStats[station.Name] = {
|
userProfile.dispatcherStats[station.Name] = {
|
||||||
time
|
time
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Number.isNaN(userProfile.dispatcherStats[station.Name].time)) userProfile.dispatcherStats[station.Name].time = 0;
|
if (Number.isNaN(userProfile.dispatcherStats[station.Name].time)) userProfile.dispatcherStats[station.Name].time = 0;
|
||||||
|
|
||||||
if (!userProfile.dispatcherTime) userProfile.dispatcherTime = 0;
|
if (!userProfile.dispatcherTime) userProfile.dispatcherTime = 0;
|
||||||
|
|
||||||
userProfile.dispatcherTime = userProfile.dispatcherTime + time;
|
userProfile.dispatcherTime = userProfile.dispatcherTime + time;
|
||||||
|
|
||||||
await MProfile.findOneAndUpdate({ id: userProfile.id }, { dispatcherStats: userProfile.dispatcherStats, dispatcherTime: userProfile.dispatcherTime })
|
await MProfile.findOneAndUpdate({ id: userProfile.id }, { dispatcherStats: userProfile.dispatcherStats, dispatcherTime: userProfile.dispatcherTime })
|
||||||
}
|
}
|
||||||
|
|
||||||
MLog.create({
|
MLog.create({
|
||||||
id: v4(),
|
id: v4(),
|
||||||
userSteamId: player.steamid,
|
userSteamId: player.steamid,
|
||||||
userAvatar: player.avatarfull,
|
userAvatar: player.avatarfull,
|
||||||
userUsername: player.personaname,
|
userUsername: player.personaname,
|
||||||
joinedDate: joinedAt,
|
joinedDate: joinedAt,
|
||||||
leftDate: date.getTime(),
|
leftDate: date.getTime(),
|
||||||
stationName: station.Name,
|
stationName: station.Name,
|
||||||
stationShort: station.Prefix,
|
stationShort: station.Prefix,
|
||||||
server: server.ServerCode
|
server: server.ServerCode
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,7 +12,7 @@ export class TrainsModule {
|
|||||||
|
|
||||||
client.on(SimrailClientEvents.TrainLeft, async (server: Server, train: Train, player: IPlayer, joinedAt: number, leftAt: number, points: number, distance: number, vehicle: string) => {
|
client.on(SimrailClientEvents.TrainLeft, async (server: Server, train: Train, player: IPlayer, joinedAt: number, leftAt: number, points: number, distance: number, vehicle: string) => {
|
||||||
if (distance) {
|
if (distance) {
|
||||||
const time = (leftAt - joinedAt) ?? 0;
|
const time = (leftAt - joinedAt) || 0;
|
||||||
const userProfile = await MProfile.findOne({ steam: player.steamid }) ?? await MProfile.create({ steam: player.steamid, id: v4(), steamName: player.personaname });
|
const userProfile = await MProfile.findOne({ steam: player.steamid }) ?? await MProfile.create({ steam: player.steamid, id: v4(), steamName: player.personaname });
|
||||||
|
|
||||||
const vehicleName = getVehicle(vehicle) ?? vehicle;
|
const vehicleName = getVehicle(vehicle) ?? vehicle;
|
@ -1,61 +1,61 @@
|
|||||||
import { Model, model, Schema } from 'mongoose';
|
import { Model, model, Schema } from 'mongoose';
|
||||||
|
|
||||||
|
|
||||||
export const raw_schema = {
|
export const raw_schema = {
|
||||||
id: {
|
id: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
userSteamId: {
|
userSteamId: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
userUsername: {
|
userUsername: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
userAvatar: {
|
userAvatar: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
joinedDate: {
|
joinedDate: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: false,
|
required: false,
|
||||||
default: undefined
|
default: undefined
|
||||||
},
|
},
|
||||||
leftDate: {
|
leftDate: {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
stationName: {
|
stationName: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
stationShort: {
|
stationShort: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
server: {
|
server: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const schema = new Schema<ILog>(raw_schema);
|
const schema = new Schema<ILog>(raw_schema);
|
||||||
schema.index({ stationName: 'text', userUsername: 'text', stationShort: 'text', userSteamId: 'text', server: 'text' })
|
schema.index({ stationName: 'text', userUsername: 'text', stationShort: 'text', userSteamId: 'text', server: 'text' })
|
||||||
|
|
||||||
export type TMLog = Model<ILog>
|
export type TMLog = Model<ILog>
|
||||||
|
|
||||||
export const MLog = model<ILog>('logs', schema);
|
export const MLog = model<ILog>('logs', schema);
|
||||||
|
|
||||||
export interface ILog {
|
export interface ILog {
|
||||||
id: string
|
id: string
|
||||||
userSteamId: string
|
userSteamId: string
|
||||||
userUsername: string
|
userUsername: string
|
||||||
userAvatar: string
|
userAvatar: string
|
||||||
joinedDate?: number
|
joinedDate?: number
|
||||||
leftDate: number
|
leftDate: number
|
||||||
stationName: string
|
stationName: string
|
||||||
stationShort: string
|
stationShort: string
|
||||||
server: string
|
server: string
|
||||||
}
|
}
|
@ -1,68 +1,68 @@
|
|||||||
/* steam api */
|
/* steam api */
|
||||||
|
|
||||||
export type IPlayer = {
|
export type IPlayer = {
|
||||||
steamid: string,
|
steamid: string,
|
||||||
communityvisibilitystate: number,
|
communityvisibilitystate: number,
|
||||||
profilestate: number,
|
profilestate: number,
|
||||||
personaname: string,
|
personaname: string,
|
||||||
commentpermission: number,
|
commentpermission: number,
|
||||||
profileurl: string,
|
profileurl: string,
|
||||||
avatar: string,
|
avatar: string,
|
||||||
avatarmedium: string,
|
avatarmedium: string,
|
||||||
avatarfull: string,
|
avatarfull: string,
|
||||||
avatarhash: string,
|
avatarhash: string,
|
||||||
personastate: number,
|
personastate: number,
|
||||||
primaryclanid: string,
|
primaryclanid: string,
|
||||||
timecreated: number,
|
timecreated: number,
|
||||||
personastateflags: number,
|
personastateflags: number,
|
||||||
gameextrainfo: string,
|
gameextrainfo: string,
|
||||||
gameid: string,
|
gameid: string,
|
||||||
loccountrycode: string,
|
loccountrycode: string,
|
||||||
locstatecode: string
|
locstatecode: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IPlayerStats = {
|
export type IPlayerStats = {
|
||||||
"steamID": string,
|
"steamID": string,
|
||||||
"gameName": string,
|
"gameName": string,
|
||||||
"stats": [
|
"stats": [
|
||||||
{
|
{
|
||||||
"name": "SCORE",
|
"name": "SCORE",
|
||||||
"value": number
|
"value": number
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DISPATCHER_TIME",
|
"name": "DISPATCHER_TIME",
|
||||||
"value": number
|
"value": number
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "DISTANCE_M",
|
"name": "DISTANCE_M",
|
||||||
"value": number
|
"value": number
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"achievements": [
|
"achievements": [
|
||||||
{
|
{
|
||||||
"name": "FINISH_MISSION",
|
"name": "FINISH_MISSION",
|
||||||
"achieved": 0 | 1
|
"achieved": 0 | 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "FINISH_ON_TIME",
|
"name": "FINISH_ON_TIME",
|
||||||
"achieved": 0 | 1
|
"achieved": 0 | 1
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "FINISH_NIGHT",
|
"name": "FINISH_NIGHT",
|
||||||
"achieved": 0 | 1
|
"achieved": 0 | 1
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IPlayerPayload = {
|
export type IPlayerPayload = {
|
||||||
response: {
|
response: {
|
||||||
players: IPlayer[]
|
players: IPlayer[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IPlayerStatsPayload = {
|
export type IPlayerStatsPayload = {
|
||||||
playerstats: IPlayerStats
|
playerstats: IPlayerStats
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
|||||||
import { RedisClientType } from 'redis'
|
import { RedisClientType } from 'redis'
|
||||||
import { SimrailClient } from '../util/SimrailClient.ts'
|
import { SimrailClient } from '../util/SimrailClient.ts'
|
||||||
/* eslint no-var: off */
|
/* eslint no-var: off */
|
||||||
declare global
|
declare global
|
||||||
{
|
{
|
||||||
declare var redis: RedisClientType,
|
declare var redis: RedisClientType,
|
||||||
client: SimrailClient;
|
client: SimrailClient;
|
||||||
|
|
||||||
}
|
}
|
@ -1,40 +1,40 @@
|
|||||||
import { IPlayerPayload, IPlayerStatsPayload } from '../types/player.js';
|
import { IPlayerPayload, IPlayerStatsPayload } from '../types/player.js';
|
||||||
|
|
||||||
const STEAM_API_KEY = process.env.STEAM_APIKEY;
|
const STEAM_API_KEY = process.env.STEAM_APIKEY;
|
||||||
|
|
||||||
const fetchFuckingSteamApi = (url: string) => {
|
const fetchFuckingSteamApi = (url: string) => {
|
||||||
let retries = 0;
|
let retries = 0;
|
||||||
|
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
const req = () => {
|
const req = () => {
|
||||||
if (retries > 5) throw new Error('request failed to api steam');
|
if (retries > 5) throw new Error('request failed to api steam');
|
||||||
fetch(url, { signal: AbortSignal.timeout(10000) }).then(x => x.json())
|
fetch(url, { signal: AbortSignal.timeout(10000) }).then(x => x.json())
|
||||||
.then(x => res(x))
|
.then(x => res(x))
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
console.log('STEAM request failed! ', url.replace(STEAM_API_KEY!, '[XXX]'), retries)
|
console.log('STEAM request failed! ', url.replace(STEAM_API_KEY!, '[XXX]'), retries)
|
||||||
|
|
||||||
retries++;
|
retries++;
|
||||||
setTimeout(() => req(), 1000);
|
setTimeout(() => req(), 1000);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
req();
|
req();
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export class PlayerUtil {
|
export class PlayerUtil {
|
||||||
public static async getPlayer(steamId: number | string) {
|
public static async getPlayer(steamId: number | string) {
|
||||||
const data = await fetchFuckingSteamApi(`https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=${STEAM_API_KEY}&format=json&steamids=${steamId}`) as IPlayerPayload;
|
const data = await fetchFuckingSteamApi(`https://api.steampowered.com/ISteamUser/GetPlayerSummaries/v2/?key=${STEAM_API_KEY}&format=json&steamids=${steamId}`) as IPlayerPayload;
|
||||||
|
|
||||||
if (!data.response.players) return;
|
if (!data.response.players) return;
|
||||||
return data.response.players[0];
|
return data.response.players[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async getPlayerStats(steamId: string) {
|
public static async getPlayerStats(steamId: string) {
|
||||||
const data = await fetchFuckingSteamApi(`http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=1422130&key=${STEAM_API_KEY}&steamid=${steamId}`) as IPlayerStatsPayload;
|
const data = await fetchFuckingSteamApi(`http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=1422130&key=${STEAM_API_KEY}&steamid=${steamId}`) as IPlayerStatsPayload;
|
||||||
|
|
||||||
|
|
||||||
if (!data.playerstats?.stats) return;
|
if (!data.playerstats?.stats) return;
|
||||||
return data.playerstats;
|
return data.playerstats;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,219 +1,219 @@
|
|||||||
import { EventEmitter } from 'node:events';
|
import { EventEmitter } from 'node:events';
|
||||||
|
|
||||||
import { IPlayer } from '../types/player.js';
|
import { IPlayer } from '../types/player.js';
|
||||||
import { PlayerUtil } from './PlayerUtil.js';
|
import { PlayerUtil } from './PlayerUtil.js';
|
||||||
import { Station, ApiResponse, Server, Train } from '@simrail/types';
|
import { Station, ApiResponse, Server, Train } from '@simrail/types';
|
||||||
|
|
||||||
export enum SimrailClientEvents {
|
export enum SimrailClientEvents {
|
||||||
StationJoined = 'stationJoined',
|
StationJoined = 'stationJoined',
|
||||||
StationLeft = 'stationLeft',
|
StationLeft = 'stationLeft',
|
||||||
TrainJoined = 'trainJoined',
|
TrainJoined = 'trainJoined',
|
||||||
TrainLeft = 'trainLeft',
|
TrainLeft = 'trainLeft',
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export declare interface SimrailClient {
|
export declare interface SimrailClient {
|
||||||
on(event: SimrailClientEvents.StationJoined, listener: (server: Server, station: Station, player: IPlayer) => void): this;
|
on(event: SimrailClientEvents.StationJoined, listener: (server: Server, station: Station, player: IPlayer) => void): this;
|
||||||
on(event: SimrailClientEvents.StationLeft, listener: (server: Server, station: Station, player: IPlayer, joinedAt: number) => void): this;
|
on(event: SimrailClientEvents.StationLeft, listener: (server: Server, station: Station, player: IPlayer, joinedAt: number) => void): this;
|
||||||
|
|
||||||
|
|
||||||
on(event: SimrailClientEvents.TrainJoined, listener: (server: Server, train: Train, player: IPlayer, startDistance: number) => void): this;
|
on(event: SimrailClientEvents.TrainJoined, listener: (server: Server, train: Train, player: IPlayer, startDistance: number) => void): this;
|
||||||
on(event: SimrailClientEvents.TrainLeft, listener: (server: Server, train: Train, player: IPlayer, joinedAt: number, leftAt: number, points: number, distance: number, vehicle: string) => void): this;
|
on(event: SimrailClientEvents.TrainLeft, listener: (server: Server, train: Train, player: IPlayer, joinedAt: number, leftAt: number, points: number, distance: number, vehicle: string) => void): this;
|
||||||
|
|
||||||
//on(event: string, listener: Function): this;
|
//on(event: string, listener: Function): this;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OccupiedStation = {
|
export type OccupiedStation = {
|
||||||
SteamId: string;
|
SteamId: string;
|
||||||
JoinedAt: number;
|
JoinedAt: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type OccupiedTrain = {
|
export type OccupiedTrain = {
|
||||||
SteamId: string;
|
SteamId: string;
|
||||||
JoinedAt: number;
|
JoinedAt: number;
|
||||||
StartPlayerDistance: number;
|
StartPlayerDistance: number;
|
||||||
StartPlayerPoints: number;
|
StartPlayerPoints: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class SimrailClient extends EventEmitter {
|
export class SimrailClient extends EventEmitter {
|
||||||
public stations: Record<Server['ServerCode'], Station[]> = {};
|
public stations: Record<Server['ServerCode'], Station[]> = {};
|
||||||
public stationsOccupied: Record<Server['ServerCode'], Record<string, OccupiedStation | null>> = {};
|
public stationsOccupied: Record<Server['ServerCode'], Record<string, OccupiedStation | null>> = {};
|
||||||
|
|
||||||
public trains: Record<Server['ServerCode'], Train[]> = {};
|
public trains: Record<Server['ServerCode'], Train[]> = {};
|
||||||
public trainsOccupied: Record<Server['ServerCode'], Record<string, OccupiedTrain | null>> = {};
|
public trainsOccupied: Record<Server['ServerCode'], Record<string, OccupiedTrain | null>> = {};
|
||||||
|
|
||||||
public constructor() {
|
public constructor() {
|
||||||
super();
|
super();
|
||||||
this.setup();
|
this.setup();
|
||||||
setTimeout(() => setInterval(() => this.update(), 500), 1000)
|
setTimeout(() => setInterval(() => this.update(), 500), 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
public getStation(server: Server['ServerCode'], name: string) {
|
public getStation(server: Server['ServerCode'], name: string) {
|
||||||
if (!this.stationsOccupied[server] || !this.stationsOccupied[server][name]) return null;
|
if (!this.stationsOccupied[server] || !this.stationsOccupied[server][name]) return null;
|
||||||
const player = PlayerUtil.getPlayer(this.stationsOccupied[server][name].SteamId);
|
const player = PlayerUtil.getPlayer(this.stationsOccupied[server][name].SteamId);
|
||||||
return { player, joinedAt: this.stationsOccupied[name].joinedAt };
|
return { player, joinedAt: this.stationsOccupied[name].joinedAt };
|
||||||
}
|
}
|
||||||
|
|
||||||
public getTrain(server: Server['ServerCode'], name: string) {
|
public getTrain(server: Server['ServerCode'], name: string) {
|
||||||
if (!this.trainsOccupied[server] || !this.trainsOccupied[server][name]) return null;
|
if (!this.trainsOccupied[server] || !this.trainsOccupied[server][name]) return null;
|
||||||
const player = PlayerUtil.getPlayer(this.trainsOccupied[server][name].SteamId);
|
const player = PlayerUtil.getPlayer(this.trainsOccupied[server][name].SteamId);
|
||||||
return { player, joinedAt: this.trainsOccupied[server][name].JoinedAt, startPlayerDistance: this.trainsOccupied[server][name].StartPlayerDistance };
|
return { player, joinedAt: this.trainsOccupied[server][name].JoinedAt, startPlayerDistance: this.trainsOccupied[server][name].StartPlayerDistance };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private async setup() {
|
private async setup() {
|
||||||
if (!await redis.json.get('stations'))
|
if (!await redis.json.get('stations'))
|
||||||
redis.json.set('stations', '$', []);
|
redis.json.set('stations', '$', []);
|
||||||
if (!await redis.json.get('trains'))
|
if (!await redis.json.get('trains'))
|
||||||
redis.json.set('trains', '$', []);
|
redis.json.set('trains', '$', []);
|
||||||
if (!await redis.json.get('trains_occupied'))
|
if (!await redis.json.get('trains_occupied'))
|
||||||
redis.json.set('trains_occupied', '$', {});
|
redis.json.set('trains_occupied', '$', {});
|
||||||
|
|
||||||
if (!await redis.json.get('stations_occupied'))
|
if (!await redis.json.get('stations_occupied'))
|
||||||
redis.json.set('stations_occupied', '$', {});
|
redis.json.set('stations_occupied', '$', {});
|
||||||
|
|
||||||
this.stations = (await redis.json.get('stations') as unknown as SimrailClient['stations']);
|
this.stations = (await redis.json.get('stations') as unknown as SimrailClient['stations']);
|
||||||
this.stationsOccupied = (await redis.json.get('stations_occupied') as unknown as SimrailClient['stationsOccupied']);
|
this.stationsOccupied = (await redis.json.get('stations_occupied') as unknown as SimrailClient['stationsOccupied']);
|
||||||
this.trains = (await redis.json.get('trains') as unknown as SimrailClient['trains']);
|
this.trains = (await redis.json.get('trains') as unknown as SimrailClient['trains']);
|
||||||
this.trainsOccupied = (await redis.json.get('trains_occupied') as unknown as SimrailClient['trainsOccupied']);
|
this.trainsOccupied = (await redis.json.get('trains_occupied') as unknown as SimrailClient['trainsOccupied']);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processStation(server: Server, stations: ApiResponse<Station>) {
|
private async processStation(server: Server, stations: ApiResponse<Station>) {
|
||||||
if (stations.result) {
|
if (stations.result) {
|
||||||
if (!this.stations[server.ServerCode]) this.stations[server.ServerCode] = [];
|
if (!this.stations[server.ServerCode]) this.stations[server.ServerCode] = [];
|
||||||
if (!this.stationsOccupied[server.ServerCode]) this.stationsOccupied[server.ServerCode] = {};
|
if (!this.stationsOccupied[server.ServerCode]) this.stationsOccupied[server.ServerCode] = {};
|
||||||
|
|
||||||
if (!this.stations[server.ServerCode].length) {
|
if (!this.stations[server.ServerCode].length) {
|
||||||
this.stations[server.ServerCode] = stations.data;
|
this.stations[server.ServerCode] = stations.data;
|
||||||
redis.json.set('stations', '$', this.stations);
|
redis.json.set('stations', '$', this.stations);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
stations.data.forEach(async (x) => {
|
stations.data.forEach(async (x) => {
|
||||||
const data = this.stations[server.ServerCode].find(y => y.Name === x.Name);
|
const data = this.stations[server.ServerCode].find(y => y.Name === x.Name);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
if (data.DispatchedBy[0]?.SteamId !== x.DispatchedBy[0]?.SteamId) {
|
if (data.DispatchedBy[0]?.SteamId !== x.DispatchedBy[0]?.SteamId) {
|
||||||
if (!data.DispatchedBy[0]?.SteamId) {
|
if (!data.DispatchedBy[0]?.SteamId) {
|
||||||
// join
|
// join
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
const player = await PlayerUtil.getPlayer(x.DispatchedBy[0]?.SteamId);
|
const player = await PlayerUtil.getPlayer(x.DispatchedBy[0]?.SteamId);
|
||||||
|
|
||||||
this.emit(SimrailClientEvents.StationJoined, server, x, player);
|
this.emit(SimrailClientEvents.StationJoined, server, x, player);
|
||||||
this.stationsOccupied[server.ServerCode][data.Prefix] = {
|
this.stationsOccupied[server.ServerCode][data.Prefix] = {
|
||||||
SteamId: x.DispatchedBy[0]?.SteamId,
|
SteamId: x.DispatchedBy[0]?.SteamId,
|
||||||
JoinedAt: date.getTime()
|
JoinedAt: date.getTime()
|
||||||
};
|
};
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// leave
|
// leave
|
||||||
const player = await PlayerUtil.getPlayer(data.DispatchedBy[0]?.SteamId)
|
const player = await PlayerUtil.getPlayer(data.DispatchedBy[0]?.SteamId)
|
||||||
|
|
||||||
this.emit(SimrailClientEvents.StationLeft, server, x, player, this.stationsOccupied[server.ServerCode][data.Prefix]?.JoinedAt);
|
this.emit(SimrailClientEvents.StationLeft, server, x, player, this.stationsOccupied[server.ServerCode][data.Prefix]?.JoinedAt);
|
||||||
delete this.stationsOccupied[server.ServerCode][data.Prefix];
|
delete this.stationsOccupied[server.ServerCode][data.Prefix];
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
redis.json.set('stations_occupied', '$', this.stationsOccupied);
|
redis.json.set('stations_occupied', '$', this.stationsOccupied);
|
||||||
|
|
||||||
this.stations[server.ServerCode] = stations.data;
|
this.stations[server.ServerCode] = stations.data;
|
||||||
redis.json.set('stations', '$', this.stations);
|
redis.json.set('stations', '$', this.stations);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processTrain(server: Server, trains: ApiResponse<Train>) {
|
private async processTrain(server: Server, trains: ApiResponse<Train>) {
|
||||||
if (trains.result) {
|
if (trains.result) {
|
||||||
if (!this.trains[server.ServerCode]) this.trains[server.ServerCode] = [];
|
if (!this.trains[server.ServerCode]) this.trains[server.ServerCode] = [];
|
||||||
if (!this.trainsOccupied[server.ServerCode]) this.trainsOccupied[server.ServerCode] = {};
|
if (!this.trainsOccupied[server.ServerCode]) this.trainsOccupied[server.ServerCode] = {};
|
||||||
|
|
||||||
if (!this.trains[server.ServerCode].length) {
|
if (!this.trains[server.ServerCode].length) {
|
||||||
this.trains[server.ServerCode] = trains.data;
|
this.trains[server.ServerCode] = trains.data;
|
||||||
|
|
||||||
redis.json.set('trains', '$', this.trains);
|
redis.json.set('trains', '$', this.trains);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
trains.data.forEach(async (x) => {
|
trains.data.forEach(async (x) => {
|
||||||
const data = this.trains[server.ServerCode].find(y => y.id === x.id);
|
const data = this.trains[server.ServerCode].find(y => y.id === x.id);
|
||||||
if (!data) return;
|
if (!data) return;
|
||||||
|
|
||||||
if (data.TrainData.ControlledBySteamID !== x.TrainData.ControlledBySteamID) {
|
if (data.TrainData.ControlledBySteamID !== x.TrainData.ControlledBySteamID) {
|
||||||
|
|
||||||
if (!data.TrainData.ControlledBySteamID) {
|
if (!data.TrainData.ControlledBySteamID) {
|
||||||
if (!x.TrainData.ControlledBySteamID) return;
|
if (!x.TrainData.ControlledBySteamID) return;
|
||||||
// join
|
// join
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
|
||||||
const player = await PlayerUtil.getPlayer(x.TrainData.ControlledBySteamID!);
|
const player = await PlayerUtil.getPlayer(x.TrainData.ControlledBySteamID!);
|
||||||
|
|
||||||
const playerStats = await PlayerUtil.getPlayerStats(x.TrainData.ControlledBySteamID!);
|
const playerStats = await PlayerUtil.getPlayerStats(x.TrainData.ControlledBySteamID!);
|
||||||
|
|
||||||
|
|
||||||
this.emit(SimrailClientEvents.TrainJoined, server, x, player, playerStats?.stats.find(x => x.name === 'DISTANCE_M')?.value);
|
this.emit(SimrailClientEvents.TrainJoined, server, x, player, playerStats?.stats.find(x => x.name === 'DISTANCE_M')?.value);
|
||||||
|
|
||||||
this.trainsOccupied[server.ServerCode][x.TrainNoLocal] = {
|
this.trainsOccupied[server.ServerCode][x.TrainNoLocal] = {
|
||||||
SteamId: x.TrainData.ControlledBySteamID!,
|
SteamId: x.TrainData.ControlledBySteamID!,
|
||||||
JoinedAt: date.getTime(),
|
JoinedAt: date.getTime(),
|
||||||
StartPlayerDistance: playerStats?.stats.find(x => x.name === 'DISTANCE_M')?.value!,
|
StartPlayerDistance: playerStats?.stats.find(x => x.name === 'DISTANCE_M')?.value!,
|
||||||
StartPlayerPoints: playerStats?.stats.find(x => x.name === "SCORE")?.value!,
|
StartPlayerPoints: playerStats?.stats.find(x => x.name === "SCORE")?.value!,
|
||||||
};
|
};
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data.TrainData.ControlledBySteamID) return;
|
if (!data.TrainData.ControlledBySteamID) return;
|
||||||
const date = new Date();
|
const date = new Date();
|
||||||
|
|
||||||
const player = await PlayerUtil.getPlayer(data.TrainData.ControlledBySteamID!);
|
const player = await PlayerUtil.getPlayer(data.TrainData.ControlledBySteamID!);
|
||||||
|
|
||||||
const playerId = data.TrainData.ControlledBySteamID!;
|
const playerId = data.TrainData.ControlledBySteamID!;
|
||||||
const trainOccupied = this.trainsOccupied[server.ServerCode][data.TrainNoLocal] && JSON.parse(JSON.stringify(this.trainsOccupied[server.ServerCode][data.TrainNoLocal])) || null;
|
const trainOccupied = this.trainsOccupied[server.ServerCode][data.TrainNoLocal] && JSON.parse(JSON.stringify(this.trainsOccupied[server.ServerCode][data.TrainNoLocal])) || null;
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
||||||
|
|
||||||
PlayerUtil.getPlayerStats(playerId).then(playerStats => {
|
PlayerUtil.getPlayerStats(playerId).then(playerStats => {
|
||||||
const oldKm = trainOccupied?.StartPlayerDistance ?? 0;
|
const oldKm = trainOccupied?.StartPlayerDistance ?? 0;
|
||||||
|
|
||||||
const distance = oldKm ? (playerStats?.stats.find(x => x.name === 'DISTANCE_M')?.value ?? 0) - oldKm : 0;
|
const distance = oldKm ? (playerStats?.stats.find(x => x.name === 'DISTANCE_M')?.value ?? 0) - oldKm : 0;
|
||||||
|
|
||||||
const oldPoints = trainOccupied?.StartPlayerPoints ?? 0;
|
const oldPoints = trainOccupied?.StartPlayerPoints ?? 0;
|
||||||
|
|
||||||
const points = oldPoints ? (playerStats?.stats.find(x => x.name === 'SCORE')?.value ?? 0) - oldPoints : 0;
|
const points = oldPoints ? (playerStats?.stats.find(x => x.name === 'SCORE')?.value ?? 0) - oldPoints : 0;
|
||||||
|
|
||||||
|
|
||||||
this.emit(SimrailClientEvents.TrainLeft, server, data, player, trainOccupied?.JoinedAt, date.getTime(), points, distance, x.Vehicles[0]);
|
this.emit(SimrailClientEvents.TrainLeft, server, data, player, trainOccupied?.JoinedAt, date.getTime(), points, distance, x.Vehicles[0]);
|
||||||
})
|
})
|
||||||
}, 80_000)
|
}, 80_000)
|
||||||
delete this.trainsOccupied[server.ServerCode][data.TrainNoLocal];
|
delete this.trainsOccupied[server.ServerCode][data.TrainNoLocal];
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
this.trains[server.ServerCode] = trains.data;
|
this.trains[server.ServerCode] = trains.data;
|
||||||
redis.json.set('trains', '$', this.trains);
|
redis.json.set('trains', '$', this.trains);
|
||||||
redis.json.set('trains_occupied', '$', this.trainsOccupied);
|
redis.json.set('trains_occupied', '$', this.trainsOccupied);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async update() {
|
private async update() {
|
||||||
const servers = (await fetch('https://panel.simrail.eu:8084/servers-open').then(x => x.json()).catch(x => ({ data: [], result: false })) as ApiResponse<Server>)
|
const servers = (await fetch('https://panel.simrail.eu:8084/servers-open').then(x => x.json()).catch(x => ({ data: [], result: false })) as ApiResponse<Server>)
|
||||||
.data?.filter(x => x.ServerName.includes('Polski')) ?? []; // no plans to support other servers
|
.data?.filter(x => x.ServerName.includes('Polski')) ?? []; // no plans to support other servers
|
||||||
|
|
||||||
if (!servers.length) console.log('SimrailAPI is down')
|
if (!servers.length) console.log('SimrailAPI is down')
|
||||||
|
|
||||||
// TODO: maybe node:worker_threads?
|
// TODO: maybe node:worker_threads?
|
||||||
// TODO: check performance
|
// TODO: check performance
|
||||||
servers.forEach(async (server) => {
|
servers.forEach(async (server) => {
|
||||||
const stations = (await fetch('https://panel.simrail.eu:8084/stations-open?serverCode=' + server.ServerCode).then(x => x.json()).catch(() => ({ result: false }))) as ApiResponse<Station>;
|
const stations = (await fetch('https://panel.simrail.eu:8084/stations-open?serverCode=' + server.ServerCode).then(x => x.json()).catch(() => ({ result: false }))) as ApiResponse<Station>;
|
||||||
const trains = (await fetch('https://panel.simrail.eu:8084/trains-open?serverCode=' + server.ServerCode).then(x => x.json()).catch(() => ({ result: false }))) as ApiResponse<Train>;
|
const trains = (await fetch('https://panel.simrail.eu:8084/trains-open?serverCode=' + server.ServerCode).then(x => x.json()).catch(() => ({ result: false }))) as ApiResponse<Train>;
|
||||||
|
|
||||||
this.processStation(server, stations);
|
this.processStation(server, stations);
|
||||||
this.processTrain(server, trains);
|
this.processTrain(server, trains);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -55,7 +55,7 @@
|
|||||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||||
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
"outDir": "../../dist/backend", /* Specify an output folder for all emitted files. */
|
||||||
// "removeComments": true, /* Disable emitting comments. */
|
// "removeComments": true, /* Disable emitting comments. */
|
||||||
// "noEmit": true, /* Disable emitting files from a compilation. */
|
// "noEmit": true, /* Disable emitting files from a compilation. */
|
||||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
24
packages/frontend/.gitignore
vendored
Normal file
24
packages/frontend/.gitignore
vendored
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
pnpm-debug.log*
|
||||||
|
lerna-debug.log*
|
||||||
|
|
||||||
|
node_modules
|
||||||
|
dist
|
||||||
|
dist-ssr
|
||||||
|
*.local
|
||||||
|
|
||||||
|
# Editor directories and files
|
||||||
|
.vscode/*
|
||||||
|
!.vscode/extensions.json
|
||||||
|
.idea
|
||||||
|
.DS_Store
|
||||||
|
*.suo
|
||||||
|
*.ntvs*
|
||||||
|
*.njsproj
|
||||||
|
*.sln
|
||||||
|
*.sw?
|
50
packages/frontend/README.md
Normal file
50
packages/frontend/README.md
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
# React + TypeScript + Vite
|
||||||
|
|
||||||
|
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||||
|
|
||||||
|
Currently, two official plugins are available:
|
||||||
|
|
||||||
|
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
|
||||||
|
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
|
||||||
|
|
||||||
|
## Expanding the ESLint configuration
|
||||||
|
|
||||||
|
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
|
||||||
|
|
||||||
|
- Configure the top-level `parserOptions` property like this:
|
||||||
|
|
||||||
|
```js
|
||||||
|
export default tseslint.config({
|
||||||
|
languageOptions: {
|
||||||
|
// other options...
|
||||||
|
parserOptions: {
|
||||||
|
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||||
|
tsconfigRootDir: import.meta.dirname,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
- Replace `tseslint.configs.recommended` to `tseslint.configs.recommendedTypeChecked` or `tseslint.configs.strictTypeChecked`
|
||||||
|
- Optionally add `...tseslint.configs.stylisticTypeChecked`
|
||||||
|
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and update the config:
|
||||||
|
|
||||||
|
```js
|
||||||
|
// eslint.config.js
|
||||||
|
import react from 'eslint-plugin-react'
|
||||||
|
|
||||||
|
export default tseslint.config({
|
||||||
|
// Set the react version
|
||||||
|
settings: { react: { version: '18.3' } },
|
||||||
|
plugins: {
|
||||||
|
// Add the react plugin
|
||||||
|
react,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
// other rules...
|
||||||
|
// Enable its recommended rules
|
||||||
|
...react.configs.recommended.rules,
|
||||||
|
...react.configs['jsx-runtime'].rules,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
```
|
28
packages/frontend/eslint.config.js
Normal file
28
packages/frontend/eslint.config.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import js from '@eslint/js'
|
||||||
|
import globals from 'globals'
|
||||||
|
import reactHooks from 'eslint-plugin-react-hooks'
|
||||||
|
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||||
|
import tseslint from 'typescript-eslint'
|
||||||
|
|
||||||
|
export default tseslint.config(
|
||||||
|
{ ignores: ['dist'] },
|
||||||
|
{
|
||||||
|
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
||||||
|
files: ['**/*.{ts,tsx}'],
|
||||||
|
languageOptions: {
|
||||||
|
ecmaVersion: 2020,
|
||||||
|
globals: globals.browser,
|
||||||
|
},
|
||||||
|
plugins: {
|
||||||
|
'react-hooks': reactHooks,
|
||||||
|
'react-refresh': reactRefresh,
|
||||||
|
},
|
||||||
|
rules: {
|
||||||
|
...reactHooks.configs.recommended.rules,
|
||||||
|
'react-refresh/only-export-components': [
|
||||||
|
'warn',
|
||||||
|
{ allowConstantExport: true },
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
13
packages/frontend/index.html
Normal file
13
packages/frontend/index.html
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
<title>Vite + React + TS</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="root"></div>
|
||||||
|
<script type="module" src="/src/main.tsx"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
29
packages/frontend/package.json
Normal file
29
packages/frontend/package.json
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
{
|
||||||
|
"name": "frontend",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": {
|
||||||
|
"start": "vite",
|
||||||
|
"build": "tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"react": "^18.3.1",
|
||||||
|
"react-dom": "^18.3.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.9.0",
|
||||||
|
"@types/react": "^18.3.3",
|
||||||
|
"@types/react-dom": "^18.3.0",
|
||||||
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
||||||
|
"eslint": "^9.9.0",
|
||||||
|
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.9",
|
||||||
|
"globals": "^15.9.0",
|
||||||
|
"typescript": "^5.5.3",
|
||||||
|
"typescript-eslint": "^8.0.1",
|
||||||
|
"vite": "^5.4.1"
|
||||||
|
}
|
||||||
|
}
|
1
packages/frontend/public/vite.svg
Normal file
1
packages/frontend/public/vite.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
After Width: | Height: | Size: 1.5 KiB |
42
packages/frontend/src/App.css
Normal file
42
packages/frontend/src/App.css
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
#root {
|
||||||
|
max-width: 1280px;
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 2rem;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.logo {
|
||||||
|
height: 6em;
|
||||||
|
padding: 1.5em;
|
||||||
|
will-change: filter;
|
||||||
|
transition: filter 300ms;
|
||||||
|
}
|
||||||
|
.logo:hover {
|
||||||
|
filter: drop-shadow(0 0 2em #646cffaa);
|
||||||
|
}
|
||||||
|
.logo.react:hover {
|
||||||
|
filter: drop-shadow(0 0 2em #61dafbaa);
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes logo-spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-reduced-motion: no-preference) {
|
||||||
|
a:nth-of-type(2) .logo {
|
||||||
|
animation: logo-spin infinite 20s linear;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
padding: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.read-the-docs {
|
||||||
|
color: #888;
|
||||||
|
}
|
35
packages/frontend/src/App.tsx
Normal file
35
packages/frontend/src/App.tsx
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { useState } from 'react'
|
||||||
|
import reactLogo from './assets/react.svg'
|
||||||
|
import viteLogo from '/vite.svg'
|
||||||
|
import './App.css'
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [count, setCount] = useState(0)
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<a href="https://vitejs.dev" target="_blank">
|
||||||
|
<img src={viteLogo} className="logo" alt="Vite logo" />
|
||||||
|
</a>
|
||||||
|
<a href="https://react.dev" target="_blank">
|
||||||
|
<img src={reactLogo} className="logo react" alt="React logo" />
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<h1>Vite + React</h1>
|
||||||
|
<div className="card">
|
||||||
|
<button onClick={() => setCount((count) => count + 1)}>
|
||||||
|
count is {count}
|
||||||
|
</button>
|
||||||
|
<p>
|
||||||
|
Edit <code>src/App.tsx</code> and save to test HMR
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<p className="read-the-docs">
|
||||||
|
Click on the Vite and React logos to learn more
|
||||||
|
</p>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App
|
1
packages/frontend/src/assets/react.svg
Normal file
1
packages/frontend/src/assets/react.svg
Normal file
@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
After Width: | Height: | Size: 4.0 KiB |
68
packages/frontend/src/index.css
Normal file
68
packages/frontend/src/index.css
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
:root {
|
||||||
|
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||||
|
line-height: 1.5;
|
||||||
|
font-weight: 400;
|
||||||
|
|
||||||
|
color-scheme: light dark;
|
||||||
|
color: rgba(255, 255, 255, 0.87);
|
||||||
|
background-color: #242424;
|
||||||
|
|
||||||
|
font-synthesis: none;
|
||||||
|
text-rendering: optimizeLegibility;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
font-weight: 500;
|
||||||
|
color: #646cff;
|
||||||
|
text-decoration: inherit;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #535bf2;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
display: flex;
|
||||||
|
place-items: center;
|
||||||
|
min-width: 320px;
|
||||||
|
min-height: 100vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 3.2em;
|
||||||
|
line-height: 1.1;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid transparent;
|
||||||
|
padding: 0.6em 1.2em;
|
||||||
|
font-size: 1em;
|
||||||
|
font-weight: 500;
|
||||||
|
font-family: inherit;
|
||||||
|
background-color: #1a1a1a;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: border-color 0.25s;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
border-color: #646cff;
|
||||||
|
}
|
||||||
|
button:focus,
|
||||||
|
button:focus-visible {
|
||||||
|
outline: 4px auto -webkit-focus-ring-color;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (prefers-color-scheme: light) {
|
||||||
|
:root {
|
||||||
|
color: #213547;
|
||||||
|
background-color: #ffffff;
|
||||||
|
}
|
||||||
|
a:hover {
|
||||||
|
color: #747bff;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
background-color: #f9f9f9;
|
||||||
|
}
|
||||||
|
}
|
10
packages/frontend/src/main.tsx
Normal file
10
packages/frontend/src/main.tsx
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { StrictMode } from 'react'
|
||||||
|
import { createRoot } from 'react-dom/client'
|
||||||
|
import App from './App.tsx'
|
||||||
|
import './index.css'
|
||||||
|
|
||||||
|
createRoot(document.getElementById('root')!).render(
|
||||||
|
<StrictMode>
|
||||||
|
<App />
|
||||||
|
</StrictMode>,
|
||||||
|
)
|
1
packages/frontend/src/vite-env.d.ts
vendored
Normal file
1
packages/frontend/src/vite-env.d.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/// <reference types="vite/client" />
|
24
packages/frontend/tsconfig.app.json
Normal file
24
packages/frontend/tsconfig.app.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2020",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["src"]
|
||||||
|
}
|
7
packages/frontend/tsconfig.json
Normal file
7
packages/frontend/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
22
packages/frontend/tsconfig.node.json
Normal file
22
packages/frontend/tsconfig.node.json
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"target": "ES2022",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
10
packages/frontend/vite.config.ts
Normal file
10
packages/frontend/vite.config.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { defineConfig } from 'vite'
|
||||||
|
import react from '@vitejs/plugin-react-swc'
|
||||||
|
|
||||||
|
// https://vitejs.dev/config/
|
||||||
|
export default defineConfig({
|
||||||
|
plugins: [react()],
|
||||||
|
build: {
|
||||||
|
outDir: '../../dist/frontend'
|
||||||
|
}
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user