1
0
forked from noxious/server

Replaced all event names with numbers for less bandwidth usage

This commit is contained in:
2025-02-11 23:12:41 +01:00
parent 8b51f6e16a
commit 9e55ac7990
57 changed files with 193 additions and 98 deletions

View File

@ -1,9 +1,10 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { CharacterHair } from '#entities/characterHair'
export default class CharacterHairCreateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterHair:create', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERHAIR_CREATE, this.handleEvent.bind(this))
}
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -9,7 +10,7 @@ interface IPayload {
export default class CharacterHairDeleteEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterHair:remove', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERHAIR_REMOVE, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { CharacterHair } from '#entities/characterHair'
import CharacterHairRepository from '#repositories/characterHairRepository'
@ -6,7 +7,7 @@ interface IPayload {}
export default class characterHairListEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterHair:list', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERHAIR_LIST, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: CharacterHair[]) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -15,7 +16,7 @@ type Payload = {
export default class CharacterHairUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterHair:update', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERHAIR_UPDATE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {

View File

@ -1,9 +1,10 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { CharacterType } from '#entities/characterType'
export default class CharacterTypeCreateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterType:create', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERTYPE_CREATE, this.handleEvent.bind(this))
}
private async handleEvent(data: undefined, callback: (response: boolean, characterType?: any) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -9,7 +10,7 @@ interface IPayload {
export default class CharacterTypeDeleteEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterType:remove', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERTYPE_REMOVE, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { CharacterType } from '#entities/characterType'
import CharacterTypeRepository from '#repositories/characterTypeRepository'
@ -6,7 +7,7 @@ interface IPayload {}
export default class CharacterTypeListEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterType:list', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERTYPE_LIST, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: CharacterType[]) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -16,7 +17,7 @@ type Payload = {
export default class CharacterTypeUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:characterType:update', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_CHARACTERTYPE_UPDATE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { ItemRarity, ItemType } from '#application/enums'
import { Item } from '#entities/item'
@ -5,7 +6,7 @@ import SpriteRepository from '#repositories/spriteRepository'
export default class ItemCreateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:item:create', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_ITEM_CREATE, this.handleEvent.bind(this))
}
private async handleEvent(data: undefined, callback: (response: boolean, item?: any) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -9,7 +10,7 @@ interface IPayload {
export default class ItemDeleteEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:item:remove', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_ITEM_REMOVE, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { Item } from '#entities/item'
import ItemRepository from '#repositories/itemRepository'
@ -6,7 +7,7 @@ interface IPayload {}
export default class ItemListEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:item:list', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_ITEM_LIST, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: Item[]) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -17,7 +18,7 @@ type Payload = {
export default class ItemUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:item:update', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_ITEM_UPDATE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { MapObject } from '#entities/mapObject'
import MapObjectRepository from '#repositories/mapObjectRepository'
@ -6,7 +7,7 @@ interface IPayload {}
export default class MapObjectListEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:mapObject:list', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAPOBJECT_LIST, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: MapObject[]) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import fs from 'fs'
import type { UUID } from '#application/types'
@ -12,7 +13,7 @@ interface IPayload {
export default class MapObjectRemoveEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:mapObject:remove', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAPOBJECT_REMOVE, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -16,7 +17,7 @@ type Payload = {
export default class MapObjectUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:mapObject:update', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAPOBJECT_UPDATE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {
@ -40,7 +41,7 @@ export default class MapObjectUpdateEvent extends BaseEvent {
return callback(true)
} catch (error) {
this.socket.emit('notification', { title: 'Error', message: 'Failed to update mapObject.' })
this.socket.emit(SocketEvent.NOTIFICATION, { title: 'Error', message: 'Failed to update mapObject.' })
return callback(false)
}
}

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import fs from 'fs/promises'
import { writeFile } from 'node:fs/promises'
@ -13,7 +14,7 @@ interface IObjectData {
export default class MapObjectUploadEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:mapObject:upload', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAPOBJECT_UPLOAD, this.handleEvent.bind(this))
}
private async handleEvent(data: IObjectData, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -10,7 +11,7 @@ interface CopyPayload {
export default class SpriteCopyEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:sprite:copy', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_SPRITE_COPY, this.handleEvent.bind(this))
}
private async handleEvent(payload: CopyPayload, callback: (success: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import fs from 'fs/promises'
import { BaseEvent } from '#application/base/baseEvent'
@ -6,7 +7,7 @@ import { Sprite } from '#entities/sprite'
export default class SpriteCreateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:sprite:create', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_SPRITE_CREATE, this.handleEvent.bind(this))
}
private async handleEvent(data: undefined, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import fs from 'fs'
import type { UUID } from '#application/types'
@ -12,7 +13,7 @@ type Payload = {
export default class GMSpriteDeleteEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:sprite:delete', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_SPRITE_DELETE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { Sprite } from '#entities/sprite'
import SpriteRepository from '#repositories/spriteRepository'
@ -6,7 +7,7 @@ interface IPayload {}
export default class SpriteListEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:sprite:list', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_SPRITE_LIST, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: Sprite[]) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import fs from 'fs'
import sharp from 'sharp'
@ -44,7 +45,7 @@ type Payload = {
export default class SpriteUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:sprite:update', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_SPRITE_UPDATE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import fs from 'fs/promises'
import type { UUID } from '#application/types'
@ -12,7 +13,7 @@ type Payload = {
export default class GMTileDeleteEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:tile:delete', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_TILE_DELETE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import { BaseEvent } from '#application/base/baseEvent'
import { Tile } from '#entities/tile'
import TileRepository from '#repositories/tileRepository'
@ -6,7 +7,7 @@ interface IPayload {}
export default class TileListEven extends BaseEvent {
public listen(): void {
this.socket.on('gm:tile:list', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_TILE_LIST, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: Tile[]) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -11,7 +12,7 @@ type Payload = {
export default class TileUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:tile:update', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_TILE_UPDATE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (success: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import fs from 'fs/promises'
import { writeFile } from 'node:fs/promises'
@ -11,7 +12,7 @@ interface ITileData {
export default class TileUploadEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:tile:upload', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_TILE_UPLOAD, this.handleEvent.bind(this))
}
private async handleEvent(data: ITileData, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { MapCacheT } from '#entities/map'
import { BaseEvent } from '#application/base/baseEvent'
@ -11,7 +12,7 @@ type Payload = {
export default class MapCreateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:map:create', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAP_CREATE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (response: MapCacheT | false) => void): Promise<void> {
@ -21,12 +22,12 @@ export default class MapCreateEvent extends BaseEvent {
this.logger.info(`GM ${(await this.getCharacter())!.getId()} has created a new map via map editor.`)
if (data.name === '') {
this.socket.emit('notification', { title: 'Error', message: 'Map name cannot be empty.' })
this.socket.emit(SocketEvent.NOTIFICATION, { title: 'Error', message: 'Map name cannot be empty.' })
return callback(false)
}
if (data.width < 1 || data.height < 1) {
this.socket.emit('notification', { title: 'Error', message: 'Map width and height must be greater than 0.' })
this.socket.emit(SocketEvent.NOTIFICATION, { title: 'Error', message: 'Map width and height must be greater than 0.' })
return callback(false)
}
@ -41,7 +42,7 @@ export default class MapCreateEvent extends BaseEvent {
return callback(await map.cache())
} catch (error: any) {
this.logger.error('gm:map:create error', error.message)
this.socket.emit('notification', { message: 'Failed to create map.' })
this.socket.emit(SocketEvent.NOTIFICATION, { message: 'Failed to create map.' })
return callback(false)
}
}

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -9,7 +10,7 @@ type Payload = {
export default class MapDeleteEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:map:delete', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAP_DELETE, this.handleEvent.bind(this))
}
private async handleEvent(data: Payload, callback: (response: boolean) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -10,7 +11,7 @@ interface IPayload {
export default class MapRequestEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:map:request', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAP_REQUEST, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: Map | null) => void): Promise<void> {

View File

@ -1,3 +1,4 @@
import { SocketEvent } from '#application/enums';
import type { UUID } from '#application/types'
import { BaseEvent } from '#application/base/baseEvent'
@ -34,7 +35,7 @@ interface IPayload {
export default class MapUpdateEvent extends BaseEvent {
public listen(): void {
this.socket.on('gm:map:update', this.handleEvent.bind(this))
this.socket.on(SocketEvent.GM_MAP_UPDATE, this.handleEvent.bind(this))
}
private async handleEvent(data: IPayload, callback: (response: Map | null) => void): Promise<void> {