Better streamlined naming in socket events

This commit is contained in:
Dennis Postma 2024-12-28 20:57:48 +01:00
parent 5b386ae455
commit 0b99d4098e
28 changed files with 56 additions and 56 deletions

View File

@ -10,10 +10,10 @@ interface CharacterConnectPayload {
export default class CharacterConnectEvent extends BaseEvent {
public listen(): void {
this.socket.on('character:connect', this.handleCharacterConnect.bind(this))
this.socket.on('character:connect', this.handleEvent.bind(this))
}
private async handleCharacterConnect({ characterId, characterHairId }: CharacterConnectPayload): Promise<void> {
private async handleEvent({ characterId, characterHairId }: CharacterConnectPayload): Promise<void> {
if (!this.socket.userId) {
this.emitError('User not authenticated')
return

View File

@ -8,10 +8,10 @@ import UserRepository from '#repositories/userRepository'
export default class CharacterCreateEvent extends BaseEvent {
public listen(): void {
this.socket.on('character:create', this.handleCharacterCreate.bind(this))
this.socket.on('character:create', this.handleEvent.bind(this))
}
private async handleCharacterCreate(data: any): Promise<any> {
private async handleEvent(data: any): Promise<any> {
// zod validate
try {
data = ZCharacterCreate.parse(data)

View File

@ -14,10 +14,10 @@ type TypeResponse = {
export default class CharacterDeleteEvent extends BaseEvent {
public listen(): void {
this.socket.on('character:delete', this.handleCharacterDelete.bind(this))
this.socket.on('character:delete', this.handleEvent.bind(this))
}
private async handleCharacterDelete(data: TypePayload, callback: (response: TypeResponse) => void): Promise<any> {
private async handleEvent(data: TypePayload, callback: (response: TypeResponse) => void): Promise<any> {
try {
const character = await CharacterRepository.getByUserAndId(this.socket.userId!, data.characterId)
if (character) {

View File

@ -8,10 +8,10 @@ type TypePayload = {
export default class AlertCommandEvent extends BaseEvent {
public listen(): void {
this.socket.on('chat:message', this.handleAlertCommand.bind(this))
this.socket.on('chat:message', this.handleEvent.bind(this))
}
private async handleAlertCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
try {
if (!ChatService.isCommand(data.message, 'alert')) {
return

View File

@ -9,10 +9,10 @@ type TypePayload = {
export default class SetTimeCommand extends BaseEvent {
public listen(): void {
this.socket.on('chat:message', this.handleAlertCommand.bind(this))
this.socket.on('chat:message', this.handleEvent.bind(this))
}
private async handleAlertCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
try {
if (!ChatService.isCommand(data.message, 'time')) {
return

View File

@ -11,10 +11,10 @@ type TypePayload = {
export default class TeleportCommandEvent extends BaseEvent {
public listen(): void {
this.socket.on('chat:message', this.handleTeleportCommand.bind(this))
this.socket.on('chat:message', this.handleEvent.bind(this))
}
private async handleTeleportCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
try {
// Check if character exists
const zoneCharacter = ZoneManager.getCharacterById(this.socket.characterId!)

View File

@ -9,10 +9,10 @@ type TypePayload = {
export default class ToggleFogCommand extends BaseEvent {
public listen(): void {
this.socket.on('chat:message', this.handleAlertCommand.bind(this))
this.socket.on('chat:message', this.handleEvent.bind(this))
}
private async handleAlertCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
try {
if (!ChatService.isCommand(data.message, 'fog')) {
return

View File

@ -9,10 +9,10 @@ type TypePayload = {
export default class ToggleRainCommand extends BaseEvent {
public listen(): void {
this.socket.on('chat:message', this.handleAlertCommand.bind(this))
this.socket.on('chat:message', this.handleEvent.bind(this))
}
private async handleAlertCommand(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: TypePayload, callback: (response: boolean) => void): Promise<void> {
try {
if (!ChatService.isCommand(data.message, 'rain')) {
return

View File

@ -15,10 +15,10 @@ type Payload = {
export default class CharacterHairUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterHair:update', this.handleObjectUpdate.bind(this))
this.socket.on('gm:characterHair:update', this.handleEvent.bind(this))
}
private async handleObjectUpdate(data: Payload, callback: (success: boolean) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -21,10 +21,10 @@ export default class CharacterTypeUpdateEvent {
) {}
public listen(): void {
this.socket.on('gm:characterType:update', this.handleObjectUpdate.bind(this))
this.socket.on('gm:characterType:update', this.handleEvent.bind(this))
}
private async handleObjectUpdate(data: Payload, callback: (success: boolean) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -23,10 +23,10 @@ export default class ItemUpdateEvent {
) {}
public listen(): void {
this.socket.on('gm:item:update', this.handleObjectUpdate.bind(this))
this.socket.on('gm:item:update', this.handleEvent.bind(this))
}
private async handleObjectUpdate(data: Payload, callback: (success: boolean) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -14,10 +14,10 @@ export default class ObjectListEvent {
) {}
public listen(): void {
this.socket.on('gm:object:list', this.handleObjectList.bind(this))
this.socket.on('gm:object:list', this.handleEvent.bind(this))
}
private async handleObjectList(data: IPayload, callback: (response: Object[]) => void): Promise<void> {
private async handleEvent(data: IPayload, callback: (response: Object[]) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback([])

View File

@ -19,10 +19,10 @@ export default class ObjectRemoveEvent {
) {}
public listen(): void {
this.socket.on('gm:object:remove', this.handleObjectRemove.bind(this))
this.socket.on('gm:object:remove', this.handleEvent.bind(this))
}
private async handleObjectRemove(data: IPayload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -23,10 +23,10 @@ export default class ObjectUpdateEvent {
) {}
public listen(): void {
this.socket.on('gm:object:update', this.handleObjectUpdate.bind(this))
this.socket.on('gm:object:update', this.handleEvent.bind(this))
}
private async handleObjectUpdate(data: Payload, callback: (success: boolean) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -21,10 +21,10 @@ export default class ObjectUploadEvent {
) {}
public listen(): void {
this.socket.on('gm:object:upload', this.handleObjectUpload.bind(this))
this.socket.on('gm:object:upload', this.handleEvent.bind(this))
}
private async handleObjectUpload(data: IObjectData, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: IObjectData, callback: (response: boolean) => void): Promise<void> {
try {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -18,10 +18,10 @@ export default class SpriteCopyEvent {
) {}
public listen(): void {
this.socket.on('gm:sprite:copy', this.handleSpriteCopy.bind(this))
this.socket.on('gm:sprite:copy', this.handleEvent.bind(this))
}
private async handleSpriteCopy(payload: CopyPayload, callback: (success: boolean) => void): Promise<void> {
private async handleEvent(payload: CopyPayload, callback: (success: boolean) => void): Promise<void> {
try {
if (!(await this.validateGameMasterAccess())) {
return callback(false)

View File

@ -14,10 +14,10 @@ export default class SpriteCreateEvent {
) {}
public listen(): void {
this.socket.on('gm:sprite:create', this.handleSpriteCreate.bind(this))
this.socket.on('gm:sprite:create', this.handleEvent.bind(this))
}
private async handleSpriteCreate(data: undefined, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {
try {
const character = await characterRepository.getById(this.socket.characterId!)
if (!character) return callback(false)

View File

@ -14,10 +14,10 @@ export default class SpriteListEvent {
) {}
public listen(): void {
this.socket.on('gm:sprite:list', this.handleSpriteList.bind(this))
this.socket.on('gm:sprite:list', this.handleEvent.bind(this))
}
private async handleSpriteList(data: any, callback: (response: Sprite[]) => void): Promise<void> {
private async handleEvent(data: any, callback: (response: Sprite[]) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId!)
if (!character) return callback([])

View File

@ -69,10 +69,10 @@ export default class SpriteUpdateEvent {
) {}
public listen(): void {
this.socket.on('gm:sprite:update', this.handleSpriteUpdate.bind(this))
this.socket.on('gm:sprite:update', this.handleEvent.bind(this))
}
private async handleSpriteUpdate(payload: UpdatePayload, callback: (success: boolean) => void): Promise<void> {
private async handleEvent(payload: UpdatePayload, callback: (success: boolean) => void): Promise<void> {
try {
if (!(await this.validateGameMasterAccess())) {
return callback(false)

View File

@ -23,10 +23,10 @@ export default class GMTileDeleteEvent {
}
public listen(): void {
this.socket.on('gm:tile:delete', this.handleTileDelete.bind(this))
this.socket.on('gm:tile:delete', this.handleEvent.bind(this))
}
private async handleTileDelete(data: Payload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -14,10 +14,10 @@ export default class TileListEvent {
) {}
public listen(): void {
this.socket.on('gm:tile:list', this.handleTileList.bind(this))
this.socket.on('gm:tile:list', this.handleEvent.bind(this))
}
private async handleTileList(data: any, callback: (response: Tile[]) => void): Promise<void> {
private async handleEvent(data: any, callback: (response: Tile[]) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return

View File

@ -17,10 +17,10 @@ export default class TileUpdateEvent {
) {}
public listen(): void {
this.socket.on('gm:tile:update', this.handleTileUpdate.bind(this))
this.socket.on('gm:tile:update', this.handleEvent.bind(this))
}
private async handleTileUpdate(data: Payload, callback: (success: boolean) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -20,10 +20,10 @@ export default class TileUploadEvent {
) {}
public listen(): void {
this.socket.on('gm:tile:upload', this.handleTileUpload.bind(this))
this.socket.on('gm:tile:upload', this.handleEvent.bind(this))
}
private async handleTileUpload(data: ITileData, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: ITileData, callback: (response: boolean) => void): Promise<void> {
try {
const character = await characterRepository.getById(this.socket.characterId as number)
if (!character) return callback(false)

View File

@ -20,10 +20,10 @@ export default class ZoneCreateEvent {
) {}
public listen(): void {
this.socket.on('gm:zone_editor:zone:create', this.handleZoneCreate.bind(this))
this.socket.on('gm:zone_editor:zone:create', this.handleEvent.bind(this))
}
private async handleZoneCreate(data: Payload, callback: (response: Zone[]) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (response: Zone[]) => void): Promise<void> {
try {
const character = await CharacterRepository.getById(this.socket.characterId as number)
if (!character) {

View File

@ -17,10 +17,10 @@ export default class ZoneDeleteEvent {
) {}
public listen(): void {
this.socket.on('gm:zone_editor:zone:delete', this.handleZoneDelete.bind(this))
this.socket.on('gm:zone_editor:zone:delete', this.handleEvent.bind(this))
}
private async handleZoneDelete(data: Payload, callback: (response: boolean) => void): Promise<void> {
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {
try {
const character = await CharacterRepository.getById(this.socket.characterId as number)
if (!character) {

View File

@ -15,10 +15,10 @@ export default class ZoneListEvent {
) {}
public listen(): void {
this.socket.on('gm:zone_editor:zone:list', this.handleZoneList.bind(this))
this.socket.on('gm:zone_editor:zone:list', this.handleEvent.bind(this))
}
private async handleZoneList(data: IPayload, callback: (response: Zone[]) => void): Promise<void> {
private async handleEvent(data: IPayload, callback: (response: Zone[]) => void): Promise<void> {
try {
const character = await CharacterRepository.getById(this.socket.characterId as number)
if (!character) {

View File

@ -17,10 +17,10 @@ export default class ZoneRequestEvent {
) {}
public listen(): void {
this.socket.on('gm:zone_editor:zone:request', this.handleZoneRequest.bind(this))
this.socket.on('gm:zone_editor:zone:request', this.handleEvent.bind(this))
}
private async handleZoneRequest(data: IPayload, callback: (response: Zone | null) => void): Promise<void> {
private async handleEvent(data: IPayload, callback: (response: Zone | null) => void): Promise<void> {
try {
const character = await CharacterRepository.getById(this.socket.characterId as number)
if (!character) {

View File

@ -3,10 +3,10 @@ import UserRepository from '#repositories/userRepository'
export default class LoginEvent extends BaseEvent {
public listen(): void {
this.socket.on('login', this.handleLogin.bind(this))
this.socket.on('login', this.handleEvent.bind(this))
}
private handleLogin(): void {
private handleEvent(): void {
try {
if (!this.socket.userId) {
this.logger.warn('Login attempt without user data')