forked from noxious/server
Updated several events to new event format
This commit is contained in:
@ -1,9 +1,28 @@
|
||||
import { Server } from 'socket.io'
|
||||
import { TSocket } from '../utilities/types'
|
||||
import { gameLogger } from '../utilities/logger'
|
||||
|
||||
export default function (io: Server, socket: TSocket) {
|
||||
socket.on('login', () => {
|
||||
if (!socket.user) return
|
||||
socket.emit('logged_in', { user: socket.user })
|
||||
})
|
||||
}
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user