1
0
forked from noxious/server

#161: Set default value for createdAt field, store zone chats into database

This commit is contained in:
2024-11-14 20:45:37 +01:00
parent 3f8f8745eb
commit 460308d555
12 changed files with 109 additions and 29 deletions

View File

@ -17,30 +17,27 @@ export default class ChatMessageEvent {
) {}
public listen(): void {
this.socket.on('chat:send_message', this.handleChatMessage.bind(this))
this.socket.on('chat:message', this.handleEvent.bind(this))
}
private async handleChatMessage(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
try {
if (!data.message || isCommand(data.message)) {
callback(false)
return
return callback(false)
}
const zoneCharacter = ZoneManager.getCharacter(this.socket.characterId!)
if (!zoneCharacter) {
gameLogger.error('chat:send_message error', 'Character not found')
callback(false)
return
gameLogger.error('chat:message error', 'Character not found')
return callback(false)
}
const character = zoneCharacter.character
const zone = await ZoneRepository.getById(character.zoneId)
if (!zone) {
gameLogger.error('chat:send_message error', 'Zone not found')
callback(false)
return
gameLogger.error('chat:message error', 'Zone not found')
return callback(false)
}
const chatService = new ChatService()
@ -50,7 +47,7 @@ export default class ChatMessageEvent {
callback(false)
} catch (error: any) {
gameLogger.error('chat:send_message error', error.message)
gameLogger.error('chat:message error', error.message)
callback(false)
}
}