This commit is contained in:
Thomas Smyth 2020-12-06 21:23:05 +00:00
parent 6107612fb2
commit 915ec298f3
12 changed files with 86 additions and 71 deletions

View File

@ -17,7 +17,7 @@ async function main() {
await server.watch();
// now mount the plugins
server.plugins.forEach(plugin => plugin.mount());
server.plugins.forEach((plugin) => plugin.mount());
}
main();

View File

@ -41,7 +41,10 @@ export default class SquadServerFactory {
if (!option.connector) continue;
// check the connector is listed in the options
if (!(optionName in pluginConfig)) throw new Error(`${Plugin.name}: ${optionName} (${option.connector} connector) is missing.`);
if (!(optionName in pluginConfig))
throw new Error(
`${Plugin.name}: ${optionName} (${option.connector} connector) is missing.`
);
// get the name of the connector
const connectorName = pluginConfig[optionName];
@ -50,17 +53,23 @@ export default class SquadServerFactory {
if (connectors[connectorName]) continue;
// create the connector
connectors[connectorName] = await SquadServerFactory.createConnector(server, option.connector, connectorName, config.connectors[connectorName])
connectors[connectorName] = await SquadServerFactory.createConnector(
server,
option.connector,
connectorName,
config.connectors[connectorName]
);
}
}
// initialise plugins
Logger.verbose('SquadServerFactory', 1, 'Initialising plugins...');
for(const pluginConfig of config.plugins) {
for (const pluginConfig of config.plugins) {
if (!pluginConfig.enabled) continue;
if (!plugins[pluginConfig.plugin]) throw new Error(`Plugin ${pluginConfig.plugin} does not exist.`);
if (!plugins[pluginConfig.plugin])
throw new Error(`Plugin ${pluginConfig.plugin} does not exist.`);
const Plugin = plugins[pluginConfig.plugin];
@ -81,7 +90,10 @@ export default class SquadServerFactory {
Logger.verbose('SquadServerFactory', 1, `Starting ${type} connector ${connectorName}...`);
if (type === 'squadlayerpool') {
return server.squadLayers[connectorConfig.type](connectorConfig.filter, connectorConfig.activeLayerFilter);
return server.squadLayers[connectorConfig.type](
connectorConfig.filter,
connectorConfig.activeLayerFilter
);
}
if (type === 'discord') {

View File

@ -52,7 +52,11 @@ export default class SquadServer extends EventEmitter {
}
async watch() {
Logger.verbose('SquadServer', 1, `Beginning to watch ${this.options.host}:${this.options.queryPort}...`);
Logger.verbose(
'SquadServer',
1,
`Beginning to watch ${this.options.host}:${this.options.queryPort}...`
);
await this.squadLayers.pull();
await this.rcon.connect();

View File

@ -11,8 +11,12 @@ export default class BasePlugin {
this.options[optionName] = connectors[this.rawOptions[optionName]];
} else {
if (option.required) {
if (!(optionName in this.rawOptions)) throw new Error(`${this.constructor.name}: ${optionName} is required but missing.`);
if (option.default === this.rawOptions[optionName]) throw new Error(`${this.constructor.name}: ${optionName} is required but is the default value.`);
if (!(optionName in this.rawOptions))
throw new Error(`${this.constructor.name}: ${optionName} is required but missing.`);
if (option.default === this.rawOptions[optionName])
throw new Error(
`${this.constructor.name}: ${optionName} is required but is the default value.`
);
}
this.options[optionName] = this.rawOptions[optionName] || option.default;

View File

@ -30,9 +30,7 @@ export default class DBLog extends BasePlugin {
}
async prepareToMount() {
this.createModel(
'Server',
{
this.createModel('Server', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
@ -41,12 +39,9 @@ export default class DBLog extends BasePlugin {
name: {
type: DataTypes.STRING
}
}
);
});
this.createModel(
'TickRate',
{
this.createModel('TickRate', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
@ -60,13 +55,12 @@ export default class DBLog extends BasePlugin {
type: DataTypes.FLOAT,
notNull: true
}
}
);
});
this.models.Server.hasMany(
this.models.TickRate,
{ foreignKey: { name: 'server', allowNull: false }, onDelete: 'CASCADE' }
);
this.models.Server.hasMany(this.models.TickRate, {
foreignKey: { name: 'server', allowNull: false },
onDelete: 'CASCADE'
});
await this.models.Server.sync();
await this.models.TickRate.sync();
@ -96,10 +90,14 @@ export default class DBLog extends BasePlugin {
}
unmount() {
this.server.removeEventListener('TICK_RATE', this.onTickRate)
this.server.removeEventListener('TICK_RATE', this.onTickRate);
}
async onTickRate(info) {
await this.models.TickRate.create({ server: this.server.id, time: info.time, tickRate: info.tickRate});
await this.models.TickRate.create({
server: this.server.id,
time: info.time,
tickRate: info.tickRate
});
}
}

View File

@ -72,7 +72,12 @@ export default class DiscordAdminCamLogs extends DiscordBasePlugin {
}
async onPlayerUnPossess(info) {
if (info.player === null || info.switchPossess === true || !(info.player.steamID in this.adminsInCam)) return;
if (
info.player === null ||
info.switchPossess === true ||
!(info.player.steamID in this.adminsInCam)
)
return;
await this.sendDiscordMessage({
embed: {

View File

@ -70,7 +70,7 @@ export default class DiscordAdminRequest extends DiscordBasePlugin {
}
unmount() {
this.server.removeEventListener(`CHAT_COMMAND:${this.options.command}`, this.onChatCommand)
this.server.removeEventListener(`CHAT_COMMAND:${this.options.command}`, this.onChatCommand);
}
async onChatCommand(info) {
@ -116,10 +116,7 @@ export default class DiscordAdminRequest extends DiscordBasePlugin {
}
};
if (
this.options.pingGroups.length > 0 &&
Date.now() - this.options.pingDelay > this.lastPing
) {
if (this.options.pingGroups.length > 0 && Date.now() - this.options.pingDelay > this.lastPing) {
message.content = this.options.pingGroups.map((groupID) => `<@&${groupID}>`).join(' ');
this.lastPing = Date.now();
}

View File

@ -19,7 +19,8 @@ export default class DiscordBasePlugin extends BasePlugin {
}
async sendDiscordMessage(message) {
if (typeof message === 'object' && 'embed' in message) message.embed.footer = { text: COPYRIGHT_MESSAGE };
if (typeof message === 'object' && 'embed' in message)
message.embed.footer = { text: COPYRIGHT_MESSAGE };
await this.channel.send(message);
}

View File

@ -83,8 +83,7 @@ export default class DiscordRcon extends BasePlugin {
if (!message.member._roles.includes(role)) continue;
for (const allowedCommand of allowedCommands)
if (commandPrefix[1].toLowerCase() === allowedCommand.toLowerCase())
hasPermission = true;
if (commandPrefix[1].toLowerCase() === allowedCommand.toLowerCase()) hasPermission = true;
}
if (!hasPermission) {

View File

@ -39,7 +39,7 @@ export default class DiscordSubsystemRestarter extends BasePlugin {
this.onMessage = this.onMessage.bind(this);
}
mount(){
mount() {
this.options.discordClient.on('message', this.onMessage);
}
@ -69,6 +69,4 @@ export default class DiscordSubsystemRestarter extends BasePlugin {
message.reply('restarted the SquadJS LogParser subsystem.');
}
}
}

View File

@ -63,10 +63,7 @@ export default class SeedingMode extends BasePlugin {
}
async broadcast() {
if (
this.server.a2sPlayerCount !== 0 &&
this.server.a2sPlayerCount < this.options.liveThreshold
)
if (this.server.a2sPlayerCount !== 0 && this.server.a2sPlayerCount < this.options.liveThreshold)
await this.server.rcon.broadcast(this.options.seedingMessage);
else if (
this.server.a2sPlayerCount !== 0 &&