Replaced all event names with numbers for less bandwidth usage
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import { SocketEvent } from '#application/enums';
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseService } from '#application/base/baseService'
|
||||
@ -27,7 +28,7 @@ class CharacterAttackService extends BaseService {
|
||||
}
|
||||
|
||||
// Emit attack event
|
||||
io.in(character.character.map.id).emit('map:character:attack', character.character.id)
|
||||
io.in(character.character.map.id).emit(SocketEvent.MAP_CHARACTER_ATTACK, character.character.id)
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SocketEvent } from '#application/enums';
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import Logger, { LoggerType } from '#application/logger'
|
||||
@ -61,7 +62,7 @@ class CharacterTeleportService {
|
||||
// If the current map is the target map and we are not joining, send move event
|
||||
if (currentMapId === options.targetMapId && !options.isInitialJoin) {
|
||||
// If the current map is the target map, send move event
|
||||
io.in(currentMapId).emit('map:character:move', {
|
||||
io.in(currentMapId).emit(SocketEvent.MAP_CHARACTER_MOVE, {
|
||||
characterId: mapCharacter.character.id,
|
||||
positionX: options.targetX,
|
||||
positionY: options.targetY,
|
||||
@ -75,7 +76,7 @@ class CharacterTeleportService {
|
||||
if (currentMapId) {
|
||||
socket.leave(currentMapId)
|
||||
MapManager.removeCharacter(characterId)
|
||||
io.in(currentMapId).emit('map:character:leave', characterId)
|
||||
io.in(currentMapId).emit(SocketEvent.MAP_CHARACTER_LEAVE, characterId)
|
||||
}
|
||||
|
||||
// Join new map
|
||||
@ -86,8 +87,8 @@ class CharacterTeleportService {
|
||||
await mapRepository.getEntityManager().populate(map!, mapRepository.POPULATE_TELEPORT as any)
|
||||
|
||||
// Notify clients
|
||||
io.in(options.targetMapId).emit('map:character:join', mapCharacter)
|
||||
socket.emit('map:character:teleport', {
|
||||
io.in(options.targetMapId).emit(SocketEvent.MAP_CHARACTER_JOIN, mapCharacter)
|
||||
socket.emit(SocketEvent.MAP_CHARACTER_TELEPORT, {
|
||||
mapId: options.targetMapId,
|
||||
characters: targetMap.getCharactersInMap()
|
||||
})
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SocketEvent } from '#application/enums';
|
||||
import type { UUID } from '#application/types'
|
||||
|
||||
import { BaseService } from '#application/base/baseService'
|
||||
@ -22,7 +23,7 @@ class ChatService extends BaseService {
|
||||
await chat.setCharacter(character).setMap(map).setMessage(message).save()
|
||||
|
||||
const io = SocketManager.getIO()
|
||||
io.to(mapId).emit('chat:message', chat)
|
||||
io.to(mapId).emit(SocketEvent.CHAT_MESSAGE, chat)
|
||||
return true
|
||||
} catch (error: any) {
|
||||
this.logger.error(`Failed to save chat message: ${error instanceof Error ? error.message : String(error)}`)
|
||||
|
Reference in New Issue
Block a user