Added enums, moved Mikro ORM config into server.ts, cleaned configuration and env files
This commit is contained in:
parent
8980691409
commit
8377fe6545
@ -1,22 +0,0 @@
|
||||
import {default as serverConfig} from './src/utilities/config';
|
||||
import { Options } from '@mikro-orm/core';
|
||||
import { MariaDbDriver } from '@mikro-orm/mariadb';
|
||||
import { Migrator } from '@mikro-orm/migrations';
|
||||
|
||||
const config: Options<MariaDbDriver> = {
|
||||
extensions: [Migrator],
|
||||
entities: ['./dist/entities/**/*.js'],
|
||||
entitiesTs: ['./src/entities/**/*.ts'],
|
||||
driver: MariaDbDriver,
|
||||
dbName: serverConfig.DB_NAME,
|
||||
host: serverConfig.DB_HOST,
|
||||
port: serverConfig.DB_PORT,
|
||||
user: serverConfig.DB_USER,
|
||||
password: serverConfig.DB_PASSWORD,
|
||||
debug: serverConfig.ENV !== 'production',
|
||||
driverOptions: {
|
||||
allowPublicKeyRetrieval: true
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
@ -1,7 +1,7 @@
|
||||
import { Entity, ManyToOne, PrimaryKey, Property } from '@mikro-orm/core';
|
||||
import { Character } from './character';
|
||||
import { CharacterItem } from './characterItem';
|
||||
import { CharacterEquipmentSlotType } from '../utilities/enums';
|
||||
import { CharacterEquipmentSlotType } from '#utilities/enums';
|
||||
|
||||
@Entity()
|
||||
export class CharacterEquipment {
|
||||
|
@ -8,7 +8,7 @@ import cors from 'cors'
|
||||
import { Server as SocketServer } from 'socket.io'
|
||||
import { Authentication } from './middleware/authentication'
|
||||
import { TSocket } from './utilities/types'
|
||||
import { MikroORM } from '@mikro-orm/mariadb'
|
||||
import { MariaDbDriver, MikroORM } from '@mikro-orm/mariadb'
|
||||
import prisma from './utilities/prisma'
|
||||
import { appLogger, watchLogs } from './utilities/logger'
|
||||
import ZoneManager from './managers/zoneManager'
|
||||
@ -17,6 +17,7 @@ import CommandManager from './managers/commandManager'
|
||||
import QueueManager from './managers/queueManager'
|
||||
import DateManager from './managers/dateManager'
|
||||
import WeatherManager from './managers/weatherManager'
|
||||
import { Migrator } from '@mikro-orm/migrations'
|
||||
|
||||
export class Server {
|
||||
private readonly app: Application
|
||||
@ -60,7 +61,21 @@ export class Server {
|
||||
|
||||
// MikroORM
|
||||
try {
|
||||
const orm = await MikroORM.init();
|
||||
const orm = await MikroORM.init({
|
||||
extensions: [Migrator],
|
||||
entities: ['./src/entities/**/*.js'],
|
||||
entitiesTs: ['./src/entities/**/*.ts'],
|
||||
driver: MariaDbDriver,
|
||||
dbName: config.DB_NAME,
|
||||
host: config.DB_HOST,
|
||||
port: config.DB_PORT,
|
||||
user: config.DB_USER,
|
||||
password: config.DB_PASSWORD,
|
||||
debug: config.ENV !== 'production',
|
||||
driverOptions: {
|
||||
allowPublicKeyRetrieval: true
|
||||
}
|
||||
});
|
||||
appLogger.info('Database 2 connected')
|
||||
} catch (error: any) {
|
||||
appLogger.error(`Database 2 connection failed: ${error.message}`)
|
||||
|
@ -3,22 +3,34 @@ import dotenv from 'dotenv'
|
||||
dotenv.config()
|
||||
|
||||
class config {
|
||||
// Server configuration
|
||||
static ENV: string = process.env.ENV || 'development'
|
||||
static REDIS_URL: string = process.env.REDIS_URL || 'redis://@127.0.0.1:6379/4'
|
||||
static HOST: string = process.env.HOST || '0.0.0.0'
|
||||
static PORT: number = process.env.PORT ? parseInt(process.env.PORT) : 6969
|
||||
static CLIENT_URL: string = process.env.CLIENT_URL ? process.env.CLIENT_URL : 'https://sylvan.quest'
|
||||
static JWT_SECRET: string = process.env.JWT_SECRET || 'secret'
|
||||
static CLIENT_URL: string = process.env.CLIENT_URL ? process.env.CLIENT_URL : 'https://noxious.gg'
|
||||
|
||||
// Database configuration
|
||||
static REDIS_URL: string = process.env.REDIS_URL || 'redis://@127.0.0.1:6379/4'
|
||||
static DATABASE_URL: string = process.env.DATABASE_URL || 'mysql://root@localhost:3306/game'
|
||||
static DB_HOST: string = process.env.DB_HOST || 'localhost'
|
||||
static DB_USER: string = process.env.DB_USER || 'root'
|
||||
static DB_PASS: string = process.env.DB_PASS || ''
|
||||
static DB_PORT: number = process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 3306
|
||||
static DB_NAME: string = process.env.DB_NAME || 'game'
|
||||
|
||||
// Game configuration
|
||||
static ALLOW_DIAGONAL_MOVEMENT: boolean = process.env.ALLOW_DIAGONAL_MOVEMENT === 'true'
|
||||
|
||||
// Default character create values
|
||||
static DEFAULT_CHARACTER_ZONE: number = parseInt(process.env.DEFAULT_CHARACTER_ZONE || '1')
|
||||
static DEFAULT_CHARACTER_X: number = parseInt(process.env.DEFAULT_CHARACTER_POS_X || '0')
|
||||
static DEFAULT_CHARACTER_Y: number = parseInt(process.env.DEFAULT_CHARACTER_POS_Y || '0')
|
||||
|
||||
// Email configuration
|
||||
static SMTP_HOST: string = process.env.SMTP_HOST || 'my.directonline.io'
|
||||
static SMTP_PORT: number = process.env.SMTP_PORT ? parseInt(process.env.SMTP_PORT) : 587
|
||||
static SMTP_USER: string = process.env.SMTP_USER || 'no-reply@sylvan.quest'
|
||||
static SMTP_USER: string = process.env.SMTP_USER || 'no-reply@noxious.gg'
|
||||
static SMTP_PASSWORD: string = process.env.SMTP_PASSWORD || 'password'
|
||||
}
|
||||
|
||||
|
40
src/utilities/enums.ts
Normal file
40
src/utilities/enums.ts
Normal file
@ -0,0 +1,40 @@
|
||||
export enum ItemType {
|
||||
WEAPON = 'WEAPON',
|
||||
HELMET = 'HELMET',
|
||||
CHEST = 'CHEST',
|
||||
LEGS = 'LEGS',
|
||||
BOOTS = 'BOOTS',
|
||||
GLOVES = 'GLOVES',
|
||||
RING = 'RING',
|
||||
NECKLACE = 'NECKLACE'
|
||||
}
|
||||
|
||||
export enum ItemRarity {
|
||||
COMMON = 'COMMON',
|
||||
UNCOMMON = 'UNCOMMON',
|
||||
RARE = 'RARE',
|
||||
EPIC = 'EPIC',
|
||||
LEGENDARY = 'LEGENDARY'
|
||||
}
|
||||
|
||||
export enum CharacterGender {
|
||||
MALE = 'MALE',
|
||||
FEMALE = 'FEMALE'
|
||||
}
|
||||
|
||||
export enum CharacterRace {
|
||||
HUMAN = 'HUMAN',
|
||||
ELF = 'ELF',
|
||||
DWARF = 'DWARF',
|
||||
ORC = 'ORC',
|
||||
GOBLIN = 'GOBLIN'
|
||||
}
|
||||
|
||||
export enum CharacterEquipmentSlotType {
|
||||
HEAD = 'HEAD',
|
||||
BODY = 'BODY',
|
||||
ARMS = 'ARMS',
|
||||
LEGS = 'LEGS',
|
||||
NECK = 'NECK',
|
||||
RING = 'RING'
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user