Did some cleaning, worked on notifications
This commit is contained in:
parent
267e61cc7f
commit
6a995a83ab
14
src/app/CommandManager.ts
Normal file
14
src/app/CommandManager.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import * as readline from 'readline';
|
||||||
|
|
||||||
|
class CommandManager
|
||||||
|
{
|
||||||
|
private commands: Map<string, Function> = new Map();
|
||||||
|
|
||||||
|
public async boot() {
|
||||||
|
console.log('[✅] Command manager loaded');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan for files
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new CommandManager();
|
@ -1,5 +1,5 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import {TSocket} from "../types/TSocket";
|
import {TSocket} from "../utilities/Types";
|
||||||
import CharacterRepository from "../repositories/CharacterRepository";
|
import CharacterRepository from "../repositories/CharacterRepository";
|
||||||
import {Character} from "@prisma/client";
|
import {Character} from "@prisma/client";
|
||||||
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import {TSocket} from "../types/TSocket";
|
import {TSocket} from "../utilities/Types";
|
||||||
import {Character} from "@prisma/client";
|
import {Character} from "@prisma/client";
|
||||||
import CharacterRepository from "../repositories/CharacterRepository";
|
import CharacterRepository from "../repositories/CharacterRepository";
|
||||||
import {ZCharacterCreate} from "../types/zod/Character";
|
import {ZCharacterCreate} from "../utilities/ZodTypes";
|
||||||
|
|
||||||
export default function CharacterCreate(socket: TSocket, io: Server) {
|
export default function CharacterCreate(socket: TSocket, io: Server) {
|
||||||
socket.on('character:create', async (data: any) => {
|
socket.on('character:create', async (data: any) => {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import {Server} from "socket.io";
|
||||||
import {TSocket} from "../types/TSocket";
|
import {TSocket} from "../utilities/Types";
|
||||||
import {Character} from "@prisma/client";
|
import {Character} from "@prisma/client";
|
||||||
import CharacterRepository from "../repositories/CharacterRepository";
|
import CharacterRepository from "../repositories/CharacterRepository";
|
||||||
import {ZCharacterDelete} from "../types/zod/Character";
|
import {ZCharacterDelete} from "../utilities/ZodTypes";
|
||||||
|
|
||||||
export default function CharacterCreate(socket: TSocket, io: Server) {
|
export default function CharacterCreate(socket: TSocket, io: Server) {
|
||||||
socket.on('character:delete', async (data: any) => {
|
socket.on('character:delete', async (data: any) => {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Socket, Server } from "socket.io";
|
||||||
import {TSocket} from "../types/TSocket";
|
import {TSocket} from "../utilities/Types";
|
||||||
import {Character} from "@prisma/client";
|
import {Character} from "@prisma/client";
|
||||||
import CharacterRepository from "../repositories/CharacterRepository";
|
import CharacterRepository from "../repositories/CharacterRepository";
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { Socket, Server } from "socket.io";
|
import { Server } from "socket.io";
|
||||||
import {TSocket} from "../types/TSocket";
|
import {TSocket} from "../utilities/Types";
|
||||||
|
|
||||||
export default function Login(socket: TSocket, io: Server) {
|
export default function Login(socket: TSocket, io: Server) {
|
||||||
socket.on('login', () => {
|
socket.on('login', () => {
|
||||||
|
17
src/app/index.d.ts
vendored
17
src/app/index.d.ts
vendored
@ -1,17 +0,0 @@
|
|||||||
import "socket.io";
|
|
||||||
|
|
||||||
declare module "socket.io" {
|
|
||||||
interface Socket {
|
|
||||||
data: {
|
|
||||||
user: {
|
|
||||||
id: string;
|
|
||||||
username: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
handshake: {
|
|
||||||
headers: {
|
|
||||||
cookie: string;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +0,0 @@
|
|||||||
███╗░░██╗███████╗░██╗░░░░░░░██╗ ░██████╗░██╗░░░██╗███████╗░██████╗████████╗
|
|
||||||
████╗░██║██╔════╝░██║░░██╗░░██║ ██╔═══██╗██║░░░██║██╔════╝██╔════╝╚══██╔══╝
|
|
||||||
██╔██╗██║█████╗░░░╚██╗████╗██╔╝ ██║██╗██║██║░░░██║█████╗░░╚█████╗░░░░██║░░░
|
|
||||||
██║╚████║██╔══╝░░░░████╔═████║░ ╚██████╔╝██║░░░██║██╔══╝░░░╚═══██╗░░░██║░░░
|
|
||||||
██║░╚███║███████╗░░╚██╔╝░╚██╔╝░ ░╚═██╔═╝░╚██████╔╝███████╗██████╔╝░░░██║░░░
|
|
||||||
╚═╝░░╚══╝╚══════╝░░░╚═╝░░░╚═╝░░ ░░░╚═╝░░░░╚═════╝░╚══════╝╚═════╝░░░░╚═╝░░░
|
|
@ -1,12 +1,12 @@
|
|||||||
// socket io jwt auth middleware
|
// socket io jwt auth middleware
|
||||||
import { verify } from 'jsonwebtoken';
|
import { verify } from 'jsonwebtoken';
|
||||||
import { TSocket } from '../types/TSocket';
|
import { TSocket } from '../utilities/Types';
|
||||||
import config from "../utilities/Config";
|
import config from "../utilities/Config";
|
||||||
import UserRepository from "../repositories/UserRepository";
|
import UserRepository from "../repositories/UserRepository";
|
||||||
import {User} from "@prisma/client";
|
import {User} from "@prisma/client";
|
||||||
|
|
||||||
export async function Authentication (socket: TSocket, next: any) {
|
export async function Authentication (socket: TSocket, next: any)
|
||||||
|
{
|
||||||
if (!socket.request.headers.cookie) {
|
if (!socket.request.headers.cookie) {
|
||||||
console.log('No cookie provided');
|
console.log('No cookie provided');
|
||||||
return next(new Error('Authentication error'));
|
return next(new Error('Authentication error'));
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
import { Socket } from 'socket.io';
|
|
||||||
import {Character as ICharacter, User} from "@prisma/client";
|
|
||||||
|
|
||||||
export type TCharacter = Socket & {
|
|
||||||
user?: User,
|
|
||||||
character?: ICharacter
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
import {Socket} from "socket.io";
|
|
||||||
import {Character, User} from '@prisma/client';
|
|
||||||
|
|
||||||
export type TSocket = Socket & {
|
|
||||||
user?: User
|
|
||||||
character?: Character
|
|
||||||
handshake?: {
|
|
||||||
query?: {
|
|
||||||
token?: any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
request?: {
|
|
||||||
headers?: {
|
|
||||||
cookie?: any
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +0,0 @@
|
|||||||
import {Character} from "@prisma/client";
|
|
||||||
|
|
||||||
export type TZoneCharacter = Character & {
|
|
||||||
|
|
||||||
}
|
|
26
src/app/utilities/Types.ts
Normal file
26
src/app/utilities/Types.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Socket } from 'socket.io';
|
||||||
|
import {Character, Character as ICharacter, User} from "@prisma/client";
|
||||||
|
|
||||||
|
export type TSocket = Socket & {
|
||||||
|
user?: User
|
||||||
|
character?: Character
|
||||||
|
handshake?: {
|
||||||
|
query?: {
|
||||||
|
token?: any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
request?: {
|
||||||
|
headers?: {
|
||||||
|
cookie?: any
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TCharacter = Socket & {
|
||||||
|
user?: User,
|
||||||
|
character?: ICharacter
|
||||||
|
}
|
||||||
|
|
||||||
|
export type TZoneCharacter = Character & {
|
||||||
|
|
||||||
|
}
|
@ -1,9 +1,9 @@
|
|||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
export const ZCharacterCreate = z.object({
|
export const ZCharacterCreate = z.object({
|
||||||
name: z.string().min(3).max(255)
|
name: z.string().min(3).max(255)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ZCharacterDelete = z.object({
|
export const ZCharacterDelete = z.object({
|
||||||
character_id: z.number()
|
character_id: z.number()
|
||||||
});
|
});
|
6
src/logo.txt
Normal file
6
src/logo.txt
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
███╗░░██╗███████╗░██╗░░░░░░░██╗ ░██████╗░██╗░░░██╗███████╗░██████╗████████╗
|
||||||
|
████╗░██║██╔════╝░██║░░██╗░░██║ ██╔═══██╗██║░░░██║██╔════╝██╔════╝╚══██╔══╝
|
||||||
|
██╔██╗██║█████╗░░░╚██╗████╗██╔╝ ██║██╗██║██║░░░██║█████╗░░╚█████╗░░░░██║░░░
|
||||||
|
██║╚████║██╔══╝░░░░████╔═████║░ ╚██████╔╝██║░░░██║██╔══╝░░░╚═══██╗░░░██║░░░
|
||||||
|
██║░╚███║███████╗░░╚██╔╝░╚██╔╝░ ░╚═██╔═╝░╚██████╔╝███████╗██████╔╝░░░██║░░░
|
||||||
|
╚═╝░░╚══╝╚══════╝░░░╚═╝░░░╚═╝░░ ░░░╚═╝░░░░╚═════╝░╚══════╝╚═════╝░░░░╚═╝░░░
|
@ -5,12 +5,13 @@ import {createServer as httpServer} from 'http';
|
|||||||
import {addAuthRoutes} from './app/utilities/Http';
|
import {addAuthRoutes} from './app/utilities/Http';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import {Server as SocketServer} from 'socket.io';
|
import {Server as SocketServer} from 'socket.io';
|
||||||
import {TSocket} from "./app/types/TSocket";
|
import {TSocket} from "./app/utilities/Types";
|
||||||
import config from './app/utilities/Config';
|
import config from './app/utilities/Config';
|
||||||
import prisma from './app/utilities/Prisma';
|
import prisma from './app/utilities/Prisma';
|
||||||
import ZoneManager from "./app/ZoneManager";
|
import ZoneManager from "./app/ZoneManager";
|
||||||
import UserManager from "./app/UserManager";
|
import UserManager from "./app/UserManager";
|
||||||
import {Authentication} from "./app/middleware/Authentication";
|
import {Authentication} from "./app/middleware/Authentication";
|
||||||
|
import CommandManager from "./app/CommandManager";
|
||||||
|
|
||||||
export class Server
|
export class Server
|
||||||
{
|
{
|
||||||
@ -36,7 +37,7 @@ export class Server
|
|||||||
*/
|
*/
|
||||||
public async start() {
|
public async start() {
|
||||||
// Print logo
|
// Print logo
|
||||||
const art = fs.readFileSync(path.join(__dirname, 'app', 'logo.txt'), 'utf8');
|
const art = fs.readFileSync(path.join(__dirname, 'logo.txt'), 'utf8');
|
||||||
console.log('\x1b[31m%s\x1b[0m', art + '\n');
|
console.log('\x1b[31m%s\x1b[0m', art + '\n');
|
||||||
|
|
||||||
// Check prisma connection
|
// Check prisma connection
|
||||||
@ -64,6 +65,9 @@ export class Server
|
|||||||
// Load zone manager
|
// Load zone manager
|
||||||
await ZoneManager.boot();
|
await ZoneManager.boot();
|
||||||
|
|
||||||
|
// Load command manager
|
||||||
|
await CommandManager.boot();
|
||||||
|
|
||||||
// Listen for socket connections
|
// Listen for socket connections
|
||||||
this.io.on('connection', this.handleConnection.bind(this));
|
this.io.on('connection', this.handleConnection.bind(this));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user