Compare commits
58 Commits
v0.0.8
...
feature/#3
Author | SHA1 | Date | |
---|---|---|---|
47be8597bf | |||
2ce9bbdedd | |||
3f8d36db5a | |||
fc91eb9873 | |||
606328dbef | |||
b508370eec | |||
22b776ef0f | |||
f76bf3df1f | |||
7da0323153 | |||
26405433a8 | |||
4e7e13d6f4 | |||
785a232776 | |||
14d296e5a9 | |||
8cca44a3b4 | |||
d75ed7a44f | |||
e21c03ee3b | |||
deac2892fb | |||
e40a56825a | |||
c47339dfcd | |||
fef0ae6e28 | |||
bebd5876da | |||
fedb5c154b | |||
9e55ac7990 | |||
8b51f6e16a | |||
e2ded75017 | |||
0cead14e71 | |||
f2905247ff | |||
e735522d76 | |||
94c619192b | |||
a8a98d0083 | |||
646c40db27 | |||
cfaea6ec7c | |||
9030550c0f | |||
c71c393a51 | |||
4d192bd5ec | |||
f46fff5b69 | |||
f5cae0db9f | |||
c627ea2412 | |||
30145e1662 | |||
778e4402ba | |||
e2bc151881 | |||
2b022ee4e0 | |||
3802b2cf9d | |||
2ee6a72984 | |||
f50e4c75a9 | |||
51cbe87755 | |||
d6aa8da2de | |||
7b4674587a | |||
8e652f8dcb | |||
5349e2ffe5 | |||
66759a87f2 | |||
b7748c254f | |||
ee080b6987 | |||
67021f9ada | |||
3270ea8729 | |||
04710edb73 | |||
d398764b6d | |||
be479b11c5 |
@ -27,7 +27,6 @@ SMTP_PORT=587
|
||||
SMTP_USER=no-reply@noxious.gg
|
||||
SMTP_PASSWORD=""
|
||||
|
||||
# Traefik configuration
|
||||
ACME_EMAIL=info@noxious.gg
|
||||
TRAEFIK_DASHBOARD_HOST=traefik.server.noxious.gg
|
||||
TRAEFIK_BASIC_AUTH=admin:$apr1$42pa8hen$p.bKJ3.gHJ9U0ZwyVxmIc0
|
||||
# SSL
|
||||
#PUBLIC_KEY_PATH=
|
||||
#PRIVATE_KEY_PATH=
|
1
.prettierignore
Normal file
1
.prettierignore
Normal file
@ -0,0 +1 @@
|
||||
migrations
|
@ -4,5 +4,8 @@
|
||||
"tabWidth": 2,
|
||||
"singleQuote": true,
|
||||
"printWidth": 200,
|
||||
"trailingComma": "none"
|
||||
"trailingComma": "none",
|
||||
"plugins": ["@ianvs/prettier-plugin-sort-imports"],
|
||||
"importOrderParserPlugins": ["typescript", "jsx", "decorators-legacy", "classProperties"],
|
||||
"importOrderCaseSensitive": false
|
||||
}
|
16
Dockerfile
16
Dockerfile
@ -1,16 +0,0 @@
|
||||
FROM node:lts-alpine
|
||||
|
||||
# Install packages
|
||||
RUN apk update
|
||||
RUN apk add --no-cache tmux coreutils
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
COPY package*.json ./
|
||||
|
||||
RUN npm ci
|
||||
|
||||
COPY . .
|
||||
|
||||
# Modify CMD to use tmux
|
||||
CMD npx mikro-orm-esm migration:up && npm run start
|
@ -5,7 +5,7 @@ This is the server for the Noxious game.
|
||||
## Projects requirements
|
||||
|
||||
- NodeJS 20.x or higher
|
||||
- MySQL 8.x or higher
|
||||
- MariaDB 11.x or higher
|
||||
- Redis 7.x or higher
|
||||
|
||||
## Installation
|
||||
@ -39,15 +39,15 @@ MikroORM is used as the ORM for the server.
|
||||
|
||||
### Create init. migrations
|
||||
|
||||
Run `npx mikro-orm-esm migration:create --initial` to create a new initial migration.
|
||||
Run `npm run mikro-orm migration:create --initial` to create a new initial migration.
|
||||
|
||||
### Create migrations
|
||||
|
||||
Run `npx mikro-orm-esm migration:create` to create a new migration. You do this when you want to add a new table or change an existing one.
|
||||
Run `npm run mikro-orm migration:create` to create a new migration. You do this when you want to add a new table or change an existing one.
|
||||
|
||||
### Apply migrations
|
||||
|
||||
Run `npx mikro-orm-esm migration:up` to apply all pending migrations.
|
||||
Run `npm run mikro-orm migration:up` to apply all pending migrations.
|
||||
|
||||
### Import default data
|
||||
|
||||
|
@ -1,33 +0,0 @@
|
||||
entryPoints:
|
||||
web:
|
||||
address: ":80"
|
||||
http:
|
||||
redirections:
|
||||
entryPoint:
|
||||
to: websecure
|
||||
scheme: https
|
||||
websecure:
|
||||
address: ":443"
|
||||
http:
|
||||
tls:
|
||||
certResolver: letsencrypt
|
||||
|
||||
certificatesResolvers:
|
||||
letsencrypt:
|
||||
acme:
|
||||
email: info@noxious.gg
|
||||
storage: /certificates/acme.json
|
||||
httpChallenge:
|
||||
entryPoint: web
|
||||
|
||||
providers:
|
||||
docker:
|
||||
endpoint: "unix:///var/run/docker.sock"
|
||||
exposedByDefault: false
|
||||
network: app-network
|
||||
|
||||
log:
|
||||
level: INFO
|
||||
|
||||
api:
|
||||
dashboard: false
|
@ -1,93 +0,0 @@
|
||||
services:
|
||||
app:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "${PORT}:${PORT}"
|
||||
environment:
|
||||
- ENV=${ENV}
|
||||
- HOST=${HOST}
|
||||
- PORT=${PORT}
|
||||
- JWT_SECRET=${JWT_SECRET}
|
||||
- CLIENT_URL=${CLIENT_URL}
|
||||
- REDIS_URL=${REDIS_URL}
|
||||
- DB_HOST=${DB_HOST}
|
||||
- DB_USER=${DB_USER}
|
||||
- DB_PASS=${DB_PASS}
|
||||
- DB_PORT=${DB_PORT}
|
||||
- DB_NAME=${DB_NAME}
|
||||
- ALLOW_DIAGONAL_MOVEMENT=${ALLOW_DIAGONAL_MOVEMENT}
|
||||
- DEFAULT_CHARACTER_ZONE=${DEFAULT_CHARACTER_ZONE}
|
||||
- DEFAULT_CHARACTER_POS_X=${DEFAULT_CHARACTER_POS_X}
|
||||
- DEFAULT_CHARACTER_POS_Y=${DEFAULT_CHARACTER_POS_Y}
|
||||
- SMTP_HOST=${SMTP_HOST}
|
||||
- SMTP_PORT=${SMTP_PORT}
|
||||
- SMTP_USER=${SMTP_USER}
|
||||
- SMTP_PASSWORD=${SMTP_PASSWORD}
|
||||
volumes:
|
||||
- app-public:/user/src/app/public
|
||||
- app-logs:/user/src/app/logs
|
||||
depends_on:
|
||||
- mariadb
|
||||
- redis
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- app-network
|
||||
labels:
|
||||
- "traefik.enable=true"
|
||||
- "traefik.http.routers.app.rule=Host(`${HOST}`)"
|
||||
- "traefik.http.routers.app.entrypoints=websecure"
|
||||
- "traefik.http.routers.app.tls=true"
|
||||
- "traefik.http.routers.app.service=app"
|
||||
- "traefik.http.services.app.loadbalancer.server.port=${PORT}"
|
||||
|
||||
mariadb:
|
||||
image: mariadb:lts
|
||||
environment:
|
||||
- MARIADB_USER=${DB_USER}
|
||||
- MARIADB_PASSWORD=${DB_PASS}
|
||||
- MARIADB_DATABASE=${DB_NAME}
|
||||
- MARIADB_RANDOM_ROOT_PASSWORD=yes
|
||||
volumes:
|
||||
- mariadb-data:/var/lib/mysql
|
||||
ports:
|
||||
- "${DB_PORT}:3306"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- app-network
|
||||
command: [ 'mariadbd', '--character-set-server=utf8mb4', '--collation-server=utf8mb4_unicode_ci' ]
|
||||
|
||||
redis:
|
||||
image: redis:7.4.2-alpine
|
||||
command: redis-server --appendonly yes
|
||||
volumes:
|
||||
- redis-data:/data
|
||||
ports:
|
||||
- "6379:6379"
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- app-network
|
||||
|
||||
traefik:
|
||||
image: traefik:v3.3.3
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock:ro
|
||||
- ./config/traefik.yml:/etc/traefik/traefik.yml:ro
|
||||
- ./certificates:/certificates
|
||||
networks:
|
||||
- app-network
|
||||
restart: unless-stopped
|
||||
|
||||
networks:
|
||||
app-network:
|
||||
driver: bridge
|
||||
|
||||
volumes:
|
||||
app-public:
|
||||
app-logs:
|
||||
mariadb-data:
|
||||
redis-data:
|
@ -1,42 +0,0 @@
|
||||
import eslint from '@eslint/js';
|
||||
import tseslint from '@typescript-eslint/eslint-plugin';
|
||||
import tsparser from '@typescript-eslint/parser';
|
||||
import importPlugin from 'eslint-plugin-import';
|
||||
|
||||
export default [
|
||||
eslint.configs.recommended,
|
||||
{
|
||||
files: ['**/*.ts'],
|
||||
languageOptions: {
|
||||
parser: tsparser,
|
||||
parserOptions: {
|
||||
project: './tsconfig.json',
|
||||
ecmaVersion: 2023,
|
||||
},
|
||||
},
|
||||
plugins: {
|
||||
'@typescript-eslint': tseslint,
|
||||
'import': importPlugin,
|
||||
},
|
||||
rules: {
|
||||
...tseslint.configs['recommended'].rules,
|
||||
...tseslint.configs['recommended-requiring-type-checking'].rules,
|
||||
'import/order': ['error', {
|
||||
'groups': [
|
||||
'builtin',
|
||||
'external',
|
||||
'internal',
|
||||
['parent', 'sibling'],
|
||||
'index',
|
||||
'object',
|
||||
'type'
|
||||
],
|
||||
'newlines-between': 'always',
|
||||
'alphabetize': {
|
||||
'order': 'asc',
|
||||
'caseInsensitive': true
|
||||
}
|
||||
}]
|
||||
}
|
||||
}
|
||||
];
|
3291
package-lock.json
generated
3291
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
30
package.json
30
package.json
@ -5,36 +5,23 @@
|
||||
"start": "tsx src/server.ts",
|
||||
"dev": "nodemon --exec tsx src/server.ts",
|
||||
"format": "prettier --write src/",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint . --fix"
|
||||
},
|
||||
"imports": {
|
||||
"#root/*": "./src/*.js",
|
||||
"#application/*": "./src/application/*.js",
|
||||
"#commands/*": "./src/commands/*.js",
|
||||
"#entities/*": "./src/entities/*.js",
|
||||
"#controllers/*": "./src/controllers/*.js",
|
||||
"#jobs/*": "./src/jobs/*.js",
|
||||
"#managers/*": "./src/managers/*.js",
|
||||
"#middleware/*": "./src/middleware/*.js",
|
||||
"#models/*": "./src/models/*.js",
|
||||
"#repositories/*": "./src/repositories/*.js",
|
||||
"#services/*": "./src/services/*.js",
|
||||
"#events/*": "./src/events/*.js"
|
||||
"mikro-orm": "tsx ./node_modules/.bin/mikro-orm-esm"
|
||||
},
|
||||
"dependencies": {
|
||||
"@mikro-orm/cli": "^6.4.2",
|
||||
"@mikro-orm/core": "^6.4.2",
|
||||
"@mikro-orm/mariadb": "^6.4.2",
|
||||
"@mikro-orm/migrations": "^6.4.2",
|
||||
"@mikro-orm/mysql": "^6.4.2",
|
||||
"@mikro-orm/reflection": "^6.4.2",
|
||||
"@mikro-orm/cli": "^6.4.2",
|
||||
"@types/ioredis": "^4.28.10",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"bufferutil": "^4.0.9",
|
||||
"bullmq": "^5.13.2",
|
||||
"cors": "^2.8.5",
|
||||
"dotenv": "^16.4.5",
|
||||
"express": "^4.19.2",
|
||||
"https": "^1.0.0",
|
||||
"ioredis": "^5.4.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"nodemailer": "^6.9.15",
|
||||
@ -42,21 +29,18 @@
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"sharp": "^0.33.4",
|
||||
"socket.io": "^4.7.5",
|
||||
"ts-node": "^10.9.2",
|
||||
"typescript": "^5.5.3",
|
||||
"utf-8-validate": "^6.0.5",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ts-node": "^10.9.2",
|
||||
"@ianvs/prettier-plugin-sort-imports": "^4.4.0",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/express": "^4.17.21",
|
||||
"@types/jsonwebtoken": "^9.0.6",
|
||||
"@types/node": "^20.14.11",
|
||||
"@types/nodemailer": "^6.4.16",
|
||||
"@typescript-eslint/eslint-plugin": "^8.18.2",
|
||||
"@typescript-eslint/parser": "^8.18.2",
|
||||
"eslint": "^9.17.0",
|
||||
"eslint-config-prettier": "^9.1.0",
|
||||
"eslint-plugin-import": "^2.31.0",
|
||||
"nodemon": "^3.1.4",
|
||||
"prettier": "^3.3.3",
|
||||
"tsx": "^4.19.2"
|
||||
|
@ -1,7 +1,6 @@
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
import { Server } from 'socket.io'
|
||||
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
|
||||
export abstract class BaseCommand {
|
||||
protected readonly logger = Logger.type(LoggerType.COMMAND)
|
||||
constructor(readonly io: Server) {}
|
||||
|
@ -1,9 +1,7 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
import type { Response } from 'express'
|
||||
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
|
||||
export abstract class BaseController {
|
||||
protected readonly logger = Logger.type(LoggerType.HTTP)
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Database from '@/application/database'
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
import { EntityManager } from '@mikro-orm/core'
|
||||
|
||||
import Database from '#application/database'
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
|
||||
export abstract class BaseEntity {
|
||||
protected readonly logger = Logger.type(LoggerType.ENTITY)
|
||||
protected entityManager?: EntityManager
|
||||
|
@ -1,22 +1,43 @@
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
import type { TSocket } from '@/application/types'
|
||||
import { Character } from '@/entities/character'
|
||||
import MapManager from '@/managers/mapManager'
|
||||
import type MapCharacter from '@/models/mapCharacter'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
import { Server } from 'socket.io'
|
||||
|
||||
import type { TSocket } from '#application/types'
|
||||
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import { Character } from '#entities/character'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
|
||||
export abstract class BaseEvent {
|
||||
protected readonly logger = Logger.type(LoggerType.GAME)
|
||||
private lastActionTimes: Map<string, number> = new Map()
|
||||
|
||||
constructor(
|
||||
readonly io: Server,
|
||||
readonly socket: TSocket
|
||||
) {}
|
||||
|
||||
protected isThrottled(actionId: string, throttleTime: number): boolean {
|
||||
const now = Date.now()
|
||||
const lastActionTime = this.lastActionTimes.get(actionId) || 0
|
||||
|
||||
if (now - lastActionTime < throttleTime) {
|
||||
return true
|
||||
}
|
||||
|
||||
this.lastActionTimes.set(actionId, now)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
protected getMapCharacter(): MapCharacter | null {
|
||||
if (!this.socket.characterId) return null
|
||||
return MapManager.getCharacterById(this.socket.characterId)
|
||||
}
|
||||
|
||||
protected async getCharacter(): Promise<Character | null> {
|
||||
if (!this.socket.characterId) return null
|
||||
const characterRepository = new CharacterRepository()
|
||||
return characterRepository.getById(this.socket.characterId!)
|
||||
return characterRepository.getById(this.socket.characterId)
|
||||
}
|
||||
|
||||
protected async isCharacterGM(): Promise<boolean> {
|
||||
@ -25,14 +46,14 @@ export abstract class BaseEvent {
|
||||
}
|
||||
|
||||
protected emitError(message: string): void {
|
||||
this.socket.emit('notification', { title: 'Server message', message })
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, { title: 'Server message', message })
|
||||
this.logger.error('Base event error', `Player ${this.socket.userId}: ${message}`)
|
||||
}
|
||||
|
||||
protected handleError(context: string, error: unknown): void {
|
||||
console.log(error)
|
||||
const errorMessage = error instanceof Error ? error.message : error && typeof error === 'object' && 'toString' in error ? error.toString() : String(error)
|
||||
this.socket.emit('notification', { title: 'Server message', message: `Server error occured. Please contact the server administrator.` })
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, { title: 'Server message', message: `Server error occured. Please contact the server administrator.` })
|
||||
this.logger.error('Base event error', errorMessage)
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
import Database from '@/application/database'
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
import { EntityManager } from '@mikro-orm/core'
|
||||
|
||||
import Database from '#application/database'
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
|
||||
export abstract class BaseRepository {
|
||||
protected readonly logger = Logger.type(LoggerType.REPOSITORY)
|
||||
private entityManager?: EntityManager
|
||||
|
@ -1,4 +1,4 @@
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
|
||||
export abstract class BaseService {
|
||||
protected readonly logger = Logger.type(LoggerType.GAME)
|
||||
|
@ -6,7 +6,7 @@ class config {
|
||||
// Server configuration
|
||||
static ENV: string = process.env.ENV || 'development'
|
||||
static HOST: string = process.env.HOST || '0.0.0.0'
|
||||
static PORT: number = process.env.PORT ? parseInt(process.env.PORT) : 6969
|
||||
static PORT: number = process.env.PORT ? parseInt(process.env.PORT) : 4000
|
||||
static JWT_SECRET: string = process.env.JWT_SECRET || 'secret'
|
||||
static CLIENT_URL: string = process.env.CLIENT_URL ? process.env.CLIENT_URL : 'https://noxious.gg'
|
||||
|
||||
@ -31,6 +31,10 @@ class config {
|
||||
static SMTP_PORT: number = process.env.SMTP_PORT ? parseInt(process.env.SMTP_PORT) : 587
|
||||
static SMTP_USER: string = process.env.SMTP_USER || 'no-reply@noxious.gg'
|
||||
static SMTP_PASSWORD: string = process.env.SMTP_PASSWORD || 'password'
|
||||
|
||||
// SSL
|
||||
static PUBLIC_KEY_PATH: string = process.env.PUBLIC_KEY_PATH || ''
|
||||
static PRIVATE_KEY_PATH: string = process.env.PRIVATE_KEY_PATH || ''
|
||||
}
|
||||
|
||||
export default config
|
||||
|
@ -1,11 +1,9 @@
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { pathToFileURL } from 'url'
|
||||
|
||||
import type { Command } from '#application/types'
|
||||
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import Storage from '#application/storage'
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
import Storage from '@/application/storage'
|
||||
import type { Command } from '@/application/types'
|
||||
|
||||
export class CommandRegistry {
|
||||
private readonly commands: Map<string, Command> = new Map()
|
||||
|
@ -1,7 +1,6 @@
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
|
||||
export class LogReader {
|
||||
private logger = Logger.type(LoggerType.CONSOLE)
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { MikroORM } from '@mikro-orm/mysql'
|
||||
// import { MikroORM } from '@mikro-orm/mysql'
|
||||
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
import config from '#root/mikro-orm.config'
|
||||
import Logger, { LoggerType } from '@/application/logger'
|
||||
import config from '@/root/mikro-orm.config'
|
||||
import { MikroORM } from '@mikro-orm/mariadb'
|
||||
|
||||
class Database {
|
||||
private static orm: MikroORM
|
||||
|
@ -1,17 +1,57 @@
|
||||
export enum SocketEvent {
|
||||
CHARACTER_CONNECT = 1,
|
||||
CHARACTER_MOVE = 2,
|
||||
CHARACTER_MOVE_ERROR = 3,
|
||||
CHARACTER_TELEPORT = 4,
|
||||
ZONE_CHARACTER_LEAVE = 5,
|
||||
ZONE_CHARACTER_JOIN = 6,
|
||||
ZONE_CHARACTER_LIST = 7,
|
||||
ZONE_CHARACTER_DELETE = 8,
|
||||
ZONE_CHARACTER_CREATE = 9,
|
||||
ZONE_CHARACTER_UPDATE = 10,
|
||||
ZONE_CHARACTER_HAIR_UPDATE = 11,
|
||||
ZONE_CHARACTER_HAIR_LIST = 12,
|
||||
ZONE_CHARACTER_TELEPORT = 13
|
||||
CLOSE = '52',
|
||||
DATA = '51',
|
||||
CHARACTER_CONNECT = '50',
|
||||
CHARACTER_CREATE = '49',
|
||||
CHARACTER_DELETE = '48',
|
||||
CHARACTER_LIST = '47',
|
||||
GM_CHARACTERHAIR_CREATE = '46',
|
||||
GM_CHARACTERHAIR_REMOVE = '45',
|
||||
GM_CHARACTERHAIR_LIST = '44',
|
||||
GM_CHARACTERHAIR_UPDATE = '43',
|
||||
GM_CHARACTERTYPE_CREATE = '42',
|
||||
GM_CHARACTERTYPE_REMOVE = '41',
|
||||
GM_CHARACTERTYPE_LIST = '40',
|
||||
GM_CHARACTERTYPE_UPDATE = '39',
|
||||
GM_ITEM_CREATE = '38',
|
||||
GM_ITEM_REMOVE = '37',
|
||||
GM_ITEM_LIST = '36',
|
||||
GM_ITEM_UPDATE = '35',
|
||||
GM_MAPOBJECT_LIST = '34',
|
||||
GM_MAPOBJECT_REMOVE = '33',
|
||||
GM_MAPOBJECT_UPDATE = '32',
|
||||
GM_MAPOBJECT_UPLOAD = '31',
|
||||
GM_SPRITE_COPY = '30',
|
||||
GM_SPRITE_CREATE = '29',
|
||||
GM_SPRITE_DELETE = '28',
|
||||
GM_SPRITE_LIST = '27',
|
||||
GM_SPRITE_UPDATE = '26',
|
||||
GM_TILE_DELETE = '25',
|
||||
GM_TILE_LIST = '24',
|
||||
GM_TILE_UPDATE = '23',
|
||||
GM_TILE_UPLOAD = '22',
|
||||
GM_MAP_CREATE = '21',
|
||||
GM_MAP_DELETE = '20',
|
||||
GM_MAP_REQUEST = '19',
|
||||
GM_MAP_UPDATE = '18',
|
||||
MAP_CHARACTER_MOVEERROR = '17',
|
||||
DISCONNECT = '16',
|
||||
USER_DISCONNECT = '15',
|
||||
LOGIN = '14',
|
||||
LOGGED_IN = '13',
|
||||
NOTIFICATION = '12',
|
||||
DATE = '11',
|
||||
FAILED = '10',
|
||||
COMPLETED = '9',
|
||||
CONNECTION = '8',
|
||||
WEATHER = '7',
|
||||
CHARACTER_DISCONNECT = '6',
|
||||
MAP_CHARACTER_ATTACK = '5',
|
||||
MAP_CHARACTER_TELEPORT = '4',
|
||||
MAP_CHARACTER_JOIN = '3',
|
||||
MAP_CHARACTER_LEAVE = '2',
|
||||
MAP_CHARACTER_MOVE = '1',
|
||||
CHAT_MESSAGE = '0'
|
||||
}
|
||||
|
||||
export enum ItemType {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import pino from 'pino'
|
||||
|
||||
const logger = pino.pino
|
||||
|
||||
export enum LoggerType {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
import config from '#application/config'
|
||||
import config from '@/application/config'
|
||||
|
||||
class Storage {
|
||||
private readonly baseDir: string
|
||||
@ -9,7 +8,7 @@ class Storage {
|
||||
|
||||
constructor() {
|
||||
this.rootDir = process.cwd()
|
||||
this.baseDir = config.ENV === 'development' ? 'src' : 'dist'
|
||||
this.baseDir = config.ENV === 'development' ? 'src' : 'src'
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,9 +1,8 @@
|
||||
import { Character } from '@/entities/character'
|
||||
import { MapEventTile } from '@/entities/mapEventTile'
|
||||
import { MapEventTileTeleport } from '@/entities/mapEventTileTeleport'
|
||||
import { Server, Socket } from 'socket.io'
|
||||
|
||||
import { Character } from '#entities/character'
|
||||
import { MapEventTile } from '#entities/mapEventTile'
|
||||
import { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
||||
|
||||
export type UUID = `${string}-${string}-${string}-${string}-${string}`
|
||||
|
||||
export type TSocket = Socket & {
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { BaseCommand } from '@/application/base/baseCommand'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { Server } from 'socket.io'
|
||||
|
||||
import { BaseCommand } from '#application/base/baseCommand'
|
||||
|
||||
type CommandInput = string[]
|
||||
|
||||
export default class AlertCommand extends BaseCommand {
|
||||
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 })
|
||||
this.io.emit(SocketEvent.NOTIFICATION, { message: message })
|
||||
}
|
||||
}
|
||||
|
@ -1,26 +1,23 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import { BaseCommand } from '@/application/base/baseCommand'
|
||||
import { CharacterGender, CharacterRace } from '@/application/enums'
|
||||
import Storage from '@/application/storage'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Character } from '@/entities/character'
|
||||
import { CharacterHair } from '@/entities/characterHair'
|
||||
import { CharacterType } from '@/entities/characterType'
|
||||
import { Map } from '@/entities/map'
|
||||
import { MapEffect } from '@/entities/mapEffect'
|
||||
import { MapObject } from '@/entities/mapObject'
|
||||
import { Sprite } from '@/entities/sprite'
|
||||
import { SpriteAction } from '@/entities/spriteAction'
|
||||
import { Tile } from '@/entities/tile'
|
||||
import { User } from '@/entities/user'
|
||||
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
||||
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
||||
import MapRepository from '@/repositories/mapRepository'
|
||||
import sharp from 'sharp'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseCommand } from '#application/base/baseCommand'
|
||||
import { CharacterGender, CharacterRace } from '#application/enums'
|
||||
import Storage from '#application/storage'
|
||||
import { Character } from '#entities/character'
|
||||
import { CharacterHair } from '#entities/characterHair'
|
||||
import { CharacterType } from '#entities/characterType'
|
||||
import { Map } from '#entities/map'
|
||||
import { MapEffect } from '#entities/mapEffect'
|
||||
import { MapObject } from '#entities/mapObject'
|
||||
import { Sprite } from '#entities/sprite'
|
||||
import { SpriteAction } from '#entities/spriteAction'
|
||||
import { Tile } from '#entities/tile'
|
||||
import { User } from '#entities/user'
|
||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
|
||||
// @TODO : Replace this with seeding
|
||||
// https://mikro-orm.io/docs/seeding
|
||||
|
||||
@ -355,7 +352,7 @@ export default class InitCommand extends BaseCommand {
|
||||
.setUser(user)
|
||||
.setName('root')
|
||||
.setRole('gm')
|
||||
.setMap((await this.mapRepository.getFirst())!)
|
||||
.setMap(await this.mapRepository.getFirst())
|
||||
.setCharacterType(await this.characterTypeRepository.getFirst())
|
||||
.setCharacterHair(await this.characterHairRepository.getFirst())
|
||||
.save()
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { BaseCommand } from '#application/base/baseCommand'
|
||||
import MapManager from '#managers/mapManager'
|
||||
import { BaseCommand } from '@/application/base/baseCommand'
|
||||
import MapManager from '@/managers/mapManager'
|
||||
|
||||
type CommandInput = string[]
|
||||
|
||||
|
@ -1,10 +1,8 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import { BaseCommand } from '@/application/base/baseCommand'
|
||||
import Storage from '@/application/storage'
|
||||
import sharp from 'sharp'
|
||||
|
||||
import { BaseCommand } from '#application/base/baseCommand'
|
||||
import Storage from '#application/storage'
|
||||
|
||||
export default class TilesCommand extends BaseCommand {
|
||||
public async execute(): Promise<void> {
|
||||
// Get all tiles
|
||||
|
@ -1,11 +1,9 @@
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
import { BaseController } from '@/application/base/baseController'
|
||||
import config from '@/application/config'
|
||||
import { loginAccountSchema, newPasswordSchema, registerAccountSchema, resetPasswordSchema } from '@/application/zodTypes'
|
||||
import UserService from '@/services/userService'
|
||||
import type { Request, Response } from 'express'
|
||||
|
||||
import { BaseController } from '#application/base/baseController'
|
||||
import config from '#application/config'
|
||||
import { loginAccountSchema, registerAccountSchema, resetPasswordSchema, newPasswordSchema } from '#application/zodTypes'
|
||||
import UserService from '#services/userService'
|
||||
import jwt from 'jsonwebtoken'
|
||||
|
||||
export class AuthController extends BaseController {
|
||||
/**
|
||||
|
@ -1,15 +1,12 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import sharp from 'sharp'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import { BaseController } from '@/application/base/baseController'
|
||||
import Storage from '@/application/storage'
|
||||
import type { UUID } from '@/application/types'
|
||||
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
||||
import type { Request, Response } from 'express'
|
||||
|
||||
import { BaseController } from '#application/base/baseController'
|
||||
import Storage from '#application/storage'
|
||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||
import sharp from 'sharp'
|
||||
|
||||
interface AvatarOptions {
|
||||
characterTypeId: UUID
|
||||
|
@ -1,13 +1,12 @@
|
||||
import { BaseController } from '@/application/base/baseController'
|
||||
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
||||
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
||||
import MapObjectRepository from '@/repositories/mapObjectRepository'
|
||||
import MapRepository from '@/repositories/mapRepository'
|
||||
import SpriteRepository from '@/repositories/spriteRepository'
|
||||
import TileRepository from '@/repositories/tileRepository'
|
||||
import type { Request, Response } from 'express'
|
||||
|
||||
import { BaseController } from '#application/base/baseController'
|
||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
import SpriteRepository from '#repositories/spriteRepository'
|
||||
import TileRepository from '#repositories/tileRepository'
|
||||
|
||||
export class CacheController extends BaseController {
|
||||
/**
|
||||
* Serve a list of tiles and send as JSON
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { BaseController } from '@/application/base/baseController'
|
||||
import Storage from '@/application/storage'
|
||||
import type { Request, Response } from 'express'
|
||||
|
||||
import { BaseController } from '#application/base/baseController'
|
||||
import Storage from '#application/storage'
|
||||
|
||||
export class TexturesController extends BaseController {
|
||||
/**
|
||||
* Download texture
|
||||
|
@ -1,18 +1,15 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { CharacterEquipment } from '@/entities/characterEquipment'
|
||||
import type { CharacterHair } from '@/entities/characterHair'
|
||||
import type { CharacterItem } from '@/entities/characterItem'
|
||||
import type { CharacterType } from '@/entities/characterType'
|
||||
import type { Chat } from '@/entities/chat'
|
||||
import type { Map } from '@/entities/map'
|
||||
import type { User } from '@/entities/user'
|
||||
import { Collection, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { CharacterEquipment } from '#entities/characterEquipment'
|
||||
import type { CharacterHair } from '#entities/characterHair'
|
||||
import type { CharacterItem } from '#entities/characterItem'
|
||||
import type { CharacterType } from '#entities/characterType'
|
||||
import type { Chat } from '#entities/chat'
|
||||
import type { Map } from '#entities/map'
|
||||
import type { User } from '#entities/user'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseCharacter extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import { CharacterEquipmentSlotType } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Character } from '@/entities/character'
|
||||
import type { CharacterItem } from '@/entities/characterItem'
|
||||
import { Enum, ManyToOne, PrimaryKey } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Character } from '#entities/character'
|
||||
import type { CharacterItem } from '#entities/characterItem'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
import { CharacterEquipmentSlotType } from '#application/enums'
|
||||
|
||||
export class BaseCharacterEquipment extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import { CharacterGender } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Character } from '@/entities/character'
|
||||
import { Sprite } from '@/entities/sprite'
|
||||
import { Collection, Entity, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
import { CharacterGender } from '#application/enums'
|
||||
import { Character } from '#entities/character'
|
||||
import { Sprite } from '#entities/sprite'
|
||||
|
||||
export class BaseCharacterHair extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,13 +1,10 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Character } from '@/entities/character'
|
||||
import type { Item } from '@/entities/item'
|
||||
import { ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Character } from '#entities/character'
|
||||
import type { Item } from '#entities/item'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseCharacterItem extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import { CharacterGender, CharacterRace } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Character } from '@/entities/character'
|
||||
import { Sprite } from '@/entities/sprite'
|
||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
import { CharacterGender, CharacterRace } from '#application/enums'
|
||||
import { Character } from '#entities/character'
|
||||
import { Sprite } from '#entities/sprite'
|
||||
|
||||
export class BaseCharacterType extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,13 +1,10 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Character } from '@/entities/character'
|
||||
import type { Map } from '@/entities/map'
|
||||
import { ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Character } from '#entities/character'
|
||||
import type { Map } from '#entities/map'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseChat extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import { ItemRarity, ItemType } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { CharacterItem } from '@/entities/characterItem'
|
||||
import { Sprite } from '@/entities/sprite'
|
||||
import { Collection, Entity, Enum, ManyToOne, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
import { ItemType, ItemRarity } from '#application/enums'
|
||||
import { CharacterItem } from '#entities/characterItem'
|
||||
import { Sprite } from '#entities/sprite'
|
||||
|
||||
export class BaseItem extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { MapEffect } from '@/entities/mapEffect'
|
||||
import type { MapEventTile } from '@/entities/mapEventTile'
|
||||
import type { PlacedMapObject } from '@/entities/placedMapObject'
|
||||
import { Collection, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { MapEffect } from '#entities/mapEffect'
|
||||
import type { MapEventTile } from '#entities/mapEventTile'
|
||||
import type { PlacedMapObject } from '#entities/placedMapObject'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseMap extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,12 +1,9 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Map } from '@/entities/map'
|
||||
import { ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Map } from '#entities/map'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseMapEffect extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import { MapEventTileType } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Map } from '@/entities/map'
|
||||
import type { MapEventTileTeleport } from '@/entities/mapEventTileTeleport'
|
||||
import { Enum, ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Map } from '#entities/map'
|
||||
import type { MapEventTileTeleport } from '#entities/mapEventTileTeleport'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
import { MapEventTileType } from '#application/enums'
|
||||
|
||||
export class BaseMapEventTile extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,13 +1,10 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Map } from '@/entities/map'
|
||||
import type { MapEventTile } from '@/entities/mapEventTile'
|
||||
import { ManyToOne, OneToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Map } from '#entities/map'
|
||||
import type { MapEventTile } from '#entities/mapEventTile'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseMapEventTileTeleport extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseMapObject extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
@ -13,8 +10,11 @@ export class BaseMapObject extends BaseEntity {
|
||||
@Property()
|
||||
name!: string
|
||||
|
||||
@Property({ type: 'json', nullable: true })
|
||||
tags?: any
|
||||
@Property({ type: 'json' })
|
||||
tags: string[] = []
|
||||
|
||||
@Property({ type: 'json' })
|
||||
pivotPoints: { x: number; y: number; }[] = []
|
||||
|
||||
@Property({ type: 'decimal', precision: 10, scale: 2 })
|
||||
originX = 0
|
||||
@ -64,6 +64,15 @@ export class BaseMapObject extends BaseEntity {
|
||||
return this.tags
|
||||
}
|
||||
|
||||
setPivotPoints(pivotPoints: { x: number; y: number; }[]) {
|
||||
this.pivotPoints = pivotPoints
|
||||
return this
|
||||
}
|
||||
|
||||
getPivotPoints() {
|
||||
return this.pivotPoints
|
||||
}
|
||||
|
||||
setOriginX(originX: number) {
|
||||
this.originX = originX
|
||||
return this
|
||||
|
@ -1,12 +1,9 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { User } from '@/entities/user'
|
||||
import { ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { User } from '#entities/user'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BasePasswordResetToken extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,13 +1,10 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Map } from '@/entities/map'
|
||||
import type { MapObject } from '@/entities/mapObject'
|
||||
import { ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Map } from '#entities/map'
|
||||
import type { MapObject } from '#entities/mapObject'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BasePlacedMapObject extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,12 +1,9 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { SpriteAction } from '@/entities/spriteAction'
|
||||
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
import { SpriteAction } from '#entities/spriteAction'
|
||||
|
||||
export class BaseSprite extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,12 +1,9 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import type { Sprite } from '@/entities/sprite'
|
||||
import { ManyToOne, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
import type { Sprite } from '#entities/sprite'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export interface SpriteImage {
|
||||
url: string
|
||||
offset: {
|
||||
|
@ -1,11 +1,8 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseTile extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,14 +1,11 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Character } from '@/entities/character'
|
||||
import { PasswordResetToken } from '@/entities/passwordResetToken'
|
||||
import { Collection, Entity, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
import bcrypt from 'bcryptjs'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
import { Character } from '#entities/character'
|
||||
import { PasswordResetToken } from '#entities/passwordResetToken'
|
||||
|
||||
export class BaseUser extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
id = randomUUID()
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseEntity } from '@/application/base/baseEntity'
|
||||
import { Entity, PrimaryKey, Property } from '@mikro-orm/core'
|
||||
|
||||
import { BaseEntity } from '#application/base/baseEntity'
|
||||
|
||||
export class BaseWorld extends BaseEntity {
|
||||
@PrimaryKey()
|
||||
date = new Date()
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseCharacter } from '@/entities/base/character'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseCharacter } from '#entities/base/character'
|
||||
|
||||
@Entity()
|
||||
export class Character extends BaseCharacter {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseCharacterEquipment } from '@/entities/base/characterEquipment'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseCharacterEquipment } from '#entities/base/characterEquipment'
|
||||
|
||||
@Entity()
|
||||
export class CharacterEquipment extends BaseCharacterEquipment {}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseCharacterHair } from '@/entities/base/characterHair'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseCharacterHair } from '#entities/base/characterHair'
|
||||
|
||||
@Entity()
|
||||
export class CharacterHair extends BaseCharacterHair {
|
||||
public async cache() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseCharacterItem } from '@/entities/base/characterItem'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseCharacterItem } from '#entities/base/characterItem'
|
||||
|
||||
@Entity()
|
||||
export class CharacterItem extends BaseCharacterItem {}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseCharacterType } from '@/entities/base/characterType'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseCharacterType } from '#entities/base/characterType'
|
||||
|
||||
@Entity()
|
||||
export class CharacterType extends BaseCharacterType {
|
||||
public async cache() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseChat } from '@/entities/base/chat'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseChat } from '#entities/base/chat'
|
||||
|
||||
@Entity()
|
||||
export class Chat extends BaseChat {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseItem } from '@/entities/base/item'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseItem } from '#entities/base/item'
|
||||
|
||||
@Entity()
|
||||
export class Item extends BaseItem {}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseMap } from '@/entities/base/map'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseMap } from '#entities/base/map'
|
||||
|
||||
export type MapCacheT = ReturnType<Map['cache']> | {}
|
||||
|
||||
@Entity()
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseMapEffect } from '@/entities/base/mapEffect'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseMapEffect } from '#entities/base/mapEffect'
|
||||
|
||||
@Entity()
|
||||
export class MapEffect extends BaseMapEffect {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseMapEventTile } from '@/entities/base/mapEventTile'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseMapEventTile } from '#entities/base/mapEventTile'
|
||||
|
||||
@Entity()
|
||||
export class MapEventTile extends BaseMapEventTile {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseMapEventTileTeleport } from '@/entities/base/mapEventTileTeleport'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseMapEventTileTeleport } from '#entities/base/mapEventTileTeleport'
|
||||
|
||||
@Entity()
|
||||
export class MapEventTileTeleport extends BaseMapEventTileTeleport {}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseMapObject } from '@/entities/base/mapObject'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseMapObject } from '#entities/base/mapObject'
|
||||
|
||||
@Entity()
|
||||
export class MapObject extends BaseMapObject {
|
||||
public async cache() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BasePasswordResetToken } from '@/entities/base/passwordResetToken'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BasePasswordResetToken } from '#entities/base/passwordResetToken'
|
||||
|
||||
@Entity()
|
||||
export class PasswordResetToken extends BasePasswordResetToken {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BasePlacedMapObject } from '@/entities/base/placedMapObject'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BasePlacedMapObject } from '#entities/base/placedMapObject'
|
||||
|
||||
@Entity()
|
||||
export class PlacedMapObject extends BasePlacedMapObject {}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseSprite } from '@/entities/base/sprite'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseSprite } from '#entities/base/sprite'
|
||||
|
||||
@Entity()
|
||||
export class Sprite extends BaseSprite {
|
||||
public async cache() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseSpriteAction } from '@/entities/base/spriteAction'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseSpriteAction } from '#entities/base/spriteAction'
|
||||
|
||||
@Entity()
|
||||
export class SpriteAction extends BaseSpriteAction {}
|
||||
|
@ -1,7 +1,6 @@
|
||||
import { BaseTile } from '@/entities/base/tile'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseTile } from '#entities/base/tile'
|
||||
|
||||
@Entity()
|
||||
export class Tile extends BaseTile {
|
||||
public async cache() {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseUser } from '@/entities/base/user'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseUser } from '#entities/base/user'
|
||||
|
||||
@Entity()
|
||||
export class User extends BaseUser {}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { BaseWorld } from '@/entities/base/world'
|
||||
import { Entity } from '@mikro-orm/core'
|
||||
|
||||
import { BaseWorld } from '#entities/base/world'
|
||||
|
||||
@Entity()
|
||||
export class World extends BaseWorld {}
|
||||
|
@ -1,10 +1,10 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import MapManager from '#managers/mapManager'
|
||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
import TeleportService from '#services/characterTeleportService'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import MapManager from '@/managers/mapManager'
|
||||
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
import TeleportService from '@/services/characterTeleportService'
|
||||
|
||||
interface CharacterConnectPayload {
|
||||
characterId: UUID
|
||||
@ -16,7 +16,7 @@ export default class CharacterConnectEvent extends BaseEvent {
|
||||
private readonly characterRepository = new CharacterRepository()
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('character:connect', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHARACTER_CONNECT, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: CharacterConnectPayload, callback: (response: any) => void): Promise<void> {
|
||||
@ -26,7 +26,7 @@ export default class CharacterConnectEvent extends BaseEvent {
|
||||
return
|
||||
}
|
||||
|
||||
const character = await this.characterRepository.getByUserAndId(this.socket.userId!, data.characterId)
|
||||
const character = await this.characterRepository.getByUserAndId(this.socket.userId, data.characterId)
|
||||
|
||||
if (!character) {
|
||||
this.emitError('Character not found or does not belong to this user')
|
||||
@ -62,7 +62,7 @@ export default class CharacterConnectEvent extends BaseEvent {
|
||||
}
|
||||
|
||||
private async checkForActiveCharacters(): Promise<boolean> {
|
||||
const characters = await this.characterRepository.getByUserId(this.socket.userId!)
|
||||
const characters = await this.characterRepository.getByUserId(this.socket.userId)
|
||||
return characters?.some((char) => MapManager.getCharacterById(char.id)) ?? false
|
||||
}
|
||||
}
|
||||
|
@ -1,72 +1,84 @@
|
||||
import { ZodError } from 'zod'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { ZCharacterCreate } from '@/application/zodTypes'
|
||||
import { Character } from '@/entities/character'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
||||
import MapRepository from '@/repositories/mapRepository'
|
||||
import UserRepository from '@/repositories/userRepository'
|
||||
import { z, ZodError } from 'zod'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { ZCharacterCreate } from '#application/zodTypes'
|
||||
import { Character } from '#entities/character'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
import UserRepository from '#repositories/userRepository'
|
||||
const MAX_CHARACTERS = 4
|
||||
|
||||
export default class CharacterCreateEvent extends BaseEvent {
|
||||
private readonly userRepository: UserRepository = new UserRepository()
|
||||
private readonly characterRepository: CharacterRepository = new CharacterRepository()
|
||||
private readonly characterTypeRepository: CharacterTypeRepository = new CharacterTypeRepository()
|
||||
private readonly mapRepository: MapRepository = new MapRepository()
|
||||
|
||||
public listen(): void {
|
||||
this.socket.on('character:create', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHARACTER_CREATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: any): Promise<any> {
|
||||
// zod validate
|
||||
private async handleEvent(data: z.infer<typeof ZCharacterCreate>, callback: (success: boolean) => void): Promise<void> {
|
||||
try {
|
||||
data = ZCharacterCreate.parse(data)
|
||||
|
||||
const userRepository = new UserRepository()
|
||||
const characterRepository = new CharacterRepository()
|
||||
const characterTypeRepository = new CharacterTypeRepository()
|
||||
const mapRepository = new MapRepository()
|
||||
|
||||
const user = await userRepository.getById(this.socket.userId!)
|
||||
|
||||
if (!user) {
|
||||
return this.socket.emit('notification', { title: 'Error', message: 'You are not logged in' })
|
||||
}
|
||||
|
||||
// Check if character name already exists
|
||||
const characterExists = await characterRepository.getByName(data.name)
|
||||
|
||||
if (characterExists) {
|
||||
return this.socket.emit('notification', { title: 'Error', message: 'Character name already exists' })
|
||||
}
|
||||
|
||||
let characters: Character[] = await characterRepository.getByUserId(user.getId())
|
||||
|
||||
if (characters.length >= 4) {
|
||||
return this.socket.emit('notification', { title: 'Error', message: 'You can only create 4 characters' })
|
||||
}
|
||||
|
||||
// @TODO: Change to default location
|
||||
const map = await mapRepository.getFirst()
|
||||
|
||||
// @TODO: Change to selected character type
|
||||
const characterType = await characterTypeRepository.getFirst()
|
||||
|
||||
const newCharacter = new Character()
|
||||
await newCharacter.setName(data.name).setUser(user).setMap(map!).setCharacterType(characterType).save()
|
||||
|
||||
if (!newCharacter) {
|
||||
return this.socket.emit('notification', { title: 'Error', message: 'Failed to create character. Please try again (later).' })
|
||||
}
|
||||
|
||||
characters = [...characters, newCharacter]
|
||||
|
||||
this.socket.emit('character:create:success')
|
||||
this.socket.emit('character:list', characters)
|
||||
|
||||
this.logger.info('character:create success')
|
||||
} catch (error: any) {
|
||||
this.logger.error(`character:create error: ${error.message}`)
|
||||
if (error instanceof ZodError) {
|
||||
return this.socket.emit('notification', { title: 'Error', message: error.issues[0]!.message })
|
||||
}
|
||||
return this.socket.emit('notification', { title: 'Error', message: 'Could not create character. Please try again (later).' })
|
||||
const validatedData = ZCharacterCreate.parse(data)
|
||||
await this.createCharacter(validatedData)
|
||||
callback(true)
|
||||
} catch (error: unknown) {
|
||||
this.returnError(error)
|
||||
callback(false)
|
||||
}
|
||||
}
|
||||
|
||||
private async createCharacter(data: z.infer<typeof ZCharacterCreate>): Promise<void> {
|
||||
const user = await this.userRepository.getById(this.socket.userId)
|
||||
if (!user) {
|
||||
throw new Error('You are not logged in')
|
||||
}
|
||||
|
||||
const characterExists = await this.characterRepository.getByName(data.name)
|
||||
if (characterExists) {
|
||||
throw new Error('Character name already exists')
|
||||
}
|
||||
|
||||
let characters = await this.characterRepository.getByUserId(user.getId())
|
||||
if (characters.length >= MAX_CHARACTERS) {
|
||||
throw new Error(`You can only create ${MAX_CHARACTERS} characters`)
|
||||
}
|
||||
|
||||
const map = await this.mapRepository.getFirst()
|
||||
if (!map) {
|
||||
throw new Error('No default map found')
|
||||
}
|
||||
|
||||
const characterType = await this.characterTypeRepository.getFirst()
|
||||
if (!characterType) {
|
||||
throw new Error('No character type found')
|
||||
}
|
||||
|
||||
const newCharacter = new Character()
|
||||
await newCharacter.setName(data.name).setUser(user).setMap(map).setCharacterType(characterType).save()
|
||||
characters = await this.characterRepository.getByUserId(user.getId())
|
||||
|
||||
this.socket.emit(SocketEvent.CHARACTER_LIST, characters)
|
||||
this.logger.info('character:create success')
|
||||
}
|
||||
|
||||
private returnError(error: unknown): void {
|
||||
this.logger.error(`character:create error: ${error instanceof Error ? error.message : 'Unknown error'}`)
|
||||
|
||||
let errorMessage = 'Could not create character. Please try again later.'
|
||||
|
||||
if (error instanceof ZodError) {
|
||||
errorMessage = error.issues[0]?.message || errorMessage
|
||||
} else if (error instanceof Error) {
|
||||
errorMessage = error.message
|
||||
}
|
||||
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Error',
|
||||
message: errorMessage
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { Character } from '#entities/character'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Character } from '@/entities/character'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
|
||||
type TypePayload = {
|
||||
characterId: UUID
|
||||
@ -14,18 +14,18 @@ type TypeResponse = {
|
||||
|
||||
export default class CharacterDeleteEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('character:delete', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHARACTER_DELETE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: TypePayload, callback: (response: TypeResponse) => void): Promise<any> {
|
||||
try {
|
||||
const characterRepository = new CharacterRepository()
|
||||
await (await characterRepository.getByUserAndId(this.socket.userId!, data.characterId))?.delete()
|
||||
const characters: Character[] = await characterRepository.getByUserId(this.socket.userId!)
|
||||
await (await characterRepository.getByUserAndId(this.socket.userId, data.characterId))?.delete()
|
||||
const characters: Character[] = await characterRepository.getByUserId(this.socket.userId)
|
||||
|
||||
this.socket.emit('character:list', characters)
|
||||
this.socket.emit(SocketEvent.CHARACTER_LIST, characters)
|
||||
} catch (error: any) {
|
||||
return this.socket.emit('notification', { message: 'Character delete failed. Please try again.' })
|
||||
return this.socket.emit(SocketEvent.NOTIFICATION, { message: 'Character delete failed. Please try again.' })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,18 +1,19 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { Character } from '#entities/character'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { Character } from '@/entities/character'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
|
||||
export default class CharacterListEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('character:list', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHARACTER_LIST, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: any): Promise<void> {
|
||||
try {
|
||||
const characterRepository = new CharacterRepository()
|
||||
let characters: Character[] = await characterRepository.getByUserId(this.socket.userId!)
|
||||
let characters: Character[] = await characterRepository.getByUserId(this.socket.userId)
|
||||
|
||||
this.socket.emit('character:list', characters)
|
||||
this.socket.emit(SocketEvent.CHARACTER_LIST, characters)
|
||||
} catch (error: any) {
|
||||
this.logger.error('character:list error', error.message)
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
import ChatService from '#services/chatService'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
import ChatService from '@/services/chatService'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -8,7 +9,7 @@ type TypePayload = {
|
||||
|
||||
export default class AlertCommandEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('chat:message', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHAT_MESSAGE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
@ -25,7 +26,7 @@ export default class AlertCommandEvent extends BaseEvent {
|
||||
return callback(false)
|
||||
}
|
||||
|
||||
this.io.emit('notification', { title: 'Message from GM', message: args.join(' ') })
|
||||
this.io.emit(SocketEvent.NOTIFICATION, { title: 'Message from GM', message: args.join(' ') })
|
||||
return callback(true)
|
||||
} catch (error: any) {
|
||||
this.logger.error('chat:alert_command error', error.message)
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import DateManager from '#managers/dateManager'
|
||||
import CharacterRepository from '#repositories/characterRepository'
|
||||
import ChatService from '#services/chatService'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import DateManager from '@/managers/dateManager'
|
||||
import CharacterRepository from '@/repositories/characterRepository'
|
||||
import ChatService from '@/services/chatService'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -9,7 +10,7 @@ type TypePayload = {
|
||||
|
||||
export default class SetTimeCommand extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('chat:message', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHAT_MESSAGE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,10 +1,10 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import MapManager from '#managers/mapManager'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
import TeleportService from '#services/characterTeleportService'
|
||||
import ChatService from '#services/chatService'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import MapManager from '@/managers/mapManager'
|
||||
import MapRepository from '@/repositories/mapRepository'
|
||||
import TeleportService from '@/services/characterTeleportService'
|
||||
import ChatService from '@/services/chatService'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -12,7 +12,7 @@ type TypePayload = {
|
||||
|
||||
export default class TeleportCommandEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('chat:message', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHAT_MESSAGE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void) {
|
||||
@ -29,7 +29,7 @@ export default class TeleportCommandEvent extends BaseEvent {
|
||||
const args = ChatService.getArgs('teleport', data.message)
|
||||
|
||||
if (!args || args.length === 0 || args.length > 3) {
|
||||
this.socket.emit('notification', {
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Server message',
|
||||
message: 'Usage: /teleport <mapId> [x] [y]'
|
||||
})
|
||||
@ -41,7 +41,7 @@ export default class TeleportCommandEvent extends BaseEvent {
|
||||
const targetY = args[2] ? parseInt(args[2], 10) : 0
|
||||
|
||||
if (!mapId || isNaN(targetX) || isNaN(targetY)) {
|
||||
this.socket.emit('notification', {
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Server message',
|
||||
message: 'Invalid parameters. X and Y coordinates must be numbers.'
|
||||
})
|
||||
@ -51,7 +51,7 @@ export default class TeleportCommandEvent extends BaseEvent {
|
||||
const mapRepository = new MapRepository()
|
||||
const map = await mapRepository.getById(mapId)
|
||||
if (!map) {
|
||||
this.socket.emit('notification', {
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Server message',
|
||||
message: 'Map not found'
|
||||
})
|
||||
@ -59,7 +59,7 @@ export default class TeleportCommandEvent extends BaseEvent {
|
||||
}
|
||||
|
||||
if (character.map.id === map.id && targetX === character.positionX && targetY === character.positionY) {
|
||||
this.socket.emit('notification', {
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Server message',
|
||||
message: 'You are already at that location'
|
||||
})
|
||||
@ -74,20 +74,20 @@ export default class TeleportCommandEvent extends BaseEvent {
|
||||
})
|
||||
|
||||
if (!success) {
|
||||
return this.socket.emit('notification', {
|
||||
return this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Server message',
|
||||
message: 'Failed to teleport'
|
||||
})
|
||||
}
|
||||
|
||||
this.socket.emit('notification', {
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Server message',
|
||||
message: `Teleported to ${map.name} (${targetX}, ${targetY})`
|
||||
})
|
||||
this.logger.info('teleport', `Character ${character.id} teleported to map ${map.id} at position (${targetX}, ${targetY})`)
|
||||
} catch (error: any) {
|
||||
this.logger.error(`Error in teleport command: ${error.message}`)
|
||||
this.socket.emit('notification', {
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, {
|
||||
title: 'Server message',
|
||||
message: 'An error occurred while teleporting'
|
||||
})
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import WeatherManager from '#managers/weatherManager'
|
||||
import ChatService from '#services/chatService'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import WeatherManager from '@/managers/weatherManager'
|
||||
import ChatService from '@/services/chatService'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -8,7 +9,7 @@ type TypePayload = {
|
||||
|
||||
export default class ToggleFogCommand extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('chat:message', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHAT_MESSAGE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import WeatherManager from '#managers/weatherManager'
|
||||
import ChatService from '#services/chatService'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import WeatherManager from '@/managers/weatherManager'
|
||||
import ChatService from '@/services/chatService'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -8,7 +9,7 @@ type TypePayload = {
|
||||
|
||||
export default class ToggleRainCommand extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('chat:message', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHAT_MESSAGE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import MapManager from '#managers/mapManager'
|
||||
import MapRepository from '#repositories/mapRepository'
|
||||
import ChatService from '#services/chatService'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import MapManager from '@/managers/mapManager'
|
||||
import ChatService from '@/services/chatService'
|
||||
|
||||
type TypePayload = {
|
||||
message: string
|
||||
@ -9,31 +9,22 @@ type TypePayload = {
|
||||
|
||||
export default class ChatMessageEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('chat:message', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.CHAT_MESSAGE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
|
||||
try {
|
||||
if (!data.message || ChatService.isCommand(data.message)) {
|
||||
return callback(false)
|
||||
}
|
||||
if (!data.message || ChatService.isCommand(data.message)) return
|
||||
|
||||
const mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
||||
if (!mapCharacter) {
|
||||
this.logger.error('chat:message error', 'Character not found')
|
||||
return callback(false)
|
||||
return
|
||||
}
|
||||
|
||||
const character = mapCharacter.character
|
||||
|
||||
const mapRepository = new MapRepository()
|
||||
const map = await mapRepository.getById(character.map.id)
|
||||
if (!map) {
|
||||
this.logger.error('chat:message error', 'Map not found')
|
||||
return callback(false)
|
||||
}
|
||||
|
||||
if (await ChatService.sendMapMessage(character.getId(), map.getId(), data.message)) {
|
||||
if (await ChatService.sendMapMessage(character.getId(), data.message)) {
|
||||
return callback(true)
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import MapManager from '#managers/mapManager'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import MapManager from '@/managers/mapManager'
|
||||
|
||||
export default class DisconnectEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
@ -13,7 +14,7 @@ export default class DisconnectEvent extends BaseEvent {
|
||||
return
|
||||
}
|
||||
|
||||
this.io.emit('user:disconnect', this.socket.userId)
|
||||
this.io.emit(SocketEvent.USER_DISCONNECT, this.socket.userId)
|
||||
|
||||
const mapCharacter = MapManager.getCharacterById(this.socket.characterId!)
|
||||
if (!mapCharacter) {
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { CharacterHair } from '#entities/characterHair'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { CharacterHair } from '@/entities/characterHair'
|
||||
|
||||
export default class CharacterHairCreateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterHair:create', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERHAIR_CREATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
||||
|
||||
interface IPayload {
|
||||
id: UUID
|
||||
@ -9,7 +9,7 @@ interface IPayload {
|
||||
|
||||
export default class CharacterHairDeleteEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterHair:remove', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERHAIR_REMOVE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { CharacterHair } from '#entities/characterHair'
|
||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { CharacterHair } from '@/entities/characterHair'
|
||||
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
||||
|
||||
interface IPayload {}
|
||||
|
||||
export default class characterHairListEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterHair:list', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERHAIR_LIST, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: CharacterHair[]) => void): Promise<void> {
|
||||
|
@ -1,9 +1,8 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { CharacterGender } from '#application/enums'
|
||||
import CharacterHairRepository from '#repositories/characterHairRepository'
|
||||
import SpriteRepository from '#repositories/spriteRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { CharacterGender, SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import CharacterHairRepository from '@/repositories/characterHairRepository'
|
||||
import SpriteRepository from '@/repositories/spriteRepository'
|
||||
|
||||
type Payload = {
|
||||
id: UUID
|
||||
@ -15,7 +14,7 @@ type Payload = {
|
||||
|
||||
export default class CharacterHairUpdateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterHair:update', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERHAIR_UPDATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { CharacterType } from '#entities/characterType'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { CharacterType } from '@/entities/characterType'
|
||||
|
||||
export default class CharacterTypeCreateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterType:create', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERTYPE_CREATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: undefined, callback: (response: boolean, characterType?: any) => void): Promise<void> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
||||
|
||||
interface IPayload {
|
||||
id: UUID
|
||||
@ -9,7 +9,7 @@ interface IPayload {
|
||||
|
||||
export default class CharacterTypeDeleteEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterType:remove', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERTYPE_REMOVE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { CharacterType } from '#entities/characterType'
|
||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { CharacterType } from '@/entities/characterType'
|
||||
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
||||
|
||||
interface IPayload {}
|
||||
|
||||
export default class CharacterTypeListEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterType:list', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERTYPE_LIST, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: CharacterType[]) => void): Promise<void> {
|
||||
|
@ -1,9 +1,8 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { CharacterGender, CharacterRace } from '#application/enums'
|
||||
import CharacterTypeRepository from '#repositories/characterTypeRepository'
|
||||
import SpriteRepository from '#repositories/spriteRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { CharacterGender, CharacterRace, SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import CharacterTypeRepository from '@/repositories/characterTypeRepository'
|
||||
import SpriteRepository from '@/repositories/spriteRepository'
|
||||
|
||||
type Payload = {
|
||||
id: UUID
|
||||
@ -16,7 +15,7 @@ type Payload = {
|
||||
|
||||
export default class CharacterTypeUpdateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:characterType:update', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_CHARACTERTYPE_UPDATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { ItemRarity, ItemType } from '#application/enums'
|
||||
import { Item } from '#entities/item'
|
||||
import SpriteRepository from '#repositories/spriteRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { ItemRarity, ItemType, SocketEvent } from '@/application/enums'
|
||||
import { Item } from '@/entities/item'
|
||||
import SpriteRepository from '@/repositories/spriteRepository'
|
||||
|
||||
export default class ItemCreateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:item:create', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_ITEM_CREATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: undefined, callback: (response: boolean, item?: any) => void): Promise<void> {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import ItemRepository from '#repositories/itemRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import ItemRepository from '@/repositories/itemRepository'
|
||||
|
||||
interface IPayload {
|
||||
id: UUID
|
||||
@ -9,7 +9,7 @@ interface IPayload {
|
||||
|
||||
export default class ItemDeleteEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:item:remove', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_ITEM_REMOVE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { Item } from '#entities/item'
|
||||
import ItemRepository from '#repositories/itemRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { Item } from '@/entities/item'
|
||||
import ItemRepository from '@/repositories/itemRepository'
|
||||
|
||||
interface IPayload {}
|
||||
|
||||
export default class ItemListEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:item:list', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_ITEM_LIST, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: Item[]) => void): Promise<void> {
|
||||
|
@ -1,9 +1,8 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { ItemType, ItemRarity } from '#application/enums'
|
||||
import ItemRepository from '#repositories/itemRepository'
|
||||
import SpriteRepository from '#repositories/spriteRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { ItemRarity, ItemType, SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import ItemRepository from '@/repositories/itemRepository'
|
||||
import SpriteRepository from '@/repositories/spriteRepository'
|
||||
|
||||
type Payload = {
|
||||
id: UUID
|
||||
@ -17,7 +16,7 @@ type Payload = {
|
||||
|
||||
export default class ItemUpdateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:item:update', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_ITEM_UPDATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { MapObject } from '#entities/mapObject'
|
||||
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import { MapObject } from '@/entities/mapObject'
|
||||
import MapObjectRepository from '@/repositories/mapObjectRepository'
|
||||
|
||||
interface IPayload {}
|
||||
|
||||
export default class MapObjectListEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:mapObject:list', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_MAPOBJECT_LIST, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {
|
||||
|
@ -1,10 +1,9 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import Storage from '#application/storage'
|
||||
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import Storage from '@/application/storage'
|
||||
import type { UUID } from '@/application/types'
|
||||
import MapObjectRepository from '@/repositories/mapObjectRepository'
|
||||
|
||||
interface IPayload {
|
||||
mapObjectId: UUID
|
||||
@ -12,7 +11,7 @@ interface IPayload {
|
||||
|
||||
export default class MapObjectRemoveEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:mapObject:remove', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_MAPOBJECT_REMOVE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,12 +1,13 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import MapObjectRepository from '#repositories/mapObjectRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import MapObjectRepository from '@/repositories/mapObjectRepository'
|
||||
|
||||
type Payload = {
|
||||
id: UUID
|
||||
name: string
|
||||
tags: string[]
|
||||
pivotPoints: { x: number; y: number; }[]
|
||||
originX: number
|
||||
originY: number
|
||||
frameRate: number
|
||||
@ -16,7 +17,7 @@ type Payload = {
|
||||
|
||||
export default class MapObjectUpdateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:mapObject:update', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_MAPOBJECT_UPDATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
|
||||
@ -30,6 +31,7 @@ export default class MapObjectUpdateEvent extends BaseEvent {
|
||||
|
||||
if (data.name !== undefined) mapObject.name = data.name
|
||||
if (data.tags !== undefined) mapObject.tags = data.tags
|
||||
if (data.pivotPoints !== undefined) mapObject.pivotPoints = data.pivotPoints
|
||||
if (data.originX !== undefined) mapObject.originX = data.originX
|
||||
if (data.originY !== undefined) mapObject.originY = data.originY
|
||||
if (data.frameRate !== undefined) mapObject.frameRate = data.frameRate
|
||||
@ -40,7 +42,7 @@ export default class MapObjectUpdateEvent extends BaseEvent {
|
||||
|
||||
return callback(true)
|
||||
} catch (error) {
|
||||
this.socket.emit('notification', { title: 'Error', message: 'Failed to update mapObject.' })
|
||||
this.socket.emit(SocketEvent.NOTIFICATION, { title: 'Error', message: 'Failed to update mapObject.' })
|
||||
return callback(false)
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,18 @@
|
||||
import fs from 'fs/promises'
|
||||
import { writeFile } from 'node:fs/promises'
|
||||
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import Storage from '@/application/storage'
|
||||
import { MapObject } from '@/entities/mapObject'
|
||||
import sharp from 'sharp'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import Storage from '#application/storage'
|
||||
import { MapObject } from '#entities/mapObject'
|
||||
|
||||
interface IObjectData {
|
||||
[key: string]: Buffer
|
||||
}
|
||||
|
||||
export default class MapObjectUploadEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:mapObject:upload', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_MAPOBJECT_UPLOAD, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: IObjectData, callback: (response: boolean) => void): Promise<void> {
|
||||
|
@ -1,8 +1,8 @@
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import { Sprite } from '#entities/sprite'
|
||||
import SpriteRepository from '#repositories/spriteRepository'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import type { UUID } from '@/application/types'
|
||||
import { Sprite } from '@/entities/sprite'
|
||||
import SpriteRepository from '@/repositories/spriteRepository'
|
||||
|
||||
interface CopyPayload {
|
||||
id: UUID
|
||||
@ -10,7 +10,7 @@ interface CopyPayload {
|
||||
|
||||
export default class SpriteCopyEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:sprite:copy', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_SPRITE_COPY, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(payload: CopyPayload, callback: (success: boolean) => void): Promise<void> {
|
||||
|
@ -1,12 +1,12 @@
|
||||
import fs from 'fs/promises'
|
||||
|
||||
import { BaseEvent } from '#application/base/baseEvent'
|
||||
import Storage from '#application/storage'
|
||||
import { Sprite } from '#entities/sprite'
|
||||
import { BaseEvent } from '@/application/base/baseEvent'
|
||||
import { SocketEvent } from '@/application/enums'
|
||||
import Storage from '@/application/storage'
|
||||
import { Sprite } from '@/entities/sprite'
|
||||
|
||||
export default class SpriteCreateEvent extends BaseEvent {
|
||||
public listen(): void {
|
||||
this.socket.on('gm:sprite:create', this.handleEvent.bind(this))
|
||||
this.socket.on(SocketEvent.GM_SPRITE_CREATE, this.handleEvent.bind(this))
|
||||
}
|
||||
|
||||
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user