1
0
forked from noxious/server

Moved service logic from repo to service, minor improvements, working hair customisation proof of concept

This commit is contained in:
2024-11-23 16:48:07 +01:00
parent d5c7cd0294
commit 1017013032
10 changed files with 118 additions and 71 deletions

View File

@ -3,9 +3,11 @@ import { TSocket } from '../../utilities/types'
import CharacterRepository from '../../repositories/characterRepository'
import { gameLogger } from '../../utilities/logger'
import ZoneManager from '../../managers/zoneManager'
import { CharacterService } from '../../services/characterService'
interface CharacterConnectPayload {
characterId: number
hairId?: number
}
export default class CharacterConnectEvent {
@ -18,7 +20,7 @@ export default class CharacterConnectEvent {
this.socket.on('character:connect', this.handleCharacterConnect.bind(this))
}
private async handleCharacterConnect({ characterId }: CharacterConnectPayload): Promise<void> {
private async handleCharacterConnect({ characterId, hairId }: CharacterConnectPayload): Promise<void> {
if (!this.socket.userId) {
this.emitError('User not authenticated')
return
@ -30,6 +32,10 @@ export default class CharacterConnectEvent {
return
}
// Update hair
const characterService = new CharacterService()
await characterService.updateHair(characterId, hairId ?? null)
const character = await this.connectCharacter(characterId)
if (!character) {
this.emitError('Character not found or does not belong to this user')