1
0
forked from noxious/server
This commit is contained in:
Zaxiure
2024-09-20 21:58:38 +02:00
parent b772ade582
commit ed92663313
27 changed files with 117 additions and 68 deletions

View File

@ -1,6 +1,7 @@
import { Server } from 'socket.io'
import { TSocket, ExtendedCharacter } from '../../utilities/types'
import CharacterRepository from '../../repositories/characterRepository'
import CharacterManager from '../../managers/characterManager'
type SocketResponseT = {
character_id: number
@ -10,8 +11,11 @@ export default function (socket: TSocket, io: Server) {
socket.on('character:connect', async (data: SocketResponseT) => {
console.log('character:connect requested', data)
try {
socket.character = (await CharacterRepository.getByUserAndId(socket.user?.id as number, data.character_id)) as ExtendedCharacter
socket.emit('character:connect', socket.character)
const foundCharacter = await CharacterRepository.getByUserAndId(socket?.user?.id as number, data.character_id);
if(!foundCharacter) return;
socket.characterId = foundCharacter.id;
CharacterManager.initCharacter(foundCharacter as ExtendedCharacter);
socket.emit('character:connect', foundCharacter)
} catch (error: any) {
console.log('character:connect error', error)
}