forked from noxious/server
Moved service logic from repo to service, minor improvements, working hair customisation proof of concept
This commit is contained in:
@ -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')
|
||||
|
Reference in New Issue
Block a user