forked from noxious/server
made typescript my bitch
This commit is contained in:
37
src/app/UserManager.ts
Normal file
37
src/app/UserManager.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import {User} from "@prisma/client";
|
||||
|
||||
interface ILoggedInUsers {
|
||||
users: User[];
|
||||
}
|
||||
|
||||
class UserManager {
|
||||
private loggedInUsers: ILoggedInUsers[] = [];
|
||||
|
||||
// Method to initialize user manager
|
||||
public async boot() {
|
||||
console.log('[✅] User manager loaded');
|
||||
}
|
||||
|
||||
// Function that adds user to logged in users
|
||||
public addUser(user: User) {
|
||||
this.loggedInUsers.push({
|
||||
users: [user]
|
||||
});
|
||||
}
|
||||
|
||||
// Function that checks if a user is already logged in
|
||||
public findUser(user: User) {
|
||||
return this.loggedInUsers.find((loggedInUser) => {
|
||||
return loggedInUser.users.includes(user);
|
||||
});
|
||||
}
|
||||
|
||||
// Function that lists all logged in users
|
||||
public listUsers() {
|
||||
return this.loggedInUsers.map((loggedInUser) => {
|
||||
return loggedInUser.users;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserManager();
|
@ -10,7 +10,7 @@ interface ILoadedZone {
|
||||
class ZoneManager {
|
||||
private loadedZones: ILoadedZone[] = [];
|
||||
|
||||
// Method to initialize zone loading
|
||||
// Method to initialize zone manager
|
||||
public async boot() {
|
||||
if (!await ZoneRepository.getById(1)) {
|
||||
const zoneService = new ZoneService();
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
import {ISocket} from "../interfaces/socket";
|
||||
|
||||
export default function characterConnect(socket: Socket, io: Server) {
|
||||
export default function characterConnect(socket: ISocket, io: Server) {
|
||||
socket.on('character:connect', (data) => {
|
||||
socket.user.username = 'hello'
|
||||
console.log(`---User ${socket.id} has joined.`);
|
||||
});
|
||||
}
|
9
src/app/events/characters.get.ts
Normal file
9
src/app/events/characters.get.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { Socket, Server } from "socket.io";
|
||||
import {ISocket} from "../interfaces/socket";
|
||||
|
||||
export default function characterConnect(socket: ISocket, io: Server) {
|
||||
socket.on('characters:get', async (data) => {
|
||||
console.log(socket.user.username)
|
||||
console.log(`---characters requested.`);
|
||||
});
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
import { Socket } from 'socket.io';
|
||||
import {Character, User} from "@prisma/client";
|
||||
import {Character as ICharacter, User} from "@prisma/client";
|
||||
|
||||
interface NQSocket extends Socket
|
||||
interface Character extends Socket
|
||||
{
|
||||
user?: User,
|
||||
character?: Character
|
||||
character?: ICharacter
|
||||
}
|
5
src/app/interfaces/socket.ts
Normal file
5
src/app/interfaces/socket.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import {Socket} from "socket.io";
|
||||
|
||||
export interface ISocket extends Socket {
|
||||
user?: any;
|
||||
}
|
Reference in New Issue
Block a user