Rename events

This commit is contained in:
Thomas Smyth 2020-09-09 09:31:48 +01:00
parent 10ace52130
commit d139a41f88
30 changed files with 207 additions and 211 deletions

View File

@ -576,13 +576,13 @@ function aPluginToLogPlayerCountEvery60Seconds(server){
A more common approach in this version of SquadJS is to react to an event happening:
```js
function aPluginToLogTeamkills(server){
server.on(LOG_PARSER_TEAMKILL, info => {
server.on(TEAMKILL, info => {
console.log(info);
});
}
```
A complete list of events that you can listen for and the information included within each is found [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events/log-parser.js), [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events/rcon.js) and [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events/server.js).
A complete list of events that you can listen for and the information included within each is found [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events.js).
Various actions can be completed in a plugin. Most of these will involve outside system, e.g. Discord.js to run a Discord bot, so they are not documented here. However, you may run RCON commands using `server.rcon.execute("Command");`.

View File

@ -227,13 +227,13 @@ function aPluginToLogPlayerCountEvery60Seconds(server){
A more common approach in this version of SquadJS is to react to an event happening:
```js
function aPluginToLogTeamkills(server){
server.on(LOG_PARSER_TEAMKILL, info => {
server.on(TEAMKILL, info => {
console.log(info);
});
}
```
A complete list of events that you can listen for and the information included within each is found [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events/log-parser.js), [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events/rcon.js) and [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events/server.js).
A complete list of events that you can listen for and the information included within each is found [here](https://github.com/Thomas-Smyth/SquadJS/blob/master/squad-server/events.js).
Various actions can be completed in a plugin. Most of these will involve outside system, e.g. Discord.js to run a Discord bot, so they are not documented here. However, you may run RCON commands using `server.rcon.execute("Command");`.

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_TEAMKILL } from 'squad-server/events/log-parser';
import { TEAMKILL } from 'squad-server/events';
export default {
name: 'auto-tk-warn',
@ -17,7 +17,7 @@ export default {
},
init: async (server, options) => {
server.on(LOG_PARSER_TEAMKILL, (info) => {
server.on(TEAMKILL, (info) => {
// ignore suicides
if (info.attacker.steamID === info.victim.steamID) return;
server.rcon.warn(info.attacker.steamID, options.message);

View File

@ -1,5 +1,5 @@
import { COPYRIGHT_MESSAGE } from 'core/constants';
import { LOG_PARSER_ADMIN_BROADCAST } from 'squad-server/events/log-parser';
import { ADMIN_BROADCAST } from 'squad-server/events';
export default {
name: 'discord-admin-broadcast',
@ -31,7 +31,7 @@ export default {
init: async (server, options) => {
const channel = await options.discordClient.channels.fetch(options.channelID);
server.on(LOG_PARSER_ADMIN_BROADCAST, async (info) => {
server.on(ADMIN_BROADCAST, async (info) => {
channel.send({
embed: {
title: 'Admin Broadcast',

View File

@ -1,8 +1,5 @@
import { COPYRIGHT_MESSAGE } from 'core/constants';
import {
LOG_PARSER_PLAYER_POSSESS,
LOG_PARSER_PLAYER_UNPOSSESS
} from 'squad-server/events/log-parser';
import { PLAYER_POSSESS, PLAYER_UNPOSSESS } from 'squad-server/events';
export default {
name: 'discord-admin-cam-logs',
@ -36,7 +33,7 @@ export default {
const adminsInCam = {};
server.on(LOG_PARSER_PLAYER_POSSESS, (info) => {
server.on(PLAYER_POSSESS, (info) => {
if (info.player === null || info.possessClassname !== 'CameraMan') return;
adminsInCam[info.player.steamID] = info.time;
@ -65,7 +62,7 @@ export default {
});
});
server.on(LOG_PARSER_PLAYER_UNPOSSESS, (info) => {
server.on(PLAYER_UNPOSSESS, (info) => {
if (info.switchPossess === true || !(info.player.steamID in adminsInCam)) return;
channel.send({

View File

@ -1,5 +1,5 @@
import { COPYRIGHT_MESSAGE } from 'core/constants';
import { RCON_CHAT_MESSAGE } from 'squad-server/events/rcon';
import { CHAT_MESSAGE } from 'squad-server/events';
export default {
name: 'discord-admin-request',
@ -64,7 +64,7 @@ export default {
const channel = await options.discordClient.channels.fetch(options.channelID);
server.on(RCON_CHAT_MESSAGE, async (info) => {
server.on(CHAT_MESSAGE, async (info) => {
if (options.ignoreChats.includes(info.chat)) return;
if (!info.message.startsWith(`${options.adminPrefix}`)) return;

View File

@ -1,5 +1,5 @@
import { COPYRIGHT_MESSAGE } from 'core/constants';
import { RCON_CHAT_MESSAGE } from 'squad-server/events/rcon';
import { CHAT_MESSAGE } from 'squad-server/events';
export default {
name: 'discord-chat',
@ -42,7 +42,7 @@ export default {
init: async (server, options) => {
const channel = await options.discordClient.channels.fetch(options.channelID);
server.on(RCON_CHAT_MESSAGE, async (info) => {
server.on(CHAT_MESSAGE, async (info) => {
if (options.ignoreChats.includes(info.chat)) return;
const playerInfo = await server.getPlayerBySteamID(info.steamID);

View File

@ -1,7 +1,7 @@
import tinygradient from 'tinygradient';
import { COPYRIGHT_MESSAGE } from 'core/constants';
import { SERVER_A2S_UPDATED } from 'squad-server/events/server';
import { A2S_INFO_UPDATED } from 'squad-server/events';
export default {
name: 'discord-server-status',
@ -77,7 +77,7 @@ export default {
await reaction.message.edit(makeEmbed(server, options));
});
server.on(SERVER_A2S_UPDATED, () => {
server.on(A2S_INFO_UPDATED, () => {
if (!options.disableStatus)
options.discordClient.user.setActivity(
`(${server.playerCount}/${server.publicSlots}) ${server.currentLayer}`,

View File

@ -1,5 +1,5 @@
import { COPYRIGHT_MESSAGE } from 'core/constants';
import { LOG_PARSER_TEAMKILL } from 'squad-server/events/log-parser';
import { TEAMKILL } from 'squad-server/events';
export default {
name: 'discord-teamkill',
@ -49,7 +49,7 @@ export default {
init: async (server, options) => {
const channel = await options.discordClient.channels.fetch(options.channelID);
server.on(LOG_PARSER_TEAMKILL, (info) => {
server.on(TEAMKILL, (info) => {
if (!info.attacker) return;
if (options.ignoreSuicides && info.suicide) return;

View File

@ -1,7 +1,6 @@
import { SquadLayerFilter } from 'core/squad-layers';
import { COPYRIGHT_MESSAGE } from 'core/constants';
import { LOG_PARSER_NEW_GAME } from 'squad-server/events/log-parser';
import { RCON_CHAT_MESSAGE } from 'squad-server/events/rcon';
import { NEW_GAME, CHAT_MESSAGE } from 'squad-server/events';
import MapVote from './mapvote.js';
@ -36,11 +35,11 @@ export default {
init: async (server, options) => {
let mapvote = null;
server.on(LOG_PARSER_NEW_GAME, () => {
server.on(NEW_GAME, () => {
mapvote = null;
});
server.on(RCON_CHAT_MESSAGE, async (info) => {
server.on(CHAT_MESSAGE, async (info) => {
const voteMatch = info.message.match(/^([0-9])/);
if (voteMatch) {
if (!mapvote) return;

View File

@ -1,6 +1,5 @@
import { COPYRIGHT_MESSAGE } from 'core/constants';
import { LOG_PARSER_NEW_GAME } from 'squad-server/events/log-parser';
import { RCON_CHAT_MESSAGE } from 'squad-server/events/rcon';
import { NEW_GAME, CHAT_MESSAGE } from 'squad-server/events';
import MapVote from './mapvote.js';
@ -75,7 +74,7 @@ export default {
if (options.alwaysOn) newMapvote(false);
server.on(LOG_PARSER_NEW_GAME, () => {
server.on(NEW_GAME, () => {
if (options.alwaysOn) {
newMapvote(false);
} else {
@ -83,7 +82,7 @@ export default {
}
});
server.on(RCON_CHAT_MESSAGE, async (info) => {
server.on(CHAT_MESSAGE, async (info) => {
const match = info.message.match(/^!mapvote ?(.*)/);
if (!match) return;

View File

@ -1,11 +1,11 @@
import {
LOG_PARSER_NEW_GAME,
LOG_PARSER_PLAYER_WOUNDED,
LOG_PARSER_PLAYER_DIED,
LOG_PARSER_PLAYER_REVIVED,
LOG_PARSER_SERVER_TICK_RATE
} from 'squad-server/events/log-parser';
import { SERVER_PLAYERS_UPDATED } from 'squad-server/events/server';
NEW_GAME,
PLAYER_WOUNDED,
PLAYER_DIED,
PLAYER_REVIVED,
TICK_RATE,
PLAYERS_UPDATED
} from 'squad-server/events';
export default {
name: 'mysql-log',
@ -49,21 +49,21 @@ export default {
init: async (server, options) => {
const serverID = options.overrideServerID === null ? server.id : options.overrideServerID;
server.on(LOG_PARSER_SERVER_TICK_RATE, (info) => {
server.on(TICK_RATE, (info) => {
options.mysqlPool.query(
'INSERT INTO ServerTickRate(time, server, tick_rate) VALUES (?,?,?)',
[info.time, serverID, info.tickRate]
);
});
server.on(SERVER_PLAYERS_UPDATED, (players) => {
server.on(PLAYERS_UPDATED, (players) => {
options.mysqlPool.query(
'INSERT INTO PlayerCount(time, server, player_count) VALUES (NOW(),?,?)',
[serverID, players.length]
);
});
server.on(LOG_PARSER_NEW_GAME, (info) => {
server.on(NEW_GAME, (info) => {
options.mysqlPool.query('call NewMatch(?,?,?,?,?,?,?)', [
serverID,
info.time,
@ -75,7 +75,7 @@ export default {
]);
});
server.on(LOG_PARSER_PLAYER_WOUNDED, (info) => {
server.on(PLAYER_WOUNDED, (info) => {
options.mysqlPool.query('call InsertPlayerWounded(?,?,?,?,?,?,?,?,?,?,?,?,?)', [
serverID,
info.time,
@ -93,7 +93,7 @@ export default {
]);
});
server.on(LOG_PARSER_PLAYER_DIED, (info) => {
server.on(PLAYER_DIED, (info) => {
options.mysqlPool.query('call InsertPlayerDied(?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [
serverID,
info.time,
@ -112,7 +112,7 @@ export default {
]);
});
server.on(LOG_PARSER_PLAYER_REVIVED, (info) => {
server.on(PLAYER_REVIVED, (info) => {
options.mysqlPool.query('call InsertPlayerRevived(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', [
serverID,
info.time,

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_CONNECTED } from 'squad-server/events/log-parser';
import { PLAYER_CONNECTED } from 'squad-server/events';
export default {
name: 'seeding-message',
@ -79,7 +79,7 @@ export default {
break;
case 'onjoin':
server.on(LOG_PARSER_PLAYER_CONNECTED, () => {
server.on(PLAYER_CONNECTED, () => {
setTimeout(() => {
const playerCount = server.players.length;

View File

@ -1,4 +1,4 @@
import { RCON_CHAT_MESSAGE } from 'squad-server/events/rcon';
import { CHAT_MESSAGE } from 'squad-server/events';
export default {
name: 'team-randomizer',
@ -19,7 +19,7 @@ export default {
init: async (server, options) => {
const commandRegex = new RegExp(`^${options.command}`, 'i');
server.on(RCON_CHAT_MESSAGE, (info) => {
server.on(CHAT_MESSAGE, (info) => {
if (info.chat !== 'ChatAdmin') return;
const match = info.message.match(commandRegex);

View File

@ -1,3 +1,44 @@
/** Occurs when the player list is updated via RCON.
*
* Data:
* - Array of PlayerObjects
*/
const PLAYERS_UPDATED = 'PLAYERS_UPDATED';
/** Occurs when the layer info is updated via RCON.
*
* Data:
* - currentLayer - Current layer.
* - nextLayer - Next layer.
*/
const LAYERS_UPDATED = 'LAYERS_UPDATED';
/** Occurs when the server info is updated via A2S.
*
* Data:
* - serverName - Name of the server.
* - maxPlayers - Maximum number of players on the server.
* - publicSlots - Maximum number of public slots.
* - reserveSlots - Maximum number of reserved slots.
* - playerCount - Player count as per A2S query.
* - publicQueue - Length of the public queue.
* - reserveQueue - Length of the reserved queue.
* - matchTimeout - Time until match ends?
* - gameVersion - Game version.
*/
const A2S_INFO_UPDATED = 'A2S_INFO_UPDATED';
/** Occurs when an admin enters admin camera.
*
* Data:
* - chat - Chat the message was sent to.
* - steamID - Steam ID of the player.
* - player - Name of the player.
* - message - Message sent.
* - time - Time message was sent, AKA now.
*/
const CHAT_MESSAGE = 'CHAT_MESSAGE';
/** Occurs when an admin broadcast is made.
*
* Data:
@ -5,7 +46,7 @@
* - message - The message that was broadcasted.
* - from - Apparently who broadcasted it, but this is broken in Squad logs.
*/
const LOG_PARSER_ADMIN_BROADCAST = 'LOG_PARSER_ADMIN_BROADCAST';
const ADMIN_BROADCAST = 'ADMIN_BROADCAST';
/** Occurs when a new layer is loaded.
*
@ -17,7 +58,37 @@ const LOG_PARSER_ADMIN_BROADCAST = 'LOG_PARSER_ADMIN_BROADCAST';
* - map - Map name (if known).
* - layer - Layer name (if known).
*/
const LOG_PARSER_NEW_GAME = 'LOG_PARSER_NEW_GAME';
const NEW_GAME = 'NEW_GAME';
/** Occurs when a player possess a new object.
*
* Data:
* - time - Date object of when the event occurred.
* - player - PlayerObject of the admin.
* - possessClassname - Classname of the object.
*/
const PLAYER_POSSESS = 'PLAYER_POSSESS';
/** Occurs when a player unpossess an object.
*
* Data:
* - time - Date object of when the event occurred.
* - player - PlayerObject of the admin.
* - switchPossess - True if switching a possess.
*/
const PLAYER_UNPOSSESS = 'PLAYER_UNPOSSESS';
/** Occurs when a new layer is loaded.
*
* Data:
* - time - Date object of when the event occurred.
* - dlc - DLC / Mod the layer was loaded from.
* - mapClassname - Classname of the map.
* - layerClassname - Classname of the layer.
* - map - Map name (if known).
* - layer - Layer name (if known).
*/
const LAYER_CHANGE = 'LAYER_CHANGE';
/** Occurs when a new player connects.
*
@ -25,7 +96,7 @@ const LOG_PARSER_NEW_GAME = 'LOG_PARSER_NEW_GAME';
* - time - Date object of when the event occurred.
* - player - PlayerObject of the player.
*/
const LOG_PARSER_PLAYER_CONNECTED = 'LOG_PARSER_PLAYER_CONNECTED';
const PLAYER_CONNECTED = 'PLAYER_CONNECTED';
/** Occurs when a player is damaged.
*
@ -36,7 +107,35 @@ const LOG_PARSER_PLAYER_CONNECTED = 'LOG_PARSER_PLAYER_CONNECTED';
* - attacker - PlayerObject of the attacking player.
* - weapon - The classname of the weapon used.
*/
const LOG_PARSER_PLAYER_DAMAGED = 'LOG_PARSER_PLAYER_DAMAGED';
const PLAYER_DAMAGED = 'PLAYER_DAMAGED';
/** Occurs when a player is wounded.
*
* Data:
* - time - Date object of when the event occurred.
* - victim - PlayerObject of the damaged player.
* - damage - Amount of damage inflicted.
* - attacker - PlayerObject of the attacking player.
* - attackerPlayerController - PlayerController of the attacking player.
* - weapon - The classname of the weapon used.
* - teamkill - Whether the kill was a teamkill.
* - suicide - Was the kill a suicide.
*/
const PLAYER_WOUNDED = 'PLAYER_WOUNDED';
/** Occurs when a player is teamkilled.
*
* Data:
* - time - Date object of when the event occurred.
* - victim - PlayerObject of the damaged player.
* - damage - Amount of damage inflicted.
* - attacker - PlayerObject of the attacking player.
* - attackerPlayerController - PlayerController of the attacking player.
* - weapon - The classname of the weapon used.
* - teamkill - Whether the kill was a teamkill.
* - suicide - Was the kill a suicide.
*/
const TEAMKILL = 'TEAMKILL';
/** Occurs when a player dies.
*
@ -51,16 +150,7 @@ const LOG_PARSER_PLAYER_DAMAGED = 'LOG_PARSER_PLAYER_DAMAGED';
* - teamkill - Whether the kill was a teamkill.
* - suicide - Was the kill a suicide.
*/
const LOG_PARSER_PLAYER_DIED = 'LOG_PARSER_PLAYER_DIED';
/** Occurs when a player possess a new object.
*
* Data:
* - time - Date object of when the event occurred.
* - player - PlayerObject of the admin.
* - possessClassname - Classname of the object.
*/
const LOG_PARSER_PLAYER_POSSESS = 'LOG_PARSER_PLAYER_POSSESS';
const PLAYER_DIED = 'PLAYER_DIED';
/** Occurs when a player is revived.
*
@ -76,44 +166,7 @@ const LOG_PARSER_PLAYER_POSSESS = 'LOG_PARSER_PLAYER_POSSESS';
* - suicide - Was the kill a suicide.
* - reviver - PlayerObject of the reviving player.
*/
const LOG_PARSER_PLAYER_REVIVED = 'LOG_PARSER_PLAYER_REVIVED';
/** Occurs when a player unpossess an object.
*
* Data:
* - time - Date object of when the event occurred.
* - player - PlayerObject of the admin.
* - switchPossess - True if switching a possess.
*/
const LOG_PARSER_PLAYER_UNPOSSESS = 'LOG_PARSER_PLAYER_UNPOSSESS';
/** Occurs when a player is teamkilled.
*
* Data:
* - time - Date object of when the event occurred.
* - victim - PlayerObject of the damaged player.
* - damage - Amount of damage inflicted.
* - attacker - PlayerObject of the attacking player.
* - attackerPlayerController - PlayerController of the attacking player.
* - weapon - The classname of the weapon used.
* - teamkill - Whether the kill was a teamkill.
* - suicide - Was the kill a suicide.
*/
const LOG_PARSER_TEAMKILL = 'LOG_PARSER_TEAMKILL';
/** Occurs when a player is wounded.
*
* Data:
* - time - Date object of when the event occurred.
* - victim - PlayerObject of the damaged player.
* - damage - Amount of damage inflicted.
* - attacker - PlayerObject of the attacking player.
* - attackerPlayerController - PlayerController of the attacking player.
* - weapon - The classname of the weapon used.
* - teamkill - Whether the kill was a teamkill.
* - suicide - Was the kill a suicide.
*/
const LOG_PARSER_PLAYER_WOUNDED = 'LOG_PARSER_PLAYER_WOUNDED';
const PLAYER_REVIVED = 'PLAYER_REVIVED';
/** Occurs when the server tick rate is updated.
*
@ -121,18 +174,31 @@ const LOG_PARSER_PLAYER_WOUNDED = 'LOG_PARSER_PLAYER_WOUNDED';
* - time - Date object of when the event occurred.
* - tickRate - Tick rate of the server.
*/
const LOG_PARSER_SERVER_TICK_RATE = 'LOG_PARSER_SERVER_TICK_RATE';
const TICK_RATE = 'TICK_RATE';
/** Occurs when an RCON error occurs.
*
* Data:
* - ErrorObject
*/
const RCON_ERROR = 'RCON_ERROR';
export {
LOG_PARSER_ADMIN_BROADCAST,
LOG_PARSER_NEW_GAME,
LOG_PARSER_PLAYER_CONNECTED,
LOG_PARSER_PLAYER_DAMAGED,
LOG_PARSER_PLAYER_DIED,
LOG_PARSER_PLAYER_POSSESS,
LOG_PARSER_PLAYER_REVIVED,
LOG_PARSER_PLAYER_UNPOSSESS,
LOG_PARSER_TEAMKILL,
LOG_PARSER_PLAYER_WOUNDED,
LOG_PARSER_SERVER_TICK_RATE
PLAYERS_UPDATED,
LAYERS_UPDATED,
A2S_INFO_UPDATED,
ADMIN_BROADCAST,
CHAT_MESSAGE,
NEW_GAME,
LAYER_CHANGE,
PLAYER_CONNECTED,
PLAYER_POSSESS,
PLAYER_UNPOSSESS,
PLAYER_DAMAGED,
TEAMKILL,
PLAYER_WOUNDED,
PLAYER_DIED,
PLAYER_REVIVED,
TICK_RATE,
RCON_ERROR
};

View File

@ -1,19 +0,0 @@
/** Occurs when an RCON error occurs.
*
* Data:
* - ErrorObject
*/
const RCON_ERROR = 'RCON_ERROR';
/** Occurs when an admin enters admin camera.
*
* Data:
* - chat - Chat the message was sent to.
* - steamID - Steam ID of the player.
* - player - Name of the player.
* - message - Message sent.
* - time - Time message was sent, AKA now.
*/
const RCON_CHAT_MESSAGE = 'RCON_CHAT_MESSAGE';
export { RCON_ERROR, RCON_CHAT_MESSAGE };

View File

@ -1,43 +0,0 @@
/** Occurs when a new layer is loaded.
*
* Data:
* - time - Date object of when the event occurred.
* - dlc - DLC / Mod the layer was loaded from.
* - mapClassname - Classname of the map.
* - layerClassname - Classname of the layer.
* - map - Map name (if known).
* - layer - Layer name (if known).
*/
const SERVER_LAYER_CHANGE = 'SERVER_LAYER_CHANGE';
/** Occurs when the player list is updated via RCON.
*
* Data:
* - Array of PlayerObjects
*/
const SERVER_PLAYERS_UPDATED = 'SERVER_PLAYERS_UPDATED';
/** Occurs when the layer info is updated via RCON.
*
* Data:
* - currentLayer - Current layer.
* - nextLayer - Next layer.
*/
const SERVER_LAYERS_UPDATED = 'SERVER_LAYERS_UPDATED';
/** Occurs when the server info is updated via A2S.
*
* Data:
* - serverName - Name of the server.
* - maxPlayers - Maximum number of players on the server.
* - publicSlots - Maximum number of public slots.
* - reserveSlots - Maximum number of reserved slots.
* - playerCount - Player count as per A2S query.
* - publicQueue - Length of the public queue.
* - reserveQueue - Length of the reserved queue.
* - matchTimeout - Time until match ends?
* - gameVersion - Game version.
*/
const SERVER_A2S_UPDATED = 'SERVER_A2S_UPDATED';
export { SERVER_LAYER_CHANGE, SERVER_PLAYERS_UPDATED, SERVER_LAYERS_UPDATED, SERVER_A2S_UPDATED };

View File

@ -6,13 +6,12 @@ import LogParser from './log-parser/index.js';
import Rcon from './rcon/index.js';
import {
SERVER_LAYER_CHANGE,
SERVER_PLAYERS_UPDATED,
SERVER_LAYERS_UPDATED,
SERVER_A2S_UPDATED
} from './events/server.js';
import { LOG_PARSER_NEW_GAME } from './events/log-parser.js';
LAYER_CHANGE,
PLAYERS_UPDATED,
LAYERS_UPDATED,
A2S_INFO_UPDATED,
NEW_GAME
} from './events.js';
export default class Server extends EventEmitter {
constructor(options = {}) {
@ -44,7 +43,7 @@ export default class Server extends EventEmitter {
this.suffixStore = {};
// setup internal listeners
this.on(LOG_PARSER_NEW_GAME, this.onLayerChange.bind(this));
this.on(NEW_GAME, this.onLayerChange.bind(this));
// setup period updaters
this.updatePlayers = this.updatePlayers.bind(this);
@ -54,7 +53,7 @@ export default class Server extends EventEmitter {
const data = await this.rcon.getMapInfo();
this.currentLayer = data.currentLayer;
this.nextLayer = data.nextLayer;
this.emit(SERVER_LAYERS_UPDATED, data);
this.emit(LAYERS_UPDATED, data);
}, this.updateInterval);
setInterval(async () => {
@ -77,7 +76,7 @@ export default class Server extends EventEmitter {
this.matchTimeout = parseFloat(data.raw.rules.MatchTimeout_f);
this.gameVersion = data.raw.version;
this.emit(SERVER_A2S_UPDATED, {
this.emit(A2S_INFO_UPDATED, {
serverName: this.serverName,
maxPlayers: this.maxPlayers,
publicSlots: this.publicSlots,
@ -116,7 +115,7 @@ export default class Server extends EventEmitter {
// delay another update
this.updatePlayerTimeout = setTimeout(this.updatePlayers, this.updateInterval);
this.emit(SERVER_PLAYERS_UPDATED, this.players);
this.emit(PLAYERS_UPDATED, this.players);
}
async getPlayerByName(name, suffix = false) {
@ -167,6 +166,6 @@ export default class Server extends EventEmitter {
onLayerChange(info) {
this.layerHistory.unshift(info);
this.layerHistory = this.layerHistory.slice(0, this.layerHistoryMaxLength);
this.emit(SERVER_LAYER_CHANGE, info);
this.emit(LAYER_CHANGE, info);
}
}

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_ADMIN_BROADCAST } from '../../events/log-parser.js';
import { ADMIN_BROADCAST } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquad: ADMIN COMMAND: Message broadcasted <(.+)> from (.+)/,
@ -11,6 +11,6 @@ export default {
from: args[4]
};
logParser.server.emit(LOG_PARSER_ADMIN_BROADCAST, data);
logParser.server.emit(ADMIN_BROADCAST, data);
}
};

View File

@ -1,6 +1,6 @@
import { SquadLayers } from 'core/squad-layers';
import { LOG_PARSER_NEW_GAME } from '../../events/log-parser.js';
import { NEW_GAME } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogWorld: Bringing World \/([A-z]+)\/Maps\/([A-z]+)\/(?:Gameplay_Layers\/)?([A-z0-9_]+)/,
@ -19,6 +19,6 @@ export default {
};
/* Emit new game event */
logParser.server.emit(LOG_PARSER_NEW_GAME, data);
logParser.server.emit(NEW_GAME, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_CONNECTED } from '../../events/log-parser.js';
import { PLAYER_CONNECTED } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogNet: Join succeeded: (.+)/,
@ -12,6 +12,6 @@ export default {
player: await logParser.server.getPlayerByName(args[3], true)
};
logParser.server.emit(LOG_PARSER_PLAYER_CONNECTED, data);
logParser.server.emit(PLAYER_CONNECTED, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_DAMAGED } from '../../events/log-parser.js';
import { PLAYER_DAMAGED } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquad: Player:(.+) ActualDamage=([0-9.]+) from (.+) caused by ([A-z_0-9]+)_C/,
@ -18,6 +18,6 @@ export default {
logParser.eventStore[args[3]] = data;
logParser.server.emit(LOG_PARSER_PLAYER_DAMAGED, data);
logParser.server.emit(PLAYER_DAMAGED, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_DIED } from '../../events/log-parser.js';
import { PLAYER_DIED } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer](?:ASQSoldier::)?Die\(\): Player:(.+) KillingDamage=(?:-)*([0-9.]+) from ([A-z_0-9]+) caused by ([A-z_0-9]+)_C/,
@ -19,6 +19,6 @@ export default {
logParser.eventStore[args[3]] = data;
logParser.server.emit(LOG_PARSER_PLAYER_DIED, data);
logParser.server.emit(PLAYER_DIED, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_POSSESS } from '../../events/log-parser.js';
import { PLAYER_POSSESS } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer](?:ASQPlayerController::)?OnPossess\(\): PC=(.+) Pawn=([A-z0-9_]+)_C/,
@ -13,6 +13,6 @@ export default {
logParser.eventStore[args[3]] = args[2];
logParser.server.emit(LOG_PARSER_PLAYER_POSSESS, data);
logParser.server.emit(PLAYER_POSSESS, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_REVIVED } from '../../events/log-parser.js';
import { PLAYER_REVIVED } from '../../events.js';
export default {
// the names are currently the wrong way around in these logs
@ -13,6 +13,6 @@ export default {
reviver: await logParser.server.getPlayerByName(args[3])
};
logParser.server.emit(LOG_PARSER_PLAYER_REVIVED, data);
logParser.server.emit(PLAYER_REVIVED, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_UNPOSSESS } from '../../events/log-parser.js';
import { PLAYER_UNPOSSESS } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer](?:ASQPlayerController::)?OnUnPossess\(\): PC=(.+)/,
@ -15,6 +15,6 @@ export default {
data.switchPossess = true;
delete logParser.eventStore[args[3]];
logParser.server.emit(LOG_PARSER_PLAYER_UNPOSSESS, data);
logParser.server.emit(PLAYER_UNPOSSESS, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_PLAYER_WOUNDED, LOG_PARSER_TEAMKILL } from '../../events/log-parser.js';
import { PLAYER_WOUNDED, TEAMKILL } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquadTrace: \[DedicatedServer](?:ASQSoldier::)?Wound\(\): Player:(.+) KillingDamage=(?:-)*([0-9.]+) from ([A-z_0-9]+) caused by ([A-z_0-9]+)_C/,
@ -16,7 +16,7 @@ export default {
logParser.eventStore[args[3]] = data;
logParser.server.emit(LOG_PARSER_PLAYER_WOUNDED, data);
if (data.teamkill) logParser.server.emit(LOG_PARSER_TEAMKILL, data);
logParser.server.emit(PLAYER_WOUNDED, data);
if (data.teamkill) logParser.server.emit(TEAMKILL, data);
}
};

View File

@ -1,4 +1,4 @@
import { LOG_PARSER_SERVER_TICK_RATE } from '../../events/log-parser.js';
import { TICK_RATE } from '../../events.js';
export default {
regex: /^\[([0-9.:-]+)]\[([ 0-9]*)]LogSquad: USQGameState: Server Tick Rate: ([0-9.]+)/,
@ -10,6 +10,6 @@ export default {
tickRate: parseFloat(args[3])
};
logParser.server.emit(LOG_PARSER_SERVER_TICK_RATE, data);
logParser.server.emit(TICK_RATE, data);
}
};

View File

@ -12,9 +12,7 @@
},
"exports": {
".": "./index.js",
"./events/log-parser": "./events/log-parser.js",
"./events/rcon": "./events/rcon.js",
"./events/server": "./events/server.js",
"./events": "./events.js",
"./log-parser": "./log-parser/index.js",
"./rcon": "./rcon/index.js",
"./plugins": "./plugins/index.js"

View File

@ -5,7 +5,7 @@ import moment from 'moment';
import RCONProtocol from './protocol.js';
import { RCON_CHAT_MESSAGE, RCON_ERROR } from '../events/rcon.js';
import { CHAT_MESSAGE, RCON_ERROR } from '../events.js';
export default class Rcon {
constructor(options = {}, emitter) {
@ -256,7 +256,7 @@ export default class Rcon {
/\[(ChatAll|ChatTeam|ChatSquad|ChatAdmin)] \[SteamID:([0-9]{17})] (.+?) : (.*)/
);
this.emitter.emit(RCON_CHAT_MESSAGE, {
this.emitter.emit(CHAT_MESSAGE, {
raw: decodedPacket.body,
chat: message[1],
steamID: message[2],