29 lines
721 B
TypeScript
29 lines
721 B
TypeScript
import { Server } from 'socket.io'
|
|
import { TSocket } from '../utilities/types'
|
|
import { gameLogger } from '../utilities/logger'
|
|
|
|
export default class LoginEvent {
|
|
constructor(
|
|
private readonly io: Server,
|
|
private readonly socket: TSocket
|
|
) {}
|
|
|
|
public listen(): void {
|
|
this.socket.on('login', this.handleLogin.bind(this))
|
|
}
|
|
|
|
private handleLogin(): void {
|
|
try {
|
|
if (!this.socket.user) {
|
|
gameLogger.warn('Login attempt without user data')
|
|
return
|
|
}
|
|
|
|
this.socket.emit('logged_in', { user: this.socket.user })
|
|
gameLogger.info(`User logged in: ${this.socket.user.id}`)
|
|
} catch (error: any) {
|
|
gameLogger.error('login error', error.message)
|
|
}
|
|
}
|
|
}
|