import { ServerSocketEvent } from '../../shared/models' ; import { ServerEvent , ServerEventName } from '../../shared/interfaces' ; export class SyncPlayersEvent extends ServerSocketEvent implements ServerEvent { event = ServerEventName . ChatPlayerListSync ; description = 'Get all currently connected players.' ; args = '' ; async callback ( ) { const player = this . player ; if ( ! player ) return this . notConnected ( ) ; this . emit ( ServerEventName . ChatPlayerListSync , this . game . playerManager . allSimplePlayers ) ; } } export class ChatMessageEvent extends ServerSocketEvent implements ServerEvent { event = ServerEventName . ChatMessage ; description = 'Send a chat message to the game.' ; args = 'message' ; async callback ( { message } = { message : '' } ) { const player = this . player ; if ( ! player ) return this . notConnected ( ) ; if ( ! player . modTier ) { if ( player . mutedUntil > Date . now ( ) ) { return this . gameError ( `You're muted, friendo. Come back at ${ new Date ( player . mutedUntil ) . toLocaleString ( ) }` ) ; } if ( player . mutedUntil ) { player . messageCooldown = 0 ; player . mutedUntil = 0 ; } if ( player . lastMessageSent ) { if ( player . lastMessageSent + 500 > Date . now ( ) ) { player . messageCooldown = player . messageCooldown || 0 ; player . messageCooldown ++ ; } else { player . messageCooldown = player . messageCooldown || 0 ; player . messageCooldown = Math . max ( player . messageCooldown , 0 ) ; } } player . lastMessageSent = Date . now ( ) ; if ( player . messageCooldown > 3 ) { player . mutedUntil = Date . now ( ) + 1000 * 60 * 15 ; } } message = message . slice ( 0 , 500 ) ; const playerGuild = this . game . guildManager . getGuild ( player . guildName ) ; this . game . chatHelper . sendMessageFromClient ( { timestamp : Date . now ( ) , message , guildTag : playerGuild ? playerGuild . tag : '' , realPlayerName : player . name , playerName : player . name , playerTitle : player . title ? `, the ${ player . title }` : '' , playerLevel : player . level . total , playerAscension : player . ascensionLevel , address : player . ip } ) ; } }